From b0fad5016b05f32ef5a741cccd6c8bb2291ca859 Mon Sep 17 00:00:00 2001 From: Will Qiu Date: Wed, 30 Nov 2022 10:31:44 +0800 Subject: [PATCH 1/3] add bundler config --- bin/bundler.rs | 3 ++ src/bundler/bundler.rs | 68 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/bin/bundler.rs b/bin/bundler.rs index 4c3664b5..8f5b7edc 100644 --- a/bin/bundler.rs +++ b/bin/bundler.rs @@ -31,6 +31,9 @@ pub struct Opt { #[clap(long, default_value = "127.0.0.1:4337")] pub rpc_listen_address: String, + + #[clap(flatten)] + pub bundler_opts: aa_bundler::bundler::bundler::BundlerOpts, } fn main() -> Result<()> { diff --git a/src/bundler/bundler.rs b/src/bundler/bundler.rs index b1e967a3..7c0647ab 100644 --- a/src/bundler/bundler.rs +++ b/src/bundler/bundler.rs @@ -1,5 +1,37 @@ +use std::str::FromStr; + +use clap::Parser; +use ethereum_types::U256; +use ethers::types::Address; + use crate::models::wallet::Wallet; +#[derive(Debug, Parser, PartialEq)] +pub struct BundlerOpts { + #[clap(long, value_parser=parse_address)] + pub beneficiary: Address, + + #[clap(long, default_value = "1", value_parser=parse_u256)] + pub gas_factor: U256, + + #[clap(long, value_parser=parse_u256)] + pub min_balance: U256, + + #[clap(long, value_parser=parse_address)] + pub entry_point: Address, + + #[clap(long, value_parser=parse_address)] + pub helper: Address, +} + +fn parse_address(s: &str) -> Result { + Address::from_str(s).map_err(|_| format!("Adress {} is not a valid address", s)) +} + +fn parse_u256(s: &str) -> Result { + U256::from_str_radix(s, 10).map_err(|_| format!("{} is not a valid U256", s)) +} + pub struct Bundler { pub wallet: Wallet, } @@ -9,3 +41,39 @@ impl Bundler { Self { wallet } } } + +#[cfg(test)] +mod test { + use super::BundlerOpts; + use clap::Parser; + use ethereum_types::{Address, U256}; + use std::str::FromStr; + + #[test] + fn test_bundle_opt() { + let args = vec![ + "bundleropts", + "--beneficiary", + "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990", + "--gas-factor", + "600", + "--min-balance", + "1", + "--entry-point", + "0x0000000000000000000000000000000000000000", + "--helper", + "0x0000000000000000000000000000000000000000", + ]; + assert_eq!( + BundlerOpts { + beneficiary: Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990") + .unwrap(), + gas_factor: U256::from(600), + min_balance: U256::from(1), + entry_point: Address::from([0; 20]), + helper: Address::from([0; 20]) + }, + BundlerOpts::try_parse_from(args).unwrap() + ); + } +} From ed80b10ede1c22b9c84e3e694ddcdd21163b2c8a Mon Sep 17 00:00:00 2001 From: Will Qiu Date: Wed, 30 Nov 2022 14:43:52 +0800 Subject: [PATCH 2/3] add network --- bin/bundler.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/bundler.rs b/bin/bundler.rs index 8f5b7edc..2cf51204 100644 --- a/bin/bundler.rs +++ b/bin/bundler.rs @@ -7,7 +7,7 @@ use anyhow::Result; use clap::Parser; use expanded_pathbuf::ExpandedPathBuf; use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info}; -use std::{future::pending, panic}; +use std::{future::pending, net::SocketAddr, panic}; #[derive(Parser)] #[clap( @@ -32,6 +32,10 @@ pub struct Opt { #[clap(long, default_value = "127.0.0.1:4337")] pub rpc_listen_address: String, + // execution client rpc endpoint + #[clap(long)] + pub network: SocketAddr, + #[clap(flatten)] pub bundler_opts: aa_bundler::bundler::bundler::BundlerOpts, } From 3900b96c58e53c32c196e05c31747a8cd0e26128 Mon Sep 17 00:00:00 2001 From: Will Qiu Date: Thu, 1 Dec 2022 21:15:13 +0800 Subject: [PATCH 3/3] fixup review comments --- bin/bundler.rs | 4 +-- src/bundler/bundler.rs | 68 ------------------------------------------ src/bundler/mod.rs | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 70 deletions(-) diff --git a/bin/bundler.rs b/bin/bundler.rs index 2cf51204..e8d7db2d 100644 --- a/bin/bundler.rs +++ b/bin/bundler.rs @@ -34,10 +34,10 @@ pub struct Opt { // execution client rpc endpoint #[clap(long)] - pub network: SocketAddr, + pub eth_client_address: SocketAddr, #[clap(flatten)] - pub bundler_opts: aa_bundler::bundler::bundler::BundlerOpts, + pub bundler_opts: aa_bundler::bundler::Opts, } fn main() -> Result<()> { diff --git a/src/bundler/bundler.rs b/src/bundler/bundler.rs index 7c0647ab..b1e967a3 100644 --- a/src/bundler/bundler.rs +++ b/src/bundler/bundler.rs @@ -1,37 +1,5 @@ -use std::str::FromStr; - -use clap::Parser; -use ethereum_types::U256; -use ethers::types::Address; - use crate::models::wallet::Wallet; -#[derive(Debug, Parser, PartialEq)] -pub struct BundlerOpts { - #[clap(long, value_parser=parse_address)] - pub beneficiary: Address, - - #[clap(long, default_value = "1", value_parser=parse_u256)] - pub gas_factor: U256, - - #[clap(long, value_parser=parse_u256)] - pub min_balance: U256, - - #[clap(long, value_parser=parse_address)] - pub entry_point: Address, - - #[clap(long, value_parser=parse_address)] - pub helper: Address, -} - -fn parse_address(s: &str) -> Result { - Address::from_str(s).map_err(|_| format!("Adress {} is not a valid address", s)) -} - -fn parse_u256(s: &str) -> Result { - U256::from_str_radix(s, 10).map_err(|_| format!("{} is not a valid U256", s)) -} - pub struct Bundler { pub wallet: Wallet, } @@ -41,39 +9,3 @@ impl Bundler { Self { wallet } } } - -#[cfg(test)] -mod test { - use super::BundlerOpts; - use clap::Parser; - use ethereum_types::{Address, U256}; - use std::str::FromStr; - - #[test] - fn test_bundle_opt() { - let args = vec![ - "bundleropts", - "--beneficiary", - "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990", - "--gas-factor", - "600", - "--min-balance", - "1", - "--entry-point", - "0x0000000000000000000000000000000000000000", - "--helper", - "0x0000000000000000000000000000000000000000", - ]; - assert_eq!( - BundlerOpts { - beneficiary: Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990") - .unwrap(), - gas_factor: U256::from(600), - min_balance: U256::from(1), - entry_point: Address::from([0; 20]), - helper: Address::from([0; 20]) - }, - BundlerOpts::try_parse_from(args).unwrap() - ); - } -} diff --git a/src/bundler/mod.rs b/src/bundler/mod.rs index f6b97184..e1765e5f 100644 --- a/src/bundler/mod.rs +++ b/src/bundler/mod.rs @@ -1 +1,68 @@ pub mod bundler; + +use std::str::FromStr; + +use clap::Parser; +use ethers::types::{Address, U256}; + +#[derive(Debug, Parser, PartialEq)] +pub struct Opts { + #[clap(long, value_parser=parse_address)] + pub beneficiary: Address, + + #[clap(long, default_value = "1", value_parser=parse_u256)] + pub gas_factor: U256, + + #[clap(long, value_parser=parse_u256)] + pub min_balance: U256, + + #[clap(long, value_parser=parse_address)] + pub entry_point: Address, + + #[clap(long, value_parser=parse_address)] + pub helper: Address, +} + +fn parse_address(s: &str) -> Result { + Address::from_str(s).map_err(|_| format!("Adress {} is not a valid address", s)) +} + +fn parse_u256(s: &str) -> Result { + U256::from_str_radix(s, 10).map_err(|_| format!("{} is not a valid U256", s)) +} + +#[cfg(test)] +mod test { + use super::Opts; + use clap::Parser; + use ethereum_types::{Address, U256}; + use std::str::FromStr; + + #[test] + fn bundle_opt() { + let args = vec![ + "bundleropts", + "--beneficiary", + "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990", + "--gas-factor", + "600", + "--min-balance", + "1", + "--entry-point", + "0x0000000000000000000000000000000000000000", + "--helper", + "0x0000000000000000000000000000000000000000", + ]; + assert_eq!( + Opts { + beneficiary: Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990") + .unwrap(), + gas_factor: U256::from(600), + min_balance: U256::from(1), + entry_point: Address::from([0; 20]), + helper: Address::from([0; 20]) + }, + Opts::try_parse_from(args).unwrap() + ); + } +}