Skip to content

Commit

Permalink
feat: support all available chains
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Dec 26, 2023
1 parent 102e8d8 commit 9962fe1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
15 changes: 9 additions & 6 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
},
utils::unwrap_path_or_home,
};
use alloy_chains::Chain;
use alloy_chains::{Chain, NamedChain};
use ethers::{providers::Middleware, types::Address};
use parking_lot::RwLock;
use silius_contracts::EntryPoint;
Expand Down Expand Up @@ -63,7 +63,7 @@ where
uopool_args.clone(),
eth_client.clone(),
block_streams,
common_args.chain.clone(),
common_args.chain,
common_args.entry_points.clone(),
)
.await?;
Expand All @@ -90,7 +90,7 @@ where
pub async fn launch_bundling<M>(
args: BundlerArgs,
eth_client: Arc<M>,
chain: Option<String>,
chain: Option<NamedChain>,
entry_points: Vec<Address>,
uopool_grpc_listen_address: String,
) -> eyre::Result<()>
Expand Down Expand Up @@ -149,7 +149,7 @@ pub async fn launch_uopool<M>(
args: UoPoolArgs,
eth_client: Arc<M>,
block_streams: Vec<BlockStream>,
chain: Option<String>,
chain: Option<NamedChain>,
entry_points: Vec<Address>,
) -> eyre::Result<()>
where
Expand Down Expand Up @@ -483,12 +483,15 @@ pub fn create_wallet(args: CreateWalletArgs) -> eyre::Result<()> {
Ok(())
}

async fn check_connected_chain<M>(eth_client: Arc<M>, chain: Option<String>) -> eyre::Result<String>
async fn check_connected_chain<M>(
eth_client: Arc<M>,
chain: Option<NamedChain>,
) -> eyre::Result<String>
where
M: Middleware + Clone + 'static,
{
if let Some(chain) = chain {
let chain = Chain::from_str(chain.as_str())?;
let chain: Chain = chain.into();

let chain_id = eth_client.get_chainid().await?.as_u64();
if chain.id() != chain_id {
Expand Down
31 changes: 27 additions & 4 deletions bin/silius/src/cli/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::{
parse_address, parse_enr, parse_send_bundle_mode, parse_u256, parse_uopool_mode,
};
use alloy_chains::NamedChain;
use clap::{Parser, ValueEnum};
use discv5::Enr;
use ethers::types::{Address, U256};
Expand All @@ -12,7 +13,6 @@ use silius_primitives::{
bundler::BUNDLE_INTERVAL,
grpc::{BUNDLER_PORT, MEMPOOL_PORT},
rpc::{HTTP_PORT, WS_PORT},
supported_chains::SUPPORTED_NAMED_CHAINS,
},
UoPoolMode,
};
Expand Down Expand Up @@ -111,15 +111,15 @@ pub struct UoPoolArgs {
}

/// Common CLI args for bundler and uopool
#[derive(Debug, Clone, Parser)]
#[derive(Debug, Clone, Parser, PartialEq)]
pub struct BundlerAndUoPoolArgs {
/// Ethereum execution client RPC endpoint.
#[clap(long, default_value = "http://127.0.0.1:8545")]
pub eth_client_address: String,

/// Chain information.
#[clap(long, value_parser = SUPPORTED_NAMED_CHAINS)]
pub chain: Option<String>,
#[clap(long)]
pub chain: Option<NamedChain>,

/// Entry point addresses.
#[clap(long, value_delimiter=',', value_parser=parse_address)]
Expand Down Expand Up @@ -328,6 +328,29 @@ mod tests {
);
}

#[test]
fn bundler_and_uopool_args() {
let args = vec![
"bundleranduopoolargs",
"--eth-client-address",
"http://127.0.0.1:8545",
"--chain",
"holesky",
"--entry-points",
"0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990",
];
assert_eq!(
BundlerAndUoPoolArgs {
eth_client_address: String::from("http://127.0.0.1:8545"),
chain: Some(NamedChain::Holesky),
entry_points: vec![
Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990").unwrap()
],
},
BundlerAndUoPoolArgs::try_parse_from(args).unwrap()
);
}

#[test]
fn rpc_args_when_http_and_ws_flag() {
let args = vec![
Expand Down
1 change: 0 additions & 1 deletion crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub mod flashbots_relay_endpoints {
/// Supported chains
pub mod supported_chains {
pub const SUPPORTED_CHAINS: [u64; 5] = [MAINNET, GOERLI, SEPOLIA, DEV, MUMBAI];
pub const SUPPORTED_NAMED_CHAINS: [&str; 5] = ["mainnet", "goerli", "sepolia", "dev", "mumbai"];

// dev
pub const DEV: u64 = 1337;
Expand Down

0 comments on commit 9962fe1

Please sign in to comment.