Skip to content

Commit

Permalink
fix init_from_keyed_account_no_params
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowana committed Sep 24, 2024
1 parent 2deb20a commit 017a220
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
6 changes: 3 additions & 3 deletions jup_interface/src/pool_pair/one_way.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use jupiter_amm_interface::{
AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas,
SwapParams,
};
use solana_sdk::{clock::Clock, pubkey::Pubkey, sysvar};
use solana_sdk::pubkey::Pubkey;
use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN;
use stakedex_sdk_common::{
account_missing_err, find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program,
unstake_it_program, DepositStake, WithdrawStake, TEMPORARY_JUP_AMM_LABEL,
find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program, unstake_it_program, DepositStake,
WithdrawStake, TEMPORARY_JUP_AMM_LABEL,
};
use std::collections::HashSet;

Expand Down
2 changes: 1 addition & 1 deletion jup_interface/src/pool_pair/prefund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn extract_incoming_stake(accounts_map: &AccountMap) -> Result<u64> {
Ok(incoming_stake)
}

fn extract_sol_reserves_lamports(accounts_map: &AccountMap) -> Result<u64> {
pub fn extract_sol_reserves_lamports(accounts_map: &AccountMap) -> Result<u64> {
let Account {
lamports: sol_reserves_lamports,
..
Expand Down
6 changes: 3 additions & 3 deletions jup_interface/src/pool_pair/two_way.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use jupiter_amm_interface::{
AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas,
SwapParams,
};
use solana_sdk::{pubkey::Pubkey, sysvar};
use solana_sdk::pubkey::Pubkey;
use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN;
use stakedex_sdk_common::{
account_missing_err, find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program,
unstake_it_program, DepositStake, WithdrawStake, TEMPORARY_JUP_AMM_LABEL,
find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program, unstake_it_program, DepositStake,
WithdrawStake, TEMPORARY_JUP_AMM_LABEL,
};
use std::collections::HashSet;

Expand Down
63 changes: 31 additions & 32 deletions stakedex_sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use itertools::Itertools;
use jupiter_amm_interface::{
AccountMap, Amm, AmmContext, ClockRef, KeyedAccount, Quote, QuoteParams, SwapParams,
AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, SwapParams,
};
use lazy_static::lazy_static;
use sanctum_lst_list::{PoolInfo, SanctumLst};
Expand All @@ -13,8 +13,8 @@ use stakedex_interface::{
StakeWrappedSolKeys, SwapViaStakeArgs,
};
use stakedex_jup_interface::{
manual_concat_get_account_metas, prefund_get_account_metas, quote_pool_pair, DepositSolWrapper,
OneWayPoolPair, PrefundRepayParams, TwoWayPoolPair,
extract_sol_reserves_lamports, manual_concat_get_account_metas, prefund_get_account_metas,
quote_pool_pair, DepositSolWrapper, OneWayPoolPair, PrefundRepayParams, TwoWayPoolPair,
};
use stakedex_lido::LidoStakedex;
use stakedex_marinade::MarinadeStakedex;
Expand All @@ -24,7 +24,7 @@ use stakedex_sdk_common::{
DepositStakeInfo, DepositStakeQuote, InitFromKeyedAccount, WithdrawStake, WithdrawStakeQuote,
DEPOSIT_STAKE_DST_TOKEN_ACCOUNT_INDEX,
};
use stakedex_spl_stake_pool::{SplStakePoolStakedex, SplStakePoolStakedexInitKeys};
use stakedex_spl_stake_pool::SplStakePoolStakedex;
use stakedex_unstake_it::{UnstakeItStakedex, UnstakeItStakedexPrefund};

pub use sanctum_lst_list::SanctumLstList;
Expand Down Expand Up @@ -78,15 +78,11 @@ fn get_keyed_account(accounts: &AccountMap, key: &Pubkey) -> Result<KeyedAccount
fn init_from_keyed_account_no_params<P: InitFromKeyedAccount>(
accounts: &AccountMap,
key: &Pubkey,
amm_context: &AmmContext,
) -> Result<P> {
let keyed_acc = get_keyed_account(accounts, key)?;

P::from_keyed_account(
&keyed_acc,
&AmmContext {
clock_ref: ClockRef::default(),
},
)
P::from_keyed_account(&keyed_acc, amm_context)
}

impl Stakedex {
Expand Down Expand Up @@ -121,21 +117,26 @@ impl Stakedex {
let mut errs = Vec::new();

let unstakeit = UnstakeItStakedexPrefund(
init_from_keyed_account_no_params(accounts, &unstake_it_program::SOL_RESERVES_ID)
init_from_keyed_account_no_params(
accounts,
&unstake_it_program::SOL_RESERVES_ID,
amm_context,
)
.unwrap_or_else(|e| {
errs.push(e);
UnstakeItStakedex::default()
}),
);

let marinade =
init_from_keyed_account_no_params(accounts, &marinade_state::ID, amm_context)
.unwrap_or_else(|e| {
errs.push(e);
UnstakeItStakedex::default()
}),
);
MarinadeStakedex::default()
});

let marinade = init_from_keyed_account_no_params(accounts, &marinade_state::ID)
let lido = init_from_keyed_account_no_params(accounts, &lido_state::ID, amm_context)
.unwrap_or_else(|e| {
errs.push(e);
MarinadeStakedex::default()
});

let lido =
init_from_keyed_account_no_params(accounts, &lido_state::ID).unwrap_or_else(|e| {
errs.push(e);
LidoStakedex::default()
});
Expand Down Expand Up @@ -204,19 +205,17 @@ impl Stakedex {

pub fn update(&mut self, account_map: &AccountMap) -> Vec<anyhow::Error> {
// unstake.it special-case: required reinitialization to save sol_reserves_lamports correctly
let maybe_unstake_it_init_err = match init_from_keyed_account_no_params(
account_map,
&unstake_it_program::SOL_RESERVES_ID,
) {
Ok(unstakeit) => {
self.unstakeit = UnstakeItStakedexPrefund(unstakeit);
None
}
Err(e) => Some(e),
};
let maybe_extract_sol_reserves_lamports_err =
match extract_sol_reserves_lamports(&account_map) {
Ok(sol_reserves_lamports) => {
self.unstakeit.0.sol_reserves_lamports = sol_reserves_lamports;
None
}
Err(err) => Some(err),
};

let mut errs = self.update_data(account_map);
if let Some(e) = maybe_unstake_it_init_err {
if let Some(e) = maybe_extract_sol_reserves_lamports_err {
errs.push(e);
}
errs
Expand Down

0 comments on commit 017a220

Please sign in to comment.