Skip to content

Commit

Permalink
fix: update stakedex with amm context (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengYuTay authored and Arrowana committed Apr 22, 2024
1 parent 2f0bac2 commit e9d8f52
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
"interfaces/*",
"jup_interface",
"libs/*",
"stakedex_sdk"
"stakedex_sdk",
]

[workspace.dependencies]
Expand All @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions common/src/init_from_keyed_account.rs
Original file line number Diff line number Diff line change
@@ -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<Self>;
fn from_keyed_account(keyed_account: &KeyedAccount, amm_context: &AmmContext) -> Result<Self>;
}
8 changes: 6 additions & 2 deletions jup_interface/src/pool_pair/one_way.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -58,7 +59,10 @@ where
W: WithdrawStake + Clone + Send + Sync,
D: DepositStake + Clone + Send + Sync,
{
fn from_keyed_account(_keyed_account: &KeyedAccount) -> Result<Self> {
fn from_keyed_account(
_keyed_account: &KeyedAccount,
_amm_context: &AmmContext,
) -> Result<Self> {
todo!() // TODO: Assess this code smell
}

Expand Down
8 changes: 6 additions & 2 deletions jup_interface/src/pool_pair/two_way.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Self> {
fn from_keyed_account(
_keyed_account: &KeyedAccount,
_amm_context: &AmmContext,
) -> Result<Self> {
panic!(); // TODO: Assess this code smell
}

Expand Down
6 changes: 3 additions & 3 deletions jup_interface/src/pool_sol/deposit_sol.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +21,8 @@ impl<T> Amm for DepositSolWrapper<T>
where
T: DepositSol + InitFromKeyedAccount + Clone + Send + Sync,
{
fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self> {
T::from_keyed_account(keyed_account).map(|t| Self(t))
fn from_keyed_account(keyed_account: &KeyedAccount, amm_context: &AmmContext) -> Result<Self> {
T::from_keyed_account(keyed_account, amm_context).map(|t| Self(t))
}

fn label(&self) -> String {
Expand Down
4 changes: 2 additions & 2 deletions libs/lido/src/stakedex_traits/base.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,7 +9,7 @@ use crate::{LidoStakedex, LIDO_LABEL};

impl InitFromKeyedAccount for LidoStakedex {
/// Initialize from lido
fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self> {
fn from_keyed_account(keyed_account: &KeyedAccount, _amm_context: &AmmContext) -> Result<Self> {
let mut res = Self::default();
res.update_lido_state(&keyed_account.account.data)?;
// NOTE: validator_list is not initialized until self.update() is
Expand Down
4 changes: 2 additions & 2 deletions libs/marinade/src/stakedex_traits/base.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +10,7 @@ use crate::{MarinadeStakedex, MARINADE_LABEL};

impl InitFromKeyedAccount for MarinadeStakedex {
/// Initialize from state
fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self> {
fn from_keyed_account(keyed_account: &KeyedAccount, _amm_context: &AmmContext) -> Result<Self> {
let mut res = Self::default();
res.update_state(&keyed_account.account.data)?;
// NOTE: validator_records is not initialized until self.update() is
Expand Down
3 changes: 2 additions & 1 deletion libs/spl_stake_pool/src/stakedex_traits/base.rs
Original file line number Diff line number Diff line change
@@ -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 spl_stake_pool::find_deposit_authority_program_address;
use stakedex_sdk_common::{account_missing_err, BaseStakePoolAmm, InitFromKeyedAccount};
Expand All @@ -14,6 +14,7 @@ impl InitFromKeyedAccount for SplStakePoolStakedex {
account,
params,
}: &KeyedAccount,
_amm_context: &AmmContext,
) -> Result<Self> {
let deposit_authority_program_address =
find_deposit_authority_program_address(&account.owner, key).0;
Expand Down
7 changes: 5 additions & 2 deletions libs/unstake_it/src/stakedex_traits/base/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<Self> {
fn from_keyed_account(
_keyed_account: &KeyedAccount,
_amm_context: &AmmContext,
) -> Result<Self> {
Ok(UnstakeItStakedex::default())
}
}
Expand Down
19 changes: 16 additions & 3 deletions stakedex_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -79,7 +81,13 @@ fn init_from_keyed_account_no_params<P: InitFromKeyedAccount>(
key: &Pubkey,
) -> Result<P> {
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<F: FnMut(&SanctumLst, SplPoolAccounts) -> T, T>(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e9d8f52

Please sign in to comment.