Skip to content

Commit

Permalink
ref: add IErc20Capped trait
Browse files Browse the repository at this point in the history
Refers #336
  • Loading branch information
bidzyyys committed Oct 15, 2024
1 parent 7b0e515 commit be3c34b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/src/token/erc20/extensions/burnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::token::erc20::{Erc20, Error};
/// their own tokens and those that they have an allowance for,
/// in a way that can be recognized off-chain (via event analysis).
pub trait IErc20Burnable {
/// The error type associated to this ERC-20 Burnable trait implementation.
/// The error type associated to the trait implementation.
type Error: Into<alloc::vec::Vec<u8>>;

/// Destroys a `value` amount of tokens from the caller. lowering the total
Expand Down
19 changes: 15 additions & 4 deletions contracts/src/token/erc20/extensions/capped.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Capped Contract.
//! Optional Capped Contract.
//!
//! Extension of ERC-20 standard that adds a cap to the supply of tokens.
//!
Expand Down Expand Up @@ -43,10 +43,21 @@ sol_storage! {
}
}

/// Extension of [`Erc-20`] that adds a cap to the supply of tokens.
pub trait IErc20Capped {
/// The error type associated to the trait implementation.
type Error: Into<alloc::vec::Vec<u8>>;

/// Returns the cap on the token's total supply.
fn cap(&self) -> U256;
}

#[public]
impl Capped {
impl IErc20Capped for Capped {
type Error = Error;

/// Returns the cap on the token's total supply.
pub fn cap(&self) -> U256 {
fn cap(&self) -> U256 {
self._cap.get()
}
}
Expand All @@ -55,7 +66,7 @@ impl Capped {
mod tests {
use alloy_primitives::uint;

use super::Capped;
use super::{Capped, IErc20Capped};

#[motsu::test]
fn cap_works(contract: Capped) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/erc20/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub mod metadata;
pub mod permit;

pub use burnable::IErc20Burnable;
pub use capped::Capped;
pub use capped::{Capped, IErc20Capped};
pub use metadata::{Erc20Metadata, IErc20Metadata};
pub use permit::Erc20Permit;
4 changes: 3 additions & 1 deletion examples/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use alloc::vec::Vec;
use alloy_primitives::{Address, FixedBytes, U256};
use openzeppelin_stylus::{
token::erc20::{
extensions::{capped, Capped, Erc20Metadata, IErc20Burnable},
extensions::{
capped, Capped, Erc20Metadata, IErc20Burnable, IErc20Capped,
},
Erc20, IErc20,
},
utils::{introspection::erc165::IErc165, Pausable},
Expand Down

0 comments on commit be3c34b

Please sign in to comment.