Skip to content

Commit

Permalink
feat(cli): basefee + priority fee flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Bostoen committed Oct 31, 2024
1 parent 225f4d4 commit 00cc3fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ pub struct SendCommand {
#[clap(long, env = "BLOB", default_value = "false")]
pub blob: bool,

/// The max fee per gas in gwei.
#[clap(long, env = "MAX_FEE")]
pub max_fee: Option<String>,

/// The max priority fee per gas in gwei.
#[clap(long, env = "PRIORITY_FEE", default_value = "2")]
pub priority_fee: String,

/// If set, the transaction will target the devnet environment.
/// This is only used in Kurtosis for internal testing purposes
#[clap(long, hide = true, env = "DEVNET", default_value = "false")]
Expand Down
25 changes: 22 additions & 3 deletions bolt-cli/src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::{
consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction},
eips::eip2718::Encodable2718,
network::{EthereumWallet, TransactionBuilder, TransactionBuilder4844},
primitives::{keccak256, Address, B256, U256},
primitives::{keccak256, utils::parse_units, Address, B256, U256},
providers::{ProviderBuilder, SendableTx},
rpc::types::TransactionRequest,
signers::{local::PrivateKeySigner, Signer},
Expand All @@ -25,16 +25,29 @@ 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).await
self.send_transaction(&wallet, max_fee, priority_fee).await
}
}

/// Send a transaction.
async fn send_transaction(self, wallet: &PrivateKeySigner) -> Result<()> {
async fn send_transaction(
self,
wallet: &PrivateKeySigner,
max_fee: Option<u128>,
priority_fee: u128,
) -> Result<()> {
let transaction_signer = EthereumWallet::from(wallet.clone());
let provider = ProviderBuilder::new()
.with_recommended_fillers()
Expand Down Expand Up @@ -73,6 +86,12 @@ 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);
}

req.set_max_priority_fee_per_gas(priority_fee);

if let Some(next_nonce) = next_nonce {
req.set_nonce(next_nonce);
}
Expand Down
2 changes: 1 addition & 1 deletion bolt-cli/src/common/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl KeystoreSecret {
/// Load the keystore passwords from a directory containing individual password files.
pub fn from_directory(root_dir: &str) -> Result<Self> {
let mut secrets = HashMap::new();
for entry in fs::read_dir(&root_dir)
for entry in fs::read_dir(root_dir)
.wrap_err(format!("failed to read secrets directory. path: {}", &root_dir))?
{
let entry = entry.wrap_err("Failed to read secrets directory entry")?;
Expand Down

0 comments on commit 00cc3fb

Please sign in to comment.