From 7484d69bb9dc5501b8986bc9f2ee3d556165b6b2 Mon Sep 17 00:00:00 2001 From: Tay Zheng Yu <32449414+ZhengYuTay@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:57:08 +0800 Subject: [PATCH] fix: update stakedex with amm context (#5) --- Cargo.lock | 4 ++-- Cargo.toml | 14 +++++++++----- common/src/init_from_keyed_account.rs | 4 ++-- jup_interface/src/pool_pair/one_way.rs | 8 ++++++-- jup_interface/src/pool_pair/two_way.rs | 8 ++++++-- jup_interface/src/pool_sol/deposit_sol.rs | 6 +++--- libs/lido/src/stakedex_traits/base.rs | 4 ++-- libs/marinade/src/stakedex_traits/base.rs | 4 ++-- .../src/stakedex_traits/base.rs | 3 ++- .../src/stakedex_traits/base/main.rs | 7 +++++-- stakedex_sdk/src/lib.rs | 19 ++++++++++++++++--- 11 files changed, 55 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89e275f..18e72e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1925,9 +1925,9 @@ dependencies = [ [[package]] name = "jupiter-amm-interface" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d08fe25539f5064257e7f372e8a172099656c248891c09c59318870de7e21a" +checksum = "126adb65422429747b45807d63b132eb69eb01863ab552b4a2e2bdf1236f7920" dependencies = [ "anyhow", "borsh 0.10.3", diff --git a/Cargo.toml b/Cargo.toml index 3e05566..4dc619f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "interfaces/*", "jup_interface", "libs/*", - "stakedex_sdk" + "stakedex_sdk", ] [workspace.dependencies] @@ -16,10 +16,12 @@ bincode = "^1.0" borsh = ">=0.9,<1.0.0" clap = "^3" itertools = ">=0.1" -jupiter-amm-interface = "~0.3.3" +jupiter-amm-interface = "~0.4.0" lazy_static = "^1.0" # set git dependencies to branch instead of locking to rev so that consumers can upgrade easily -lido = { git = "https://github.com/jup-ag/solido", rev = "2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967", features = ["no-entrypoint"] } +lido = { git = "https://github.com/jup-ag/solido", rev = "2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967", features = [ + "no-entrypoint", +] } marinade_finance_interface = { git = "https://github.com/jup-ag/marinade_finance_interface", rev = "5747b5350c5505fc2ea597c3f8ae1f8cf71c363d" } # rev = "4d1895b" num-derive = ">=0.1" num-traits = ">=0.1" @@ -29,8 +31,10 @@ sanctum-macros = "^1.2" serde = "^1" serde_json = "^1" spl-associated-token-account = { version = ">=1", features = ["no-entrypoint"] } -spl-math = { version = "0.1.0", features = ["no-entrypoint"]} -spl-stake-pool = { git = "https://github.com/solana-labs/solana-program-library.git", rev = "a3996814cb44eab2834f72113b742c875ac7b1b9", features = ["no-entrypoint"] } +spl-math = { version = "0.1.0", features = ["no-entrypoint"] } +spl-stake-pool = { git = "https://github.com/solana-labs/solana-program-library.git", rev = "a3996814cb44eab2834f72113b742c875ac7b1b9", features = [ + "no-entrypoint", +] } #spl-stake-pool = { version = "^1", features = ["no-entrypoint"] } spl-token = ">=3.0" thiserror = "^1.0" diff --git a/common/src/init_from_keyed_account.rs b/common/src/init_from_keyed_account.rs index 972426a..b3a8063 100644 --- a/common/src/init_from_keyed_account.rs +++ b/common/src/init_from_keyed_account.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use jupiter_amm_interface::KeyedAccount; +use jupiter_amm_interface::{AmmContext, KeyedAccount}; pub trait InitFromKeyedAccount: Sized { - fn from_keyed_account(keyed_account: &KeyedAccount) -> Result; + fn from_keyed_account(keyed_account: &KeyedAccount, amm_context: &AmmContext) -> Result; } diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index 4ea2b1a..1fc570c 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -1,6 +1,7 @@ use anyhow::{anyhow, Result}; use jupiter_amm_interface::{ - AccountMap, Amm, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, SwapParams, + AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, + SwapParams, }; use solana_sdk::{clock::Clock, pubkey::Pubkey, sysvar}; use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN; @@ -58,7 +59,10 @@ where W: WithdrawStake + Clone + Send + Sync, D: DepositStake + Clone + Send + Sync, { - fn from_keyed_account(_keyed_account: &KeyedAccount) -> Result { + fn from_keyed_account( + _keyed_account: &KeyedAccount, + _amm_context: &AmmContext, + ) -> Result { todo!() // TODO: Assess this code smell } diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index aad479c..e48c364 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -1,6 +1,7 @@ use anyhow::{anyhow, Result}; use jupiter_amm_interface::{ - AccountMap, Amm, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, SwapParams, + AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, + SwapParams, }; use solana_sdk::{clock::Clock, pubkey::Pubkey, sysvar}; use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN; @@ -60,7 +61,10 @@ where P1: DepositStake + WithdrawStake + Clone + Send + Sync, P2: DepositStake + WithdrawStake + Clone + Send + Sync, { - fn from_keyed_account(_keyed_account: &KeyedAccount) -> Result { + fn from_keyed_account( + _keyed_account: &KeyedAccount, + _amm_context: &AmmContext, + ) -> Result { panic!(); // TODO: Assess this code smell } diff --git a/jup_interface/src/pool_sol/deposit_sol.rs b/jup_interface/src/pool_sol/deposit_sol.rs index 5cc39af..70be2a0 100644 --- a/jup_interface/src/pool_sol/deposit_sol.rs +++ b/jup_interface/src/pool_sol/deposit_sol.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use jupiter_amm_interface::{ - Amm, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, SwapParams, + Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, SwapParams, }; use solana_sdk::{account::Account, instruction::AccountMeta, pubkey::Pubkey, system_program}; use spl_token::native_mint; @@ -21,8 +21,8 @@ impl Amm for DepositSolWrapper where T: DepositSol + InitFromKeyedAccount + Clone + Send + Sync, { - fn from_keyed_account(keyed_account: &KeyedAccount) -> Result { - T::from_keyed_account(keyed_account).map(|t| Self(t)) + fn from_keyed_account(keyed_account: &KeyedAccount, amm_context: &AmmContext) -> Result { + T::from_keyed_account(keyed_account, amm_context).map(|t| Self(t)) } fn label(&self) -> String { diff --git a/libs/lido/src/stakedex_traits/base.rs b/libs/lido/src/stakedex_traits/base.rs index 890eee5..c7b563a 100644 --- a/libs/lido/src/stakedex_traits/base.rs +++ b/libs/lido/src/stakedex_traits/base.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use jupiter_amm_interface::{AccountMap, KeyedAccount}; +use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; use solana_program::{pubkey::Pubkey, sysvar}; use stakedex_sdk_common::{ account_missing_err, lido_program, lido_state, stsol, BaseStakePoolAmm, InitFromKeyedAccount, @@ -9,7 +9,7 @@ use crate::{LidoStakedex, LIDO_LABEL}; impl InitFromKeyedAccount for LidoStakedex { /// Initialize from lido - fn from_keyed_account(keyed_account: &KeyedAccount) -> Result { + fn from_keyed_account(keyed_account: &KeyedAccount, _amm_context: &AmmContext) -> Result { let mut res = Self::default(); res.update_lido_state(&keyed_account.account.data)?; // NOTE: validator_list is not initialized until self.update() is diff --git a/libs/marinade/src/stakedex_traits/base.rs b/libs/marinade/src/stakedex_traits/base.rs index 2fc94c9..6496241 100644 --- a/libs/marinade/src/stakedex_traits/base.rs +++ b/libs/marinade/src/stakedex_traits/base.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use jupiter_amm_interface::{AccountMap, KeyedAccount}; +use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; use solana_program::pubkey::Pubkey; use stakedex_sdk_common::{ account_missing_err, marinade_program, marinade_state, msol, BaseStakePoolAmm, @@ -10,7 +10,7 @@ use crate::{MarinadeStakedex, MARINADE_LABEL}; impl InitFromKeyedAccount for MarinadeStakedex { /// Initialize from state - fn from_keyed_account(keyed_account: &KeyedAccount) -> Result { + fn from_keyed_account(keyed_account: &KeyedAccount, _amm_context: &AmmContext) -> Result { let mut res = Self::default(); res.update_state(&keyed_account.account.data)?; // NOTE: validator_records is not initialized until self.update() is diff --git a/libs/spl_stake_pool/src/stakedex_traits/base.rs b/libs/spl_stake_pool/src/stakedex_traits/base.rs index 6adf5b6..34baf4e 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/base.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/base.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use jupiter_amm_interface::{AccountMap, KeyedAccount}; +use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; use solana_program::{clock::Clock, pubkey::Pubkey, sysvar}; use stakedex_sdk_common::{account_missing_err, BaseStakePoolAmm, InitFromKeyedAccount}; @@ -13,6 +13,7 @@ impl InitFromKeyedAccount for SplStakePoolStakedex { account, params, }: &KeyedAccount, + _amm_context: &AmmContext, ) -> Result { let mut res = Self { stake_pool_program: account.owner, diff --git a/libs/unstake_it/src/stakedex_traits/base/main.rs b/libs/unstake_it/src/stakedex_traits/base/main.rs index af2c1d8..d136e87 100644 --- a/libs/unstake_it/src/stakedex_traits/base/main.rs +++ b/libs/unstake_it/src/stakedex_traits/base/main.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use jupiter_amm_interface::{AccountMap, KeyedAccount}; +use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; use solana_program::pubkey::Pubkey; use stakedex_sdk_common::{ account_missing_err, unstake_it_pool, unstake_it_program, BaseStakePoolAmm, @@ -9,7 +9,10 @@ use stakedex_sdk_common::{ use crate::{UnstakeItStakedex, UNSTAKE_IT_LABEL}; impl InitFromKeyedAccount for UnstakeItStakedex { - fn from_keyed_account(_keyed_account: &KeyedAccount) -> Result { + fn from_keyed_account( + _keyed_account: &KeyedAccount, + _amm_context: &AmmContext, + ) -> Result { Ok(UnstakeItStakedex::default()) } } diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index e464285..bbf7312 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -2,7 +2,9 @@ use std::collections::HashMap; use anyhow::{anyhow, Result}; use itertools::Itertools; -use jupiter_amm_interface::{AccountMap, Amm, KeyedAccount, Quote, QuoteParams, SwapParams}; +use jupiter_amm_interface::{ + AccountMap, Amm, AmmContext, ClockRef, KeyedAccount, Quote, QuoteParams, SwapParams, +}; use lazy_static::lazy_static; use sanctum_lst_list::{PoolInfo, SanctumLst, SanctumLstList, SplPoolAccounts}; use solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey, system_program}; @@ -79,7 +81,13 @@ fn init_from_keyed_account_no_params( key: &Pubkey, ) -> Result

{ let keyed_acc = get_keyed_account(accounts, key)?; - P::from_keyed_account(&keyed_acc) + + P::from_keyed_account( + &keyed_acc, + &AmmContext { + clock_ref: ClockRef::default(), + }, + ) } fn sanctum_lst_list_map_all_spl_like T, T>( @@ -142,7 +150,12 @@ impl Stakedex { get_keyed_account(accounts, &pool) .map_or_else(Err, |mut ka| { ka.params = Some(name.as_str().into()); - SplStakePoolStakedex::from_keyed_account(&ka) + SplStakePoolStakedex::from_keyed_account( + &ka, + &AmmContext { + clock_ref: ClockRef::default(), + }, + ) }) .unwrap_or_else(|e| { errs.push(e);