tensor_amm/hooked/
currency.rs

1use std::fmt::{self, Display, Formatter};
2use std::ops::Deref;
3
4use borsh::{BorshDeserialize, BorshSerialize};
5use solana_program::pubkey::Pubkey;
6
7#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, Default, Eq, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct Currency(Pubkey);
10
11impl Deref for Currency {
12    type Target = Pubkey;
13
14    fn deref(&self) -> &Self::Target {
15        &self.0
16    }
17}
18
19impl Display for Currency {
20    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
21        if self.is_sol() {
22            write!(f, "SOL")
23        } else {
24            write!(f, "{}", self.0)
25        }
26    }
27}
28
29impl Currency {
30    pub fn new(pubkey: Pubkey) -> Self {
31        Self(pubkey)
32    }
33
34    pub fn sol() -> Self {
35        Self::default()
36    }
37
38    pub fn is_sol(&self) -> bool {
39        *self == Self::default()
40    }
41}