Skip to content

Commit

Permalink
Merge pull request #20 from karnotxyz/feat/added_proxy_versions
Browse files Browse the repository at this point in the history
feat : added different proxy versions in proxy client
  • Loading branch information
apoorvsadana authored Jul 3, 2024
2 parents 23d83c3 + 06f4def commit 71dec05
Show file tree
Hide file tree
Showing 24 changed files with 3,121 additions and 801 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::Arc;

use crate::interfaces::manager::StarkgateManager;
use starknet_proxy_client::proxy_support::ProxySupport;
use utils::{LocalWalletSignerMiddleware, StarknetContractClient};

use ethers::types::Address;
use starknet_proxy_client::clients::proxy_5_0_0::ProxySupport5_0_0;

pub struct StarkgateManagerContractClient {
manager: StarkgateManager<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport5_0_0<LocalWalletSignerMiddleware>,
manager_implementation: Address,
}

Expand All @@ -20,7 +20,7 @@ impl StarkgateManagerContractClient {
) -> Self {
Self {
manager: StarkgateManager::new(address, client.clone()),
proxy_support: ProxySupport::new(address, client.clone()),
proxy_support: ProxySupport5_0_0::new(address, client.clone()),
manager_implementation: implementation_address,
}
}
Expand All @@ -32,8 +32,8 @@ impl AsRef<StarkgateManager<LocalWalletSignerMiddleware>> for StarkgateManagerCo
}
}

