Skip to content

Commit

Permalink
Allow Configurable Max Fee Per Gas in Tx Sending (#45)
Browse files Browse the repository at this point in the history
* max fee per gas config

* no deps clippy

* custom
  • Loading branch information
rauljordan authored Jul 2, 2024
1 parent 695f074 commit c199292
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ jobs:
- name: cargo clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
args: -- --no-deps
10 changes: 9 additions & 1 deletion check/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
}
}
let verbose = cfg.common_cfg.verbose;
let receipt = run_tx("cache", tx, None, &client, verbose).await?;
let receipt = run_tx(
"cache",
tx,
None,
cfg.common_cfg.max_fee_per_gas_gwei,
&client,
verbose,
)
.await?;

let address = cfg.program_address.debug_lavender();

Expand Down
20 changes: 17 additions & 3 deletions check/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl DeployConfig {
"deploy",
tx,
Some(gas),
self.check_config.common_cfg.max_fee_per_gas_gwei,
client,
self.check_config.common_cfg.verbose,
)
Expand Down Expand Up @@ -181,6 +182,7 @@ impl DeployConfig {
"activate",
tx,
Some(gas),
self.check_config.common_cfg.max_fee_per_gas_gwei,
client,
self.check_config.common_cfg.verbose,
)
Expand All @@ -202,14 +204,18 @@ pub async fn run_tx(
name: &str,
tx: Eip1559TransactionRequest,
gas: Option<U256>,
max_fee_per_gas_gwei: Option<U256>,
client: &SignerClient,
verbose: bool,
) -> Result<TransactionReceipt> {
let mut tx = TypedTransaction::Eip1559(tx);
let mut tx = tx;
if let Some(gas) = gas {
tx.set_gas(gas);
tx.gas = Some(gas);
}

if let Some(max_fee) = 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();
if verbose {
Expand Down Expand Up @@ -257,3 +263,11 @@ pub fn format_gas(gas: U256) -> String {
text.pink()
}
}

fn gwei_to_wei(gwei: U256) -> Result<U256> {
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"),
}
}
5 changes: 4 additions & 1 deletion check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +93,9 @@ struct CommonConfig {
/// in project's directory tree are included.
#[arg(long)]
source_files_for_project_hash: Vec<String>,
#[arg(long)]
/// Optional max fee per gas in gwei units.
max_fee_per_gas_gwei: Option<U256>,
}

#[derive(Args, Clone, Debug)]
Expand Down

0 comments on commit c199292

Please sign in to comment.