Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bundler config #21

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -31,6 +31,13 @@ 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,
zsluedem marked this conversation as resolved.
Show resolved Hide resolved

#[clap(flatten)]
pub bundler_opts: aa_bundler::bundler::bundler::BundlerOpts,
}

fn main() -> Result<()> {
Expand Down
68 changes: 68 additions & 0 deletions src/bundler/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
use std::str::FromStr;

use clap::Parser;
use ethereum_types::U256;
zsluedem marked this conversation as resolved.
Show resolved Hide resolved
use ethers::types::Address;

use crate::models::wallet::Wallet;

#[derive(Debug, Parser, PartialEq)]
pub struct BundlerOpts {
zsluedem marked this conversation as resolved.
Show resolved Hide resolved
#[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, String> {
Address::from_str(s).map_err(|_| format!("Adress {} is not a valid address", s))
}

fn parse_u256(s: &str) -> Result<U256, String> {
U256::from_str_radix(s, 10).map_err(|_| format!("{} is not a valid U256", s))
}

pub struct Bundler {
pub wallet: Wallet,
}
Expand All @@ -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() {
zsluedem marked this conversation as resolved.
Show resolved Hide resolved
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()
);
}
}