Skip to content

Commit

Permalink
Add support for JLP token
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 4, 2024
1 parent decad20 commit f6b1cc8
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -39,6 +39,7 @@ fn token_to_coin(token: &MaybeToken) -> Result<&'static str, Box<dyn std::error:
Token::mSOL => "msol",
Token::stSOL => "lido-staked-sol",
Token::wSOL => "solana",
Token::JLP => "jupiter-perpetuals-liquidity-provider-token",
unsupported_token => {
return Err(format!(
"Coin Gecko price data not available for {}",
Expand Down Expand Up @@ -89,6 +90,8 @@ pub async fn get_current_price(token: &MaybeToken) -> Result<Decimal, Box<dyn st
tether: Option<CurrencyList>,
#[serde(rename = "uxd-stablecoin")]
uxd: Option<CurrencyList>,
#[serde(rename = "jupiter-perpetuals-liquidity-provider-token")]
jlp: Option<CurrencyList>,
}

let coins = reqwest::get(url).await?.json::<Coins>().await?;
Expand All @@ -100,6 +103,7 @@ pub async fn get_current_price(token: &MaybeToken) -> Result<Decimal, Box<dyn st
.or(coins.tether)
.or(coins.uxd)
.or(coins.bsol)
.or(coins.jlp)
.ok_or_else(|| format!("Simple price data not available for {coin}").into())
.map(|price| {
let price = Decimal::from_f64(price.usd).unwrap();
Expand Down
14 changes: 10 additions & 4 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Token {
tumSOL,
tustSOL,
wSOL,
JLP,
}

impl Token {
Expand All @@ -58,6 +59,7 @@ impl Token {
Token::tumSOL => pubkey!("8cn7JcYVjDZesLa3RTt3NXne4WcDw9PdUneQWuByehwW"),
Token::tustSOL => pubkey!("27CaAiuFW3EwLcTCaiBnexqm5pxht845AHgSuq36byKX"),
Token::wSOL => spl_token::native_mint::id(),
Token::JLP => pubkey!("27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"),
}
}

Expand All @@ -78,12 +80,13 @@ impl Token {
Token::tumSOL => "tum◎",
Token::tustSOL => "tust◎",
Token::wSOL => "(◎)",
Token::JLP => "JLP:",
}
}

pub fn decimals(&self) -> u8 {
match self {
Token::USDC | Token::USDT | Token::UXD | Token::tuUSDC => 6,
Token::USDC | Token::USDT | Token::UXD | Token::tuUSDC | Token::JLP => 6,
Token::stSOL
| Token::tuSOL
| Token::bSOL
Expand Down Expand Up @@ -120,7 +123,8 @@ impl Token {
| Token::bSOL
| Token::mSOL
| Token::stSOL
| Token::wSOL => None,
| Token::wSOL
| Token::JLP => None,
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
None
// Some(crate::tulip::liquidity_token(self))
Expand All @@ -139,7 +143,8 @@ impl Token {
| Token::bSOL
| Token::mSOL
| Token::stSOL
| Token::wSOL => {
| Token::wSOL
| Token::JLP => {
unreachable!()
}
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
Expand Down Expand Up @@ -184,7 +189,8 @@ impl Token {
| Token::bSOL
| Token::mSOL
| Token::stSOL
| Token::wSOL => coin_gecko::get_current_price(&MaybeToken(Some(*self))).await,
| Token::wSOL
| Token::JLP => coin_gecko::get_current_price(&MaybeToken(Some(*self))).await,
Token::tuUSDC | Token::tuSOL | Token::tumSOL | Token::tustSOL => {
Err("tulip support disabled".into())
//crate::tulip::get_current_price(rpc_client, self).await
Expand Down

0 comments on commit f6b1cc8

Please sign in to comment.