From 06f4def47a96ef4eaa21fefac1be0256a55cf8c7 Mon Sep 17 00:00:00 2001 From: Arun Jangra Date: Wed, 3 Jul 2024 18:50:53 +0530 Subject: [PATCH] refactoring and renaming --- .../src/clients/starkgate_manager.rs | 10 +++++----- .../src/clients/starkgate_registry.rs | 10 +++++----- .../src/clients/sovereign.rs | 10 +++++----- .../src/clients/validity.rs | 10 +++++----- .../src/clients/eth_bridge.rs | 10 +++++----- crates/l2/starknet-proxy-client/src/clients/mod.rs | 1 - .../starknet-proxy-client/src/clients/proxy_3_0_2.rs | 6 +++--- .../starknet-proxy-client/src/clients/proxy_5_0_0.rs | 6 +++--- crates/l2/starknet-proxy-client/src/deploy.rs | 4 ++-- crates/l2/starknet-proxy-client/src/interfaces/mod.rs | 1 + .../src/{clients => interfaces}/proxy.rs | 0 crates/l2/starknet-proxy-client/src/lib.rs | 1 + .../src/clients/token_bridge.rs | 10 +++++----- 13 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 crates/l2/starknet-proxy-client/src/interfaces/mod.rs rename crates/l2/starknet-proxy-client/src/{clients => interfaces}/proxy.rs (100%) diff --git a/crates/l2/starkgate-manager-client/src/clients/starkgate_manager.rs b/crates/l2/starkgate-manager-client/src/clients/starkgate_manager.rs index b58987e..0f78e43 100644 --- a/crates/l2/starkgate-manager-client/src/clients/starkgate_manager.rs +++ b/crates/l2/starkgate-manager-client/src/clients/starkgate_manager.rs @@ -4,11 +4,11 @@ use crate::interfaces::manager::StarkgateManager; use utils::{LocalWalletSignerMiddleware, StarknetContractClient}; use ethers::types::Address; -use starknet_proxy_client::clients::proxy_5_0_0::ProxySupportLatest; +use starknet_proxy_client::clients::proxy_5_0_0::ProxySupport5_0_0; pub struct StarkgateManagerContractClient { manager: StarkgateManager, - proxy_support: ProxySupportLatest, + proxy_support: ProxySupport5_0_0, manager_implementation: Address, } @@ -20,7 +20,7 @@ impl StarkgateManagerContractClient { ) -> Self { Self { manager: StarkgateManager::new(address, client.clone()), - proxy_support: ProxySupportLatest::new(address, client.clone()), + proxy_support: ProxySupport5_0_0::new(address, client.clone()), manager_implementation: implementation_address, } } @@ -32,8 +32,8 @@ impl AsRef> for StarkgateManagerCo } } -impl AsRef> for StarkgateManagerContractClient { - fn as_ref(&self) -> &ProxySupportLatest { +impl AsRef> for StarkgateManagerContractClient { + fn as_ref(&self) -> &ProxySupport5_0_0 { &self.proxy_support } } diff --git a/crates/l2/starkgate-registry-client/src/clients/starkgate_registry.rs b/crates/l2/starkgate-registry-client/src/clients/starkgate_registry.rs index f35ed53..604897d 100644 --- a/crates/l2/starkgate-registry-client/src/clients/starkgate_registry.rs +++ b/crates/l2/starkgate-registry-client/src/clients/starkgate_registry.rs @@ -4,11 +4,11 @@ use crate::interfaces::registry::StarkgateRegistry; use utils::{LocalWalletSignerMiddleware, StarknetContractClient}; use ethers::types::Address; -use starknet_proxy_client::clients::proxy_5_0_0::ProxySupportLatest; +use starknet_proxy_client::clients::proxy_5_0_0::ProxySupport5_0_0; pub struct StarkgateRegistryContractClient { registry: StarkgateRegistry, - proxy_support: ProxySupportLatest, + proxy_support: ProxySupport5_0_0, registry_implementation: Address, } @@ -20,7 +20,7 @@ impl StarkgateRegistryContractClient { ) -> Self { Self { registry: StarkgateRegistry::new(address, client.clone()), - proxy_support: ProxySupportLatest::new(address, client.clone()), + proxy_support: ProxySupport5_0_0::new(address, client.clone()), registry_implementation: implementation_address, } } @@ -31,8 +31,8 @@ impl AsRef> for StarkgateRegistry } } -impl AsRef> for StarkgateRegistryContractClient { - fn as_ref(&self) -> &ProxySupportLatest { +impl AsRef> for StarkgateRegistryContractClient { + fn as_ref(&self) -> &ProxySupport5_0_0 { &self.proxy_support } } diff --git a/crates/l2/starknet-core-contract-client/src/clients/sovereign.rs b/crates/l2/starknet-core-contract-client/src/clients/sovereign.rs index 66b4f56..a2c3b6c 100644 --- a/crates/l2/starknet-core-contract-client/src/clients/sovereign.rs +++ b/crates/l2/starknet-core-contract-client/src/clients/sovereign.rs @@ -4,7 +4,7 @@ use crate::interfaces::{ GovernedFinalizable, Operator, StarknetGovernance, StarknetMessaging, StarknetSovereignContract, }; use ethers::types::Address; -use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport; +use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport3_0_2; use utils::{LocalWalletSignerMiddleware, StarknetContractClient}; /// Client to interact with a Starknet core contract running in `Sovereign` mode @@ -12,7 +12,7 @@ pub struct StarknetSovereignContractClient { core_contract: StarknetSovereignContract, messaging: StarknetMessaging, operator: Operator, - proxy_support: ProxySupport, + proxy_support: ProxySupport3_0_2, governance: StarknetGovernance, governed_finalizable: GovernedFinalizable, core_contract_implementation: Address, @@ -28,7 +28,7 @@ impl StarknetSovereignContractClient { core_contract: StarknetSovereignContract::new(address, client.clone()), messaging: StarknetMessaging::new(address, client.clone()), operator: Operator::new(address, client.clone()), - proxy_support: ProxySupport::new(address, client.clone()), + proxy_support: ProxySupport3_0_2::new(address, client.clone()), governance: StarknetGovernance::new(address, client.clone()), governed_finalizable: GovernedFinalizable::new(address, client.clone()), core_contract_implementation: implementation_address, @@ -48,8 +48,8 @@ impl AsRef> for StarknetSovereign &self.messaging } } -impl AsRef> for StarknetSovereignContractClient { - fn as_ref(&self) -> &ProxySupport { +impl AsRef> for StarknetSovereignContractClient { + fn as_ref(&self) -> &ProxySupport3_0_2 { &self.proxy_support } } diff --git a/crates/l2/starknet-core-contract-client/src/clients/validity.rs b/crates/l2/starknet-core-contract-client/src/clients/validity.rs index 3b2b408..1520feb 100644 --- a/crates/l2/starknet-core-contract-client/src/clients/validity.rs +++ b/crates/l2/starknet-core-contract-client/src/clients/validity.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use ethers::abi::Address; -use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport; +use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport3_0_2; use crate::interfaces::{ GovernedFinalizable, Operator, StarknetGovernance, StarknetMessaging, StarknetValidityContract, @@ -13,7 +13,7 @@ pub struct StarknetValidityContractClient { core_contract: StarknetValidityContract, messaging: StarknetMessaging, operator: Operator, - proxy_support: ProxySupport, + proxy_support: ProxySupport3_0_2, governance: StarknetGovernance, governed_finalizable: GovernedFinalizable, core_contract_implementation: ethers::addressbook::Address, @@ -29,7 +29,7 @@ impl StarknetValidityContractClient { core_contract: StarknetValidityContract::new(address, client.clone()), messaging: StarknetMessaging::new(address, client.clone()), operator: Operator::new(address, client.clone()), - proxy_support: ProxySupport::new(address, client.clone()), + proxy_support: ProxySupport3_0_2::new(address, client.clone()), governance: StarknetGovernance::new(address, client.clone()), governed_finalizable: GovernedFinalizable::new(address, client.clone()), core_contract_implementation: implementation_address, @@ -49,8 +49,8 @@ impl AsRef> for StarknetValidityC &self.messaging } } -impl AsRef> for StarknetValidityContractClient { - fn as_ref(&self) -> &ProxySupport { +impl AsRef> for StarknetValidityContractClient { + fn as_ref(&self) -> &ProxySupport3_0_2 { &self.proxy_support } } diff --git a/crates/l2/starknet-eth-bridge-client/src/clients/eth_bridge.rs b/crates/l2/starknet-eth-bridge-client/src/clients/eth_bridge.rs index b141c7d..2fd66e3 100644 --- a/crates/l2/starknet-eth-bridge-client/src/clients/eth_bridge.rs +++ b/crates/l2/starknet-eth-bridge-client/src/clients/eth_bridge.rs @@ -4,12 +4,12 @@ use crate::interfaces::eth_bridge::StarknetEthBridge; use utils::{LocalWalletSignerMiddleware, StarknetContractClient}; use ethers::types::Address; -use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport; +use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport3_0_2; /// Client to interact with a Starknet Eth Bridge pub struct StarknetEthBridgeContractClient { eth_bridge: StarknetEthBridge, - proxy_support: ProxySupport, + proxy_support: ProxySupport3_0_2, eth_bridge_implementation: Address, } @@ -21,7 +21,7 @@ impl StarknetEthBridgeContractClient { ) -> Self { Self { eth_bridge: StarknetEthBridge::new(address, client.clone()), - proxy_support: ProxySupport::new(address, client.clone()), + proxy_support: ProxySupport3_0_2::new(address, client.clone()), eth_bridge_implementation: implementation_address, } } @@ -33,8 +33,8 @@ impl AsRef> for StarknetEthBridge } } -impl AsRef> for StarknetEthBridgeContractClient { - fn as_ref(&self) -> &ProxySupport { +impl AsRef> for StarknetEthBridgeContractClient { + fn as_ref(&self) -> &ProxySupport3_0_2 { &self.proxy_support } } diff --git a/crates/l2/starknet-proxy-client/src/clients/mod.rs b/crates/l2/starknet-proxy-client/src/clients/mod.rs index dbc44bb..0466744 100644 --- a/crates/l2/starknet-proxy-client/src/clients/mod.rs +++ b/crates/l2/starknet-proxy-client/src/clients/mod.rs @@ -1,3 +1,2 @@ -pub mod proxy; pub mod proxy_3_0_2; pub mod proxy_5_0_0; diff --git a/crates/l2/starknet-proxy-client/src/clients/proxy_3_0_2.rs b/crates/l2/starknet-proxy-client/src/clients/proxy_3_0_2.rs index 0362f55..86c5b14 100644 --- a/crates/l2/starknet-proxy-client/src/clients/proxy_3_0_2.rs +++ b/crates/l2/starknet-proxy-client/src/clients/proxy_3_0_2.rs @@ -1,4 +1,4 @@ -use crate::clients::proxy::{ProxyInitializeData, ProxySupportTrait}; +use crate::interfaces::proxy::{ProxyInitializeData, ProxySupportTrait}; use async_trait::async_trait; use ethers::addressbook::Address; use ethers::contract::{abigen, ContractError}; @@ -7,7 +7,7 @@ use ethers::prelude::{Bytes, TransactionReceipt}; use utils::errors::Error; abigen!( - ProxySupport, + ProxySupport3_0_2, r#"[ function isFrozen() external view virtual returns (bool) function initialize(bytes calldata data) external notCalledDirectly @@ -22,7 +22,7 @@ abigen!( #[async_trait] impl ProxySupportTrait for T where - T: AsRef> + Send + Sync, + T: AsRef> + Send + Sync, { async fn is_frozen(&self) -> Result> { self.as_ref().is_frozen().call().await.map_err(Into::into) diff --git a/crates/l2/starknet-proxy-client/src/clients/proxy_5_0_0.rs b/crates/l2/starknet-proxy-client/src/clients/proxy_5_0_0.rs index 65d9eee..384eb24 100644 --- a/crates/l2/starknet-proxy-client/src/clients/proxy_5_0_0.rs +++ b/crates/l2/starknet-proxy-client/src/clients/proxy_5_0_0.rs @@ -1,4 +1,4 @@ -use crate::clients::proxy::{ProxyInitializeData, ProxySupportLatestTrait}; +use crate::interfaces::proxy::{ProxyInitializeData, ProxySupportLatestTrait}; use async_trait::async_trait; use ethers::addressbook::Address; use ethers::contract::{abigen, ContractError}; @@ -7,7 +7,7 @@ use ethers::prelude::{Bytes, TransactionReceipt}; use utils::errors::Error; abigen!( - ProxySupportLatest, + ProxySupport5_0_0, r#"[ function isFrozen() external view virtual returns (bool) function initialize(bytes calldata data) external notCalledDirectly @@ -31,7 +31,7 @@ abigen!( #[async_trait] impl ProxySupportLatestTrait for T where - T: AsRef> + Send + Sync, + T: AsRef> + Send + Sync, { async fn is_frozen(&self) -> Result> { self.as_ref().is_frozen().call().await.map_err(Into::into) diff --git a/crates/l2/starknet-proxy-client/src/deploy.rs b/crates/l2/starknet-proxy-client/src/deploy.rs index 3ead66b..3222efa 100644 --- a/crates/l2/starknet-proxy-client/src/deploy.rs +++ b/crates/l2/starknet-proxy-client/src/deploy.rs @@ -57,14 +57,14 @@ pub async fn deploy_contract_behind_proxy( log::debug!("ℹ️ Contract deployed : {:?}", contract.address().clone()); - let type_of_proxy = match proxy_type { + let proxy_code = match proxy_type { ProxyVersion::SafeProxy3_0_2 => SAFE_PROXY_3_0_2, ProxyVersion::SafeProxy5_0_0 => SAFE_PROXY_5_0_0, ProxyVersion::UnsafeProxy => UNSAFE_PROXY, }; let proxy_contract = - deploy_contract(client.clone(), type_of_proxy, Token::Uint(U256::from(0))).await?; + deploy_contract(client.clone(), proxy_code, Token::Uint(U256::from(0))).await?; log::debug!( "ℹ️ Proxy for contract [{:?}] deployed : {:?}", diff --git a/crates/l2/starknet-proxy-client/src/interfaces/mod.rs b/crates/l2/starknet-proxy-client/src/interfaces/mod.rs new file mode 100644 index 0000000..44dcc92 --- /dev/null +++ b/crates/l2/starknet-proxy-client/src/interfaces/mod.rs @@ -0,0 +1 @@ +pub mod proxy; diff --git a/crates/l2/starknet-proxy-client/src/clients/proxy.rs b/crates/l2/starknet-proxy-client/src/interfaces/proxy.rs similarity index 100% rename from crates/l2/starknet-proxy-client/src/clients/proxy.rs rename to crates/l2/starknet-proxy-client/src/interfaces/proxy.rs diff --git a/crates/l2/starknet-proxy-client/src/lib.rs b/crates/l2/starknet-proxy-client/src/lib.rs index 4ecad0d..67a4707 100644 --- a/crates/l2/starknet-proxy-client/src/lib.rs +++ b/crates/l2/starknet-proxy-client/src/lib.rs @@ -1,2 +1,3 @@ pub mod clients; pub mod deploy; +pub mod interfaces; diff --git a/crates/l2/starknet-token-bridge-client/src/clients/token_bridge.rs b/crates/l2/starknet-token-bridge-client/src/clients/token_bridge.rs index 2c033a9..af6e9e0 100644 --- a/crates/l2/starknet-token-bridge-client/src/clients/token_bridge.rs +++ b/crates/l2/starknet-token-bridge-client/src/clients/token_bridge.rs @@ -4,12 +4,12 @@ use crate::interfaces::token_bridge::StarknetTokenBridge; use utils::{LocalWalletSignerMiddleware, StarknetContractClient}; use ethers::types::Address; -use starknet_proxy_client::clients::proxy_5_0_0::ProxySupportLatest; +use starknet_proxy_client::clients::proxy_5_0_0::ProxySupport5_0_0; /// Client to interact with a Token Bridge (ERC20) pub struct StarknetTokenBridgeContractClient { token_bridge: StarknetTokenBridge, - proxy_support: ProxySupportLatest, + proxy_support: ProxySupport5_0_0, token_bridge_implementation: Address, } @@ -21,7 +21,7 @@ impl StarknetTokenBridgeContractClient { ) -> Self { Self { token_bridge: StarknetTokenBridge::new(address, client.clone()), - proxy_support: ProxySupportLatest::new(address, client.clone()), + proxy_support: ProxySupport5_0_0::new(address, client.clone()), token_bridge_implementation: implementation_address, } } @@ -33,8 +33,8 @@ impl AsRef> for StarknetTokenBr } } -impl AsRef> for StarknetTokenBridgeContractClient { - fn as_ref(&self) -> &ProxySupportLatest { +impl AsRef> for StarknetTokenBridgeContractClient { + fn as_ref(&self) -> &ProxySupport5_0_0 { &self.proxy_support } }