-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add interfaces for each abstract contract used by the Starknet …
- Loading branch information
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
crates/starknet-core-contract-client/src/interfaces/governance.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
crates/starknet-core-contract-client/src/interfaces/governed_finalizable.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters