Skip to content

Commit

Permalink
feat: Add NativeCurrency trait and implement for Ether
Browse files Browse the repository at this point in the history
Introduced `NativeCurrency` trait representing native blockchain currencies. Implemented this trait for `Ether` and updated the `prelude` and entity modules accordingly.
  • Loading branch information
shuhuiluo committed Sep 4, 2024
1 parent 18dc2c0 commit 84be7ba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/entities/ether.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::prelude::*;
/// Represents the native currency of the blockchain.
pub type Ether = CurrencyLike<true, Option<Token>>;

impl NativeCurrency for Ether {}

impl Currency for Ether {
/// Retrieves the address associated with the currency.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pub mod base_currency;
pub mod currency;
pub mod ether;
pub mod fractions;
pub mod native_currency;
pub mod token;
pub mod weth9;
12 changes: 12 additions & 0 deletions src/entities/native_currency.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::prelude::*;

/// Represents the native currency of the chain on which it resides
pub trait NativeCurrency: Currency {
fn is_native(&self) -> bool {
true
}

fn is_token(&self) -> bool {
false
}
}
1 change: 1 addition & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use crate::{
percent::Percent,
price::Price,
},
native_currency::NativeCurrency,
token::Token,
weth9::WETH9,
},
Expand Down

0 comments on commit 84be7ba

Please sign in to comment.