Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add interfaces for each abstract contract used by the Starknet … #6

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions crates/starknet-core-contract-client/src/clients/sovereign.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use crate::{
interfaces::{Operator, ProxySupport, StarknetMessaging, StarknetSovereignContract},
interfaces::{Operator, ProxySupport, StarknetMessaging, StarknetSovereignContract, StarknetGovernance, GovernedFinalizable},
LocalMiddleware,
};
use ethers::types::Address;
Expand All @@ -12,6 +12,8 @@ pub struct StarknetSovereignContractClient {
messaging: StarknetMessaging<LocalMiddleware>,
operator: Operator<LocalMiddleware>,
proxy_support: ProxySupport<LocalMiddleware>,
governance: StarknetGovernance<LocalMiddleware>,
governed_finalizable: GovernedFinalizable<LocalMiddleware>
}

impl StarknetSovereignContractClient {
Expand All @@ -20,7 +22,9 @@ 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),
proxy_support: ProxySupport::new(address, client.clone()),
governance: StarknetGovernance::new(address, client.clone()),
governed_finalizable: GovernedFinalizable::new(address, client.clone())
}
}
}
Expand All @@ -45,3 +49,13 @@ impl AsRef<Operator<LocalMiddleware>> for StarknetSovereignContractClient {
&self.operator
}
}
impl AsRef<StarknetGovernance<LocalMiddleware>> for StarknetSovereignContractClient {
fn as_ref(&self) -> &StarknetGovernance<LocalMiddleware> {
&self.governance
}
}
impl AsRef<GovernedFinalizable<LocalMiddleware>> for StarknetSovereignContractClient {
fn as_ref(&self) -> &GovernedFinalizable<LocalMiddleware> {
&self.governed_finalizable
}
}
72 changes: 72 additions & 0 deletions crates/starknet-core-contract-client/src/interfaces/governance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use async_trait::async_trait;
use ethers::{prelude::abigen, providers::Middleware, types::H160};

use crate::Error;

type Adress = H160;

abigen!(
StarknetGovernance,
r#"[
function starknetIsGovernor(address user) external view returns (bool)
function starknetNominateNewGovernor(address newGovernor) external
function starknetRemoveGovernor(address governorForRemoval) external
function starknetAcceptGovernance() external
function starknetCancelNomination() external
]"#,
);

#[async_trait]
pub trait StarknetGovernanceTrait<M: Middleware> {
async fn starknet_is_governor(&self, user: Adress) -> Result<bool, Error<M>>;
async fn starknet_nominate_new_governor(&self, new_governor: Adress) -> Result<(), Error<M>>;
async fn starknet_remove_governor(&self, governor_for_removal: Adress) -> Result<(), Error<M>>;
async fn starknet_accept_governance(&self) -> Result<(), Error<M>>;
async fn starknet_cancel_nomination(&self) -> Result<(), Error<M>>;
}

#[async_trait]
impl<T, M: Middleware> StarknetGovernanceTrait<M> for T
where
T: AsRef<StarknetGovernance<M>> + Send + Sync,
{
async fn starknet_is_governor(&self, user: Adress) -> Result<bool, Error<M>> {
self.as_ref()
.starknet_is_governor(user)
.call()
.await
.map_err(Into::into)
}

async fn starknet_nominate_new_governor(&self, new_governor: Adress) -> Result<(), Error<M>> {
self.as_ref()
.starknet_nominate_new_governor(new_governor)
.call()
.await
.map_err(Into::into)
}

async fn starknet_remove_governor(&self, governor_for_removal: Adress) -> Result<(), Error<M>> {
self.as_ref()
.starknet_remove_governor(governor_for_removal)
.call()
.await
.map_err(Into::into)
}

async fn starknet_accept_governance(&self) -> Result<(), Error<M>> {
self.as_ref()
.starknet_accept_governance()
.call()
.await
.map_err(Into::into)
}

async fn starknet_cancel_nomination(&self) -> Result<(), Error<M>> {
self.as_ref()
.starknet_cancel_nomination()
.call()
.await
.map_err(Into::into)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use async_trait::async_trait;
use ethers::{prelude::abigen, providers::Middleware};

use crate::Error;

abigen!(
GovernedFinalizable,
r#"[
function isFinalized() public view returns (bool)
function finalize() external onlyGovernance notFinalized
]"#,
);

#[async_trait]
pub trait GovernedFinalizableTrait<M: Middleware> {
async fn is_finalized(&self) -> Result<bool, Error<M>>;
async fn finalize(&self) -> Result<(), Error<M>>;
}

#[async_trait]
impl<T, M: Middleware> GovernedFinalizableTrait<M> for T
where
T: AsRef<GovernedFinalizable<M>> + Send + Sync,
{
async fn is_finalized(&self) -> Result<bool, Error<M>> {
self.as_ref()
.is_finalized()
.call()
.await
.map_err(Into::into)
}

async fn finalize(&self) -> Result<(), Error<M>> {
self.as_ref()
.finalize()
.call()
.await
.map_err(Into::into)
}
}
4 changes: 4 additions & 0 deletions crates/starknet-core-contract-client/src/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ mod operator;
mod proxy_support;
mod sovereign_core_contract;
mod validity_core_contract;
mod governance;
mod governed_finalizable;

pub use messaging::{StarknetMessaging, StarknetMessagingTrait};
pub use operator::{Operator, OperatorTrait};
pub use proxy_support::{ProxySupport, ProxySupportTrait};
pub use sovereign_core_contract::{StarknetSovereignContract, StarknetSovereignContractTrait};
pub use validity_core_contract::{StarknetValidityContract, StarknetValidityContractTrait};
pub use governance::{StarknetGovernance, StarknetGovernanceTrait};
pub use governed_finalizable::{GovernedFinalizable, GovernedFinalizableTrait};