diff --git a/config.stage.toml b/config.stage.toml new file mode 100644 index 0000000..f7d5807 --- /dev/null +++ b/config.stage.toml @@ -0,0 +1,33 @@ +[canonical_network] +type = "evm" +name = "Sepolia Mainnet" +address = "0xb2ead588f14e69266d1b87936b75325181377076" +provider = { rpc_endpoint = "https://eth.llamarpc.com" } +wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } + +[[bridged_networks]] +type = "evm" +name = "World Chain Sepolia" +address = "0xb2ead588f14e69266d1b87936b75325181377076" +state_bridge_address = "0x2F418Aa7D500B525EE8B80BB5F643A877ef82e09" +world_id_address = "0xE177F37AF0A862A02edFEa4F59C02668E9d0aAA4" +provider = { rpc_endpoint = "https://eth.llamarpc.com" } +wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } + +[[bridged_networks]] +type = "evm" +name = "Optimism Sepolia" +address = "0xb2ead588f14e69266d1b87936b75325181377076" +state_bridge_address = "0x158379286D7083dDA05930CD3C6374954Fb511aA" +world_id_address = "0xf07d3efadD82A1F0b4C5Cc3476806d9a170147Ba" +provider = { rpc_endpoint = "https://eth.llamarpc.com" } +wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } + +[[bridged_networks]] +type = "evm" +name = "Base Sepolia" +address = "0xb2ead588f14e69266d1b87936b75325181377076" +state_bridge_address = "0x5fFe37995158528d97A819bA390C1F81d74eB2b9" +world_id_address = "0x163b09b4fE21177c455D850BD815B6D583732432" +provider = { rpc_endpoint = "https://eth.llamarpc.com" } +wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } \ No newline at end of file diff --git a/config.toml b/config.toml index 90c5b0d..a3230e9 100644 --- a/config.toml +++ b/config.toml @@ -7,18 +7,27 @@ wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" -name = "Ethereum Mainnet" +name = "World Chain Mainnet" +address = "0xf7134CE138832c146F2a91D64621eE90c2bddEa" +state_bridge_address = "0x4c175eE61C3c1da847E339e1158D61BBd2537046" +world_id_address = "0x047eE5313F98E26Cc8177fA38877cB36292D2364" +provider = { rpc_endpoint = "https://eth.llamarpc.com" } +wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } + +[[bridged_networks]] +type = "evm" +name = "Optimism Mainnet" address = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa" -state_bridge_address = "0x87584289Fac5116180938bB0921caC1848A3d6fE" -world_id_address = "0x87584289Fac5116180938bB0921caC1848A3d6fE" +state_bridge_address = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F" +world_id_address = "0xB3E7771a6e2d7DD8C0666042B7a07C39b938eb7d" provider = { rpc_endpoint = "https://eth.llamarpc.com" } wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" -name = "Ethereum Mainnet" +name = "Polygon Mainnet" address = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa" -state_bridge_address = "0x87584289Fac5116180938bB0921caC1848A3d6fE" -world_id_address = "0x87584289Fac5116180938bB0921caC1848A3d6fE" +state_bridge_address = "0x76Db75dc752305E2deBd44c479680352F3Bb766f" +world_id_address = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F" provider = { rpc_endpoint = "https://eth.llamarpc.com" } wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } diff --git a/src/main.rs b/src/main.rs index 8ad3ff2..5b1c9a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,7 +186,7 @@ fn init_relays(cfg: Config) -> Result> { let signer = AlloySigner::new(state_bridge); relayers.push(Relayer::Evm(EVMRelay::new( - Signer::Alloy(signer), + Signer::AlloySigner(signer), n.world_id_address, n.provider.rpc_endpoint.clone(), ))); @@ -203,7 +203,7 @@ fn init_relays(cfg: Config) -> Result> { ); relayers.push(Relayer::Evm(EVMRelay::new( - Signer::TxSitter(signer), + Signer::TxSitterSigner(signer), n.world_id_address, n.provider.rpc_endpoint.clone(), ))); diff --git a/src/relay/signer.rs b/src/relay/signer.rs index d6078d6..5cc3af8 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -22,16 +22,17 @@ pub(crate) trait RelaySigner { async fn propagate_root(&self) -> Result<()>; } -pub enum Signer { - Alloy(AlloySigner), - TxSitter(TxSitterSigner), -} - -impl RelaySigner for Signer { - async fn propagate_root(&self) -> Result<()> { - match self { - Signer::Alloy(signer) => signer.propagate_root().await, - Signer::TxSitter(signer) => signer.propagate_root().await, +macro_rules! signer { + ($($signer_type:ident),+ $(,)?) => { + pub enum Signer { + $($signer_type($signer_type),)+ + } + impl RelaySigner for Signer { + async fn propagate_root(&self) -> Result<()> { + match self { + $(Signer::$signer_type(signer) => signer.propagate_root().await,)+ + } + } } } } @@ -172,3 +173,5 @@ impl RelaySigner for TxSitterSigner { Ok(()) } } + +signer!(AlloySigner, TxSitterSigner); diff --git a/src/transaction.rs b/src/transaction.rs deleted file mode 100644 index 5dda143..0000000 --- a/src/transaction.rs +++ /dev/null @@ -1,72 +0,0 @@ -use std::sync::Arc; - -use ethers::providers::Middleware; -use ethers::types::transaction::eip2718::TypedTransaction; -use ethers::types::{Bytes, TransactionRequest, H160, H256, U256}; -use eyre::{self}; -use tokio::time::Duration; - -use crate::abi::IStateBridge; - -pub const FIVE_SECONDS: Duration = Duration::from_secs(5); - -pub async fn construct_state_bridge_tx( - to: H160, - middleware: Arc, -) -> eyre::Result { - let calldata = IStateBridge::new(H160::zero(), middleware.clone()) - .propagate_root() - .calldata() - .expect("Could not get calldata for propagateRoot()"); - - let tx = - fill_and_simulate_legacy_transaction(calldata, to, middleware).await?; - - Ok(tx) -} - -async fn fill_and_simulate_legacy_transaction( - calldata: Bytes, - to: H160, - middleware: Arc, -) -> eyre::Result { - let gas_price = middleware.get_gas_price().await?; - let tx = TransactionRequest::new() - .to(to) - .data(calldata) - .gas_price(gas_price); - let mut tx: TypedTransaction = tx.into(); - let gas_limit = middleware.estimate_gas(&tx, None).await?; - - tx.set_gas(gas_limit * U256::from(120) / U256::from(100)); // 20% buffer - - //match fill transaction, it will fail if the calldata fails - middleware.fill_transaction(&mut tx, None).await?; - middleware.call(&tx, None).await?; - - Ok(tx) -} - -pub async fn wait_for_tx_receipt( - pending_tx: H256, - mut timeout: Duration, - middleware: Arc, -) -> eyre::Result<()> { - while middleware - .get_transaction_receipt(pending_tx) - .await? - .is_none() - { - tokio::time::sleep(FIVE_SECONDS).await; - timeout -= FIVE_SECONDS; - - if timeout.is_zero() { - tracing::error!("Tx timed out: {pending_tx}"); - return Err(eyre::eyre!("Pending tx timed out: {pending_tx}")); - } - } - - tracing::info!("Tx confirmed: {pending_tx:?}"); - - Ok(()) -}