Skip to content

Commit

Permalink
Add USDT support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Mar 27, 2024
1 parent 45c9016 commit e5d953d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/coin_gecko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn token_to_coin(token: &MaybeToken) -> Result<&'static str, Box<dyn std::error:
None => "solana",
Some(token) => match token {
Token::USDC => "usd-coin",
Token::USDT => "tether",
Token::UXD => "uxd-stablecoin",
Token::bSOL => "blazestake-staked-sol",
Token::mSOL => "msol",
Expand Down Expand Up @@ -84,6 +85,8 @@ pub async fn get_current_price(token: &MaybeToken) -> Result<Decimal, Box<dyn st
msol: Option<CurrencyList>,
#[serde(rename = "lido-staked-sol")]
stsol: Option<CurrencyList>,
#[serde(rename = "tether")]
tether: Option<CurrencyList>,
#[serde(rename = "uxd-stablecoin")]
uxd: Option<CurrencyList>,
}
Expand All @@ -94,6 +97,7 @@ pub async fn get_current_price(token: &MaybeToken) -> Result<Decimal, Box<dyn st
.solana
.or(coins.msol)
.or(coins.stsol)
.or(coins.tether)
.or(coins.uxd)
.or(coins.bsol)
.ok_or_else(|| format!("Simple price data not available for {coin}").into())
Expand Down
11 changes: 7 additions & 4 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use {
#[allow(non_camel_case_types)]
pub enum Token {
USDC,
USDT,
UXD,
bSOL,
mSOL,
Expand All @@ -47,6 +48,7 @@ impl Token {
pub fn mint(&self) -> Pubkey {
match self {
Token::USDC => pubkey!("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
Token::USDT => pubkey!("BQcdHdAQW1hczDbBi9hiegXAR7A98Q9jx3X3iBBBDiq4"),
Token::UXD => pubkey!("7kbnvuGBxxj8AG9qp8Scn56muWGaRaFqxg1FsRp3PaFT"),
Token::tuUSDC => pubkey!("Amig8TisuLpzun8XyGfC5HJHHGUQEscjLgoTWsCCKihg"),
Token::bSOL => pubkey!("bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1"),
Expand All @@ -66,6 +68,7 @@ impl Token {
pub fn symbol(&self) -> &'static str {
match self {
Token::USDC => "($)",
Token::USDT => "USDT$",
Token::UXD => "UXD$",
Token::tuUSDC => "tu($)",
Token::bSOL => "b◎",
Expand All @@ -80,7 +83,7 @@ impl Token {

pub fn decimals(&self) -> u8 {
match self {
Token::USDC | Token::UXD | Token::tuUSDC => 6,
Token::USDC | Token::USDT | Token::UXD | Token::tuUSDC => 6,
Token::stSOL
| Token::tuSOL
| Token::bSOL
Expand Down Expand Up @@ -111,7 +114,7 @@ impl Token {

pub fn liquidity_token(&self) -> Option<MaybeToken> {
match self {
Token::USDC | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
Token::USDC | Token::USDT | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
None
}
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
Expand All @@ -126,7 +129,7 @@ impl Token {
_rpc_client: &RpcClient,
) -> Result<Decimal, Box<dyn std::error::Error>> {
match self {
Token::USDC | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
Token::USDC | Token::USDT | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
unreachable!()
}
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
Expand Down Expand Up @@ -165,7 +168,7 @@ impl Token {
return Ok(Decimal::from_f64(1.).unwrap());
}
match self {
Token::USDC | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
Token::USDC | Token::USDT | Token::UXD | Token::bSOL | Token::mSOL | Token::stSOL | Token::wSOL => {
coin_gecko::get_current_price(&MaybeToken(Some(*self))).await
}
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
Expand Down

0 comments on commit e5d953d

Please sign in to comment.