-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
smart-contracts/osmosis/packages/quasar-types/src/pool_pair.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,65 @@ | ||
use cosmwasm_std::Coin; | ||
|
||
#[derive(Debug)] | ||
pub struct PoolPair<S, T> { | ||
pub base: S, | ||
pub quote: T, | ||
} | ||
|
||
impl<S, T> PoolPair<S, T> { | ||
pub fn new(base: S, quote: T) -> Self { | ||
Self { base, quote } | ||
} | ||
} | ||
|
||
pub trait Contains<T> { | ||
fn contains(&self, value: T) -> bool; | ||
} | ||
|
||
impl Contains<&str> for PoolPair<String, String> { | ||
fn contains(&self, value: &str) -> bool { | ||
value == self.base || value == self.quote | ||
} | ||
} | ||
|
||
impl Contains<&str> for PoolPair<Coin, Coin> { | ||
fn contains(&self, value: &str) -> bool { | ||
value == self.base.denom || value == self.quote.denom | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use cosmwasm_std::coin; | ||
|
||
#[test] | ||
fn test_string_pair() { | ||
let base = "base".to_string(); | ||
let quote = "quote".to_string(); | ||
let pair = PoolPair::new(base.clone(), quote.clone()); | ||
assert_eq!(base, pair.base); | ||
assert_eq!(quote, pair.quote); | ||
|
||
assert!(pair.contains(&base)); | ||
assert!(pair.contains("e)); | ||
assert!(pair.contains(base.as_str())); | ||
assert!(!pair.contains(&"other".to_string())); | ||
assert!(!pair.contains("other")); | ||
} | ||
|
||
#[test] | ||
fn test_coin_pair() { | ||
let base = coin(123u128, "base"); | ||
let quote = coin(456u128, "quote"); | ||
let pair = PoolPair::new(base.clone(), quote.clone()); | ||
assert_eq!(base, pair.base); | ||
assert_eq!(quote, pair.quote); | ||
|
||
assert!(pair.contains(&base.denom)); | ||
assert!(pair.contains("e.denom)); | ||
assert!(pair.contains(base.denom.as_str())); | ||
assert!(!pair.contains(&"other".to_string())); | ||
assert!(!pair.contains("other")); | ||
} | ||
} |