impl AsRef<ProxySupport<LocalWalletSignerMiddleware>> for StarkgateManagerContractClient {
fn as_ref(&self) -> &ProxySupport<LocalWalletSignerMiddleware> {
impl AsRef<ProxySupport5_0_0<LocalWalletSignerMiddleware>> for StarkgateManagerContractClient {
fn as_ref(&self) -> &ProxySupport5_0_0<LocalWalletSignerMiddleware> {
&self.proxy_support
}
}
Expand Down
28 changes: 17 additions & 11 deletions crates/l2/starkgate-manager-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::sync::Arc;

use clients::starkgate_manager::StarkgateManagerContractClient;
use starknet_proxy_client::deploy::{
deploy_contract_behind_safe_proxy, deploy_contract_behind_unsafe_proxy, Error,
};
use starknet_proxy_client::deploy::{deploy_contract_behind_proxy, Error, ProxyVersion};
use utils::{LocalWalletSignerMiddleware, NO_CONSTRUCTOR_ARG};
pub mod clients;
pub mod interfaces;
Expand All @@ -14,24 +12,32 @@ pub async fn deploy_starkgate_manager_behind_unsafe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarkgateManagerContractClient, Error> {
// Deploy the Starkgate Manager contract (no explicit constructor)
let manager_contract =
deploy_contract_behind_unsafe_proxy(client.clone(), STARKGATE_MANAGER, NO_CONSTRUCTOR_ARG)
.await?;
let manager_contract = deploy_contract_behind_proxy(
client.clone(),
STARKGATE_MANAGER,
NO_CONSTRUCTOR_ARG,
ProxyVersion::UnsafeProxy,
)
.await?;

Ok(StarkgateManagerContractClient::new(
manager_contract.address(),
manager_contract.0.address(),
client.clone(),
manager_contract.address(),
manager_contract.1.address(),
))
}

pub async fn deploy_starkgate_manager_behind_safe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarkgateManagerContractClient, Error> {
// Deploy the Starkgate Manager contract (no explicit constructor)
let (manager_contract, manager_contract_implementation) =
deploy_contract_behind_safe_proxy(client.clone(), STARKGATE_MANAGER, NO_CONSTRUCTOR_ARG)
.await?;
let (manager_contract, manager_contract_implementation) = deploy_contract_behind_proxy(
client.clone(),
STARKGATE_MANAGER,
NO_CONSTRUCTOR_ARG,
ProxyVersion::SafeProxy5_0_0,
)
.await?;

Ok(StarkgateManagerContractClient::new(
manager_contract.address(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::Arc;

use crate::interfaces::registry::StarkgateRegistry;
use starknet_proxy_client::proxy_support::ProxySupport;
use utils::{LocalWalletSignerMiddleware, StarknetContractClient};

use ethers::types::Address;
use starknet_proxy_client::clients::proxy_5_0_0::ProxySupport5_0_0;

pub struct StarkgateRegistryContractClient {
registry: StarkgateRegistry<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport5_0_0<LocalWalletSignerMiddleware>,
registry_implementation: Address,
}

Expand All @@ -20,7 +20,7 @@ impl StarkgateRegistryContractClient {
) -> Self {
Self {
registry: StarkgateRegistry::new(address, client.clone()),
proxy_support: ProxySupport::new(address, client.clone()),
proxy_support: ProxySupport5_0_0::new(address, client.clone()),
registry_implementation: implementation_address,
}
}
Expand All @@ -31,8 +31,8 @@ impl AsRef<StarkgateRegistry<LocalWalletSignerMiddleware>> for StarkgateRegistry
}
}

impl AsRef<ProxySupport<LocalWalletSignerMiddleware>> for StarkgateRegistryContractClient {
fn as_ref(&self) -> &ProxySupport<LocalWalletSignerMiddleware> {
impl AsRef<ProxySupport5_0_0<LocalWalletSignerMiddleware>> for StarkgateRegistryContractClient {
fn as_ref(&self) -> &ProxySupport5_0_0<LocalWalletSignerMiddleware> {
&self.proxy_support
}
}
Expand Down
28 changes: 17 additions & 11 deletions crates/l2/starkgate-registry-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::sync::Arc;

use clients::starkgate_registry::StarkgateRegistryContractClient;
use starknet_proxy_client::deploy::{
deploy_contract_behind_safe_proxy, deploy_contract_behind_unsafe_proxy, Error,
};
use starknet_proxy_client::deploy::{deploy_contract_behind_proxy, Error, ProxyVersion};
use utils::{LocalWalletSignerMiddleware, NO_CONSTRUCTOR_ARG};

pub mod clients;
Expand All @@ -15,24 +13,32 @@ pub async fn deploy_starkgate_registry_behind_unsafe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarkgateRegistryContractClient, Error> {
// Deploy the Starkgate Registry contract (no explicit constructor)
let registry_contract =
deploy_contract_behind_unsafe_proxy(client.clone(), STARKGATE_REGISTRY, NO_CONSTRUCTOR_ARG)
.await?;
let registry_contract = deploy_contract_behind_proxy(
client.clone(),
STARKGATE_REGISTRY,
NO_CONSTRUCTOR_ARG,
ProxyVersion::UnsafeProxy,
)
.await?;

Ok(StarkgateRegistryContractClient::new(
registry_contract.address(),
registry_contract.0.address(),
client.clone(),
registry_contract.address(),
registry_contract.1.address(),
))
}

pub async fn deploy_starkgate_registry_behind_safe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarkgateRegistryContractClient, Error> {
// Deploy the Starkgate Registry contract (no explicit constructor)
let (registry_contract, registry_contract_implementation) =
deploy_contract_behind_safe_proxy(client.clone(), STARKGATE_REGISTRY, NO_CONSTRUCTOR_ARG)
.await?;
let (registry_contract, registry_contract_implementation) = deploy_contract_behind_proxy(
client.clone(),
STARKGATE_REGISTRY,
NO_CONSTRUCTOR_ARG,
ProxyVersion::SafeProxy5_0_0,
)
.await?;

Ok(StarkgateRegistryContractClient::new(
registry_contract.address(),
Expand Down
10 changes: 5 additions & 5 deletions crates/l2/starknet-core-contract-client/src/clients/sovereign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::interfaces::{
GovernedFinalizable, Operator, StarknetGovernance, StarknetMessaging, StarknetSovereignContract,
};
use ethers::types::Address;
use starknet_proxy_client::proxy_support::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
pub struct StarknetSovereignContractClient {
core_contract: StarknetSovereignContract<LocalWalletSignerMiddleware>,
messaging: StarknetMessaging<LocalWalletSignerMiddleware>,
operator: Operator<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport3_0_2<LocalWalletSignerMiddleware>,
governance: StarknetGovernance<LocalWalletSignerMiddleware>,
governed_finalizable: GovernedFinalizable<LocalWalletSignerMiddleware>,
core_contract_implementation: Address,
Expand All @@ -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,
Expand All @@ -48,8 +48,8 @@ impl AsRef<StarknetMessaging<LocalWalletSignerMiddleware>> for StarknetSovereign
&self.messaging
}
}
impl AsRef<ProxySupport<LocalWalletSignerMiddleware>> for StarknetSovereignContractClient {
fn as_ref(&self) -> &ProxySupport<LocalWalletSignerMiddleware> {
impl AsRef<ProxySupport3_0_2<LocalWalletSignerMiddleware>> for StarknetSovereignContractClient {
fn as_ref(&self) -> &ProxySupport3_0_2<LocalWalletSignerMiddleware> {
&self.proxy_support
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/l2/starknet-core-contract-client/src/clients/validity.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::sync::Arc;

use ethers::abi::Address;
use starknet_proxy_client::clients::proxy_3_0_2::ProxySupport3_0_2;

use crate::interfaces::{
GovernedFinalizable, Operator, StarknetGovernance, StarknetMessaging, StarknetValidityContract,
};
use starknet_proxy_client::proxy_support::ProxySupport;
use utils::{LocalWalletSignerMiddleware, StarknetContractClient};

/// Client to interact with a Starknet core contract running in `Validity` mode
pub struct StarknetValidityContractClient {
core_contract: StarknetValidityContract<LocalWalletSignerMiddleware>,
messaging: StarknetMessaging<LocalWalletSignerMiddleware>,
operator: Operator<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport3_0_2<LocalWalletSignerMiddleware>,
governance: StarknetGovernance<LocalWalletSignerMiddleware>,
governed_finalizable: GovernedFinalizable<LocalWalletSignerMiddleware>,
core_contract_implementation: ethers::addressbook::Address,
Expand All @@ -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,
Expand All @@ -49,8 +49,8 @@ impl AsRef<StarknetMessaging<LocalWalletSignerMiddleware>> for StarknetValidityC
&self.messaging
}
}
impl AsRef<ProxySupport<LocalWalletSignerMiddleware>> for StarknetValidityContractClient {
fn as_ref(&self) -> &ProxySupport<LocalWalletSignerMiddleware> {
impl AsRef<ProxySupport3_0_2<LocalWalletSignerMiddleware>> for StarknetValidityContractClient {
fn as_ref(&self) -> &ProxySupport3_0_2<LocalWalletSignerMiddleware> {
&self.proxy_support
}
}
Expand Down
50 changes: 33 additions & 17 deletions crates/l2/starknet-core-contract-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::sync::Arc;

use crate::clients::StarknetValidityContractClient;
use clients::StarknetSovereignContractClient;
use starknet_proxy_client::deploy::{
deploy_contract_behind_safe_proxy, deploy_contract_behind_unsafe_proxy, Error,
};
use starknet_proxy_client::deploy::{deploy_contract_behind_proxy, Error, ProxyVersion};
use utils::{LocalWalletSignerMiddleware, NO_CONSTRUCTOR_ARG};

pub mod clients;
Expand All @@ -19,14 +17,18 @@ pub async fn deploy_starknet_sovereign_behind_unsafe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarknetSovereignContractClient, Error> {
// Deploy the Starknet Core contract (no explicit constructor)
let core_contract =
deploy_contract_behind_unsafe_proxy(client.clone(), STARKNET_SOVEREIGN, NO_CONSTRUCTOR_ARG)
.await?;
let core_contract = deploy_contract_behind_proxy(
client.clone(),
STARKNET_SOVEREIGN,
NO_CONSTRUCTOR_ARG,
ProxyVersion::UnsafeProxy,
)
.await?;

Ok(StarknetSovereignContractClient::new(
core_contract.address(),
core_contract.0.address(),
client.clone(),
core_contract.address(),
core_contract.1.address(),
))
}

Expand All @@ -36,9 +38,13 @@ pub async fn deploy_starknet_sovereign_behind_safe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarknetSovereignContractClient, Error> {
// Deploy the Starknet Core contract (no explicit constructor)
let (core_contract, core_contract_implementation) =
deploy_contract_behind_safe_proxy(client.clone(), STARKNET_SOVEREIGN, NO_CONSTRUCTOR_ARG)
.await?;
let (core_contract, core_contract_implementation) = deploy_contract_behind_proxy(
client.clone(),
STARKNET_SOVEREIGN,
NO_CONSTRUCTOR_ARG,
ProxyVersion::SafeProxy3_0_2,
)
.await?;

Ok(StarknetSovereignContractClient::new(
core_contract.address(),
Expand All @@ -53,13 +59,18 @@ pub async fn deploy_starknet_validity_behind_unsafe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarknetValidityContractClient, Error> {
// Deploy the Starknet Core contract (no explicit constructor)
let core_contract =
deploy_contract_behind_unsafe_proxy(client.clone(), STARKNET, NO_CONSTRUCTOR_ARG).await?;
let core_contract = deploy_contract_behind_proxy(
client.clone(),
STARKNET,
NO_CONSTRUCTOR_ARG,
ProxyVersion::UnsafeProxy,
)
.await?;

Ok(StarknetValidityContractClient::new(
core_contract.address(),
core_contract.0.address(),
client.clone(),
core_contract.address(),
core_contract.1.address(),
))
}

Expand All @@ -69,8 +80,13 @@ pub async fn deploy_starknet_validity_behind_safe_proxy(
client: Arc<LocalWalletSignerMiddleware>,
) -> Result<StarknetValidityContractClient, Error> {
// Deploy the Starknet Core contract (no explicit constructor)
let (core_contract, core_contract_implementation) =
deploy_contract_behind_safe_proxy(client.clone(), STARKNET, NO_CONSTRUCTOR_ARG).await?;
let (core_contract, core_contract_implementation) = deploy_contract_behind_proxy(
client.clone(),
STARKNET,
NO_CONSTRUCTOR_ARG,
ProxyVersion::SafeProxy3_0_2,
)
.await?;

Ok(StarknetValidityContractClient::new(
core_contract.address(),
Expand Down
10 changes: 5 additions & 5 deletions crates/l2/starknet-eth-bridge-client/src/clients/eth_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::sync::Arc;

use crate::interfaces::eth_bridge::StarknetEthBridge;
use starknet_proxy_client::proxy_support::ProxySupport;
use utils::{LocalWalletSignerMiddleware, StarknetContractClient};

use ethers::types::Address;
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<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport<LocalWalletSignerMiddleware>,
proxy_support: ProxySupport3_0_2<LocalWalletSignerMiddleware>,
eth_bridge_implementation: Address,
}

Expand All @@ -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,
}
}
Expand All @@ -33,8 +33,8 @@ impl AsRef<StarknetEthBridge<LocalWalletSignerMiddleware>> for StarknetEthBridge
}
}

impl AsRef<ProxySupport<LocalWalletSignerMiddleware>> for StarknetEthBridgeContractClient {
fn as_ref(&self) -> &ProxySupport<LocalWalletSignerMiddleware> {
impl AsRef<ProxySupport3_0_2<LocalWalletSignerMiddleware>> for StarknetEthBridgeContractClient {
fn as_ref(&self) -> &ProxySupport3_0_2<LocalWalletSignerMiddleware> {
&self.proxy_support
}
}
Expand Down
Loading

0 comments on commit 71dec05

Please sign in to comment.