From 9307f14bc42ee2c06a11945a261ee06841335514 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:49:05 +0100 Subject: [PATCH] chore: update send command impl --- bolt-cli/src/cli.rs | 4 ++-- bolt-cli/src/commands/send.rs | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/bolt-cli/src/cli.rs b/bolt-cli/src/cli.rs index c0e708c18..57cd595e8 100644 --- a/bolt-cli/src/cli.rs +++ b/bolt-cli/src/cli.rs @@ -103,11 +103,11 @@ pub struct SendCommand { /// The max fee per gas in gwei. #[clap(long, env = "MAX_FEE")] - pub max_fee: Option, + pub max_fee: Option, /// The max priority fee per gas in gwei. #[clap(long, env = "PRIORITY_FEE", default_value = "2")] - pub priority_fee: String, + pub priority_fee: u128, /// If set, the transaction will target the devnet environment. /// This is only used in Kurtosis for internal testing purposes diff --git a/bolt-cli/src/commands/send.rs b/bolt-cli/src/commands/send.rs index 788894b70..fdbdb1bd6 100644 --- a/bolt-cli/src/commands/send.rs +++ b/bolt-cli/src/commands/send.rs @@ -1,10 +1,12 @@ use std::time::Duration; use alloy::{ - consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction}, + consensus::{ + constants::GWEI_TO_WEI, BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction, + }, eips::eip2718::Encodable2718, network::{EthereumWallet, TransactionBuilder, TransactionBuilder4844}, - primitives::{keccak256, utils::parse_units, Address, B256, U256}, + primitives::{keccak256, Address, B256, U256}, providers::{ProviderBuilder, SendableTx}, rpc::types::TransactionRequest, signers::{local::PrivateKeySigner, Signer}, @@ -25,29 +27,16 @@ impl SendCommand { /// Run the `send` command. pub async fn run(self) -> Result<()> { let wallet: PrivateKeySigner = self.private_key.parse().wrap_err("invalid private key")?; - let max_fee = self.max_fee.as_ref().map(|fee| { - parse_units(fee, "gwei").expect("Correct unit").try_into().expect("Correct unit") - }); - - let priority_fee = parse_units(&self.priority_fee, "gwei") - .expect("Correct unit") - .try_into() - .expect("Correct unit"); if self.devnet { self.send_devnet_transaction(&wallet).await } else { - self.send_transaction(&wallet, max_fee, priority_fee).await + self.send_transaction(&wallet).await } } /// Send a transaction. - async fn send_transaction( - self, - wallet: &PrivateKeySigner, - max_fee: Option, - priority_fee: u128, - ) -> Result<()> { + async fn send_transaction(self, wallet: &PrivateKeySigner) -> Result<()> { let transaction_signer = EthereumWallet::from(wallet.clone()); let provider = ProviderBuilder::new() .with_recommended_fillers() @@ -86,11 +75,11 @@ impl SendCommand { for _ in 0..self.count { // generate a simple self-transfer of ETH let mut req = create_tx_request(wallet.address(), self.blob); - if let Some(max_fee) = max_fee { - req.set_max_fee_per_gas(max_fee); + if let Some(max_fee) = self.max_fee { + req.set_max_fee_per_gas(max_fee * GWEI_TO_WEI as u128); } - req.set_max_priority_fee_per_gas(priority_fee); + req.set_max_priority_fee_per_gas(self.priority_fee * GWEI_TO_WEI as u128); if let Some(next_nonce) = next_nonce { req.set_nonce(next_nonce);