From 652f9d26de3230be24e221ef9a795290f4775208 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 13 Jun 2024 10:32:51 -0500 Subject: [PATCH] max fee per gas config --- check/src/deploy.rs | 16 +++++++++++++--- check/src/main.rs | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/check/src/deploy.rs b/check/src/deploy.rs index 7f2792d..8c9702b 100644 --- a/check/src/deploy.rs +++ b/check/src/deploy.rs @@ -197,10 +197,12 @@ impl DeployConfig { gas: Option, client: &SignerClient, ) -> Result { - let mut tx = TypedTransaction::Eip1559(tx); - if let Some(gas) = gas { - tx.set_gas(gas); + let mut tx = tx; + tx.gas = gas; + if let Some(max_fee) = self.max_fee_per_gas_gwei { + tx.max_fee_per_gas = Some(gwei_to_wei(max_fee)?); } + let tx = TypedTransaction::Eip1559(tx); let tx = client.send_transaction(tx, None).await?; let tx_hash = tx.tx_hash(); @@ -230,3 +232,11 @@ fn format_gas(gas: U256) -> String { text.pink() } } + +fn gwei_to_wei(gwei: U256) -> Result { + let wei_per_gwei: U256 = U256::from(10u64.pow(9)); + match gwei.checked_mul(wei_per_gwei) { + Some(wei) => Ok(wei), + None => bail!("overflow occurred while converting gwei to wei"), + } +} diff --git a/check/src/main.rs b/check/src/main.rs index 4de49b2..9bc67c7 100644 --- a/check/src/main.rs +++ b/check/src/main.rs @@ -2,7 +2,7 @@ // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md use clap::{ArgGroup, Args, Parser}; -use ethers::types::H160; +use ethers::types::{H160, U256}; use eyre::{eyre, Context, Result}; use std::path::PathBuf; use tokio::runtime::Builder; @@ -83,6 +83,9 @@ struct DeployConfig { /// Only perform gas estimation. #[arg(long)] estimate_gas: bool, + #[arg(long)] + /// Optional max fee per gas in gwei units. + max_fee_per_gas_gwei: Option, } #[derive(Clone, Debug, Args)]