Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Jun 5, 2023
1 parent df3c562 commit b1e926b
Show file tree
Hide file tree
Showing 73 changed files with 2,986 additions and 3,385 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
toolchain: stable
components: rustfmt, clippy

- name: Install cargo-sort
- name: Install cargo tools
run: |
cargo install cargo-sort
cargo install cargo-sort cargo-udeps
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
Expand Down
22 changes: 14 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/primitives",
"crates/rpc",
"crates/uopool",
"examples",
"tests",
]
default-members = ["bin/bundler"]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ lint:
cargo fmt --all -- --check
cargo clippy --all -- -D warnings -A clippy::derive_partial_eq_without_eq -D clippy::unwrap_used -D clippy::uninlined_format_args
cargo sort --check
cargo udeps --workspace

clean:
cd thirdparty/account-abstraction && yarn clean && cd ../..
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Bundler was tested on the following networks:
| :--------: | :-------: | :-------: |
| Ethereum | :soon: | :soon: (Goerli), :heavy_check_mark: (Sepolia) |

## Examples

To get started, check the examples [here](./examples/). More examples will be added in the future.

## Contributing

Thank you for showing interest in contributing to the project!
Expand Down
4 changes: 4 additions & 0 deletions bin/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ ethers = { workspace = true }
expanded-pathbuf = "0.1"
jsonrpsee = { version = "0.16", features = ["server", "macros"] }
tokio = { version = "1.18", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"

[lib]
path = "src/lib.rs"

[[bin]]
path = "src/bundler.rs"
name = "bundler"
Expand Down
12 changes: 9 additions & 3 deletions bin/bundler/src/bundler-rpc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use aa_bundler_grpc::{bundler_client::BundlerClient, uo_pool_client::UoPoolClient};
use aa_bundler_rpc::{DebugApiServer, DebugApiServerImpl, EthApiServer, EthApiServerImpl};
use aa_bundler_rpc::{
debug_api::{DebugApiServer, DebugApiServerImpl},
eth_api::{EthApiServer, EthApiServerImpl},
web3_api::{Web3ApiServer, Web3ApiServerImpl},
};
use anyhow::Result;
use clap::Parser;
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info};
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder};
use std::{collections::HashSet, future::pending};
use tracing::info;

