diff --git a/check/src/activate.rs b/check/src/activate.rs index c84f59f..12d266c 100644 --- a/check/src/activate.rs +++ b/check/src/activate.rs @@ -62,6 +62,22 @@ pub async fn activate_contract(cfg: &ActivateConfig) -> Result<()> { .value(data_fee) .data(data); let tx = TypedTransaction::Eip1559(tx); + if cfg.estimate_gas { + let gas = client.estimate_gas(&tx, None).await?; + let gas_price = client.get_gas_price().await?; + greyln!("estimates"); + greyln!("activation tx gas: {}", gas.debug_lavender()); + greyln!( + "gas price: {} gwei", + format_units(gas_price, "gwei")?.debug_lavender() + ); + let total_cost = gas_price.checked_mul(gas).unwrap_or_default(); + let eth_estimate = format_units(total_cost, "ether")?; + greyln!( + "activation tx total cost: {} ETH", + eth_estimate.debug_lavender() + ); + } let tx = client.send_transaction(tx, None).await?; match tx.await? { Some(receipt) => { diff --git a/check/src/check.rs b/check/src/check.rs index e315d03..0f9f165 100644 --- a/check/src/check.rs +++ b/check/src/check.rs @@ -89,7 +89,7 @@ pub async fn check(cfg: &CheckConfig) -> Result { let address = cfg.contract_address.unwrap_or(H160::random()); let fee = check_activate(code.clone().into(), address, &provider).await?; let visual_fee = format_data_fee(fee).unwrap_or("???".red()); - greyln!("wasm data fee: {visual_fee}"); + greyln!("wasm data fee: {visual_fee} ETH"); Ok(ContractCheck::Ready { code, fee }) } @@ -151,7 +151,7 @@ pub fn format_file_size(len: usize, mid: u64, max: u64) -> String { fn format_data_fee(fee: U256) -> Result { let fee: u64 = (fee / U256::from(1e9)).try_into()?; let fee: f64 = fee as f64 / 1e9; - let text = format!("Ξ{fee:.6}"); + let text = format!("{fee:.6}"); Ok(if fee <= 5e14 { text.mint() } else if fee <= 5e15 { diff --git a/check/src/deploy.rs b/check/src/deploy.rs index 9c5d79e..4dc424a 100644 --- a/check/src/deploy.rs +++ b/check/src/deploy.rs @@ -15,6 +15,7 @@ use cargo_stylus_util::{ color::{Color, DebugColor}, sys, }; +use ethers::core::utils::format_units; use ethers::{ core::k256::ecdsa::SigningKey, middleware::SignerMiddleware, @@ -86,6 +87,10 @@ pub async fn deploy(cfg: DeployConfig) -> Result<()> { .deploy_contract(contract.code(), sender, &client) .await?; + if cfg.estimate_gas { + return Ok(()); + } + match contract { ContractCheck::Ready { .. } => { cfg.activate(sender, contract_addr, data_fee, &client) @@ -115,7 +120,19 @@ impl DeployConfig { .await?; if self.check_config.common_cfg.verbose || self.estimate_gas { - greyln!("deploy gas estimate: {}", format_gas(gas)); + let gas_price = client.get_gas_price().await?; + greyln!("estimates"); + greyln!("deployment tx gas: {}", gas.debug_lavender()); + greyln!( + "gas price: {} gwei", + format_units(gas_price, "gwei")?.debug_lavender() + ); + let total_cost = gas_price.checked_mul(gas).unwrap_or_default(); + let eth_estimate = format_units(total_cost, "ether")?; + greyln!( + "deployment tx total cost: {} ETH", + eth_estimate.debug_lavender() + ); } if self.estimate_gas { let nonce = client.get_transaction_count(sender, None).await?; @@ -184,9 +201,6 @@ https://docs.arbitrum.io/stylus/concepts/stylus-cache-manager"#, if self.check_config.common_cfg.verbose || self.estimate_gas { greyln!("activation gas estimate: {}", format_gas(gas)); } - if self.estimate_gas { - return Ok(()); - } let receipt = run_tx( "activate", diff --git a/check/src/main.rs b/check/src/main.rs index 848bf93..239d6f4 100644 --- a/check/src/main.rs +++ b/check/src/main.rs @@ -121,6 +121,9 @@ pub struct ActivateConfig { /// Percent to bump the estimated activation data fee by. Default of 20% #[arg(long, default_value = "20")] data_fee_bump_percent: u64, + /// Whether or not to just estimate gas without sending a tx. + #[arg(long)] + estimate_gas: bool, } #[derive(Args, Clone, Debug)]