diff --git a/contracts b/contracts index 9a72fc2de137..b077dd4e1c1c 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 9a72fc2de1377df53027d6ec61347a5ec5b04fef +Subproject commit b077dd4e1c1c5b761a51681837650b76583b70c6 diff --git a/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs b/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs index f4b206134d0d..462fd0fb5e11 100644 --- a/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs +++ b/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs @@ -3,14 +3,14 @@ use std::sync::Arc; use ethers::{ abi::Address, contract::abigen, - middleware::Middleware, prelude::{Http, Provider}, - types::{BlockNumber, H256, U64}, }; abigen!( ChainRegistar, r"[ + struct RegisteredChainConfig {address pendingChainAdmin;address chainAdmin;address diamondProxy;address l2BridgeAddress;} + function getRegisteredChainConfig(uint256 chainId) public view returns (RegisteredChainConfig memory) event NewChainDeployed(uint256 indexed chainId, address author, address diamondProxy, address chainAdmin) event NewChainRegistrationProposal(uint256 indexed chainId, address author, bytes32 key) event SharedBridgeRegistered(uint256 indexed chainId, address l2Address) @@ -18,43 +18,6 @@ abigen!( ); #[derive(Clone, Copy)] -struct ChainRegistrationResultBuilder { - pub diamond_proxy: Option
, - pub chain_admin: Option
, - pub l2_shared_bridge: Option
, -} - -impl ChainRegistrationResultBuilder { - fn new() -> Self { - Self { - diamond_proxy: None, - chain_admin: None, - l2_shared_bridge: None, - } - } - fn with_diamond_proxy(mut self, address: Address) -> Self { - self.diamond_proxy = Some(address); - self - } - fn with_chain_admin(mut self, address: Address) -> Self { - self.chain_admin = Some(address); - self - } - - fn with_l2_shared_bridge(mut self, address: Address) -> Self { - self.l2_shared_bridge = Some(address); - self - } - - fn build(self) -> ChainRegistrationResult { - ChainRegistrationResult { - diamond_proxy: self.diamond_proxy.unwrap(), - chain_admin: self.chain_admin.unwrap(), - l2_shared_bridge: self.l2_shared_bridge.unwrap(), - } - } -} - pub struct ChainRegistrationResult { pub diamond_proxy: Address, pub chain_admin: Address, @@ -67,27 +30,14 @@ pub async fn load_contracts_for_chain( l2_chain_id: u64, ) -> anyhow::Result { let client = Arc::new(Provider::::try_from(l1_rpc)?); - let block = client.get_block_number().await?; let contract = ChainRegistar::new(chain_registrar, client); - let events = contract - .events() - .from_block(block.saturating_sub(U64::from(100000))) - .to_block(BlockNumber::Latest) - .topic1(H256::from_low_u64_be(l2_chain_id)); - let result = events.query().await?; - let mut builder = ChainRegistrationResultBuilder::new(); - for event in &result { - match event { - ChainRegistarEvents::NewChainDeployedFilter(event) => { - builder = builder - .with_diamond_proxy(event.diamond_proxy) - .with_chain_admin(event.chain_admin); - } - ChainRegistarEvents::SharedBridgeRegisteredFilter(event) => { - builder = builder.with_l2_shared_bridge(event.l_2_address); - } - _ => {} - } - } - Ok(builder.build()) + let (pending_chain_admin, _chain_admin, diamond_proxy, l2_bridge_address) = contract + .get_registered_chain_config(l2_chain_id.into()) + .await?; + + Ok(ChainRegistrationResult { + diamond_proxy, + chain_admin: pending_chain_admin, + l2_shared_bridge: l2_bridge_address, + }) }