#[derive(Parser)]
#[clap(
Expand Down Expand Up @@ -42,10 +47,11 @@ async fn main() -> Result<()> {

let rpc_api: HashSet<String> = HashSet::from_iter(opt.rpc_api.iter().cloned());

api.merge(Web3ApiServerImpl {}.into_rpc())?;

if rpc_api.contains("eth") {
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
Expand Down
14 changes: 11 additions & 3 deletions bin/bundler/src/bundler-uopool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use aa_bundler_grpc::{uopool_service_run, UoPoolServiceOpts};
use aa_bundler_primitives::{parse_address, parse_u256, Chain, SUPPORTED_CHAINS};
use aa_bundler::{
cli::UoPoolServiceOpts,
utils::{parse_address, parse_u256},
};
use aa_bundler_grpc::uopool_service_run;
use aa_bundler_primitives::{chain::SUPPORTED_CHAINS, Chain};
use anyhow::{format_err, Result};
use clap::Parser;
use ethers::{
Expand Down Expand Up @@ -61,11 +65,15 @@ async fn main() -> Result<()> {
info!("Starting uopool gRPC service...");

uopool_service_run(
opt.uopool_opts,
opt.uopool_opts.uopool_grpc_listen_address,
opt.entry_points,
eth_provider,
chain,
opt.max_verification_gas,
opt.uopool_opts.min_stake,
opt.uopool_opts.min_unstake_delay,
opt.uopool_opts.min_priority_fee_per_gas,
opt.uopool_opts.uo_pool_mode,
)
.await?;

Expand Down
33 changes: 23 additions & 10 deletions bin/bundler/src/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use aa_bundler::{
cli::{BundlerServiceOpts, UoPoolServiceOpts},
utils::{parse_address, parse_u256},
};
use aa_bundler_grpc::{
bundler_client::BundlerClient, bundler_service_run, uo_pool_client::UoPoolClient,
uopool_service_run, BundlerServiceOpts, UoPoolServiceOpts,
uopool_service_run,
};
use aa_bundler_primitives::{parse_address, parse_u256, Chain, Wallet, SUPPORTED_CHAINS};
use aa_bundler_primitives::{chain::SUPPORTED_CHAINS, Chain, Wallet};
use aa_bundler_rpc::{
DebugApiServer, DebugApiServerImpl, EthApiServer, EthApiServerImpl, Web3ApiServer,
Web3ApiServerImpl,
debug_api::{DebugApiServer, DebugApiServerImpl},
eth_api::{EthApiServer, EthApiServerImpl},
web3_api::{Web3ApiServer, Web3ApiServerImpl},
};
use anyhow::{format_err, Result};
use clap::Parser;
Expand All @@ -14,8 +19,9 @@ use ethers::{
types::{Address, U256},
};
use expanded_pathbuf::ExpandedPathBuf;
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info};
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder};
use std::{collections::HashSet, future::pending, panic, sync::Arc};
use tracing::info;

#[derive(Parser)]
#[clap(
Expand Down Expand Up @@ -95,7 +101,7 @@ fn main() -> Result<()> {
}
}

let wallet = Wallet::from_file(opt.mnemonic_file.clone(), chain_id)
let wallet = Wallet::from_file(opt.mnemonic_file.clone(), &chain_id)
.map_err(|error| format_err!("Could not load mnemonic file: {}", error))?;
info!("{:?}", wallet.signer);

Expand All @@ -105,11 +111,15 @@ fn main() -> Result<()> {
if !opt.no_uopool {
info!("Starting uopool gRPC service...");
uopool_service_run(
opt.uopool_opts,
opt.uopool_opts.uopool_grpc_listen_address,
opt.entry_points.clone(),
eth_provider,
chain,
opt.max_verification_gas,
opt.uopool_opts.min_stake,
opt.uopool_opts.min_unstake_delay,
opt.uopool_opts.min_priority_fee_per_gas,
opt.uopool_opts.uo_pool_mode,
)
.await?;
info!(
Expand All @@ -128,11 +138,15 @@ fn main() -> Result<()> {

info!("Starting bundler gRPC service...");
bundler_service_run(
opt.bundler_opts,
opt.bundler_opts.bundler_grpc_listen_address,
wallet,
opt.entry_points,
chain,
opt.eth_client_address,
chain,
opt.bundler_opts.beneficiary,
opt.bundler_opts.gas_factor,
opt.bundler_opts.min_balance,
opt.bundler_opts.bundle_interval,
uopool_grpc_client.clone(),
);
info!(
Expand All @@ -158,7 +172,6 @@ fn main() -> Result<()> {
if rpc_api.contains("eth") {
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
Expand Down
81 changes: 81 additions & 0 deletions bin/bundler/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::utils::{parse_address, parse_u256, parse_uopool_mode};
use aa_bundler_primitives::UoPoolMode;
use clap::Parser;
use ethers::types::{Address, U256};
use std::net::SocketAddr;

#[derive(Clone, Copy, Debug, Parser, PartialEq)]
pub struct UoPoolServiceOpts {
#[clap(long, default_value = "127.0.0.1:3001")]
pub uopool_grpc_listen_address: SocketAddr,

#[clap(long, value_parser=parse_u256, default_value = "1")]
pub min_stake: U256,

#[clap(long, value_parser=parse_u256, default_value = "0")]
pub min_unstake_delay: U256,

#[clap(long, value_parser=parse_u256, default_value = "0")]
pub min_priority_fee_per_gas: U256,

#[clap(long, default_value = "standard", value_parser=parse_uopool_mode)]
pub uo_pool_mode: UoPoolMode,
}

#[derive(Clone, Copy, Debug, Parser, PartialEq)]
pub struct BundlerServiceOpts {
#[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, default_value = "127.0.0.1:3002")]
pub bundler_grpc_listen_address: SocketAddr,

#[clap(long, default_value = "10")]
pub bundle_interval: u64,
}

#[cfg(test)]
mod tests {
use super::*;
use std::{
net::{IpAddr, Ipv4Addr},
str::FromStr,
};

#[test]
fn bundler_opts() {
let args = vec![
"bundleropts",
"--beneficiary",
"0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990",
"--gas-factor",
"600",
"--min-balance",
"1",
"--bundler-grpc-listen-address",
"127.0.0.1:3002",
"--bundle-interval",
"10",
];
assert_eq!(
BundlerServiceOpts {
beneficiary: Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990")
.unwrap(),
gas_factor: U256::from(600),
min_balance: U256::from(1),
bundler_grpc_listen_address: SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
3002
),
bundle_interval: 10,
},
BundlerServiceOpts::try_parse_from(args).unwrap()
);
}
}
7 changes: 4 additions & 3 deletions bin/bundler/src/create-wallet.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use aa_bundler_primitives::{parse_u256, Wallet};
use aa_bundler::utils::parse_u256;
use aa_bundler_primitives::Wallet;
use anyhow::Result;
use clap::Parser;
use dirs::home_dir;
use ethers::types::U256;
use expanded_pathbuf::ExpandedPathBuf;
use jsonrpsee::tracing::info;
use tracing::info;

#[derive(Parser)]
#[clap(
Expand Down Expand Up @@ -33,7 +34,7 @@ fn main() -> Result<()> {
.map(ExpandedPathBuf)?
};

let wallet = Wallet::new(path, opt.chain_id)?;
let wallet = Wallet::build_random(path, &opt.chain_id)?;
info!("{:?}", wallet.signer);

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions bin/bundler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod cli;
pub mod utils;
18 changes: 18 additions & 0 deletions bin/bundler/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use aa_bundler_primitives::UoPoolMode;
use ethers::types::{Address, U256};
use std::str::FromStr;

/// Parses address from string
pub fn parse_address(s: &str) -> Result<Address, String> {
Address::from_str(s).map_err(|_| format!("String {s} is not a valid address"))
}

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

/// Parses UoPoolMode from string
pub fn parse_uopool_mode(s: &str) -> Result<UoPoolMode, String> {
UoPoolMode::from_str(s).map_err(|_| format!("String {s} is not a valid UoPoolMode"))
}
Loading

0 comments on commit b1e926b

Please sign in to comment.