From 11506040a302f38301d1adf970491d72bcdfe4e7 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Thu, 14 Mar 2024 20:29:23 -0400 Subject: [PATCH 01/33] manual concat --- common/src/consts.rs | 4 + jup_interface/src/pool_pair/common.rs | 98 +++++++++- jup_interface/src/pool_pair/one_way.rs | 4 +- jup_interface/src/pool_pair/two_way.rs | 6 +- stakedex_sdk/src/lib.rs | 82 +++++++- stakedex_sdk/tests/test_main.rs | 259 +++++++++++++++++++------ 6 files changed, 385 insertions(+), 68 deletions(-) diff --git a/common/src/consts.rs b/common/src/consts.rs index c061346..d8a67c3 100644 --- a/common/src/consts.rs +++ b/common/src/consts.rs @@ -6,6 +6,10 @@ pub const ZERO_DATA_ACC_RENT_EXEMPT_LAMPORTS: u64 = 890_880; pub const DEPOSIT_STAKE_DST_TOKEN_ACCOUNT_INDEX: usize = 4; +pub const PREFUND_WITHDRAW_STAKE_SRC_TOKEN_MINT_IDX: usize = 3; + +pub const DEPOSIT_STAKE_DST_TOKEN_MINT_IDX: usize = 4; + /// Also applies to PrefundSwapViaStake pub const SWAP_VIA_STAKE_SRC_TOKEN_MINT_ACCOUNT_INDEX: usize = 5; diff --git a/jup_interface/src/pool_pair/common.rs b/jup_interface/src/pool_pair/common.rs index e0b0742..4382224 100644 --- a/jup_interface/src/pool_pair/common.rs +++ b/jup_interface/src/pool_pair/common.rs @@ -3,19 +3,111 @@ use jupiter_amm_interface::{Quote, QuoteParams, SwapParams}; use rust_decimal::prelude::*; use solana_sdk::{instruction::AccountMeta, pubkey::Pubkey, stake, system_program, sysvar}; use spl_token::native_mint; -use stakedex_interface::{PrefundSwapViaStakeKeys, PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN}; +use stakedex_interface::{ + DepositStakeKeys, PrefundSwapViaStakeKeys, PrefundWithdrawStakeKeys, + DEPOSIT_STAKE_IX_ACCOUNTS_LEN, PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN, + PREFUND_WITHDRAW_STAKE_IX_ACCOUNTS_LEN, +}; use stakedex_sdk_common::{ apply_global_fee, find_bridge_stake, find_fee_token_acc, slumdog_stake_create_with_seed, stakedex_program, unstake_it_pool, unstake_it_program, DepositStake, DepositStakeInfo, DepositStakeQuote, SwapViaStakeQuoteErr, WithdrawStake, WithdrawStakeQuote, - WithdrawStakeQuoteErr, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS, + WithdrawStakeQuoteErr, DEPOSIT_STAKE_DST_TOKEN_MINT_IDX, + PREFUND_WITHDRAW_STAKE_SRC_TOKEN_MINT_IDX, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS, SWAP_VIA_STAKE_DST_TOKEN_MINT_ACCOUNT_INDEX, SWAP_VIA_STAKE_SRC_TOKEN_MINT_ACCOUNT_INDEX, }; use std::collections::HashSet; use crate::PrefundRepayParams; -pub fn get_account_metas( +pub mod jup_v6_program_id { + solana_sdk::declare_id!("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"); +} + +/// Due to CPI restrictions, PrefundSwapViaStake cannot be CPI'd directly and needs to be +/// split into 2 CPIs. +/// +/// Returns: +/// [ +/// ...PrefundWithdrawStake metas, +/// jup_v6_program_id as separator, +/// ...DepositStake metas +/// ] +pub fn manual_concat_get_account_metas( + swap_params: &SwapParams, + prefund_repay_params: &PrefundRepayParams, + withdraw_from: &W, + deposit_to: &D, + bridge_stake_seed: u32, +) -> Result> { + // TODO: this is doing the same computation as it did in quote, should we cache this somehow? + let prefund_split_lamports = prefund_repay_params.prefund_split_lamports()?; + let (withdraw_quote, deposit_quote) = first_avail_prefund_quote( + swap_params.in_amount, + prefund_split_lamports, + withdraw_from, + deposit_to, + )?; + let bridge_stake_seed_le_bytes = bridge_stake_seed.to_le_bytes(); + let bridge_stake = find_bridge_stake( + &swap_params.token_transfer_authority, + &bridge_stake_seed_le_bytes, + ) + .0; + let slumdog_stake = slumdog_stake_create_with_seed(&bridge_stake)?; + let deposit_stake_info = DepositStakeInfo { addr: bridge_stake }; + let mut prefund_withdraw_prefix = + <[AccountMeta; PREFUND_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]>::from(PrefundWithdrawStakeKeys { + user: swap_params.token_transfer_authority, + src_token_from: swap_params.source_token_account, + bridge_stake, + src_token_mint: swap_params.source_mint, + prefunder: stakedex_program::PREFUNDER_ID, + slumdog_stake, + unstakeit_program: unstake_it_program::ID, + unstake_pool: unstake_it_pool::ID, + pool_sol_reserves: unstake_it_program::SOL_RESERVES_ID, + unstake_fee: unstake_it_program::FEE_ID, + slumdog_stake_acc_record: find_stake_account_record(&slumdog_stake).0, + unstake_protocol_fee: unstake_it_program::PROTOCOL_FEE_ID, + unstake_protocol_fee_dest: prefund_repay_params.protocol_fee_dest, + clock: sysvar::clock::ID, + stake_program: stake::program::ID, + system_program: system_program::ID, + }); + if prefund_withdraw_prefix[PREFUND_WITHDRAW_STAKE_SRC_TOKEN_MINT_IDX].pubkey == native_mint::ID + { + prefund_withdraw_prefix[PREFUND_WITHDRAW_STAKE_SRC_TOKEN_MINT_IDX].is_writable = false; + } + let mut deposit_prefix = + <[AccountMeta; DEPOSIT_STAKE_IX_ACCOUNTS_LEN]>::from(DepositStakeKeys { + user: swap_params.token_transfer_authority, + stake_account: bridge_stake, + dest_token_to: swap_params.destination_token_account, + dest_token_fee_token_account: find_fee_token_acc(&swap_params.destination_mint).0, + dest_token_mint: swap_params.destination_mint, + }); + if deposit_prefix[DEPOSIT_STAKE_DST_TOKEN_MINT_IDX].pubkey == native_mint::ID { + deposit_prefix[DEPOSIT_STAKE_DST_TOKEN_MINT_IDX].is_writable = false; + } + Ok(prefund_withdraw_prefix + .into_iter() + .chain(withdraw_from.virtual_ix(&withdraw_quote)?.accounts) + .chain(std::iter::once(AccountMeta { + pubkey: jup_v6_program_id::ID, + is_signer: false, + is_writable: false, + })) + .chain(deposit_prefix) + .chain( + deposit_to + .virtual_ix(&deposit_quote, &deposit_stake_info)? + .accounts, + ) + .collect()) +} + +pub fn prefund_get_account_metas( swap_params: &SwapParams, prefund_repay_params: &PrefundRepayParams, withdraw_from: &W, diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index a31ca48..dee71a0 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -11,7 +11,7 @@ use stakedex_sdk_common::{ use std::collections::HashSet; use crate::{ - get_account_metas, jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META, + jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META, manual_concat_get_account_metas, prepare_underlying_liquidities, quote_pool_pair, PrefundRepayParams, }; @@ -134,7 +134,7 @@ where fn get_swap_and_account_metas(&self, swap_params: &SwapParams) -> Result { let bridge_stake_seed = rand::random(); let mut account_metas = vec![STAKEDEX_ACCOUNT_META.clone()]; - account_metas.extend(get_account_metas( + account_metas.extend(manual_concat_get_account_metas( swap_params, self.prefund_repay_params_checked()?, &self.withdraw, diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index 4c497ef..8bfa04c 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -11,7 +11,7 @@ use stakedex_sdk_common::{ use std::collections::HashSet; use crate::{ - get_account_metas, jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META, + jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META, manual_concat_get_account_metas, prepare_underlying_liquidities, quote_pool_pair, PrefundRepayParams, }; @@ -141,7 +141,7 @@ where let other_account_metas = if swap_params.source_mint == self.p1.staked_sol_mint() && swap_params.destination_mint == self.p2.staked_sol_mint() { - get_account_metas( + manual_concat_get_account_metas( swap_params, self.prefund_repay_params_checked()?, &self.p1, @@ -151,7 +151,7 @@ where } else if swap_params.source_mint == self.p2.staked_sol_mint() && swap_params.destination_mint == self.p1.staked_sol_mint() { - get_account_metas( + manual_concat_get_account_metas( swap_params, self.prefund_repay_params_checked()?, &self.p2, diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index 5c74336..5da75fb 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -8,12 +8,13 @@ use sanctum_lst_list::{PoolInfo, SanctumLst, SanctumLstList, SplPoolAccounts}; use solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey, system_program}; use spl_token::native_mint; use stakedex_interface::{ - DepositStakeKeys, PrefundSwapViaStakeIxArgs, PrefundSwapViaStakeKeys, StakeWrappedSolIxArgs, + DepositStakeKeys, PrefundSwapViaStakeIxArgs, PrefundSwapViaStakeKeys, + PrefundWithdrawStakeIxArgs, PrefundWithdrawStakeKeys, StakeWrappedSolIxArgs, StakeWrappedSolKeys, SwapViaStakeArgs, }; use stakedex_jup_interface::{ - get_account_metas, quote_pool_pair, DepositSolWrapper, OneWayPoolPair, PrefundRepayParams, - TwoWayPoolPair, + jup_v6_program_id, manual_concat_get_account_metas, prefund_get_account_metas, quote_pool_pair, + DepositSolWrapper, OneWayPoolPair, PrefundRepayParams, TwoWayPoolPair, }; use stakedex_lido::LidoStakedex; use stakedex_marinade::MarinadeStakedex; @@ -281,7 +282,78 @@ impl Stakedex { ) } - pub fn swap_via_stake_ix( + pub fn manual_concat_prefund_swap_via_stake_ixs( + &self, + swap_params: &SwapParams, + bridge_stake_seed: u32, + ) -> Result<[Instruction; 2]> { + let withdraw_from = self + .get_withdraw_stake_pool(&swap_params.source_mint) + .ok_or_else(|| anyhow!("pool not found for src mint {}", swap_params.source_mint))?; + let deposit_to = self + .get_deposit_stake_pool(&swap_params.destination_mint) + .ok_or_else(|| { + anyhow!( + "pool not found for dst mint {}", + swap_params.destination_mint + ) + })?; + let mut prefund_withdraw_stake_ix = stakedex_interface::prefund_withdraw_stake_ix( + // dont cares for keys, since we replace them with + // get_account_metas() + PrefundWithdrawStakeKeys { + user: Pubkey::default(), + src_token_from: Pubkey::default(), + bridge_stake: Pubkey::default(), + src_token_mint: Pubkey::default(), + prefunder: Pubkey::default(), + slumdog_stake: Pubkey::default(), + unstakeit_program: Pubkey::default(), + unstake_pool: Pubkey::default(), + pool_sol_reserves: Pubkey::default(), + unstake_fee: Pubkey::default(), + slumdog_stake_acc_record: Pubkey::default(), + unstake_protocol_fee: Pubkey::default(), + unstake_protocol_fee_dest: Pubkey::default(), + clock: Pubkey::default(), + stake_program: Pubkey::default(), + system_program: Pubkey::default(), + }, + PrefundWithdrawStakeIxArgs { + args: SwapViaStakeArgs { + amount: swap_params.in_amount, + bridge_stake_seed, + }, + }, + )?; + let mut deposit_stake_ix = stakedex_interface::deposit_stake_ix( + // dont cares for keys, since we replace them with + // get_account_metas() + DepositStakeKeys { + user: Pubkey::default(), + stake_account: Pubkey::default(), + dest_token_to: Pubkey::default(), + dest_token_fee_token_account: Pubkey::default(), + dest_token_mint: Pubkey::default(), + }, + )?; + let metas = manual_concat_get_account_metas( + swap_params, + &self.prefund_repay_params(), + withdraw_from, + deposit_to, + bridge_stake_seed, + )?; + let split_at = metas + .iter() + .position(|meta| meta.pubkey == jup_v6_program_id::ID) + .unwrap(); + prefund_withdraw_stake_ix.accounts = metas[..split_at].into(); + deposit_stake_ix.accounts = metas[split_at + 1..].into(); + Ok([prefund_withdraw_stake_ix, deposit_stake_ix]) + } + + pub fn prefund_swap_via_stake_ix( &self, swap_params: &SwapParams, bridge_stake_seed: u32, @@ -329,7 +401,7 @@ impl Stakedex { }, )?; // TODO: this is doing the same computation as it did in quote, should we cache this somehow? - ix.accounts = get_account_metas( + ix.accounts = prefund_get_account_metas( swap_params, &self.prefund_repay_params(), withdraw_from, diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index 9f8e3da..2dc97a2 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -1,4 +1,4 @@ -use jupiter_amm_interface::{QuoteParams, SwapMode, SwapParams}; +use jupiter_amm_interface::{Quote, QuoteParams, SwapMode, SwapParams}; use lazy_static::lazy_static; use solana_account_decoder::UiAccountEncoding; use solana_client::{ @@ -9,6 +9,7 @@ use solana_sdk::{ account::Account, address_lookup_table::{state::AddressLookupTable, AddressLookupTableAccount}, compute_budget, + instruction::Instruction, message::{v0::Message, VersionedMessage}, program_pack::Pack, pubkey::Pubkey, @@ -17,7 +18,7 @@ use solana_sdk::{ use spl_associated_token_account::get_associated_token_address; use spl_token::native_mint; use stakedex_sdk::{srlut, Stakedex, SWAP_VIA_STAKE_COMPUTE_BUDGET_LIMIT}; -use stakedex_sdk_common::{bsol, daosol, jitosol, jsol, msol, pwrsol}; +use stakedex_sdk_common::{bsol, jitosol, jsol, msol, pwrsol}; use std::{cmp, collections::HashMap, iter::zip}; // JSOL whale. Last known balances: @@ -90,7 +91,12 @@ const SMALL_JSOL_SWAP_AMT: u64 = 10_000_000_000; // 10 JSOL #[test] fn test_swap_via_stake_jsol_unstakeit() { - test_swap_via_stake(jsol::ID, native_mint::ID, SMALL_JSOL_SWAP_AMT); + test_prefund_swap_via_stake(jsol::ID, native_mint::ID, SMALL_JSOL_SWAP_AMT); +} + +#[test] +fn test_manual_concat_swap_via_stake_jsol_unstakeit() { + test_manual_concat_prefund_swap_via_stake(jsol::ID, native_mint::ID, SMALL_JSOL_SWAP_AMT); } /* @@ -119,19 +125,37 @@ fn test_swap_via_stake_jsol_cogentsol() { } */ +// jito already tests spl -> spl +/* #[test] fn test_swap_via_stake_jsol_daosol() { - test_swap_via_stake(jsol::ID, daosol::ID, SMALL_JSOL_SWAP_AMT); + test_prefund_swap_via_stake(jsol::ID, daosol::ID, SMALL_JSOL_SWAP_AMT); } +#[test] +fn test_manual_concat_swap_via_stake_jsol_daosol() { + test_manual_concat_prefund_swap_via_stake(jsol::ID, daosol::ID, SMALL_JSOL_SWAP_AMT); +} + */ + #[test] fn test_swap_via_stake_jsol_jitosol() { - test_swap_via_stake(jsol::ID, jitosol::ID, SMALL_JSOL_SWAP_AMT); + test_prefund_swap_via_stake(jsol::ID, jitosol::ID, SMALL_JSOL_SWAP_AMT); +} + +#[test] +fn test_manual_concat_swap_via_stake_jsol_jitosol() { + test_manual_concat_prefund_swap_via_stake(jsol::ID, jitosol::ID, SMALL_JSOL_SWAP_AMT); } #[test] fn test_swap_via_stake_jsol_pwrsol() { - test_swap_via_stake(jsol::ID, pwrsol::ID, SMALL_JSOL_SWAP_AMT); + test_prefund_swap_via_stake(jsol::ID, pwrsol::ID, SMALL_JSOL_SWAP_AMT); +} + +#[test] +fn test_manual_concat_swap_via_stake_jsol_pwrsol() { + test_manual_concat_prefund_swap_via_stake(jsol::ID, pwrsol::ID, SMALL_JSOL_SWAP_AMT); } /* @@ -160,7 +184,12 @@ fn test_swap_via_stake_jsol_scnsol() { #[test] fn test_swap_via_stake_jsol_msol() { - test_swap_via_stake(jsol::ID, msol::ID, SMALL_JSOL_SWAP_AMT); + test_prefund_swap_via_stake(jsol::ID, msol::ID, SMALL_JSOL_SWAP_AMT); +} + +#[test] +fn test_manual_concat_swap_via_stake_jsol_msol() { + test_manual_concat_prefund_swap_via_stake(jsol::ID, msol::ID, SMALL_JSOL_SWAP_AMT); } // scnsol to xsol @@ -230,10 +259,24 @@ fn test_swap_via_stake_scnsol_msol() { */ // Set amount to u64::MAX to swap the entire input ATA balance -fn test_swap_via_stake(input_mint: Pubkey, output_mint: Pubkey, amount: u64) { - sim_swap_via_stake( +fn test_prefund_swap_via_stake(input_mint: Pubkey, output_mint: Pubkey, amount: u64) { + test_sim_prefund_swap_via_stake( + &STAKEDEX, + TestSwapViaStakeArgs { + amount, + input_mint, + output_mint, + signer: whale::ID, + src_token_acc: get_associated_token_address(&whale::ID, &input_mint), + dst_token_acc: get_associated_token_address(&whale::ID, &output_mint), + }, + ); +} + +// Set amount to u64::MAX to swap the entire input ATA balance +fn test_manual_concat_prefund_swap_via_stake(input_mint: Pubkey, output_mint: Pubkey, amount: u64) { + test_sim_manual_concat_prefund_swap_via_stake( &STAKEDEX, - &RPC, TestSwapViaStakeArgs { amount, input_mint, @@ -310,8 +353,9 @@ fn test_jsol_drain_vsa_edge_case() { }, ); } - */ +*/ +#[derive(Clone, Copy, Debug)] pub struct TestSwapViaStakeArgs { pub amount: u64, pub input_mint: Pubkey, @@ -324,9 +368,9 @@ pub struct TestSwapViaStakeArgs { /// - uses min(amount, src_balance) as input amount /// - if dst_token_acc is signer's ATA and doesn't exist, prefixes /// the simulated tx with a create ATA instruction -pub fn sim_swap_via_stake( - stakedex: &Stakedex, - rpc: &RpcClient, +/// +/// Returns (amt_to_swap, prefix_ixs, before_source_amount, before_destination_amount) +fn setup_swap_via_stake( TestSwapViaStakeArgs { amount, input_mint, @@ -335,7 +379,7 @@ pub fn sim_swap_via_stake( src_token_acc, dst_token_acc, }: TestSwapViaStakeArgs, -) { +) -> (u64, Vec, u64, u64) { let source_balance = RPC .get_token_account_balance(&src_token_acc) .map_err(|err| { @@ -352,29 +396,47 @@ pub fn sim_swap_via_stake( compute_budget::ComputeBudgetInstruction::set_compute_unit_price(3), ]); - let (before_destination_amount, mut ixs) = match RPC.get_token_account_balance(&dst_token_acc) { - Ok(b) => (b.amount.parse().unwrap(), ixs), - Err(_e) => { - let ata = get_associated_token_address(&signer, &output_mint); - if dst_token_acc != ata { - panic!("dst_token_acc {dst_token_acc} does not exist and is not ATA"); + let (before_destination_amount, prefix_ixs) = + match RPC.get_token_account_balance(&dst_token_acc) { + Ok(b) => (b.amount.parse().unwrap(), ixs), + Err(_e) => { + let ata = get_associated_token_address(&signer, &output_mint); + if dst_token_acc != ata { + panic!("dst_token_acc {dst_token_acc} does not exist and is not ATA"); + } + ixs.push( + spl_associated_token_account::instruction::create_associated_token_account( + &signer, + &signer, + &output_mint, + // TODO: support token-22 + &spl_token::ID, + ), + ); + (0, ixs) } - ixs.push( - spl_associated_token_account::instruction::create_associated_token_account( - &signer, - &signer, - &output_mint, - // TODO: support token-22 - &spl_token::ID, - ), - ); - (0, ixs) - } - }; + }; let before_source_amount: u64 = source_balance.amount.parse().unwrap(); let amount = cmp::min(before_source_amount, amount); - let quote = match stakedex.quote_swap_via_stake(&QuoteParams { + ( + amount, + prefix_ixs, + before_source_amount, + before_destination_amount, + ) +} + +fn quote_swap_via_stake( + stakedex: &Stakedex, + amount: u64, + TestSwapViaStakeArgs { + input_mint, + output_mint, + .. + }: TestSwapViaStakeArgs, +) -> Quote { + match stakedex.quote_swap_via_stake(&QuoteParams { amount, input_mint, output_mint, @@ -401,28 +463,24 @@ pub fn sim_swap_via_stake( return; */ } - }; + } +} - ixs.push( - stakedex - .swap_via_stake_ix( - &SwapParams { - jupiter_program_id: &jupiter_program::ID, - in_amount: quote.in_amount, - out_amount: quote.out_amount, - destination_mint: output_mint, - source_mint: input_mint, - destination_token_account: dst_token_acc, - source_token_account: src_token_acc, - token_transfer_authority: signer, - open_order_address: None, - quote_mint_to_referrer: None, - }, - 0, - ) - .unwrap(), - ); - let rbh = rpc.get_latest_blockhash().unwrap(); +fn simulate_check_swap_via_stake( + TestSwapViaStakeArgs { + amount, + input_mint, + output_mint, + signer, + src_token_acc, + dst_token_acc, + }: TestSwapViaStakeArgs, + quote: Quote, + ixs: Vec, + before_source_amount: u64, + before_destination_amount: u64, +) { + let rbh = RPC.get_latest_blockhash().unwrap(); let tx = VersionedTransaction { signatures: vec![Default::default()], // for payer message: VersionedMessage::V0( @@ -476,3 +534,94 @@ pub fn sim_swap_via_stake( // presumably due to precision losses in pseudo_reverse() assert_eq!(quote.out_amount, actual_out_amount); } + +pub fn test_sim_prefund_swap_via_stake(stakedex: &Stakedex, args: TestSwapViaStakeArgs) { + let TestSwapViaStakeArgs { + input_mint, + output_mint, + signer, + src_token_acc, + dst_token_acc, + .. + } = args; + + let (amount, mut ixs, before_source_amount, before_destination_amount) = + setup_swap_via_stake(args); + + let quote = quote_swap_via_stake(stakedex, amount, args); + + ixs.push( + stakedex + .prefund_swap_via_stake_ix( + &SwapParams { + jupiter_program_id: &jupiter_program::ID, + in_amount: quote.in_amount, + out_amount: quote.out_amount, + destination_mint: output_mint, + source_mint: input_mint, + destination_token_account: dst_token_acc, + source_token_account: src_token_acc, + token_transfer_authority: signer, + open_order_address: None, + quote_mint_to_referrer: None, + }, + 0, + ) + .unwrap(), + ); + + simulate_check_swap_via_stake( + args, + quote, + ixs, + before_source_amount, + before_destination_amount, + ); +} + +pub fn test_sim_manual_concat_prefund_swap_via_stake( + stakedex: &Stakedex, + args: TestSwapViaStakeArgs, +) { + let TestSwapViaStakeArgs { + input_mint, + output_mint, + signer, + src_token_acc, + dst_token_acc, + .. + } = args; + + let (amount, mut ixs, before_source_amount, before_destination_amount) = + setup_swap_via_stake(args); + + let quote = quote_swap_via_stake(stakedex, amount, args); + + ixs.extend( + stakedex + .manual_concat_prefund_swap_via_stake_ixs( + &SwapParams { + jupiter_program_id: &jupiter_program::ID, + in_amount: quote.in_amount, + out_amount: quote.out_amount, + destination_mint: output_mint, + source_mint: input_mint, + destination_token_account: dst_token_acc, + source_token_account: src_token_acc, + token_transfer_authority: signer, + open_order_address: None, + quote_mint_to_referrer: None, + }, + 0, + ) + .unwrap(), + ); + + simulate_check_swap_via_stake( + args, + quote, + ixs, + before_source_amount, + before_destination_amount, + ); +} From daea7368c2355114963e078520d4c743a7531579 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Fri, 15 Mar 2024 11:04:13 -0400 Subject: [PATCH 02/33] placeholder --- jup_interface/src/pool_pair/common.rs | 10 +--------- stakedex_sdk/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/jup_interface/src/pool_pair/common.rs b/jup_interface/src/pool_pair/common.rs index 4382224..5bb7ff0 100644 --- a/jup_interface/src/pool_pair/common.rs +++ b/jup_interface/src/pool_pair/common.rs @@ -20,10 +20,6 @@ use std::collections::HashSet; use crate::PrefundRepayParams; -pub mod jup_v6_program_id { - solana_sdk::declare_id!("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"); -} - /// Due to CPI restrictions, PrefundSwapViaStake cannot be CPI'd directly and needs to be /// split into 2 CPIs. /// @@ -93,11 +89,7 @@ pub fn manual_concat_get_account_metas Date: Fri, 15 Mar 2024 13:46:34 -0400 Subject: [PATCH 03/33] checked ops --- libs/spl_stake_pool/src/lib.rs | 6 +++++- .../src/stakedex_traits/withdraw_stake.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index 4dd81ff..d5b4547 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -47,7 +47,11 @@ impl SplStakePoolStakedex { validator_index: usize, withdraw_amount: u64, ) -> Result { - let validator_list_entry = self.validator_list.validators.get(validator_index).unwrap(); + let validator_list_entry = self + .validator_list + .validators + .get(validator_index) + .ok_or(StakePoolError::ValidatorNotFound)?; // only handle withdrawal from active stake accounts for simplicity. // Likely other stake pools can't accept non active stake anyway if validator_list_entry.status != StakeStatus::Active.into() { diff --git a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs index bfc9e51..94ac588 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs @@ -30,11 +30,12 @@ impl<'a> WithdrawStakeQuoteIter<'a> { .pool .get_withdraw_stake_quote_for_validator_copied(curr_index, self.withdraw_amount) .unwrap_or_default(); - let next_state = if curr_index >= self.pool.validator_list.validators.len() - 1 { - WithdrawStakeQuoteIterState::Ended - } else { - WithdrawStakeQuoteIterState::Normal(curr_index + 1) - }; + let next_state = + if curr_index >= self.pool.validator_list.validators.len().checked_sub(1)? { + WithdrawStakeQuoteIterState::Ended + } else { + WithdrawStakeQuoteIterState::Normal(curr_index.checked_add(1)?) + }; Some((wsq, next_state)) } From 66499950d0424f952da29de993c99acc559cd71c Mon Sep 17 00:00:00 2001 From: billythedummy Date: Tue, 19 Mar 2024 11:55:27 -0400 Subject: [PATCH 04/33] update sanctum-lst-list, fix clippy warnings for unused imports of trait-only mods --- Cargo.lock | 2 +- Cargo.toml | 2 +- libs/lido/src/stakedex_traits/mod.rs | 1 - libs/marinade/src/lib.rs | 2 -- libs/marinade/src/stakedex_traits/mod.rs | 4 ---- libs/spl_stake_pool/src/lib.rs | 1 - libs/spl_stake_pool/src/stakedex_traits/mod.rs | 5 ----- libs/unstake_it/src/stakedex_traits/base/mod.rs | 3 --- libs/unstake_it/src/stakedex_traits/deposit_stake/mod.rs | 3 --- libs/unstake_it/src/stakedex_traits/mod.rs | 1 - 10 files changed, 2 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e788bfd..e26749a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3124,7 +3124,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "sanctum-lst-list" version = "0.1.0" -source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#e05d193afc6be61235239f32faf8c5e7929c1078" +source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#111f01f26f4a45345976f35cbe7f1cca82e4b66c" dependencies = [ "sanctum-macros", "serde", diff --git a/Cargo.toml b/Cargo.toml index 59dd390..22fce4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ unstake_interface = { git = "https://github.com/igneous-labs/sanctum-unstake-pro unstake-lib = { git = "https://github.com/igneous-labs/sanctum-unstake-program.git", rev = "069f941" } # sanctum solana utils -sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-solana-utils.git", branch = "master" } # rev = "38f9fce" +sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-solana-utils.git", branch = "master" } # rev = "111f01" # solana core crates solana-program = "^1" diff --git a/libs/lido/src/stakedex_traits/mod.rs b/libs/lido/src/stakedex_traits/mod.rs index 8e27440..c951516 100644 --- a/libs/lido/src/stakedex_traits/mod.rs +++ b/libs/lido/src/stakedex_traits/mod.rs @@ -1,5 +1,4 @@ mod base; mod withdraw_stake; -pub use base::*; pub use withdraw_stake::*; diff --git a/libs/marinade/src/lib.rs b/libs/marinade/src/lib.rs index 590e985..61dbe63 100644 --- a/libs/marinade/src/lib.rs +++ b/libs/marinade/src/lib.rs @@ -12,8 +12,6 @@ use marinade_finance_interface::{ }; use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey}; -pub use stakedex_traits::*; - pub const MARINADE_LABEL: &str = "Marinade"; #[derive(Clone)] diff --git a/libs/marinade/src/stakedex_traits/mod.rs b/libs/marinade/src/stakedex_traits/mod.rs index 4114fae..ff0fcde 100644 --- a/libs/marinade/src/stakedex_traits/mod.rs +++ b/libs/marinade/src/stakedex_traits/mod.rs @@ -1,7 +1,3 @@ mod base; mod deposit_sol; mod deposit_stake; - -pub use base::*; -pub use deposit_sol::*; -pub use deposit_stake::*; diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index d5b4547..aff7787 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -8,7 +8,6 @@ use spl_stake_pool::{ use stakedex_sdk_common::{WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS}; mod stakedex_traits; -pub use stakedex_traits::*; /// A SPL stake pool with possibly custom program ID #[derive(Clone, Default)] diff --git a/libs/spl_stake_pool/src/stakedex_traits/mod.rs b/libs/spl_stake_pool/src/stakedex_traits/mod.rs index 1b6161e..6ce232a 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/mod.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/mod.rs @@ -2,8 +2,3 @@ mod base; mod deposit_sol; mod deposit_stake; mod withdraw_stake; - -pub use base::*; -pub use deposit_sol::*; -pub use deposit_stake::*; -pub use withdraw_stake::*; diff --git a/libs/unstake_it/src/stakedex_traits/base/mod.rs b/libs/unstake_it/src/stakedex_traits/base/mod.rs index 7ebc3ea..2892305 100644 --- a/libs/unstake_it/src/stakedex_traits/base/mod.rs +++ b/libs/unstake_it/src/stakedex_traits/base/mod.rs @@ -1,5 +1,2 @@ mod main; mod prefund; - -pub use main::*; -pub use prefund::*; diff --git a/libs/unstake_it/src/stakedex_traits/deposit_stake/mod.rs b/libs/unstake_it/src/stakedex_traits/deposit_stake/mod.rs index feb0bab..4f99d9f 100644 --- a/libs/unstake_it/src/stakedex_traits/deposit_stake/mod.rs +++ b/libs/unstake_it/src/stakedex_traits/deposit_stake/mod.rs @@ -3,6 +3,3 @@ mod main; mod prefund; pub(crate) use common::*; - -pub use main::*; -pub use prefund::*; diff --git a/libs/unstake_it/src/stakedex_traits/mod.rs b/libs/unstake_it/src/stakedex_traits/mod.rs index afc727c..fd92b97 100644 --- a/libs/unstake_it/src/stakedex_traits/mod.rs +++ b/libs/unstake_it/src/stakedex_traits/mod.rs @@ -1,5 +1,4 @@ mod base; mod deposit_stake; -pub use base::*; pub(crate) use deposit_stake::*; From 53957a8cf341772ac7a6abfbbdb7f166beb7bdcd Mon Sep 17 00:00:00 2001 From: billythedummy Date: Sat, 30 Mar 2024 17:04:17 -0400 Subject: [PATCH 05/33] update interface --- .../stakedex_deposit_sol_interface/idl.json | 44 +- .../src/instructions.rs | 501 ++++++-- .../stakedex_deposit_stake_interface/idl.json | 104 +- .../src/instructions.rs | 1108 +++++++++-------- .../idl.json | 88 +- .../src/instructions.rs | 606 ++++----- 6 files changed, 1369 insertions(+), 1082 deletions(-) diff --git a/interfaces/stakedex_deposit_sol_interface/idl.json b/interfaces/stakedex_deposit_sol_interface/idl.json index 510eeb5..69a868e 100644 --- a/interfaces/stakedex_deposit_sol_interface/idl.json +++ b/interfaces/stakedex_deposit_sol_interface/idl.json @@ -48,10 +48,10 @@ } }, { - "name": "SoceanStakePoolDepositSol", + "name": "SplStakePoolDepositSol", "accounts": [ { - "name": "soceanStakePoolProgram", + "name": "splStakePoolProgram", "isMut": false, "isSigner": false }, @@ -74,24 +74,54 @@ "name": "stakePoolManagerFee", "isMut": true, "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 2 + } + }, + { + "name": "SanctumSplStakePoolDepositSol", + "accounts": [ + { + "name": "SanctumSplStakePoolProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakePool", + "isMut": true, + "isSigner": false }, { - "name": "clock", + "name": "stakePoolWithdrawAuthority", "isMut": false, "isSigner": false + }, + { + "name": "stakePoolReserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "stakePoolManagerFee", + "isMut": true, + "isSigner": false } ], "args": [], "discriminant": { "type": "u8", - "value": 1 + "value": 3 } }, { - "name": "SplStakePoolDepositSol", + "name": "SanctumSplMultiStakePoolDepositSol", "accounts": [ { - "name": "splStakePoolProgram", + "name": "SanctumSplMultiStakePoolProgram", "isMut": false, "isSigner": false }, @@ -119,7 +149,7 @@ "args": [], "discriminant": { "type": "u8", - "value": 2 + "value": 4 } } ], diff --git a/interfaces/stakedex_deposit_sol_interface/src/instructions.rs b/interfaces/stakedex_deposit_sol_interface/src/instructions.rs index 6476179..3cf5613 100644 --- a/interfaces/stakedex_deposit_sol_interface/src/instructions.rs +++ b/interfaces/stakedex_deposit_sol_interface/src/instructions.rs @@ -10,8 +10,9 @@ use std::io::Read; #[derive(Clone, Debug, PartialEq)] pub enum StakedexDepositSolProgramIx { MarinadeDepositSol, - SoceanStakePoolDepositSol, SplStakePoolDepositSol, + SanctumSplStakePoolDepositSol, + SanctumSplMultiStakePoolDepositSol, } impl StakedexDepositSolProgramIx { pub fn deserialize(buf: &[u8]) -> std::io::Result { @@ -21,8 +22,11 @@ impl StakedexDepositSolProgramIx { let maybe_discm = maybe_discm_buf[0]; match maybe_discm { MARINADE_DEPOSIT_SOL_IX_DISCM => Ok(Self::MarinadeDepositSol), - SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM => Ok(Self::SoceanStakePoolDepositSol), SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM => Ok(Self::SplStakePoolDepositSol), + SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM => Ok(Self::SanctumSplStakePoolDepositSol), + SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM => { + Ok(Self::SanctumSplMultiStakePoolDepositSol) + } _ => Err(std::io::Error::new( std::io::ErrorKind::Other, format!("discm {:?} not found", maybe_discm), @@ -32,12 +36,15 @@ impl StakedexDepositSolProgramIx { pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { match self { Self::MarinadeDepositSol => writer.write_all(&[MARINADE_DEPOSIT_SOL_IX_DISCM]), - Self::SoceanStakePoolDepositSol => { - writer.write_all(&[SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) - } Self::SplStakePoolDepositSol => { writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) } + Self::SanctumSplStakePoolDepositSol => { + writer.write_all(&[SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) + } + Self::SanctumSplMultiStakePoolDepositSol => { + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) + } } } pub fn try_to_vec(&self) -> std::io::Result> { @@ -297,44 +304,41 @@ pub fn marinade_deposit_sol_verify_account_privileges<'me, 'info>( marinade_deposit_sol_verify_writable_privileges(accounts)?; Ok(()) } -pub const SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 6; +pub const SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 5; #[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolDepositSolAccounts<'me, 'info> { - pub socean_stake_pool_program: &'me AccountInfo<'info>, +pub struct SplStakePoolDepositSolAccounts<'me, 'info> { + pub spl_stake_pool_program: &'me AccountInfo<'info>, pub stake_pool: &'me AccountInfo<'info>, pub stake_pool_withdraw_authority: &'me AccountInfo<'info>, pub stake_pool_reserve_stake: &'me AccountInfo<'info>, pub stake_pool_manager_fee: &'me AccountInfo<'info>, - pub clock: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolDepositSolKeys { - pub socean_stake_pool_program: Pubkey, +pub struct SplStakePoolDepositSolKeys { + pub spl_stake_pool_program: Pubkey, pub stake_pool: Pubkey, pub stake_pool_withdraw_authority: Pubkey, pub stake_pool_reserve_stake: Pubkey, pub stake_pool_manager_fee: Pubkey, - pub clock: Pubkey, } -impl From> for SoceanStakePoolDepositSolKeys { - fn from(accounts: SoceanStakePoolDepositSolAccounts) -> Self { +impl From> for SplStakePoolDepositSolKeys { + fn from(accounts: SplStakePoolDepositSolAccounts) -> Self { Self { - socean_stake_pool_program: *accounts.socean_stake_pool_program.key, + spl_stake_pool_program: *accounts.spl_stake_pool_program.key, stake_pool: *accounts.stake_pool.key, stake_pool_withdraw_authority: *accounts.stake_pool_withdraw_authority.key, stake_pool_reserve_stake: *accounts.stake_pool_reserve_stake.key, stake_pool_manager_fee: *accounts.stake_pool_manager_fee.key, - clock: *accounts.clock.key, } } } -impl From - for [AccountMeta; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +impl From + for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] { - fn from(keys: SoceanStakePoolDepositSolKeys) -> Self { + fn from(keys: SplStakePoolDepositSolKeys) -> Self { [ AccountMeta { - pubkey: keys.socean_stake_pool_program, + pubkey: keys.spl_stake_pool_program, is_signer: false, is_writable: false, }, @@ -358,78 +362,292 @@ impl From is_signer: false, is_writable: true, }, + ] + } +} +impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> for SplStakePoolDepositSolKeys { + fn from(pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { + Self { + spl_stake_pool_program: pubkeys[0], + stake_pool: pubkeys[1], + stake_pool_withdraw_authority: pubkeys[2], + stake_pool_reserve_stake: pubkeys[3], + stake_pool_manager_fee: pubkeys[4], + } + } +} +impl<'info> From> + for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +{ + fn from(accounts: SplStakePoolDepositSolAccounts<'_, 'info>) -> Self { + [ + accounts.spl_stake_pool_program.clone(), + accounts.stake_pool.clone(), + accounts.stake_pool_withdraw_authority.clone(), + accounts.stake_pool_reserve_stake.clone(), + accounts.stake_pool_manager_fee.clone(), + ] + } +} +impl<'me, 'info> From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositSolAccounts<'me, 'info> +{ + fn from(arr: &'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { + Self { + spl_stake_pool_program: &arr[0], + stake_pool: &arr[1], + stake_pool_withdraw_authority: &arr[2], + stake_pool_reserve_stake: &arr[3], + stake_pool_manager_fee: &arr[4], + } + } +} +pub const SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM: u8 = 2u8; +#[derive(Clone, Debug, PartialEq)] +pub struct SplStakePoolDepositSolIxData; +impl SplStakePoolDepositSolIxData { + pub fn deserialize(buf: &[u8]) -> std::io::Result { + let mut reader = buf; + let mut maybe_discm_buf = [0u8; 1]; + reader.read_exact(&mut maybe_discm_buf)?; + let maybe_discm = maybe_discm_buf[0]; + if maybe_discm != SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!( + "discm does not match. Expected: {:?}. Received: {:?}", + SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM, maybe_discm + ), + )); + } + Ok(Self) + } + pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) + } + pub fn try_to_vec(&self) -> std::io::Result> { + let mut data = Vec::new(); + self.serialize(&mut data)?; + Ok(data) + } +} +pub fn spl_stake_pool_deposit_sol_ix_with_program_id( + program_id: Pubkey, + keys: SplStakePoolDepositSolKeys, +) -> std::io::Result { + let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = keys.into(); + Ok(Instruction { + program_id, + accounts: Vec::from(metas), + data: SplStakePoolDepositSolIxData.try_to_vec()?, + }) +} +pub fn spl_stake_pool_deposit_sol_ix( + keys: SplStakePoolDepositSolKeys, +) -> std::io::Result { + spl_stake_pool_deposit_sol_ix_with_program_id(crate::ID, keys) +} +pub fn spl_stake_pool_deposit_sol_invoke_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositSolAccounts<'_, '_>, +) -> ProgramResult { + let keys: SplStakePoolDepositSolKeys = accounts.into(); + let ix = spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + invoke_instruction(&ix, accounts) +} +pub fn spl_stake_pool_deposit_sol_invoke( + accounts: SplStakePoolDepositSolAccounts<'_, '_>, +) -> ProgramResult { + spl_stake_pool_deposit_sol_invoke_with_program_id(crate::ID, accounts) +} +pub fn spl_stake_pool_deposit_sol_invoke_signed_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositSolAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + let keys: SplStakePoolDepositSolKeys = accounts.into(); + let ix = spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + invoke_instruction_signed(&ix, accounts, seeds) +} +pub fn spl_stake_pool_deposit_sol_invoke_signed( + accounts: SplStakePoolDepositSolAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + spl_stake_pool_deposit_sol_invoke_signed_with_program_id(crate::ID, accounts, seeds) +} +pub fn spl_stake_pool_deposit_sol_verify_account_keys( + accounts: SplStakePoolDepositSolAccounts<'_, '_>, + keys: SplStakePoolDepositSolKeys, +) -> Result<(), (Pubkey, Pubkey)> { + for (actual, expected) in [ + ( + accounts.spl_stake_pool_program.key, + &keys.spl_stake_pool_program, + ), + (accounts.stake_pool.key, &keys.stake_pool), + ( + accounts.stake_pool_withdraw_authority.key, + &keys.stake_pool_withdraw_authority, + ), + ( + accounts.stake_pool_reserve_stake.key, + &keys.stake_pool_reserve_stake, + ), + ( + accounts.stake_pool_manager_fee.key, + &keys.stake_pool_manager_fee, + ), + ] { + if actual != expected { + return Err((*actual, *expected)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( + accounts: SplStakePoolDepositSolAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + for should_be_writable in [ + accounts.stake_pool, + accounts.stake_pool_reserve_stake, + accounts.stake_pool_manager_fee, + ] { + if !should_be_writable.is_writable { + return Err((should_be_writable, ProgramError::InvalidAccountData)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_sol_verify_account_privileges<'me, 'info>( + accounts: SplStakePoolDepositSolAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + spl_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; + Ok(()) +} +pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 5; +#[derive(Copy, Clone, Debug)] +pub struct SanctumSplStakePoolDepositSolAccounts<'me, 'info> { + pub sanctum_spl_stake_pool_program: &'me AccountInfo<'info>, + pub stake_pool: &'me AccountInfo<'info>, + pub stake_pool_withdraw_authority: &'me AccountInfo<'info>, + pub stake_pool_reserve_stake: &'me AccountInfo<'info>, + pub stake_pool_manager_fee: &'me AccountInfo<'info>, +} +#[derive(Copy, Clone, Debug)] +pub struct SanctumSplStakePoolDepositSolKeys { + pub sanctum_spl_stake_pool_program: Pubkey, + pub stake_pool: Pubkey, + pub stake_pool_withdraw_authority: Pubkey, + pub stake_pool_reserve_stake: Pubkey, + pub stake_pool_manager_fee: Pubkey, +} +impl From> for SanctumSplStakePoolDepositSolKeys { + fn from(accounts: SanctumSplStakePoolDepositSolAccounts) -> Self { + Self { + sanctum_spl_stake_pool_program: *accounts.sanctum_spl_stake_pool_program.key, + stake_pool: *accounts.stake_pool.key, + stake_pool_withdraw_authority: *accounts.stake_pool_withdraw_authority.key, + stake_pool_reserve_stake: *accounts.stake_pool_reserve_stake.key, + stake_pool_manager_fee: *accounts.stake_pool_manager_fee.key, + } + } +} +impl From + for [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +{ + fn from(keys: SanctumSplStakePoolDepositSolKeys) -> Self { + [ AccountMeta { - pubkey: keys.clock, + pubkey: keys.sanctum_spl_stake_pool_program, is_signer: false, is_writable: false, }, + AccountMeta { + pubkey: keys.stake_pool, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.stake_pool_withdraw_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_pool_reserve_stake, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.stake_pool_manager_fee, + is_signer: false, + is_writable: true, + }, ] } } -impl From<[Pubkey; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> - for SoceanStakePoolDepositSolKeys +impl From<[Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SanctumSplStakePoolDepositSolKeys { - fn from(pubkeys: [Pubkey; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { + fn from(pubkeys: [Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { Self { - socean_stake_pool_program: pubkeys[0], + sanctum_spl_stake_pool_program: pubkeys[0], stake_pool: pubkeys[1], stake_pool_withdraw_authority: pubkeys[2], stake_pool_reserve_stake: pubkeys[3], stake_pool_manager_fee: pubkeys[4], - clock: pubkeys[5], } } } -impl<'info> From> - for [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] { - fn from(accounts: SoceanStakePoolDepositSolAccounts<'_, 'info>) -> Self { + fn from(accounts: SanctumSplStakePoolDepositSolAccounts<'_, 'info>) -> Self { [ - accounts.socean_stake_pool_program.clone(), + accounts.sanctum_spl_stake_pool_program.clone(), accounts.stake_pool.clone(), accounts.stake_pool_withdraw_authority.clone(), accounts.stake_pool_reserve_stake.clone(), accounts.stake_pool_manager_fee.clone(), - accounts.clock.clone(), ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> - for SoceanStakePoolDepositSolAccounts<'me, 'info> +impl<'me, 'info> From<&'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SanctumSplStakePoolDepositSolAccounts<'me, 'info> { - fn from(arr: &'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { + fn from( + arr: &'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN], + ) -> Self { Self { - socean_stake_pool_program: &arr[0], + sanctum_spl_stake_pool_program: &arr[0], stake_pool: &arr[1], stake_pool_withdraw_authority: &arr[2], stake_pool_reserve_stake: &arr[3], stake_pool_manager_fee: &arr[4], - clock: &arr[5], } } } -pub const SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM: u8 = 1u8; +pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM: u8 = 3u8; #[derive(Clone, Debug, PartialEq)] -pub struct SoceanStakePoolDepositSolIxData; -impl SoceanStakePoolDepositSolIxData { +pub struct SanctumSplStakePoolDepositSolIxData; +impl SanctumSplStakePoolDepositSolIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM { + if maybe_discm != SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM, maybe_discm + SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) + writer.write_all(&[SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -437,58 +655,58 @@ impl SoceanStakePoolDepositSolIxData { Ok(data) } } -pub fn socean_stake_pool_deposit_sol_ix_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_sol_ix_with_program_id( program_id: Pubkey, - keys: SoceanStakePoolDepositSolKeys, + keys: SanctumSplStakePoolDepositSolKeys, ) -> std::io::Result { - let metas: [AccountMeta; SOCEAN_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: SoceanStakePoolDepositSolIxData.try_to_vec()?, + data: SanctumSplStakePoolDepositSolIxData.try_to_vec()?, }) } -pub fn socean_stake_pool_deposit_sol_ix( - keys: SoceanStakePoolDepositSolKeys, +pub fn sanctum_spl_stake_pool_deposit_sol_ix( + keys: SanctumSplStakePoolDepositSolKeys, ) -> std::io::Result { - socean_stake_pool_deposit_sol_ix_with_program_id(crate::ID, keys) + sanctum_spl_stake_pool_deposit_sol_ix_with_program_id(crate::ID, keys) } -pub fn socean_stake_pool_deposit_sol_invoke_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_sol_invoke_with_program_id( program_id: Pubkey, - accounts: SoceanStakePoolDepositSolAccounts<'_, '_>, + accounts: SanctumSplStakePoolDepositSolAccounts<'_, '_>, ) -> ProgramResult { - let keys: SoceanStakePoolDepositSolKeys = accounts.into(); - let ix = socean_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplStakePoolDepositSolKeys = accounts.into(); + let ix = sanctum_spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn socean_stake_pool_deposit_sol_invoke( - accounts: SoceanStakePoolDepositSolAccounts<'_, '_>, +pub fn sanctum_spl_stake_pool_deposit_sol_invoke( + accounts: SanctumSplStakePoolDepositSolAccounts<'_, '_>, ) -> ProgramResult { - socean_stake_pool_deposit_sol_invoke_with_program_id(crate::ID, accounts) + sanctum_spl_stake_pool_deposit_sol_invoke_with_program_id(crate::ID, accounts) } -pub fn socean_stake_pool_deposit_sol_invoke_signed_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_sol_invoke_signed_with_program_id( program_id: Pubkey, - accounts: SoceanStakePoolDepositSolAccounts<'_, '_>, + accounts: SanctumSplStakePoolDepositSolAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: SoceanStakePoolDepositSolKeys = accounts.into(); - let ix = socean_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplStakePoolDepositSolKeys = accounts.into(); + let ix = sanctum_spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn socean_stake_pool_deposit_sol_invoke_signed( - accounts: SoceanStakePoolDepositSolAccounts<'_, '_>, +pub fn sanctum_spl_stake_pool_deposit_sol_invoke_signed( + accounts: SanctumSplStakePoolDepositSolAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - socean_stake_pool_deposit_sol_invoke_signed_with_program_id(crate::ID, accounts, seeds) + sanctum_spl_stake_pool_deposit_sol_invoke_signed_with_program_id(crate::ID, accounts, seeds) } -pub fn socean_stake_pool_deposit_sol_verify_account_keys( - accounts: SoceanStakePoolDepositSolAccounts<'_, '_>, - keys: SoceanStakePoolDepositSolKeys, +pub fn sanctum_spl_stake_pool_deposit_sol_verify_account_keys( + accounts: SanctumSplStakePoolDepositSolAccounts<'_, '_>, + keys: SanctumSplStakePoolDepositSolKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ ( - accounts.socean_stake_pool_program.key, - &keys.socean_stake_pool_program, + accounts.sanctum_spl_stake_pool_program.key, + &keys.sanctum_spl_stake_pool_program, ), (accounts.stake_pool.key, &keys.stake_pool), ( @@ -503,7 +721,6 @@ pub fn socean_stake_pool_deposit_sol_verify_account_keys( accounts.stake_pool_manager_fee.key, &keys.stake_pool_manager_fee, ), - (accounts.clock.key, &keys.clock), ] { if actual != expected { return Err((*actual, *expected)); @@ -511,8 +728,8 @@ pub fn socean_stake_pool_deposit_sol_verify_account_keys( } Ok(()) } -pub fn socean_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( - accounts: SoceanStakePoolDepositSolAccounts<'me, 'info>, +pub fn sanctum_spl_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( + accounts: SanctumSplStakePoolDepositSolAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ accounts.stake_pool, @@ -525,33 +742,37 @@ pub fn socean_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn socean_stake_pool_deposit_sol_verify_account_privileges<'me, 'info>( - accounts: SoceanStakePoolDepositSolAccounts<'me, 'info>, +pub fn sanctum_spl_stake_pool_deposit_sol_verify_account_privileges<'me, 'info>( + accounts: SanctumSplStakePoolDepositSolAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - socean_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; + sanctum_spl_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; Ok(()) } -pub const SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 5; +pub const SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 5; #[derive(Copy, Clone, Debug)] -pub struct SplStakePoolDepositSolAccounts<'me, 'info> { - pub spl_stake_pool_program: &'me AccountInfo<'info>, +pub struct SanctumSplMultiStakePoolDepositSolAccounts<'me, 'info> { + pub sanctum_spl_multi_stake_pool_program: &'me AccountInfo<'info>, pub stake_pool: &'me AccountInfo<'info>, pub stake_pool_withdraw_authority: &'me AccountInfo<'info>, pub stake_pool_reserve_stake: &'me AccountInfo<'info>, pub stake_pool_manager_fee: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct SplStakePoolDepositSolKeys { - pub spl_stake_pool_program: Pubkey, +pub struct SanctumSplMultiStakePoolDepositSolKeys { + pub sanctum_spl_multi_stake_pool_program: Pubkey, pub stake_pool: Pubkey, pub stake_pool_withdraw_authority: Pubkey, pub stake_pool_reserve_stake: Pubkey, pub stake_pool_manager_fee: Pubkey, } -impl From> for SplStakePoolDepositSolKeys { - fn from(accounts: SplStakePoolDepositSolAccounts) -> Self { +impl From> + for SanctumSplMultiStakePoolDepositSolKeys +{ + fn from(accounts: SanctumSplMultiStakePoolDepositSolAccounts) -> Self { Self { - spl_stake_pool_program: *accounts.spl_stake_pool_program.key, + sanctum_spl_multi_stake_pool_program: *accounts + .sanctum_spl_multi_stake_pool_program + .key, stake_pool: *accounts.stake_pool.key, stake_pool_withdraw_authority: *accounts.stake_pool_withdraw_authority.key, stake_pool_reserve_stake: *accounts.stake_pool_reserve_stake.key, @@ -559,13 +780,13 @@ impl From> for SplStakePoolDepositSolKeys } } } -impl From - for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +impl From + for [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] { - fn from(keys: SplStakePoolDepositSolKeys) -> Self { + fn from(keys: SanctumSplMultiStakePoolDepositSolKeys) -> Self { [ AccountMeta { - pubkey: keys.spl_stake_pool_program, + pubkey: keys.sanctum_spl_multi_stake_pool_program, is_signer: false, is_writable: false, }, @@ -592,10 +813,12 @@ impl From ] } } -impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> for SplStakePoolDepositSolKeys { - fn from(pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { +impl From<[Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolDepositSolKeys +{ + fn from(pubkeys: [Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { Self { - spl_stake_pool_program: pubkeys[0], + sanctum_spl_multi_stake_pool_program: pubkeys[0], stake_pool: pubkeys[1], stake_pool_withdraw_authority: pubkeys[2], stake_pool_reserve_stake: pubkeys[3], @@ -603,12 +826,12 @@ impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> for SplStakePool } } } -impl<'info> From> - for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] { - fn from(accounts: SplStakePoolDepositSolAccounts<'_, 'info>) -> Self { + fn from(accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, 'info>) -> Self { [ - accounts.spl_stake_pool_program.clone(), + accounts.sanctum_spl_multi_stake_pool_program.clone(), accounts.stake_pool.clone(), accounts.stake_pool_withdraw_authority.clone(), accounts.stake_pool_reserve_stake.clone(), @@ -616,12 +839,15 @@ impl<'info> From> ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> - for SplStakePoolDepositSolAccounts<'me, 'info> +impl<'me, 'info> + From<&'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolDepositSolAccounts<'me, 'info> { - fn from(arr: &'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN]) -> Self { + fn from( + arr: &'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN], + ) -> Self { Self { - spl_stake_pool_program: &arr[0], + sanctum_spl_multi_stake_pool_program: &arr[0], stake_pool: &arr[1], stake_pool_withdraw_authority: &arr[2], stake_pool_reserve_stake: &arr[3], @@ -629,28 +855,28 @@ impl<'me, 'info> From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_SOL_IX_AC } } } -pub const SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM: u8 = 2u8; +pub const SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM: u8 = 4u8; #[derive(Clone, Debug, PartialEq)] -pub struct SplStakePoolDepositSolIxData; -impl SplStakePoolDepositSolIxData { +pub struct SanctumSplMultiStakePoolDepositSolIxData; +impl SanctumSplMultiStakePoolDepositSolIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM { + if maybe_discm != SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM, maybe_discm + SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -658,58 +884,63 @@ impl SplStakePoolDepositSolIxData { Ok(data) } } -pub fn spl_stake_pool_deposit_sol_ix_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_sol_ix_with_program_id( program_id: Pubkey, - keys: SplStakePoolDepositSolKeys, + keys: SanctumSplMultiStakePoolDepositSolKeys, ) -> std::io::Result { - let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = + keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: SplStakePoolDepositSolIxData.try_to_vec()?, + data: SanctumSplMultiStakePoolDepositSolIxData.try_to_vec()?, }) } -pub fn spl_stake_pool_deposit_sol_ix( - keys: SplStakePoolDepositSolKeys, +pub fn sanctum_spl_multi_stake_pool_deposit_sol_ix( + keys: SanctumSplMultiStakePoolDepositSolKeys, ) -> std::io::Result { - spl_stake_pool_deposit_sol_ix_with_program_id(crate::ID, keys) + sanctum_spl_multi_stake_pool_deposit_sol_ix_with_program_id(crate::ID, keys) } -pub fn spl_stake_pool_deposit_sol_invoke_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_sol_invoke_with_program_id( program_id: Pubkey, - accounts: SplStakePoolDepositSolAccounts<'_, '_>, + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, '_>, ) -> ProgramResult { - let keys: SplStakePoolDepositSolKeys = accounts.into(); - let ix = spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplMultiStakePoolDepositSolKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn spl_stake_pool_deposit_sol_invoke( - accounts: SplStakePoolDepositSolAccounts<'_, '_>, +pub fn sanctum_spl_multi_stake_pool_deposit_sol_invoke( + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, '_>, ) -> ProgramResult { - spl_stake_pool_deposit_sol_invoke_with_program_id(crate::ID, accounts) + sanctum_spl_multi_stake_pool_deposit_sol_invoke_with_program_id(crate::ID, accounts) } -pub fn spl_stake_pool_deposit_sol_invoke_signed_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_sol_invoke_signed_with_program_id( program_id: Pubkey, - accounts: SplStakePoolDepositSolAccounts<'_, '_>, + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: SplStakePoolDepositSolKeys = accounts.into(); - let ix = spl_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplMultiStakePoolDepositSolKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_deposit_sol_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn spl_stake_pool_deposit_sol_invoke_signed( - accounts: SplStakePoolDepositSolAccounts<'_, '_>, +pub fn sanctum_spl_multi_stake_pool_deposit_sol_invoke_signed( + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - spl_stake_pool_deposit_sol_invoke_signed_with_program_id(crate::ID, accounts, seeds) -} -pub fn spl_stake_pool_deposit_sol_verify_account_keys( - accounts: SplStakePoolDepositSolAccounts<'_, '_>, - keys: SplStakePoolDepositSolKeys, + sanctum_spl_multi_stake_pool_deposit_sol_invoke_signed_with_program_id( + crate::ID, + accounts, + seeds, + ) +} +pub fn sanctum_spl_multi_stake_pool_deposit_sol_verify_account_keys( + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'_, '_>, + keys: SanctumSplMultiStakePoolDepositSolKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ ( - accounts.spl_stake_pool_program.key, - &keys.spl_stake_pool_program, + accounts.sanctum_spl_multi_stake_pool_program.key, + &keys.sanctum_spl_multi_stake_pool_program, ), (accounts.stake_pool.key, &keys.stake_pool), ( @@ -731,8 +962,8 @@ pub fn spl_stake_pool_deposit_sol_verify_account_keys( } Ok(()) } -pub fn spl_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( - accounts: SplStakePoolDepositSolAccounts<'me, 'info>, +pub fn sanctum_spl_multi_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ accounts.stake_pool, @@ -745,9 +976,9 @@ pub fn spl_stake_pool_deposit_sol_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn spl_stake_pool_deposit_sol_verify_account_privileges<'me, 'info>( - accounts: SplStakePoolDepositSolAccounts<'me, 'info>, +pub fn sanctum_spl_multi_stake_pool_deposit_sol_verify_account_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolDepositSolAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - spl_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; + sanctum_spl_multi_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; Ok(()) } diff --git a/interfaces/stakedex_deposit_stake_interface/idl.json b/interfaces/stakedex_deposit_stake_interface/idl.json index 2948130..aad877c 100644 --- a/interfaces/stakedex_deposit_stake_interface/idl.json +++ b/interfaces/stakedex_deposit_stake_interface/idl.json @@ -3,10 +3,10 @@ "name": "stakedex_deposit_stake", "instructions": [ { - "name": "SoceanStakePoolDepositStake", + "name": "SplStakePoolDepositStake", "accounts": [ { - "name": "soceanStakePoolProgram", + "name": "splStakePoolProgram", "isMut": false, "isSigner": false }, @@ -69,19 +69,19 @@ "args": [], "discriminant": { "type": "u8", - "value": 0 + "value": 1 } }, { - "name": "SplStakePoolDepositStake", + "name": "MarinadeDepositStake", "accounts": [ { - "name": "splStakePoolProgram", + "name": "marinadeProgram", "isMut": false, "isSigner": false }, { - "name": "depositStakeSplStakePool", + "name": "depositStakeMarinadeState", "isMut": true, "isSigner": false }, @@ -91,37 +91,32 @@ "isSigner": false }, { - "name": "depositStakeDepositAuthority", - "isMut": false, - "isSigner": false - }, - { - "name": "depositStakeWithdrawAuthority", - "isMut": false, + "name": "depositStakeStakeList", + "isMut": true, "isSigner": false }, { - "name": "depositStakeValidatorStake", + "name": "depositStakeDuplicationFlag", "isMut": true, "isSigner": false }, { - "name": "depositStakeReserveStake", - "isMut": true, + "name": "depositStakeMsolMintAuth", + "isMut": false, "isSigner": false }, { - "name": "depositStakeManagerFee", - "isMut": true, + "name": "clock", + "isMut": false, "isSigner": false }, { - "name": "clock", + "name": "rent", "isMut": false, "isSigner": false }, { - "name": "stakeHistory", + "name": "systemProgram", "isMut": false, "isSigner": false }, @@ -139,64 +134,64 @@ "args": [], "discriminant": { "type": "u8", - "value": 1 + "value": 2 } }, { - "name": "MarinadeDepositStake", + "name": "UnstakeItDepositStake", "accounts": [ { - "name": "marinadeProgram", + "name": "unstakeitProgram", "isMut": false, "isSigner": false }, { - "name": "depositStakeMarinadeState", + "name": "depositStakeUnstakePool", "isMut": true, "isSigner": false }, { - "name": "depositStakeValidatorList", + "name": "depositStakePoolSolReserves", "isMut": true, "isSigner": false }, { - "name": "depositStakeStakeList", - "isMut": true, + "name": "depositStakeUnstakeFee", + "isMut": false, "isSigner": false }, { - "name": "depositStakeDuplicationFlag", + "name": "depositStakeStakeAccRecord", "isMut": true, "isSigner": false }, { - "name": "depositStakeMsolMintAuth", + "name": "depositStakeProtocolFee", "isMut": false, "isSigner": false }, { - "name": "clock", - "isMut": false, + "name": "depositStakeProtocolFeeDest", + "isMut": true, "isSigner": false }, { - "name": "rent", + "name": "clock", "isMut": false, "isSigner": false }, { - "name": "systemProgram", + "name": "stakeProgram", "isMut": false, "isSigner": false }, { - "name": "tokenProgram", + "name": "systemProgram", "isMut": false, "isSigner": false }, { - "name": "stakeProgram", + "name": "tokenProgram", "isMut": false, "isSigner": false } @@ -204,44 +199,49 @@ "args": [], "discriminant": { "type": "u8", - "value": 2 + "value": 3 } }, { - "name": "UnstakeItDepositStake", + "name": "SanctumSplStakePoolDepositStake", "accounts": [ { - "name": "unstakeitProgram", + "name": "sanctumSplStakePoolProgram", "isMut": false, "isSigner": false }, { - "name": "depositStakeUnstakePool", + "name": "depositStakeSplStakePool", "isMut": true, "isSigner": false }, { - "name": "depositStakePoolSolReserves", + "name": "depositStakeValidatorList", "isMut": true, "isSigner": false }, { - "name": "depositStakeUnstakeFee", + "name": "depositStakeDepositAuthority", "isMut": false, "isSigner": false }, { - "name": "depositStakeStakeAccRecord", + "name": "depositStakeWithdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "depositStakeValidatorStake", "isMut": true, "isSigner": false }, { - "name": "depositStakeProtocolFee", - "isMut": false, + "name": "depositStakeReserveStake", + "isMut": true, "isSigner": false }, { - "name": "depositStakeProtocolFeeDest", + "name": "depositStakeManagerFee", "isMut": true, "isSigner": false }, @@ -251,17 +251,17 @@ "isSigner": false }, { - "name": "stakeProgram", + "name": "stakeHistory", "isMut": false, "isSigner": false }, { - "name": "systemProgram", + "name": "tokenProgram", "isMut": false, "isSigner": false }, { - "name": "tokenProgram", + "name": "stakeProgram", "isMut": false, "isSigner": false } @@ -269,14 +269,14 @@ "args": [], "discriminant": { "type": "u8", - "value": 3 + "value": 4 } }, { - "name": "SanctumSplStakePoolDepositStake", + "name": "SanctumSplMultiStakePoolDepositStake", "accounts": [ { - "name": "sanctumSplStakePoolProgram", + "name": "sanctumSplMultiStakePoolProgram", "isMut": false, "isSigner": false }, @@ -339,7 +339,7 @@ "args": [], "discriminant": { "type": "u8", - "value": 4 + "value": 5 } } ], diff --git a/interfaces/stakedex_deposit_stake_interface/src/instructions.rs b/interfaces/stakedex_deposit_stake_interface/src/instructions.rs index 5ca5aa0..f0494f6 100644 --- a/interfaces/stakedex_deposit_stake_interface/src/instructions.rs +++ b/interfaces/stakedex_deposit_stake_interface/src/instructions.rs @@ -9,11 +9,11 @@ use solana_program::{ use std::io::Read; #[derive(Clone, Debug, PartialEq)] pub enum StakedexDepositStakeProgramIx { - SoceanStakePoolDepositStake, SplStakePoolDepositStake, MarinadeDepositStake, UnstakeItDepositStake, SanctumSplStakePoolDepositStake, + SanctumSplMultiStakePoolDepositStake, } impl StakedexDepositStakeProgramIx { pub fn deserialize(buf: &[u8]) -> std::io::Result { @@ -22,13 +22,15 @@ impl StakedexDepositStakeProgramIx { reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; match maybe_discm { - SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM => Ok(Self::SoceanStakePoolDepositStake), SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM => Ok(Self::SplStakePoolDepositStake), MARINADE_DEPOSIT_STAKE_IX_DISCM => Ok(Self::MarinadeDepositStake), UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM => Ok(Self::UnstakeItDepositStake), SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM => { Ok(Self::SanctumSplStakePoolDepositStake) } + SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM => { + Ok(Self::SanctumSplMultiStakePoolDepositStake) + } _ => Err(std::io::Error::new( std::io::ErrorKind::Other, format!("discm {:?} not found", maybe_discm), @@ -37,9 +39,6 @@ impl StakedexDepositStakeProgramIx { } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { match self { - Self::SoceanStakePoolDepositStake => { - writer.write_all(&[SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) - } Self::SplStakePoolDepositStake => { writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } @@ -48,6 +47,9 @@ impl StakedexDepositStakeProgramIx { Self::SanctumSplStakePoolDepositStake => { writer.write_all(&[SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } + Self::SanctumSplMultiStakePoolDepositStake => { + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) + } } } pub fn try_to_vec(&self) -> std::io::Result> { @@ -71,10 +73,10 @@ fn invoke_instruction_signed<'info, A: Into<[AccountInfo<'info>; N]>, const N: u let account_info: [AccountInfo<'info>; N] = accounts.into(); invoke_signed(ix, &account_info, seeds) } -pub const SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; +pub const SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; #[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolDepositStakeAccounts<'me, 'info> { - pub socean_stake_pool_program: &'me AccountInfo<'info>, +pub struct SplStakePoolDepositStakeAccounts<'me, 'info> { + pub spl_stake_pool_program: &'me AccountInfo<'info>, pub deposit_stake_spl_stake_pool: &'me AccountInfo<'info>, pub deposit_stake_validator_list: &'me AccountInfo<'info>, pub deposit_stake_deposit_authority: &'me AccountInfo<'info>, @@ -88,8 +90,8 @@ pub struct SoceanStakePoolDepositStakeAccounts<'me, 'info> { pub stake_program: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolDepositStakeKeys { - pub socean_stake_pool_program: Pubkey, +pub struct SplStakePoolDepositStakeKeys { + pub spl_stake_pool_program: Pubkey, pub deposit_stake_spl_stake_pool: Pubkey, pub deposit_stake_validator_list: Pubkey, pub deposit_stake_deposit_authority: Pubkey, @@ -102,10 +104,10 @@ pub struct SoceanStakePoolDepositStakeKeys { pub token_program: Pubkey, pub stake_program: Pubkey, } -impl From> for SoceanStakePoolDepositStakeKeys { - fn from(accounts: SoceanStakePoolDepositStakeAccounts) -> Self { +impl From> for SplStakePoolDepositStakeKeys { + fn from(accounts: SplStakePoolDepositStakeAccounts) -> Self { Self { - socean_stake_pool_program: *accounts.socean_stake_pool_program.key, + spl_stake_pool_program: *accounts.spl_stake_pool_program.key, deposit_stake_spl_stake_pool: *accounts.deposit_stake_spl_stake_pool.key, deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, deposit_stake_deposit_authority: *accounts.deposit_stake_deposit_authority.key, @@ -120,13 +122,13 @@ impl From> for SoceanStakePoolDeposi } } } -impl From - for [AccountMeta; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl From + for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(keys: SoceanStakePoolDepositStakeKeys) -> Self { + fn from(keys: SplStakePoolDepositStakeKeys) -> Self { [ AccountMeta { - pubkey: keys.socean_stake_pool_program, + pubkey: keys.spl_stake_pool_program, is_signer: false, is_writable: false, }, @@ -188,12 +190,10 @@ impl From ] } } -impl From<[Pubkey; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for SoceanStakePoolDepositStakeKeys -{ - fn from(pubkeys: [Pubkey; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { +impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for SplStakePoolDepositStakeKeys { + fn from(pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - socean_stake_pool_program: pubkeys[0], + spl_stake_pool_program: pubkeys[0], deposit_stake_spl_stake_pool: pubkeys[1], deposit_stake_validator_list: pubkeys[2], deposit_stake_deposit_authority: pubkeys[3], @@ -208,12 +208,12 @@ impl From<[Pubkey; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> } } } -impl<'info> From> - for [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(accounts: SoceanStakePoolDepositStakeAccounts<'_, 'info>) -> Self { + fn from(accounts: SplStakePoolDepositStakeAccounts<'_, 'info>) -> Self { [ - accounts.socean_stake_pool_program.clone(), + accounts.spl_stake_pool_program.clone(), accounts.deposit_stake_spl_stake_pool.clone(), accounts.deposit_stake_validator_list.clone(), accounts.deposit_stake_deposit_authority.clone(), @@ -228,14 +228,12 @@ impl<'info> From> ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for SoceanStakePoolDepositStakeAccounts<'me, 'info> +impl<'me, 'info> From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositStakeAccounts<'me, 'info> { - fn from( - arr: &'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], - ) -> Self { + fn from(arr: &'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - socean_stake_pool_program: &arr[0], + spl_stake_pool_program: &arr[0], deposit_stake_spl_stake_pool: &arr[1], deposit_stake_validator_list: &arr[2], deposit_stake_deposit_authority: &arr[3], @@ -250,28 +248,28 @@ impl<'me, 'info> From<&'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_ } } } -pub const SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 0u8; +pub const SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 1u8; #[derive(Clone, Debug, PartialEq)] -pub struct SoceanStakePoolDepositStakeIxData; -impl SoceanStakePoolDepositStakeIxData { +pub struct SplStakePoolDepositStakeIxData; +impl SplStakePoolDepositStakeIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { + if maybe_discm != SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm + SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -279,58 +277,58 @@ impl SoceanStakePoolDepositStakeIxData { Ok(data) } } -pub fn socean_stake_pool_deposit_stake_ix_with_program_id( +pub fn spl_stake_pool_deposit_stake_ix_with_program_id( program_id: Pubkey, - keys: SoceanStakePoolDepositStakeKeys, + keys: SplStakePoolDepositStakeKeys, ) -> std::io::Result { - let metas: [AccountMeta; SOCEAN_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: SoceanStakePoolDepositStakeIxData.try_to_vec()?, + data: SplStakePoolDepositStakeIxData.try_to_vec()?, }) } -pub fn socean_stake_pool_deposit_stake_ix( - keys: SoceanStakePoolDepositStakeKeys, +pub fn spl_stake_pool_deposit_stake_ix( + keys: SplStakePoolDepositStakeKeys, ) -> std::io::Result { - socean_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) + spl_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) } -pub fn socean_stake_pool_deposit_stake_invoke_with_program_id( +pub fn spl_stake_pool_deposit_stake_invoke_with_program_id( program_id: Pubkey, - accounts: SoceanStakePoolDepositStakeAccounts<'_, '_>, + accounts: SplStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - let keys: SoceanStakePoolDepositStakeKeys = accounts.into(); - let ix = socean_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SplStakePoolDepositStakeKeys = accounts.into(); + let ix = spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn socean_stake_pool_deposit_stake_invoke( - accounts: SoceanStakePoolDepositStakeAccounts<'_, '_>, +pub fn spl_stake_pool_deposit_stake_invoke( + accounts: SplStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - socean_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) + spl_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) } -pub fn socean_stake_pool_deposit_stake_invoke_signed_with_program_id( +pub fn spl_stake_pool_deposit_stake_invoke_signed_with_program_id( program_id: Pubkey, - accounts: SoceanStakePoolDepositStakeAccounts<'_, '_>, + accounts: SplStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: SoceanStakePoolDepositStakeKeys = accounts.into(); - let ix = socean_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SplStakePoolDepositStakeKeys = accounts.into(); + let ix = spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn socean_stake_pool_deposit_stake_invoke_signed( - accounts: SoceanStakePoolDepositStakeAccounts<'_, '_>, +pub fn spl_stake_pool_deposit_stake_invoke_signed( + accounts: SplStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - socean_stake_pool_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) + spl_stake_pool_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) } -pub fn socean_stake_pool_deposit_stake_verify_account_keys( - accounts: SoceanStakePoolDepositStakeAccounts<'_, '_>, - keys: SoceanStakePoolDepositStakeKeys, +pub fn spl_stake_pool_deposit_stake_verify_account_keys( + accounts: SplStakePoolDepositStakeAccounts<'_, '_>, + keys: SplStakePoolDepositStakeKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ ( - accounts.socean_stake_pool_program.key, - &keys.socean_stake_pool_program, + accounts.spl_stake_pool_program.key, + &keys.spl_stake_pool_program, ), ( accounts.deposit_stake_spl_stake_pool.key, @@ -371,8 +369,8 @@ pub fn socean_stake_pool_deposit_stake_verify_account_keys( } Ok(()) } -pub fn socean_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( - accounts: SoceanStakePoolDepositStakeAccounts<'me, 'info>, +pub fn spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: SplStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ accounts.deposit_stake_spl_stake_pool, @@ -387,73 +385,68 @@ pub fn socean_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn socean_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( - accounts: SoceanStakePoolDepositStakeAccounts<'me, 'info>, +pub fn spl_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: SplStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - socean_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; + spl_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } -pub const SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; +pub const MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 11; #[derive(Copy, Clone, Debug)] -pub struct SplStakePoolDepositStakeAccounts<'me, 'info> { - pub spl_stake_pool_program: &'me AccountInfo<'info>, - pub deposit_stake_spl_stake_pool: &'me AccountInfo<'info>, +pub struct MarinadeDepositStakeAccounts<'me, 'info> { + pub marinade_program: &'me AccountInfo<'info>, + pub deposit_stake_marinade_state: &'me AccountInfo<'info>, pub deposit_stake_validator_list: &'me AccountInfo<'info>, - pub deposit_stake_deposit_authority: &'me AccountInfo<'info>, - pub deposit_stake_withdraw_authority: &'me AccountInfo<'info>, - pub deposit_stake_validator_stake: &'me AccountInfo<'info>, - pub deposit_stake_reserve_stake: &'me AccountInfo<'info>, - pub deposit_stake_manager_fee: &'me AccountInfo<'info>, + pub deposit_stake_stake_list: &'me AccountInfo<'info>, + pub deposit_stake_duplication_flag: &'me AccountInfo<'info>, + pub deposit_stake_msol_mint_auth: &'me AccountInfo<'info>, pub clock: &'me AccountInfo<'info>, - pub stake_history: &'me AccountInfo<'info>, + pub rent: &'me AccountInfo<'info>, + pub system_program: &'me AccountInfo<'info>, pub token_program: &'me AccountInfo<'info>, pub stake_program: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct SplStakePoolDepositStakeKeys { - pub spl_stake_pool_program: Pubkey, - pub deposit_stake_spl_stake_pool: Pubkey, +pub struct MarinadeDepositStakeKeys { + pub marinade_program: Pubkey, + pub deposit_stake_marinade_state: Pubkey, pub deposit_stake_validator_list: Pubkey, - pub deposit_stake_deposit_authority: Pubkey, - pub deposit_stake_withdraw_authority: Pubkey, - pub deposit_stake_validator_stake: Pubkey, - pub deposit_stake_reserve_stake: Pubkey, - pub deposit_stake_manager_fee: Pubkey, + pub deposit_stake_stake_list: Pubkey, + pub deposit_stake_duplication_flag: Pubkey, + pub deposit_stake_msol_mint_auth: Pubkey, pub clock: Pubkey, - pub stake_history: Pubkey, + pub rent: Pubkey, + pub system_program: Pubkey, pub token_program: Pubkey, pub stake_program: Pubkey, } -impl From> for SplStakePoolDepositStakeKeys { - fn from(accounts: SplStakePoolDepositStakeAccounts) -> Self { +impl From> for MarinadeDepositStakeKeys { + fn from(accounts: MarinadeDepositStakeAccounts) -> Self { Self { - spl_stake_pool_program: *accounts.spl_stake_pool_program.key, - deposit_stake_spl_stake_pool: *accounts.deposit_stake_spl_stake_pool.key, + marinade_program: *accounts.marinade_program.key, + deposit_stake_marinade_state: *accounts.deposit_stake_marinade_state.key, deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, - deposit_stake_deposit_authority: *accounts.deposit_stake_deposit_authority.key, - deposit_stake_withdraw_authority: *accounts.deposit_stake_withdraw_authority.key, - deposit_stake_validator_stake: *accounts.deposit_stake_validator_stake.key, - deposit_stake_reserve_stake: *accounts.deposit_stake_reserve_stake.key, - deposit_stake_manager_fee: *accounts.deposit_stake_manager_fee.key, + deposit_stake_stake_list: *accounts.deposit_stake_stake_list.key, + deposit_stake_duplication_flag: *accounts.deposit_stake_duplication_flag.key, + deposit_stake_msol_mint_auth: *accounts.deposit_stake_msol_mint_auth.key, clock: *accounts.clock.key, - stake_history: *accounts.stake_history.key, + rent: *accounts.rent.key, + system_program: *accounts.system_program.key, token_program: *accounts.token_program.key, stake_program: *accounts.stake_program.key, } } } -impl From - for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] -{ - fn from(keys: SplStakePoolDepositStakeKeys) -> Self { +impl From for [AccountMeta; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { + fn from(keys: MarinadeDepositStakeKeys) -> Self { [ AccountMeta { - pubkey: keys.spl_stake_pool_program, + pubkey: keys.marinade_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_spl_stake_pool, + pubkey: keys.deposit_stake_marinade_state, is_signer: false, is_writable: true, }, @@ -463,37 +456,32 @@ impl From is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_deposit_authority, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.deposit_stake_withdraw_authority, + pubkey: keys.deposit_stake_stake_list, is_signer: false, - is_writable: false, + is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_validator_stake, + pubkey: keys.deposit_stake_duplication_flag, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_reserve_stake, + pubkey: keys.deposit_stake_msol_mint_auth, is_signer: false, - is_writable: true, + is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_manager_fee, + pubkey: keys.clock, is_signer: false, - is_writable: true, + is_writable: false, }, AccountMeta { - pubkey: keys.clock, + pubkey: keys.rent, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.stake_history, + pubkey: keys.system_program, is_signer: false, is_writable: false, }, @@ -510,86 +498,83 @@ impl From ] } } -impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for SplStakePoolDepositStakeKeys { - fn from(pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { +impl From<[Pubkey; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for MarinadeDepositStakeKeys { + fn from(pubkeys: [Pubkey; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - spl_stake_pool_program: pubkeys[0], - deposit_stake_spl_stake_pool: pubkeys[1], + marinade_program: pubkeys[0], + deposit_stake_marinade_state: pubkeys[1], deposit_stake_validator_list: pubkeys[2], - deposit_stake_deposit_authority: pubkeys[3], - deposit_stake_withdraw_authority: pubkeys[4], - deposit_stake_validator_stake: pubkeys[5], - deposit_stake_reserve_stake: pubkeys[6], - deposit_stake_manager_fee: pubkeys[7], - clock: pubkeys[8], - stake_history: pubkeys[9], - token_program: pubkeys[10], - stake_program: pubkeys[11], + deposit_stake_stake_list: pubkeys[3], + deposit_stake_duplication_flag: pubkeys[4], + deposit_stake_msol_mint_auth: pubkeys[5], + clock: pubkeys[6], + rent: pubkeys[7], + system_program: pubkeys[8], + token_program: pubkeys[9], + stake_program: pubkeys[10], } } } -impl<'info> From> - for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(accounts: SplStakePoolDepositStakeAccounts<'_, 'info>) -> Self { + fn from(accounts: MarinadeDepositStakeAccounts<'_, 'info>) -> Self { [ - accounts.spl_stake_pool_program.clone(), - accounts.deposit_stake_spl_stake_pool.clone(), + accounts.marinade_program.clone(), + accounts.deposit_stake_marinade_state.clone(), accounts.deposit_stake_validator_list.clone(), - accounts.deposit_stake_deposit_authority.clone(), - accounts.deposit_stake_withdraw_authority.clone(), - accounts.deposit_stake_validator_stake.clone(), - accounts.deposit_stake_reserve_stake.clone(), - accounts.deposit_stake_manager_fee.clone(), + accounts.deposit_stake_stake_list.clone(), + accounts.deposit_stake_duplication_flag.clone(), + accounts.deposit_stake_msol_mint_auth.clone(), accounts.clock.clone(), - accounts.stake_history.clone(), + accounts.rent.clone(), + accounts.system_program.clone(), accounts.token_program.clone(), accounts.stake_program.clone(), ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for SplStakePoolDepositStakeAccounts<'me, 'info> +impl<'me, 'info> From<&'me [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for MarinadeDepositStakeAccounts<'me, 'info> { - fn from(arr: &'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { + fn from(arr: &'me [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - spl_stake_pool_program: &arr[0], - deposit_stake_spl_stake_pool: &arr[1], + marinade_program: &arr[0], + deposit_stake_marinade_state: &arr[1], deposit_stake_validator_list: &arr[2], - deposit_stake_deposit_authority: &arr[3], - deposit_stake_withdraw_authority: &arr[4], - deposit_stake_validator_stake: &arr[5], - deposit_stake_reserve_stake: &arr[6], - deposit_stake_manager_fee: &arr[7], - clock: &arr[8], - stake_history: &arr[9], - token_program: &arr[10], - stake_program: &arr[11], + deposit_stake_stake_list: &arr[3], + deposit_stake_duplication_flag: &arr[4], + deposit_stake_msol_mint_auth: &arr[5], + clock: &arr[6], + rent: &arr[7], + system_program: &arr[8], + token_program: &arr[9], + stake_program: &arr[10], } } } -pub const SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 1u8; +pub const MARINADE_DEPOSIT_STAKE_IX_DISCM: u8 = 2u8; #[derive(Clone, Debug, PartialEq)] -pub struct SplStakePoolDepositStakeIxData; -impl SplStakePoolDepositStakeIxData { +pub struct MarinadeDepositStakeIxData; +impl MarinadeDepositStakeIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { + if maybe_discm != MARINADE_DEPOSIT_STAKE_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm + MARINADE_DEPOSIT_STAKE_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) + writer.write_all(&[MARINADE_DEPOSIT_STAKE_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -597,89 +582,77 @@ impl SplStakePoolDepositStakeIxData { Ok(data) } } -pub fn spl_stake_pool_deposit_stake_ix_with_program_id( +pub fn marinade_deposit_stake_ix_with_program_id( program_id: Pubkey, - keys: SplStakePoolDepositStakeKeys, + keys: MarinadeDepositStakeKeys, ) -> std::io::Result { - let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: SplStakePoolDepositStakeIxData.try_to_vec()?, + data: MarinadeDepositStakeIxData.try_to_vec()?, }) } -pub fn spl_stake_pool_deposit_stake_ix( - keys: SplStakePoolDepositStakeKeys, -) -> std::io::Result { - spl_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) +pub fn marinade_deposit_stake_ix(keys: MarinadeDepositStakeKeys) -> std::io::Result { + marinade_deposit_stake_ix_with_program_id(crate::ID, keys) } -pub fn spl_stake_pool_deposit_stake_invoke_with_program_id( +pub fn marinade_deposit_stake_invoke_with_program_id( program_id: Pubkey, - accounts: SplStakePoolDepositStakeAccounts<'_, '_>, + accounts: MarinadeDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - let keys: SplStakePoolDepositStakeKeys = accounts.into(); - let ix = spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: MarinadeDepositStakeKeys = accounts.into(); + let ix = marinade_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn spl_stake_pool_deposit_stake_invoke( - accounts: SplStakePoolDepositStakeAccounts<'_, '_>, +pub fn marinade_deposit_stake_invoke( + accounts: MarinadeDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - spl_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) + marinade_deposit_stake_invoke_with_program_id(crate::ID, accounts) } -pub fn spl_stake_pool_deposit_stake_invoke_signed_with_program_id( +pub fn marinade_deposit_stake_invoke_signed_with_program_id( program_id: Pubkey, - accounts: SplStakePoolDepositStakeAccounts<'_, '_>, + accounts: MarinadeDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: SplStakePoolDepositStakeKeys = accounts.into(); - let ix = spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: MarinadeDepositStakeKeys = accounts.into(); + let ix = marinade_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn spl_stake_pool_deposit_stake_invoke_signed( - accounts: SplStakePoolDepositStakeAccounts<'_, '_>, +pub fn marinade_deposit_stake_invoke_signed( + accounts: MarinadeDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - spl_stake_pool_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) + marinade_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) } -pub fn spl_stake_pool_deposit_stake_verify_account_keys( - accounts: SplStakePoolDepositStakeAccounts<'_, '_>, - keys: SplStakePoolDepositStakeKeys, +pub fn marinade_deposit_stake_verify_account_keys( + accounts: MarinadeDepositStakeAccounts<'_, '_>, + keys: MarinadeDepositStakeKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ + (accounts.marinade_program.key, &keys.marinade_program), ( - accounts.spl_stake_pool_program.key, - &keys.spl_stake_pool_program, - ), - ( - accounts.deposit_stake_spl_stake_pool.key, - &keys.deposit_stake_spl_stake_pool, + accounts.deposit_stake_marinade_state.key, + &keys.deposit_stake_marinade_state, ), ( accounts.deposit_stake_validator_list.key, &keys.deposit_stake_validator_list, ), ( - accounts.deposit_stake_deposit_authority.key, - &keys.deposit_stake_deposit_authority, - ), - ( - accounts.deposit_stake_withdraw_authority.key, - &keys.deposit_stake_withdraw_authority, - ), - ( - accounts.deposit_stake_validator_stake.key, - &keys.deposit_stake_validator_stake, + accounts.deposit_stake_stake_list.key, + &keys.deposit_stake_stake_list, ), ( - accounts.deposit_stake_reserve_stake.key, - &keys.deposit_stake_reserve_stake, + accounts.deposit_stake_duplication_flag.key, + &keys.deposit_stake_duplication_flag, ), ( - accounts.deposit_stake_manager_fee.key, - &keys.deposit_stake_manager_fee, + accounts.deposit_stake_msol_mint_auth.key, + &keys.deposit_stake_msol_mint_auth, ), (accounts.clock.key, &keys.clock), - (accounts.stake_history.key, &keys.stake_history), + (accounts.rent.key, &keys.rent), + (accounts.system_program.key, &keys.system_program), (accounts.token_program.key, &keys.token_program), (accounts.stake_program.key, &keys.stake_program), ] { @@ -689,15 +662,14 @@ pub fn spl_stake_pool_deposit_stake_verify_account_keys( } Ok(()) } -pub fn spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( - accounts: SplStakePoolDepositStakeAccounts<'me, 'info>, +pub fn marinade_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: MarinadeDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ - accounts.deposit_stake_spl_stake_pool, + accounts.deposit_stake_marinade_state, accounts.deposit_stake_validator_list, - accounts.deposit_stake_validator_stake, - accounts.deposit_stake_reserve_stake, - accounts.deposit_stake_manager_fee, + accounts.deposit_stake_stake_list, + accounts.deposit_stake_duplication_flag, ] { if !should_be_writable.is_writable { return Err((should_be_writable, ProgramError::InvalidAccountData)); @@ -705,196 +677,196 @@ pub fn spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn spl_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( - accounts: SplStakePoolDepositStakeAccounts<'me, 'info>, +pub fn marinade_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: MarinadeDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - spl_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; + marinade_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } -pub const MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 11; +pub const UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 11; #[derive(Copy, Clone, Debug)] -pub struct MarinadeDepositStakeAccounts<'me, 'info> { - pub marinade_program: &'me AccountInfo<'info>, - pub deposit_stake_marinade_state: &'me AccountInfo<'info>, - pub deposit_stake_validator_list: &'me AccountInfo<'info>, - pub deposit_stake_stake_list: &'me AccountInfo<'info>, - pub deposit_stake_duplication_flag: &'me AccountInfo<'info>, - pub deposit_stake_msol_mint_auth: &'me AccountInfo<'info>, +pub struct UnstakeItDepositStakeAccounts<'me, 'info> { + pub unstakeit_program: &'me AccountInfo<'info>, + pub deposit_stake_unstake_pool: &'me AccountInfo<'info>, + pub deposit_stake_pool_sol_reserves: &'me AccountInfo<'info>, + pub deposit_stake_unstake_fee: &'me AccountInfo<'info>, + pub deposit_stake_stake_acc_record: &'me AccountInfo<'info>, + pub deposit_stake_protocol_fee: &'me AccountInfo<'info>, + pub deposit_stake_protocol_fee_dest: &'me AccountInfo<'info>, pub clock: &'me AccountInfo<'info>, - pub rent: &'me AccountInfo<'info>, + pub stake_program: &'me AccountInfo<'info>, pub system_program: &'me AccountInfo<'info>, pub token_program: &'me AccountInfo<'info>, - pub stake_program: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct MarinadeDepositStakeKeys { - pub marinade_program: Pubkey, - pub deposit_stake_marinade_state: Pubkey, - pub deposit_stake_validator_list: Pubkey, - pub deposit_stake_stake_list: Pubkey, - pub deposit_stake_duplication_flag: Pubkey, - pub deposit_stake_msol_mint_auth: Pubkey, +pub struct UnstakeItDepositStakeKeys { + pub unstakeit_program: Pubkey, + pub deposit_stake_unstake_pool: Pubkey, + pub deposit_stake_pool_sol_reserves: Pubkey, + pub deposit_stake_unstake_fee: Pubkey, + pub deposit_stake_stake_acc_record: Pubkey, + pub deposit_stake_protocol_fee: Pubkey, + pub deposit_stake_protocol_fee_dest: Pubkey, pub clock: Pubkey, - pub rent: Pubkey, + pub stake_program: Pubkey, pub system_program: Pubkey, pub token_program: Pubkey, - pub stake_program: Pubkey, } -impl From> for MarinadeDepositStakeKeys { - fn from(accounts: MarinadeDepositStakeAccounts) -> Self { +impl From> for UnstakeItDepositStakeKeys { + fn from(accounts: UnstakeItDepositStakeAccounts) -> Self { Self { - marinade_program: *accounts.marinade_program.key, - deposit_stake_marinade_state: *accounts.deposit_stake_marinade_state.key, - deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, - deposit_stake_stake_list: *accounts.deposit_stake_stake_list.key, - deposit_stake_duplication_flag: *accounts.deposit_stake_duplication_flag.key, - deposit_stake_msol_mint_auth: *accounts.deposit_stake_msol_mint_auth.key, + unstakeit_program: *accounts.unstakeit_program.key, + deposit_stake_unstake_pool: *accounts.deposit_stake_unstake_pool.key, + deposit_stake_pool_sol_reserves: *accounts.deposit_stake_pool_sol_reserves.key, + deposit_stake_unstake_fee: *accounts.deposit_stake_unstake_fee.key, + deposit_stake_stake_acc_record: *accounts.deposit_stake_stake_acc_record.key, + deposit_stake_protocol_fee: *accounts.deposit_stake_protocol_fee.key, + deposit_stake_protocol_fee_dest: *accounts.deposit_stake_protocol_fee_dest.key, clock: *accounts.clock.key, - rent: *accounts.rent.key, + stake_program: *accounts.stake_program.key, system_program: *accounts.system_program.key, token_program: *accounts.token_program.key, - stake_program: *accounts.stake_program.key, } } } -impl From for [AccountMeta; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(keys: MarinadeDepositStakeKeys) -> Self { +impl From for [AccountMeta; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { + fn from(keys: UnstakeItDepositStakeKeys) -> Self { [ AccountMeta { - pubkey: keys.marinade_program, + pubkey: keys.unstakeit_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_marinade_state, + pubkey: keys.deposit_stake_unstake_pool, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_validator_list, + pubkey: keys.deposit_stake_pool_sol_reserves, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_stake_list, + pubkey: keys.deposit_stake_unstake_fee, is_signer: false, - is_writable: true, + is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_duplication_flag, + pubkey: keys.deposit_stake_stake_acc_record, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_msol_mint_auth, + pubkey: keys.deposit_stake_protocol_fee, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.clock, + pubkey: keys.deposit_stake_protocol_fee_dest, is_signer: false, - is_writable: false, + is_writable: true, }, AccountMeta { - pubkey: keys.rent, + pubkey: keys.clock, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.system_program, + pubkey: keys.stake_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.token_program, + pubkey: keys.system_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.stake_program, + pubkey: keys.token_program, is_signer: false, is_writable: false, }, ] } } -impl From<[Pubkey; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for MarinadeDepositStakeKeys { - fn from(pubkeys: [Pubkey; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { +impl From<[Pubkey; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for UnstakeItDepositStakeKeys { + fn from(pubkeys: [Pubkey; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - marinade_program: pubkeys[0], - deposit_stake_marinade_state: pubkeys[1], - deposit_stake_validator_list: pubkeys[2], - deposit_stake_stake_list: pubkeys[3], - deposit_stake_duplication_flag: pubkeys[4], - deposit_stake_msol_mint_auth: pubkeys[5], - clock: pubkeys[6], - rent: pubkeys[7], - system_program: pubkeys[8], - token_program: pubkeys[9], - stake_program: pubkeys[10], + unstakeit_program: pubkeys[0], + deposit_stake_unstake_pool: pubkeys[1], + deposit_stake_pool_sol_reserves: pubkeys[2], + deposit_stake_unstake_fee: pubkeys[3], + deposit_stake_stake_acc_record: pubkeys[4], + deposit_stake_protocol_fee: pubkeys[5], + deposit_stake_protocol_fee_dest: pubkeys[6], + clock: pubkeys[7], + stake_program: pubkeys[8], + system_program: pubkeys[9], + token_program: pubkeys[10], } } } -impl<'info> From> - for [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(accounts: MarinadeDepositStakeAccounts<'_, 'info>) -> Self { + fn from(accounts: UnstakeItDepositStakeAccounts<'_, 'info>) -> Self { [ - accounts.marinade_program.clone(), - accounts.deposit_stake_marinade_state.clone(), - accounts.deposit_stake_validator_list.clone(), - accounts.deposit_stake_stake_list.clone(), - accounts.deposit_stake_duplication_flag.clone(), - accounts.deposit_stake_msol_mint_auth.clone(), + accounts.unstakeit_program.clone(), + accounts.deposit_stake_unstake_pool.clone(), + accounts.deposit_stake_pool_sol_reserves.clone(), + accounts.deposit_stake_unstake_fee.clone(), + accounts.deposit_stake_stake_acc_record.clone(), + accounts.deposit_stake_protocol_fee.clone(), + accounts.deposit_stake_protocol_fee_dest.clone(), accounts.clock.clone(), - accounts.rent.clone(), + accounts.stake_program.clone(), accounts.system_program.clone(), accounts.token_program.clone(), - accounts.stake_program.clone(), ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for MarinadeDepositStakeAccounts<'me, 'info> +impl<'me, 'info> From<&'me [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for UnstakeItDepositStakeAccounts<'me, 'info> { - fn from(arr: &'me [AccountInfo<'info>; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { + fn from(arr: &'me [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - marinade_program: &arr[0], - deposit_stake_marinade_state: &arr[1], - deposit_stake_validator_list: &arr[2], - deposit_stake_stake_list: &arr[3], - deposit_stake_duplication_flag: &arr[4], - deposit_stake_msol_mint_auth: &arr[5], - clock: &arr[6], - rent: &arr[7], - system_program: &arr[8], - token_program: &arr[9], - stake_program: &arr[10], + unstakeit_program: &arr[0], + deposit_stake_unstake_pool: &arr[1], + deposit_stake_pool_sol_reserves: &arr[2], + deposit_stake_unstake_fee: &arr[3], + deposit_stake_stake_acc_record: &arr[4], + deposit_stake_protocol_fee: &arr[5], + deposit_stake_protocol_fee_dest: &arr[6], + clock: &arr[7], + stake_program: &arr[8], + system_program: &arr[9], + token_program: &arr[10], } } } -pub const MARINADE_DEPOSIT_STAKE_IX_DISCM: u8 = 2u8; +pub const UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM: u8 = 3u8; #[derive(Clone, Debug, PartialEq)] -pub struct MarinadeDepositStakeIxData; -impl MarinadeDepositStakeIxData { +pub struct UnstakeItDepositStakeIxData; +impl UnstakeItDepositStakeIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != MARINADE_DEPOSIT_STAKE_IX_DISCM { + if maybe_discm != UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - MARINADE_DEPOSIT_STAKE_IX_DISCM, maybe_discm + UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[MARINADE_DEPOSIT_STAKE_IX_DISCM]) + writer.write_all(&[UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -902,79 +874,84 @@ impl MarinadeDepositStakeIxData { Ok(data) } } -pub fn marinade_deposit_stake_ix_with_program_id( +pub fn unstake_it_deposit_stake_ix_with_program_id( program_id: Pubkey, - keys: MarinadeDepositStakeKeys, + keys: UnstakeItDepositStakeKeys, ) -> std::io::Result { - let metas: [AccountMeta; MARINADE_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: MarinadeDepositStakeIxData.try_to_vec()?, + data: UnstakeItDepositStakeIxData.try_to_vec()?, }) } -pub fn marinade_deposit_stake_ix(keys: MarinadeDepositStakeKeys) -> std::io::Result { - marinade_deposit_stake_ix_with_program_id(crate::ID, keys) +pub fn unstake_it_deposit_stake_ix( + keys: UnstakeItDepositStakeKeys, +) -> std::io::Result { + unstake_it_deposit_stake_ix_with_program_id(crate::ID, keys) } -pub fn marinade_deposit_stake_invoke_with_program_id( +pub fn unstake_it_deposit_stake_invoke_with_program_id( program_id: Pubkey, - accounts: MarinadeDepositStakeAccounts<'_, '_>, + accounts: UnstakeItDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - let keys: MarinadeDepositStakeKeys = accounts.into(); - let ix = marinade_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: UnstakeItDepositStakeKeys = accounts.into(); + let ix = unstake_it_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn marinade_deposit_stake_invoke( - accounts: MarinadeDepositStakeAccounts<'_, '_>, +pub fn unstake_it_deposit_stake_invoke( + accounts: UnstakeItDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - marinade_deposit_stake_invoke_with_program_id(crate::ID, accounts) + unstake_it_deposit_stake_invoke_with_program_id(crate::ID, accounts) } -pub fn marinade_deposit_stake_invoke_signed_with_program_id( +pub fn unstake_it_deposit_stake_invoke_signed_with_program_id( program_id: Pubkey, - accounts: MarinadeDepositStakeAccounts<'_, '_>, + accounts: UnstakeItDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: MarinadeDepositStakeKeys = accounts.into(); - let ix = marinade_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: UnstakeItDepositStakeKeys = accounts.into(); + let ix = unstake_it_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn marinade_deposit_stake_invoke_signed( - accounts: MarinadeDepositStakeAccounts<'_, '_>, +pub fn unstake_it_deposit_stake_invoke_signed( + accounts: UnstakeItDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - marinade_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) + unstake_it_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) } -pub fn marinade_deposit_stake_verify_account_keys( - accounts: MarinadeDepositStakeAccounts<'_, '_>, - keys: MarinadeDepositStakeKeys, +pub fn unstake_it_deposit_stake_verify_account_keys( + accounts: UnstakeItDepositStakeAccounts<'_, '_>, + keys: UnstakeItDepositStakeKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ - (accounts.marinade_program.key, &keys.marinade_program), + (accounts.unstakeit_program.key, &keys.unstakeit_program), ( - accounts.deposit_stake_marinade_state.key, - &keys.deposit_stake_marinade_state, + accounts.deposit_stake_unstake_pool.key, + &keys.deposit_stake_unstake_pool, ), ( - accounts.deposit_stake_validator_list.key, - &keys.deposit_stake_validator_list, + accounts.deposit_stake_pool_sol_reserves.key, + &keys.deposit_stake_pool_sol_reserves, ), ( - accounts.deposit_stake_stake_list.key, - &keys.deposit_stake_stake_list, + accounts.deposit_stake_unstake_fee.key, + &keys.deposit_stake_unstake_fee, ), ( - accounts.deposit_stake_duplication_flag.key, - &keys.deposit_stake_duplication_flag, + accounts.deposit_stake_stake_acc_record.key, + &keys.deposit_stake_stake_acc_record, ), ( - accounts.deposit_stake_msol_mint_auth.key, - &keys.deposit_stake_msol_mint_auth, + accounts.deposit_stake_protocol_fee.key, + &keys.deposit_stake_protocol_fee, + ), + ( + accounts.deposit_stake_protocol_fee_dest.key, + &keys.deposit_stake_protocol_fee_dest, ), (accounts.clock.key, &keys.clock), - (accounts.rent.key, &keys.rent), + (accounts.stake_program.key, &keys.stake_program), (accounts.system_program.key, &keys.system_program), (accounts.token_program.key, &keys.token_program), - (accounts.stake_program.key, &keys.stake_program), ] { if actual != expected { return Err((*actual, *expected)); @@ -982,14 +959,14 @@ pub fn marinade_deposit_stake_verify_account_keys( } Ok(()) } -pub fn marinade_deposit_stake_verify_writable_privileges<'me, 'info>( - accounts: MarinadeDepositStakeAccounts<'me, 'info>, +pub fn unstake_it_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: UnstakeItDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ - accounts.deposit_stake_marinade_state, - accounts.deposit_stake_validator_list, - accounts.deposit_stake_stake_list, - accounts.deposit_stake_duplication_flag, + accounts.deposit_stake_unstake_pool, + accounts.deposit_stake_pool_sol_reserves, + accounts.deposit_stake_stake_acc_record, + accounts.deposit_stake_protocol_fee_dest, ] { if !should_be_writable.is_writable { return Err((should_be_writable, ProgramError::InvalidAccountData)); @@ -997,93 +974,103 @@ pub fn marinade_deposit_stake_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn marinade_deposit_stake_verify_account_privileges<'me, 'info>( - accounts: MarinadeDepositStakeAccounts<'me, 'info>, +pub fn unstake_it_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: UnstakeItDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - marinade_deposit_stake_verify_writable_privileges(accounts)?; + unstake_it_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } -pub const UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 11; +pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; #[derive(Copy, Clone, Debug)] -pub struct UnstakeItDepositStakeAccounts<'me, 'info> { - pub unstakeit_program: &'me AccountInfo<'info>, - pub deposit_stake_unstake_pool: &'me AccountInfo<'info>, - pub deposit_stake_pool_sol_reserves: &'me AccountInfo<'info>, - pub deposit_stake_unstake_fee: &'me AccountInfo<'info>, - pub deposit_stake_stake_acc_record: &'me AccountInfo<'info>, - pub deposit_stake_protocol_fee: &'me AccountInfo<'info>, - pub deposit_stake_protocol_fee_dest: &'me AccountInfo<'info>, +pub struct SanctumSplStakePoolDepositStakeAccounts<'me, 'info> { + pub sanctum_spl_stake_pool_program: &'me AccountInfo<'info>, + pub deposit_stake_spl_stake_pool: &'me AccountInfo<'info>, + pub deposit_stake_validator_list: &'me AccountInfo<'info>, + pub deposit_stake_deposit_authority: &'me AccountInfo<'info>, + pub deposit_stake_withdraw_authority: &'me AccountInfo<'info>, + pub deposit_stake_validator_stake: &'me AccountInfo<'info>, + pub deposit_stake_reserve_stake: &'me AccountInfo<'info>, + pub deposit_stake_manager_fee: &'me AccountInfo<'info>, pub clock: &'me AccountInfo<'info>, - pub stake_program: &'me AccountInfo<'info>, - pub system_program: &'me AccountInfo<'info>, + pub stake_history: &'me AccountInfo<'info>, pub token_program: &'me AccountInfo<'info>, + pub stake_program: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct UnstakeItDepositStakeKeys { - pub unstakeit_program: Pubkey, - pub deposit_stake_unstake_pool: Pubkey, - pub deposit_stake_pool_sol_reserves: Pubkey, - pub deposit_stake_unstake_fee: Pubkey, - pub deposit_stake_stake_acc_record: Pubkey, - pub deposit_stake_protocol_fee: Pubkey, - pub deposit_stake_protocol_fee_dest: Pubkey, +pub struct SanctumSplStakePoolDepositStakeKeys { + pub sanctum_spl_stake_pool_program: Pubkey, + pub deposit_stake_spl_stake_pool: Pubkey, + pub deposit_stake_validator_list: Pubkey, + pub deposit_stake_deposit_authority: Pubkey, + pub deposit_stake_withdraw_authority: Pubkey, + pub deposit_stake_validator_stake: Pubkey, + pub deposit_stake_reserve_stake: Pubkey, + pub deposit_stake_manager_fee: Pubkey, pub clock: Pubkey, - pub stake_program: Pubkey, - pub system_program: Pubkey, + pub stake_history: Pubkey, pub token_program: Pubkey, + pub stake_program: Pubkey, } -impl From> for UnstakeItDepositStakeKeys { - fn from(accounts: UnstakeItDepositStakeAccounts) -> Self { +impl From> for SanctumSplStakePoolDepositStakeKeys { + fn from(accounts: SanctumSplStakePoolDepositStakeAccounts) -> Self { Self { - unstakeit_program: *accounts.unstakeit_program.key, - deposit_stake_unstake_pool: *accounts.deposit_stake_unstake_pool.key, - deposit_stake_pool_sol_reserves: *accounts.deposit_stake_pool_sol_reserves.key, - deposit_stake_unstake_fee: *accounts.deposit_stake_unstake_fee.key, - deposit_stake_stake_acc_record: *accounts.deposit_stake_stake_acc_record.key, - deposit_stake_protocol_fee: *accounts.deposit_stake_protocol_fee.key, - deposit_stake_protocol_fee_dest: *accounts.deposit_stake_protocol_fee_dest.key, + sanctum_spl_stake_pool_program: *accounts.sanctum_spl_stake_pool_program.key, + deposit_stake_spl_stake_pool: *accounts.deposit_stake_spl_stake_pool.key, + deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, + deposit_stake_deposit_authority: *accounts.deposit_stake_deposit_authority.key, + deposit_stake_withdraw_authority: *accounts.deposit_stake_withdraw_authority.key, + deposit_stake_validator_stake: *accounts.deposit_stake_validator_stake.key, + deposit_stake_reserve_stake: *accounts.deposit_stake_reserve_stake.key, + deposit_stake_manager_fee: *accounts.deposit_stake_manager_fee.key, clock: *accounts.clock.key, - stake_program: *accounts.stake_program.key, - system_program: *accounts.system_program.key, + stake_history: *accounts.stake_history.key, token_program: *accounts.token_program.key, + stake_program: *accounts.stake_program.key, } } } -impl From for [AccountMeta; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(keys: UnstakeItDepositStakeKeys) -> Self { +impl From + for [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +{ + fn from(keys: SanctumSplStakePoolDepositStakeKeys) -> Self { [ AccountMeta { - pubkey: keys.unstakeit_program, + pubkey: keys.sanctum_spl_stake_pool_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_unstake_pool, + pubkey: keys.deposit_stake_spl_stake_pool, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_pool_sol_reserves, + pubkey: keys.deposit_stake_validator_list, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_unstake_fee, + pubkey: keys.deposit_stake_deposit_authority, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.deposit_stake_stake_acc_record, + pubkey: keys.deposit_stake_withdraw_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_stake_validator_stake, is_signer: false, is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_protocol_fee, + pubkey: keys.deposit_stake_reserve_stake, is_signer: false, - is_writable: false, + is_writable: true, }, AccountMeta { - pubkey: keys.deposit_stake_protocol_fee_dest, + pubkey: keys.deposit_stake_manager_fee, is_signer: false, is_writable: true, }, @@ -1093,100 +1080,108 @@ impl From for [AccountMeta; UNSTAKE_IT_DEPOSIT_STAKE_ is_writable: false, }, AccountMeta { - pubkey: keys.stake_program, + pubkey: keys.stake_history, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.system_program, + pubkey: keys.token_program, is_signer: false, is_writable: false, }, AccountMeta { - pubkey: keys.token_program, + pubkey: keys.stake_program, is_signer: false, is_writable: false, }, ] } } -impl From<[Pubkey; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> for UnstakeItDepositStakeKeys { - fn from(pubkeys: [Pubkey; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { +impl From<[Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplStakePoolDepositStakeKeys +{ + fn from(pubkeys: [Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - unstakeit_program: pubkeys[0], - deposit_stake_unstake_pool: pubkeys[1], - deposit_stake_pool_sol_reserves: pubkeys[2], - deposit_stake_unstake_fee: pubkeys[3], - deposit_stake_stake_acc_record: pubkeys[4], - deposit_stake_protocol_fee: pubkeys[5], - deposit_stake_protocol_fee_dest: pubkeys[6], - clock: pubkeys[7], - stake_program: pubkeys[8], - system_program: pubkeys[9], + sanctum_spl_stake_pool_program: pubkeys[0], + deposit_stake_spl_stake_pool: pubkeys[1], + deposit_stake_validator_list: pubkeys[2], + deposit_stake_deposit_authority: pubkeys[3], + deposit_stake_withdraw_authority: pubkeys[4], + deposit_stake_validator_stake: pubkeys[5], + deposit_stake_reserve_stake: pubkeys[6], + deposit_stake_manager_fee: pubkeys[7], + clock: pubkeys[8], + stake_history: pubkeys[9], token_program: pubkeys[10], + stake_program: pubkeys[11], } } } -impl<'info> From> - for [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(accounts: UnstakeItDepositStakeAccounts<'_, 'info>) -> Self { + fn from(accounts: SanctumSplStakePoolDepositStakeAccounts<'_, 'info>) -> Self { [ - accounts.unstakeit_program.clone(), - accounts.deposit_stake_unstake_pool.clone(), - accounts.deposit_stake_pool_sol_reserves.clone(), - accounts.deposit_stake_unstake_fee.clone(), - accounts.deposit_stake_stake_acc_record.clone(), - accounts.deposit_stake_protocol_fee.clone(), - accounts.deposit_stake_protocol_fee_dest.clone(), + accounts.sanctum_spl_stake_pool_program.clone(), + accounts.deposit_stake_spl_stake_pool.clone(), + accounts.deposit_stake_validator_list.clone(), + accounts.deposit_stake_deposit_authority.clone(), + accounts.deposit_stake_withdraw_authority.clone(), + accounts.deposit_stake_validator_stake.clone(), + accounts.deposit_stake_reserve_stake.clone(), + accounts.deposit_stake_manager_fee.clone(), accounts.clock.clone(), - accounts.stake_program.clone(), - accounts.system_program.clone(), + accounts.stake_history.clone(), accounts.token_program.clone(), + accounts.stake_program.clone(), ] } } -impl<'me, 'info> From<&'me [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for UnstakeItDepositStakeAccounts<'me, 'info> +impl<'me, 'info> + From<&'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplStakePoolDepositStakeAccounts<'me, 'info> { - fn from(arr: &'me [AccountInfo<'info>; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { + fn from( + arr: &'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], + ) -> Self { Self { - unstakeit_program: &arr[0], - deposit_stake_unstake_pool: &arr[1], - deposit_stake_pool_sol_reserves: &arr[2], - deposit_stake_unstake_fee: &arr[3], - deposit_stake_stake_acc_record: &arr[4], - deposit_stake_protocol_fee: &arr[5], - deposit_stake_protocol_fee_dest: &arr[6], - clock: &arr[7], - stake_program: &arr[8], - system_program: &arr[9], + sanctum_spl_stake_pool_program: &arr[0], + deposit_stake_spl_stake_pool: &arr[1], + deposit_stake_validator_list: &arr[2], + deposit_stake_deposit_authority: &arr[3], + deposit_stake_withdraw_authority: &arr[4], + deposit_stake_validator_stake: &arr[5], + deposit_stake_reserve_stake: &arr[6], + deposit_stake_manager_fee: &arr[7], + clock: &arr[8], + stake_history: &arr[9], token_program: &arr[10], + stake_program: &arr[11], } } } -pub const UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM: u8 = 3u8; +pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 4u8; #[derive(Clone, Debug, PartialEq)] -pub struct UnstakeItDepositStakeIxData; -impl UnstakeItDepositStakeIxData { +pub struct SanctumSplStakePoolDepositStakeIxData; +impl SanctumSplStakePoolDepositStakeIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM { + if maybe_discm != SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM, maybe_discm + SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[UNSTAKE_IT_DEPOSIT_STAKE_IX_DISCM]) + writer.write_all(&[SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -1194,84 +1189,91 @@ impl UnstakeItDepositStakeIxData { Ok(data) } } -pub fn unstake_it_deposit_stake_ix_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_stake_ix_with_program_id( program_id: Pubkey, - keys: UnstakeItDepositStakeKeys, + keys: SanctumSplStakePoolDepositStakeKeys, ) -> std::io::Result { - let metas: [AccountMeta; UNSTAKE_IT_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: UnstakeItDepositStakeIxData.try_to_vec()?, + data: SanctumSplStakePoolDepositStakeIxData.try_to_vec()?, }) } -pub fn unstake_it_deposit_stake_ix( - keys: UnstakeItDepositStakeKeys, +pub fn sanctum_spl_stake_pool_deposit_stake_ix( + keys: SanctumSplStakePoolDepositStakeKeys, ) -> std::io::Result { - unstake_it_deposit_stake_ix_with_program_id(crate::ID, keys) + sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) } -pub fn unstake_it_deposit_stake_invoke_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_stake_invoke_with_program_id( program_id: Pubkey, - accounts: UnstakeItDepositStakeAccounts<'_, '_>, + accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - let keys: UnstakeItDepositStakeKeys = accounts.into(); - let ix = unstake_it_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplStakePoolDepositStakeKeys = accounts.into(); + let ix = sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn unstake_it_deposit_stake_invoke( - accounts: UnstakeItDepositStakeAccounts<'_, '_>, +pub fn sanctum_spl_stake_pool_deposit_stake_invoke( + accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - unstake_it_deposit_stake_invoke_with_program_id(crate::ID, accounts) + sanctum_spl_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) } -pub fn unstake_it_deposit_stake_invoke_signed_with_program_id( +pub fn sanctum_spl_stake_pool_deposit_stake_invoke_signed_with_program_id( program_id: Pubkey, - accounts: UnstakeItDepositStakeAccounts<'_, '_>, + accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: UnstakeItDepositStakeKeys = accounts.into(); - let ix = unstake_it_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplStakePoolDepositStakeKeys = accounts.into(); + let ix = sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn unstake_it_deposit_stake_invoke_signed( - accounts: UnstakeItDepositStakeAccounts<'_, '_>, +pub fn sanctum_spl_stake_pool_deposit_stake_invoke_signed( + accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - unstake_it_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) + sanctum_spl_stake_pool_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) } -pub fn unstake_it_deposit_stake_verify_account_keys( - accounts: UnstakeItDepositStakeAccounts<'_, '_>, - keys: UnstakeItDepositStakeKeys, +pub fn sanctum_spl_stake_pool_deposit_stake_verify_account_keys( + accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, + keys: SanctumSplStakePoolDepositStakeKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ - (accounts.unstakeit_program.key, &keys.unstakeit_program), ( - accounts.deposit_stake_unstake_pool.key, - &keys.deposit_stake_unstake_pool, + accounts.sanctum_spl_stake_pool_program.key, + &keys.sanctum_spl_stake_pool_program, ), ( - accounts.deposit_stake_pool_sol_reserves.key, - &keys.deposit_stake_pool_sol_reserves, + accounts.deposit_stake_spl_stake_pool.key, + &keys.deposit_stake_spl_stake_pool, ), ( - accounts.deposit_stake_unstake_fee.key, - &keys.deposit_stake_unstake_fee, + accounts.deposit_stake_validator_list.key, + &keys.deposit_stake_validator_list, ), ( - accounts.deposit_stake_stake_acc_record.key, - &keys.deposit_stake_stake_acc_record, + accounts.deposit_stake_deposit_authority.key, + &keys.deposit_stake_deposit_authority, ), ( - accounts.deposit_stake_protocol_fee.key, - &keys.deposit_stake_protocol_fee, + accounts.deposit_stake_withdraw_authority.key, + &keys.deposit_stake_withdraw_authority, ), ( - accounts.deposit_stake_protocol_fee_dest.key, - &keys.deposit_stake_protocol_fee_dest, + accounts.deposit_stake_validator_stake.key, + &keys.deposit_stake_validator_stake, + ), + ( + accounts.deposit_stake_reserve_stake.key, + &keys.deposit_stake_reserve_stake, + ), + ( + accounts.deposit_stake_manager_fee.key, + &keys.deposit_stake_manager_fee, ), (accounts.clock.key, &keys.clock), - (accounts.stake_program.key, &keys.stake_program), - (accounts.system_program.key, &keys.system_program), + (accounts.stake_history.key, &keys.stake_history), (accounts.token_program.key, &keys.token_program), + (accounts.stake_program.key, &keys.stake_program), ] { if actual != expected { return Err((*actual, *expected)); @@ -1279,14 +1281,15 @@ pub fn unstake_it_deposit_stake_verify_account_keys( } Ok(()) } -pub fn unstake_it_deposit_stake_verify_writable_privileges<'me, 'info>( - accounts: UnstakeItDepositStakeAccounts<'me, 'info>, +pub fn sanctum_spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: SanctumSplStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ - accounts.deposit_stake_unstake_pool, - accounts.deposit_stake_pool_sol_reserves, - accounts.deposit_stake_stake_acc_record, - accounts.deposit_stake_protocol_fee_dest, + accounts.deposit_stake_spl_stake_pool, + accounts.deposit_stake_validator_list, + accounts.deposit_stake_validator_stake, + accounts.deposit_stake_reserve_stake, + accounts.deposit_stake_manager_fee, ] { if !should_be_writable.is_writable { return Err((should_be_writable, ProgramError::InvalidAccountData)); @@ -1294,16 +1297,16 @@ pub fn unstake_it_deposit_stake_verify_writable_privileges<'me, 'info>( } Ok(()) } -pub fn unstake_it_deposit_stake_verify_account_privileges<'me, 'info>( - accounts: UnstakeItDepositStakeAccounts<'me, 'info>, +pub fn sanctum_spl_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: SanctumSplStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - unstake_it_deposit_stake_verify_writable_privileges(accounts)?; + sanctum_spl_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } -pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; +pub const SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 12; #[derive(Copy, Clone, Debug)] -pub struct SanctumSplStakePoolDepositStakeAccounts<'me, 'info> { - pub sanctum_spl_stake_pool_program: &'me AccountInfo<'info>, +pub struct SanctumSplMultiStakePoolDepositStakeAccounts<'me, 'info> { + pub sanctum_spl_multi_stake_pool_program: &'me AccountInfo<'info>, pub deposit_stake_spl_stake_pool: &'me AccountInfo<'info>, pub deposit_stake_validator_list: &'me AccountInfo<'info>, pub deposit_stake_deposit_authority: &'me AccountInfo<'info>, @@ -1317,8 +1320,8 @@ pub struct SanctumSplStakePoolDepositStakeAccounts<'me, 'info> { pub stake_program: &'me AccountInfo<'info>, } #[derive(Copy, Clone, Debug)] -pub struct SanctumSplStakePoolDepositStakeKeys { - pub sanctum_spl_stake_pool_program: Pubkey, +pub struct SanctumSplMultiStakePoolDepositStakeKeys { + pub sanctum_spl_multi_stake_pool_program: Pubkey, pub deposit_stake_spl_stake_pool: Pubkey, pub deposit_stake_validator_list: Pubkey, pub deposit_stake_deposit_authority: Pubkey, @@ -1331,10 +1334,14 @@ pub struct SanctumSplStakePoolDepositStakeKeys { pub token_program: Pubkey, pub stake_program: Pubkey, } -impl From> for SanctumSplStakePoolDepositStakeKeys { - fn from(accounts: SanctumSplStakePoolDepositStakeAccounts) -> Self { +impl From> + for SanctumSplMultiStakePoolDepositStakeKeys +{ + fn from(accounts: SanctumSplMultiStakePoolDepositStakeAccounts) -> Self { Self { - sanctum_spl_stake_pool_program: *accounts.sanctum_spl_stake_pool_program.key, + sanctum_spl_multi_stake_pool_program: *accounts + .sanctum_spl_multi_stake_pool_program + .key, deposit_stake_spl_stake_pool: *accounts.deposit_stake_spl_stake_pool.key, deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, deposit_stake_deposit_authority: *accounts.deposit_stake_deposit_authority.key, @@ -1349,13 +1356,13 @@ impl From> for SanctumSplStakePo } } } -impl From - for [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl From + for [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(keys: SanctumSplStakePoolDepositStakeKeys) -> Self { + fn from(keys: SanctumSplMultiStakePoolDepositStakeKeys) -> Self { [ AccountMeta { - pubkey: keys.sanctum_spl_stake_pool_program, + pubkey: keys.sanctum_spl_multi_stake_pool_program, is_signer: false, is_writable: false, }, @@ -1417,12 +1424,12 @@ impl From ] } } -impl From<[Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for SanctumSplStakePoolDepositStakeKeys +impl From<[Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolDepositStakeKeys { - fn from(pubkeys: [Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { + fn from(pubkeys: [Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]) -> Self { Self { - sanctum_spl_stake_pool_program: pubkeys[0], + sanctum_spl_multi_stake_pool_program: pubkeys[0], deposit_stake_spl_stake_pool: pubkeys[1], deposit_stake_validator_list: pubkeys[2], deposit_stake_deposit_authority: pubkeys[3], @@ -1437,12 +1444,12 @@ impl From<[Pubkey; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> } } } -impl<'info> From> - for [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +impl<'info> From> + for [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { - fn from(accounts: SanctumSplStakePoolDepositStakeAccounts<'_, 'info>) -> Self { + fn from(accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, 'info>) -> Self { [ - accounts.sanctum_spl_stake_pool_program.clone(), + accounts.sanctum_spl_multi_stake_pool_program.clone(), accounts.deposit_stake_spl_stake_pool.clone(), accounts.deposit_stake_validator_list.clone(), accounts.deposit_stake_deposit_authority.clone(), @@ -1458,14 +1465,14 @@ impl<'info> From> } } impl<'me, 'info> - From<&'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> - for SanctumSplStakePoolDepositStakeAccounts<'me, 'info> + From<&'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolDepositStakeAccounts<'me, 'info> { fn from( - arr: &'me [AccountInfo<'info>; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], + arr: &'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], ) -> Self { Self { - sanctum_spl_stake_pool_program: &arr[0], + sanctum_spl_multi_stake_pool_program: &arr[0], deposit_stake_spl_stake_pool: &arr[1], deposit_stake_validator_list: &arr[2], deposit_stake_deposit_authority: &arr[3], @@ -1480,28 +1487,28 @@ impl<'me, 'info> } } } -pub const SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 4u8; +pub const SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM: u8 = 5u8; #[derive(Clone, Debug, PartialEq)] -pub struct SanctumSplStakePoolDepositStakeIxData; -impl SanctumSplStakePoolDepositStakeIxData { +pub struct SanctumSplMultiStakePoolDepositStakeIxData; +impl SanctumSplMultiStakePoolDepositStakeIxData { pub fn deserialize(buf: &[u8]) -> std::io::Result { let mut reader = buf; let mut maybe_discm_buf = [0u8; 1]; reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { + if maybe_discm != SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!( "discm does not match. Expected: {:?}. Received: {:?}", - SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm + SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM, maybe_discm ), )); } Ok(Self) } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } pub fn try_to_vec(&self) -> std::io::Result> { let mut data = Vec::new(); @@ -1509,58 +1516,63 @@ impl SanctumSplStakePoolDepositStakeIxData { Ok(data) } } -pub fn sanctum_spl_stake_pool_deposit_stake_ix_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_stake_ix_with_program_id( program_id: Pubkey, - keys: SanctumSplStakePoolDepositStakeKeys, + keys: SanctumSplMultiStakePoolDepositStakeKeys, ) -> std::io::Result { - let metas: [AccountMeta; SANCTUM_SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = keys.into(); + let metas: [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = + keys.into(); Ok(Instruction { program_id, accounts: Vec::from(metas), - data: SanctumSplStakePoolDepositStakeIxData.try_to_vec()?, + data: SanctumSplMultiStakePoolDepositStakeIxData.try_to_vec()?, }) } -pub fn sanctum_spl_stake_pool_deposit_stake_ix( - keys: SanctumSplStakePoolDepositStakeKeys, +pub fn sanctum_spl_multi_stake_pool_deposit_stake_ix( + keys: SanctumSplMultiStakePoolDepositStakeKeys, ) -> std::io::Result { - sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) + sanctum_spl_multi_stake_pool_deposit_stake_ix_with_program_id(crate::ID, keys) } -pub fn sanctum_spl_stake_pool_deposit_stake_invoke_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_stake_invoke_with_program_id( program_id: Pubkey, - accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - let keys: SanctumSplStakePoolDepositStakeKeys = accounts.into(); - let ix = sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplMultiStakePoolDepositStakeKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction(&ix, accounts) } -pub fn sanctum_spl_stake_pool_deposit_stake_invoke( - accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, +pub fn sanctum_spl_multi_stake_pool_deposit_stake_invoke( + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, '_>, ) -> ProgramResult { - sanctum_spl_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) + sanctum_spl_multi_stake_pool_deposit_stake_invoke_with_program_id(crate::ID, accounts) } -pub fn sanctum_spl_stake_pool_deposit_stake_invoke_signed_with_program_id( +pub fn sanctum_spl_multi_stake_pool_deposit_stake_invoke_signed_with_program_id( program_id: Pubkey, - accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - let keys: SanctumSplStakePoolDepositStakeKeys = accounts.into(); - let ix = sanctum_spl_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; + let keys: SanctumSplMultiStakePoolDepositStakeKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_deposit_stake_ix_with_program_id(program_id, keys)?; invoke_instruction_signed(&ix, accounts, seeds) } -pub fn sanctum_spl_stake_pool_deposit_stake_invoke_signed( - accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, +pub fn sanctum_spl_multi_stake_pool_deposit_stake_invoke_signed( + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, '_>, seeds: &[&[&[u8]]], ) -> ProgramResult { - sanctum_spl_stake_pool_deposit_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) -} -pub fn sanctum_spl_stake_pool_deposit_stake_verify_account_keys( - accounts: SanctumSplStakePoolDepositStakeAccounts<'_, '_>, - keys: SanctumSplStakePoolDepositStakeKeys, + sanctum_spl_multi_stake_pool_deposit_stake_invoke_signed_with_program_id( + crate::ID, + accounts, + seeds, + ) +} +pub fn sanctum_spl_multi_stake_pool_deposit_stake_verify_account_keys( + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'_, '_>, + keys: SanctumSplMultiStakePoolDepositStakeKeys, ) -> Result<(), (Pubkey, Pubkey)> { for (actual, expected) in [ ( - accounts.sanctum_spl_stake_pool_program.key, - &keys.sanctum_spl_stake_pool_program, + accounts.sanctum_spl_multi_stake_pool_program.key, + &keys.sanctum_spl_multi_stake_pool_program, ), ( accounts.deposit_stake_spl_stake_pool.key, @@ -1601,8 +1613,8 @@ pub fn sanctum_spl_stake_pool_deposit_stake_verify_account_keys( } Ok(()) } -pub fn sanctum_spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( - accounts: SanctumSplStakePoolDepositStakeAccounts<'me, 'info>, +pub fn sanctum_spl_multi_stake_pool_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { for should_be_writable in [ accounts.deposit_stake_spl_stake_pool, @@ -1617,9 +1629,9 @@ pub fn sanctum_spl_stake_pool_deposit_stake_verify_writable_privileges<'me, 'inf } Ok(()) } -pub fn sanctum_spl_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( - accounts: SanctumSplStakePoolDepositStakeAccounts<'me, 'info>, +pub fn sanctum_spl_multi_stake_pool_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolDepositStakeAccounts<'me, 'info>, ) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - sanctum_spl_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; + sanctum_spl_multi_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } diff --git a/interfaces/stakedex_withdraw_stake_interface/idl.json b/interfaces/stakedex_withdraw_stake_interface/idl.json index 3cea86f..c552cd3 100644 --- a/interfaces/stakedex_withdraw_stake_interface/idl.json +++ b/interfaces/stakedex_withdraw_stake_interface/idl.json @@ -3,10 +3,10 @@ "name": "stakedex_withdraw_stake", "instructions": [ { - "name": "SoceanStakePoolWithdrawStake", + "name": "SplStakePoolWithdrawStake", "accounts": [ { - "name": "soceanStakePoolProgram", + "name": "splStakePoolProgram", "isMut": false, "isSigner": false }, @@ -59,29 +59,24 @@ "args": [], "discriminant": { "type": "u8", - "value": 0 + "value": 1 } }, { - "name": "SplStakePoolWithdrawStake", + "name": "LidoWithdrawStake", "accounts": [ { - "name": "splStakePoolProgram", + "name": "lidoProgram", "isMut": false, "isSigner": false }, { - "name": "withdrawStakeSplStakePool", - "isMut": true, - "isSigner": false - }, - { - "name": "withdrawStakeValidatorList", + "name": "withdrawStakeSolido", "isMut": true, "isSigner": false }, { - "name": "withdrawStakeWithdrawAuthority", + "name": "withdrawStakeVoter", "isMut": false, "isSigner": false }, @@ -91,7 +86,12 @@ "isSigner": false }, { - "name": "withdrawStakeManagerFee", + "name": "withdrawStakeStakeAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "withdrawStakeValidatorList", "isMut": true, "isSigner": false }, @@ -119,25 +119,30 @@ "args": [], "discriminant": { "type": "u8", - "value": 1 + "value": 2 } }, { - "name": "LidoWithdrawStake", + "name": "MarinadeWithdrawStake", "accounts": [ { - "name": "lidoProgram", + "name": "marinadeProgram", "isMut": false, "isSigner": false }, { - "name": "withdrawStakeSolido", + "name": "withdrawStakeMarinadeState", "isMut": true, "isSigner": false }, { - "name": "withdrawStakeVoter", - "isMut": false, + "name": "withdrawStakeMarinadeTreasury", + "isMut": true, + "isSigner": false + }, + { + "name": "withdrawStakeValidatorList", + "isMut": true, "isSigner": false }, { @@ -146,13 +151,18 @@ "isSigner": false }, { - "name": "withdrawStakeStakeAuthority", + "name": "withdrawStakeStakeList", + "isMut": true, + "isSigner": false + }, + { + "name": "withdrawStakeWithdrawAuthority", "isMut": false, "isSigner": false }, { - "name": "withdrawStakeValidatorList", - "isMut": true, + "name": "withdrawStakeDepositAuthority", + "isMut": false, "isSigner": false }, { @@ -179,30 +189,30 @@ "args": [], "discriminant": { "type": "u8", - "value": 2 + "value": 3 } }, { - "name": "MarinadeWithdrawStake", + "name": "SanctumSplStakePoolWithdrawStake", "accounts": [ { - "name": "marinadeProgram", + "name": "sanctumSplStakePoolProgram", "isMut": false, "isSigner": false }, { - "name": "withdrawStakeMarinadeState", + "name": "withdrawStakeSplStakePool", "isMut": true, "isSigner": false }, { - "name": "withdrawStakeMarinadeTreasury", + "name": "withdrawStakeValidatorList", "isMut": true, "isSigner": false }, { - "name": "withdrawStakeValidatorList", - "isMut": true, + "name": "withdrawStakeWithdrawAuthority", + "isMut": false, "isSigner": false }, { @@ -211,20 +221,10 @@ "isSigner": false }, { - "name": "withdrawStakeStakeList", + "name": "withdrawStakeManagerFee", "isMut": true, "isSigner": false }, - { - "name": "withdrawStakeWithdrawAuthority", - "isMut": false, - "isSigner": false - }, - { - "name": "withdrawStakeDepositAuthority", - "isMut": false, - "isSigner": false - }, { "name": "clock", "isMut": false, @@ -249,14 +249,14 @@ "args": [], "discriminant": { "type": "u8", - "value": 3 + "value": 4 } }, { - "name": "SanctumSplStakePoolWithdrawStake", + "name": "SanctumSplMultiStakePoolWithdrawStake", "accounts": [ { - "name": "sanctumSplStakePoolProgram", + "name": "sanctumSplMultiStakePoolProgram", "isMut": false, "isSigner": false }, @@ -309,7 +309,7 @@ "args": [], "discriminant": { "type": "u8", - "value": 4 + "value": 5 } } ], diff --git a/interfaces/stakedex_withdraw_stake_interface/src/instructions.rs b/interfaces/stakedex_withdraw_stake_interface/src/instructions.rs index 101da52..30d3e89 100644 --- a/interfaces/stakedex_withdraw_stake_interface/src/instructions.rs +++ b/interfaces/stakedex_withdraw_stake_interface/src/instructions.rs @@ -9,11 +9,11 @@ use solana_program::{ use std::io::Read; #[derive(Clone, Debug, PartialEq)] pub enum StakedexWithdrawStakeProgramIx { - SoceanStakePoolWithdrawStake, SplStakePoolWithdrawStake, LidoWithdrawStake, MarinadeWithdrawStake, SanctumSplStakePoolWithdrawStake, + SanctumSplMultiStakePoolWithdrawStake, } impl StakedexWithdrawStakeProgramIx { pub fn deserialize(buf: &[u8]) -> std::io::Result { @@ -22,13 +22,15 @@ impl StakedexWithdrawStakeProgramIx { reader.read_exact(&mut maybe_discm_buf)?; let maybe_discm = maybe_discm_buf[0]; match maybe_discm { - SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM => Ok(Self::SoceanStakePoolWithdrawStake), SPL_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM => Ok(Self::SplStakePoolWithdrawStake), LIDO_WITHDRAW_STAKE_IX_DISCM => Ok(Self::LidoWithdrawStake), MARINADE_WITHDRAW_STAKE_IX_DISCM => Ok(Self::MarinadeWithdrawStake), SANCTUM_SPL_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM => { Ok(Self::SanctumSplStakePoolWithdrawStake) } + SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM => { + Ok(Self::SanctumSplMultiStakePoolWithdrawStake) + } _ => Err(std::io::Error::new( std::io::ErrorKind::Other, format!("discm {:?} not found", maybe_discm), @@ -37,9 +39,6 @@ impl StakedexWithdrawStakeProgramIx { } pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { match self { - Self::SoceanStakePoolWithdrawStake => { - writer.write_all(&[SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) - } Self::SplStakePoolWithdrawStake => { writer.write_all(&[SPL_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) } @@ -48,6 +47,9 @@ impl StakedexWithdrawStakeProgramIx { Self::SanctumSplStakePoolWithdrawStake => { writer.write_all(&[SANCTUM_SPL_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) } + Self::SanctumSplMultiStakePoolWithdrawStake => { + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) + } } } pub fn try_to_vec(&self) -> std::io::Result> { @@ -71,297 +73,6 @@ fn invoke_instruction_signed<'info, A: Into<[AccountInfo<'info>; N]>, const N: u let account_info: [AccountInfo<'info>; N] = accounts.into(); invoke_signed(ix, &account_info, seeds) } -pub const SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN: usize = 10; -#[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolWithdrawStakeAccounts<'me, 'info> { - pub socean_stake_pool_program: &'me AccountInfo<'info>, - pub withdraw_stake_spl_stake_pool: &'me AccountInfo<'info>, - pub withdraw_stake_validator_list: &'me AccountInfo<'info>, - pub withdraw_stake_withdraw_authority: &'me AccountInfo<'info>, - pub withdraw_stake_stake_to_split: &'me AccountInfo<'info>, - pub withdraw_stake_manager_fee: &'me AccountInfo<'info>, - pub clock: &'me AccountInfo<'info>, - pub token_program: &'me AccountInfo<'info>, - pub stake_program: &'me AccountInfo<'info>, - pub system_program: &'me AccountInfo<'info>, -} -#[derive(Copy, Clone, Debug)] -pub struct SoceanStakePoolWithdrawStakeKeys { - pub socean_stake_pool_program: Pubkey, - pub withdraw_stake_spl_stake_pool: Pubkey, - pub withdraw_stake_validator_list: Pubkey, - pub withdraw_stake_withdraw_authority: Pubkey, - pub withdraw_stake_stake_to_split: Pubkey, - pub withdraw_stake_manager_fee: Pubkey, - pub clock: Pubkey, - pub token_program: Pubkey, - pub stake_program: Pubkey, - pub system_program: Pubkey, -} -impl From> for SoceanStakePoolWithdrawStakeKeys { - fn from(accounts: SoceanStakePoolWithdrawStakeAccounts) -> Self { - Self { - socean_stake_pool_program: *accounts.socean_stake_pool_program.key, - withdraw_stake_spl_stake_pool: *accounts.withdraw_stake_spl_stake_pool.key, - withdraw_stake_validator_list: *accounts.withdraw_stake_validator_list.key, - withdraw_stake_withdraw_authority: *accounts.withdraw_stake_withdraw_authority.key, - withdraw_stake_stake_to_split: *accounts.withdraw_stake_stake_to_split.key, - withdraw_stake_manager_fee: *accounts.withdraw_stake_manager_fee.key, - clock: *accounts.clock.key, - token_program: *accounts.token_program.key, - stake_program: *accounts.stake_program.key, - system_program: *accounts.system_program.key, - } - } -} -impl From - for [AccountMeta; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] -{ - fn from(keys: SoceanStakePoolWithdrawStakeKeys) -> Self { - [ - AccountMeta { - pubkey: keys.socean_stake_pool_program, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.withdraw_stake_spl_stake_pool, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.withdraw_stake_validator_list, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.withdraw_stake_withdraw_authority, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.withdraw_stake_stake_to_split, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.withdraw_stake_manager_fee, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.clock, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.token_program, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.stake_program, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.system_program, - is_signer: false, - is_writable: false, - }, - ] - } -} -impl From<[Pubkey; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]> - for SoceanStakePoolWithdrawStakeKeys -{ - fn from(pubkeys: [Pubkey; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]) -> Self { - Self { - socean_stake_pool_program: pubkeys[0], - withdraw_stake_spl_stake_pool: pubkeys[1], - withdraw_stake_validator_list: pubkeys[2], - withdraw_stake_withdraw_authority: pubkeys[3], - withdraw_stake_stake_to_split: pubkeys[4], - withdraw_stake_manager_fee: pubkeys[5], - clock: pubkeys[6], - token_program: pubkeys[7], - stake_program: pubkeys[8], - system_program: pubkeys[9], - } - } -} -impl<'info> From> - for [AccountInfo<'info>; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] -{ - fn from(accounts: SoceanStakePoolWithdrawStakeAccounts<'_, 'info>) -> Self { - [ - accounts.socean_stake_pool_program.clone(), - accounts.withdraw_stake_spl_stake_pool.clone(), - accounts.withdraw_stake_validator_list.clone(), - accounts.withdraw_stake_withdraw_authority.clone(), - accounts.withdraw_stake_stake_to_split.clone(), - accounts.withdraw_stake_manager_fee.clone(), - accounts.clock.clone(), - accounts.token_program.clone(), - accounts.stake_program.clone(), - accounts.system_program.clone(), - ] - } -} -impl<'me, 'info> From<&'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]> - for SoceanStakePoolWithdrawStakeAccounts<'me, 'info> -{ - fn from( - arr: &'me [AccountInfo<'info>; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN], - ) -> Self { - Self { - socean_stake_pool_program: &arr[0], - withdraw_stake_spl_stake_pool: &arr[1], - withdraw_stake_validator_list: &arr[2], - withdraw_stake_withdraw_authority: &arr[3], - withdraw_stake_stake_to_split: &arr[4], - withdraw_stake_manager_fee: &arr[5], - clock: &arr[6], - token_program: &arr[7], - stake_program: &arr[8], - system_program: &arr[9], - } - } -} -pub const SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM: u8 = 0u8; -#[derive(Clone, Debug, PartialEq)] -pub struct SoceanStakePoolWithdrawStakeIxData; -impl SoceanStakePoolWithdrawStakeIxData { - pub fn deserialize(buf: &[u8]) -> std::io::Result { - let mut reader = buf; - let mut maybe_discm_buf = [0u8; 1]; - reader.read_exact(&mut maybe_discm_buf)?; - let maybe_discm = maybe_discm_buf[0]; - if maybe_discm != SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - format!( - "discm does not match. Expected: {:?}. Received: {:?}", - SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM, maybe_discm - ), - )); - } - Ok(Self) - } - pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { - writer.write_all(&[SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) - } - pub fn try_to_vec(&self) -> std::io::Result> { - let mut data = Vec::new(); - self.serialize(&mut data)?; - Ok(data) - } -} -pub fn socean_stake_pool_withdraw_stake_ix_with_program_id( - program_id: Pubkey, - keys: SoceanStakePoolWithdrawStakeKeys, -) -> std::io::Result { - let metas: [AccountMeta; SOCEAN_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] = keys.into(); - Ok(Instruction { - program_id, - accounts: Vec::from(metas), - data: SoceanStakePoolWithdrawStakeIxData.try_to_vec()?, - }) -} -pub fn socean_stake_pool_withdraw_stake_ix( - keys: SoceanStakePoolWithdrawStakeKeys, -) -> std::io::Result { - socean_stake_pool_withdraw_stake_ix_with_program_id(crate::ID, keys) -} -pub fn socean_stake_pool_withdraw_stake_invoke_with_program_id( - program_id: Pubkey, - accounts: SoceanStakePoolWithdrawStakeAccounts<'_, '_>, -) -> ProgramResult { - let keys: SoceanStakePoolWithdrawStakeKeys = accounts.into(); - let ix = socean_stake_pool_withdraw_stake_ix_with_program_id(program_id, keys)?; - invoke_instruction(&ix, accounts) -} -pub fn socean_stake_pool_withdraw_stake_invoke( - accounts: SoceanStakePoolWithdrawStakeAccounts<'_, '_>, -) -> ProgramResult { - socean_stake_pool_withdraw_stake_invoke_with_program_id(crate::ID, accounts) -} -pub fn socean_stake_pool_withdraw_stake_invoke_signed_with_program_id( - program_id: Pubkey, - accounts: SoceanStakePoolWithdrawStakeAccounts<'_, '_>, - seeds: &[&[&[u8]]], -) -> ProgramResult { - let keys: SoceanStakePoolWithdrawStakeKeys = accounts.into(); - let ix = socean_stake_pool_withdraw_stake_ix_with_program_id(program_id, keys)?; - invoke_instruction_signed(&ix, accounts, seeds) -} -pub fn socean_stake_pool_withdraw_stake_invoke_signed( - accounts: SoceanStakePoolWithdrawStakeAccounts<'_, '_>, - seeds: &[&[&[u8]]], -) -> ProgramResult { - socean_stake_pool_withdraw_stake_invoke_signed_with_program_id(crate::ID, accounts, seeds) -} -pub fn socean_stake_pool_withdraw_stake_verify_account_keys( - accounts: SoceanStakePoolWithdrawStakeAccounts<'_, '_>, - keys: SoceanStakePoolWithdrawStakeKeys, -) -> Result<(), (Pubkey, Pubkey)> { - for (actual, expected) in [ - ( - accounts.socean_stake_pool_program.key, - &keys.socean_stake_pool_program, - ), - ( - accounts.withdraw_stake_spl_stake_pool.key, - &keys.withdraw_stake_spl_stake_pool, - ), - ( - accounts.withdraw_stake_validator_list.key, - &keys.withdraw_stake_validator_list, - ), - ( - accounts.withdraw_stake_withdraw_authority.key, - &keys.withdraw_stake_withdraw_authority, - ), - ( - accounts.withdraw_stake_stake_to_split.key, - &keys.withdraw_stake_stake_to_split, - ), - ( - accounts.withdraw_stake_manager_fee.key, - &keys.withdraw_stake_manager_fee, - ), - (accounts.clock.key, &keys.clock), - (accounts.token_program.key, &keys.token_program), - (accounts.stake_program.key, &keys.stake_program), - (accounts.system_program.key, &keys.system_program), - ] { - if actual != expected { - return Err((*actual, *expected)); - } - } - Ok(()) -} -pub fn socean_stake_pool_withdraw_stake_verify_writable_privileges<'me, 'info>( - accounts: SoceanStakePoolWithdrawStakeAccounts<'me, 'info>, -) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - for should_be_writable in [ - accounts.withdraw_stake_spl_stake_pool, - accounts.withdraw_stake_validator_list, - accounts.withdraw_stake_stake_to_split, - accounts.withdraw_stake_manager_fee, - ] { - if !should_be_writable.is_writable { - return Err((should_be_writable, ProgramError::InvalidAccountData)); - } - } - Ok(()) -} -pub fn socean_stake_pool_withdraw_stake_verify_account_privileges<'me, 'info>( - accounts: SoceanStakePoolWithdrawStakeAccounts<'me, 'info>, -) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { - socean_stake_pool_withdraw_stake_verify_writable_privileges(accounts)?; - Ok(()) -} pub const SPL_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN: usize = 10; #[derive(Copy, Clone, Debug)] pub struct SplStakePoolWithdrawStakeAccounts<'me, 'info> { @@ -1533,3 +1244,306 @@ pub fn sanctum_spl_stake_pool_withdraw_stake_verify_account_privileges<'me, 'inf sanctum_spl_stake_pool_withdraw_stake_verify_writable_privileges(accounts)?; Ok(()) } +pub const SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN: usize = 10; +#[derive(Copy, Clone, Debug)] +pub struct SanctumSplMultiStakePoolWithdrawStakeAccounts<'me, 'info> { + pub sanctum_spl_multi_stake_pool_program: &'me AccountInfo<'info>, + pub withdraw_stake_spl_stake_pool: &'me AccountInfo<'info>, + pub withdraw_stake_validator_list: &'me AccountInfo<'info>, + pub withdraw_stake_withdraw_authority: &'me AccountInfo<'info>, + pub withdraw_stake_stake_to_split: &'me AccountInfo<'info>, + pub withdraw_stake_manager_fee: &'me AccountInfo<'info>, + pub clock: &'me AccountInfo<'info>, + pub token_program: &'me AccountInfo<'info>, + pub stake_program: &'me AccountInfo<'info>, + pub system_program: &'me AccountInfo<'info>, +} +#[derive(Copy, Clone, Debug)] +pub struct SanctumSplMultiStakePoolWithdrawStakeKeys { + pub sanctum_spl_multi_stake_pool_program: Pubkey, + pub withdraw_stake_spl_stake_pool: Pubkey, + pub withdraw_stake_validator_list: Pubkey, + pub withdraw_stake_withdraw_authority: Pubkey, + pub withdraw_stake_stake_to_split: Pubkey, + pub withdraw_stake_manager_fee: Pubkey, + pub clock: Pubkey, + pub token_program: Pubkey, + pub stake_program: Pubkey, + pub system_program: Pubkey, +} +impl From> + for SanctumSplMultiStakePoolWithdrawStakeKeys +{ + fn from(accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts) -> Self { + Self { + sanctum_spl_multi_stake_pool_program: *accounts + .sanctum_spl_multi_stake_pool_program + .key, + withdraw_stake_spl_stake_pool: *accounts.withdraw_stake_spl_stake_pool.key, + withdraw_stake_validator_list: *accounts.withdraw_stake_validator_list.key, + withdraw_stake_withdraw_authority: *accounts.withdraw_stake_withdraw_authority.key, + withdraw_stake_stake_to_split: *accounts.withdraw_stake_stake_to_split.key, + withdraw_stake_manager_fee: *accounts.withdraw_stake_manager_fee.key, + clock: *accounts.clock.key, + token_program: *accounts.token_program.key, + stake_program: *accounts.stake_program.key, + system_program: *accounts.system_program.key, + } + } +} +impl From + for [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] +{ + fn from(keys: SanctumSplMultiStakePoolWithdrawStakeKeys) -> Self { + [ + AccountMeta { + pubkey: keys.sanctum_spl_multi_stake_pool_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.withdraw_stake_spl_stake_pool, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.withdraw_stake_validator_list, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.withdraw_stake_withdraw_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.withdraw_stake_stake_to_split, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.withdraw_stake_manager_fee, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.clock, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.token_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.system_program, + is_signer: false, + is_writable: false, + }, + ] + } +} +impl From<[Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolWithdrawStakeKeys +{ + fn from( + pubkeys: [Pubkey; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + sanctum_spl_multi_stake_pool_program: pubkeys[0], + withdraw_stake_spl_stake_pool: pubkeys[1], + withdraw_stake_validator_list: pubkeys[2], + withdraw_stake_withdraw_authority: pubkeys[3], + withdraw_stake_stake_to_split: pubkeys[4], + withdraw_stake_manager_fee: pubkeys[5], + clock: pubkeys[6], + token_program: pubkeys[7], + stake_program: pubkeys[8], + system_program: pubkeys[9], + } + } +} +impl<'info> From> + for [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] +{ + fn from(accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, 'info>) -> Self { + [ + accounts.sanctum_spl_multi_stake_pool_program.clone(), + accounts.withdraw_stake_spl_stake_pool.clone(), + accounts.withdraw_stake_validator_list.clone(), + accounts.withdraw_stake_withdraw_authority.clone(), + accounts.withdraw_stake_stake_to_split.clone(), + accounts.withdraw_stake_manager_fee.clone(), + accounts.clock.clone(), + accounts.token_program.clone(), + accounts.stake_program.clone(), + accounts.system_program.clone(), + ] + } +} +impl<'me, 'info> + From<&'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN]> + for SanctumSplMultiStakePoolWithdrawStakeAccounts<'me, 'info> +{ + fn from( + arr: &'me [AccountInfo<'info>; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + sanctum_spl_multi_stake_pool_program: &arr[0], + withdraw_stake_spl_stake_pool: &arr[1], + withdraw_stake_validator_list: &arr[2], + withdraw_stake_withdraw_authority: &arr[3], + withdraw_stake_stake_to_split: &arr[4], + withdraw_stake_manager_fee: &arr[5], + clock: &arr[6], + token_program: &arr[7], + stake_program: &arr[8], + system_program: &arr[9], + } + } +} +pub const SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM: u8 = 5u8; +#[derive(Clone, Debug, PartialEq)] +pub struct SanctumSplMultiStakePoolWithdrawStakeIxData; +impl SanctumSplMultiStakePoolWithdrawStakeIxData { + pub fn deserialize(buf: &[u8]) -> std::io::Result { + let mut reader = buf; + let mut maybe_discm_buf = [0u8; 1]; + reader.read_exact(&mut maybe_discm_buf)?; + let maybe_discm = maybe_discm_buf[0]; + if maybe_discm != SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!( + "discm does not match. Expected: {:?}. Received: {:?}", + SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM, maybe_discm + ), + )); + } + Ok(Self) + } + pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { + writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_DISCM]) + } + pub fn try_to_vec(&self) -> std::io::Result> { + let mut data = Vec::new(); + self.serialize(&mut data)?; + Ok(data) + } +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_ix_with_program_id( + program_id: Pubkey, + keys: SanctumSplMultiStakePoolWithdrawStakeKeys, +) -> std::io::Result { + let metas: [AccountMeta; SANCTUM_SPL_MULTI_STAKE_POOL_WITHDRAW_STAKE_IX_ACCOUNTS_LEN] = + keys.into(); + Ok(Instruction { + program_id, + accounts: Vec::from(metas), + data: SanctumSplMultiStakePoolWithdrawStakeIxData.try_to_vec()?, + }) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_ix( + keys: SanctumSplMultiStakePoolWithdrawStakeKeys, +) -> std::io::Result { + sanctum_spl_multi_stake_pool_withdraw_stake_ix_with_program_id(crate::ID, keys) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_invoke_with_program_id( + program_id: Pubkey, + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, '_>, +) -> ProgramResult { + let keys: SanctumSplMultiStakePoolWithdrawStakeKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_withdraw_stake_ix_with_program_id(program_id, keys)?; + invoke_instruction(&ix, accounts) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_invoke( + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, '_>, +) -> ProgramResult { + sanctum_spl_multi_stake_pool_withdraw_stake_invoke_with_program_id(crate::ID, accounts) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_invoke_signed_with_program_id( + program_id: Pubkey, + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + let keys: SanctumSplMultiStakePoolWithdrawStakeKeys = accounts.into(); + let ix = sanctum_spl_multi_stake_pool_withdraw_stake_ix_with_program_id(program_id, keys)?; + invoke_instruction_signed(&ix, accounts, seeds) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_invoke_signed( + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + sanctum_spl_multi_stake_pool_withdraw_stake_invoke_signed_with_program_id( + crate::ID, + accounts, + seeds, + ) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_verify_account_keys( + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'_, '_>, + keys: SanctumSplMultiStakePoolWithdrawStakeKeys, +) -> Result<(), (Pubkey, Pubkey)> { + for (actual, expected) in [ + ( + accounts.sanctum_spl_multi_stake_pool_program.key, + &keys.sanctum_spl_multi_stake_pool_program, + ), + ( + accounts.withdraw_stake_spl_stake_pool.key, + &keys.withdraw_stake_spl_stake_pool, + ), + ( + accounts.withdraw_stake_validator_list.key, + &keys.withdraw_stake_validator_list, + ), + ( + accounts.withdraw_stake_withdraw_authority.key, + &keys.withdraw_stake_withdraw_authority, + ), + ( + accounts.withdraw_stake_stake_to_split.key, + &keys.withdraw_stake_stake_to_split, + ), + ( + accounts.withdraw_stake_manager_fee.key, + &keys.withdraw_stake_manager_fee, + ), + (accounts.clock.key, &keys.clock), + (accounts.token_program.key, &keys.token_program), + (accounts.stake_program.key, &keys.stake_program), + (accounts.system_program.key, &keys.system_program), + ] { + if actual != expected { + return Err((*actual, *expected)); + } + } + Ok(()) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_verify_writable_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + for should_be_writable in [ + accounts.withdraw_stake_spl_stake_pool, + accounts.withdraw_stake_validator_list, + accounts.withdraw_stake_stake_to_split, + accounts.withdraw_stake_manager_fee, + ] { + if !should_be_writable.is_writable { + return Err((should_be_writable, ProgramError::InvalidAccountData)); + } + } + Ok(()) +} +pub fn sanctum_spl_multi_stake_pool_withdraw_stake_verify_account_privileges<'me, 'info>( + accounts: SanctumSplMultiStakePoolWithdrawStakeAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + sanctum_spl_multi_stake_pool_withdraw_stake_verify_writable_privileges(accounts)?; + Ok(()) +} From a649b346dd8092b1ba56bdd5c7790f6890d300bf Mon Sep 17 00:00:00 2001 From: billythedummy Date: Tue, 2 Apr 2024 15:20:20 -0400 Subject: [PATCH 06/33] update list --- Cargo.lock | 4 ++-- Cargo.toml | 5 ++++- libs/spl_stake_pool/src/lib.rs | 3 ++- stakedex_sdk/src/lib.rs | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e26749a..dee92c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3123,8 +3123,8 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "sanctum-lst-list" -version = "0.1.0" -source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#111f01f26f4a45345976f35cbe7f1cca82e4b66c" +version = "0.2.0" +source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#b4f05b27086fcdf98c3cdf16d3c9531b6a98160b" dependencies = [ "sanctum-macros", "serde", diff --git a/Cargo.toml b/Cargo.toml index 22fce4f..cff476d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ num-derive = ">=0.1" num-traits = ">=0.1" rand = "0.8.5" rust_decimal = ">=1.0,<=1.32.0" # anything >1.32 uses borsh ^1 -sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = e05d193 sanctum-macros = "^1.2" serde = "^1" serde_json = "^1" @@ -41,6 +40,10 @@ unstake-lib = { git = "https://github.com/igneous-labs/sanctum-unstake-program.g # sanctum solana utils sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-solana-utils.git", branch = "master" } # rev = "111f01" +# sanctum-lst-list +# keep branch = "master" for flexibility of downstream crates +sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = b4f05b2 + # solana core crates solana-program = "^1" solana-sdk = "^1" diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index aff7787..29ec752 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -9,7 +9,8 @@ use stakedex_sdk_common::{WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS mod stakedex_traits; -/// A SPL stake pool with possibly custom program ID +/// A SPL stake pool with possibly custom program ID. +/// Works for different deploys of spl stake pool prog - spl, sanctum spl, sanctum spl multi #[derive(Clone, Default)] pub struct SplStakePoolStakedex { pub stake_pool_addr: Pubkey, diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index 28438ac..e464285 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -89,7 +89,9 @@ fn sanctum_lst_list_map_all_spl_like T .sanctum_lst_list .iter() .filter_map(move |lst| match lst.pool { - PoolInfo::SanctumSpl(accounts) | PoolInfo::Spl(accounts) => Some(f(lst, accounts)), + PoolInfo::SanctumSpl(accounts) + | PoolInfo::Spl(accounts) + | PoolInfo::SanctumSplMulti(accounts) => Some(f(lst, accounts)), PoolInfo::Lido | PoolInfo::Marinade | PoolInfo::ReservePool | PoolInfo::SPool(..) => { None } From 7cf20c35ccf6fd017df87b8f616fdd865fc4c3fc Mon Sep 17 00:00:00 2001 From: billythedummy Date: Tue, 2 Apr 2024 15:25:07 -0400 Subject: [PATCH 07/33] doc --- interfaces/stakedex_interface/README.md | 2 ++ libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs | 2 ++ libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs | 2 ++ libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/interfaces/stakedex_interface/README.md b/interfaces/stakedex_interface/README.md index 6f049fd..7000232 100644 --- a/interfaces/stakedex_interface/README.md +++ b/interfaces/stakedex_interface/README.md @@ -10,6 +10,8 @@ This is the on-chain program's interface. However the `StakeWrappedSol` and `Swa For example, to swap from scnSOL to laineSOL by withdrawing stake from socean then depositing the withdrawn stake to laine stake pool, you would append the `SoceanStakePoolWithdrawStake` instruction accounts, followed by the `SplStakePoolWithdrawStake` instruction accounts to a `SwapViaStake` instruction. +- Since the `stakedex_deposit_sol_interface`, `stakedex_deposit_stake_interface`, and `stakedex_withdraw_stake_interface` IDLs are only used for their instructions' accounts slice definitions, their instruction discriminants are not used. + ## Generate In workspace root: diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs index a0e2fdd..3eec6e3 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs @@ -49,6 +49,8 @@ impl DepositSol for SplStakePoolStakedex { } fn virtual_ix(&self) -> Result { + // spl_stake_pool_deposit_sol_ix works for all spl-stake-pool like + // (spl, sanctum-spl, sanctum-spl-multi) because the accounts interface is the exact same Ok(spl_stake_pool_deposit_sol_ix(SplStakePoolDepositSolKeys { spl_stake_pool_program: self.stake_pool_program, stake_pool: self.stake_pool_addr, diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs index c0df565..68f0e42 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs @@ -125,6 +125,8 @@ impl DepositStake for SplStakePoolStakedex { None, ) .0; + // spl_stake_pool_deposit_stake_ix works for all spl-stake-pool like + // (spl, sanctum-spl, sanctum-spl-multi) because the accounts interface is the exact same Ok(spl_stake_pool_deposit_stake_ix( SplStakePoolDepositStakeKeys { spl_stake_pool_program: self.stake_pool_program, diff --git a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs index 94ac588..bcfa0c1 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs @@ -112,6 +112,8 @@ impl WithdrawStakeBase for SplStakePoolStakedex { None, ) .0; + // spl_stake_pool_withdraw_stake_ix works for all spl-stake-pool like + // (spl, sanctum-spl, sanctum-spl-multi) because the accounts interface is the exact same Ok(spl_stake_pool_withdraw_stake_ix( SplStakePoolWithdrawStakeKeys { spl_stake_pool_program: self.stake_pool_program, From 589b7c2facee1af97e1ce93e1a737f94247f2d72 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Mon, 22 Apr 2024 15:43:47 +1000 Subject: [PATCH 08/33] feat: Store deposit auth PDA for fast quote --- libs/spl_stake_pool/src/lib.rs | 1 + libs/spl_stake_pool/src/stakedex_traits/base.rs | 4 ++++ .../src/stakedex_traits/deposit_stake.rs | 12 ++---------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index 29ec752..f7cd1ec 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -19,6 +19,7 @@ pub struct SplStakePoolStakedex { pub stake_pool: StakePool, pub validator_list: ValidatorList, pub curr_epoch: Epoch, + pub deposit_authority_program_address: Pubkey, } impl SplStakePoolStakedex { diff --git a/libs/spl_stake_pool/src/stakedex_traits/base.rs b/libs/spl_stake_pool/src/stakedex_traits/base.rs index 6adf5b6..b779292 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/base.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/base.rs @@ -1,6 +1,7 @@ use anyhow::Result; use jupiter_amm_interface::{AccountMap, 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}; use crate::SplStakePoolStakedex; @@ -14,9 +15,12 @@ impl InitFromKeyedAccount for SplStakePoolStakedex { params, }: &KeyedAccount, ) -> Result { + let deposit_authority_program_address = + find_deposit_authority_program_address(&account.owner, key).0; let mut res = Self { stake_pool_program: account.owner, stake_pool_addr: *key, + deposit_authority_program_address, ..Default::default() }; diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs index 68f0e42..5e4eda7 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs @@ -1,8 +1,6 @@ use anyhow::Result; use solana_program::{instruction::Instruction, stake, sysvar}; -use spl_stake_pool::{ - find_deposit_authority_program_address, find_stake_program_address, state::StakeStatus, -}; +use spl_stake_pool::{find_stake_program_address, state::StakeStatus}; use stakedex_deposit_stake_interface::{ spl_stake_pool_deposit_stake_ix, SplStakePoolDepositStakeKeys, SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN, @@ -13,13 +11,7 @@ use crate::SplStakePoolStakedex; impl DepositStake for SplStakePoolStakedex { fn can_accept_stake_deposits(&self) -> bool { - if self.stake_pool.stake_deposit_authority - != find_deposit_authority_program_address( - &self.stake_pool_program, - &self.stake_pool_addr, - ) - .0 - { + if self.stake_pool.stake_deposit_authority != self.deposit_authority_program_address { return false; } self.is_updated_this_epoch() From 100252c6d311ebeab856df84fca5ce704a137a09 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 29 Apr 2024 16:18:02 +0800 Subject: [PATCH 09/33] accept iterator for sanctumlst --- Cargo.lock | 2 +- Cargo.toml | 1 + stakedex_sdk/Cargo.toml | 2 +- stakedex_sdk/src/lib.rs | 78 ++++++++++++++++++--------------- stakedex_sdk/tests/test_main.rs | 6 ++- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dee92c4..3fca5fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4683,7 +4683,7 @@ dependencies = [ [[package]] name = "stakedex_sdk" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "itertools", diff --git a/Cargo.toml b/Cargo.toml index cff476d..cf4c2c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ rust_decimal = ">=1.0,<=1.32.0" # anything >1.32 uses borsh ^1 sanctum-macros = "^1.2" serde = "^1" serde_json = "^1" +solana-readonly-account = "^1" spl-associated-token-account = { version = ">=1", features = ["no-entrypoint"] } spl-math = { version = "0.1.0", features = ["no-entrypoint"]} spl-stake-pool = { version = "^1", features = ["no-entrypoint"] } diff --git a/stakedex_sdk/Cargo.toml b/stakedex_sdk/Cargo.toml index 02db964..bbee73b 100644 --- a/stakedex_sdk/Cargo.toml +++ b/stakedex_sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stakedex_sdk" -version = "0.2.0" +version = "0.3.0" edition = "2021" [features] diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index e464285..fd38afa 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -4,7 +4,7 @@ use anyhow::{anyhow, Result}; use itertools::Itertools; use jupiter_amm_interface::{AccountMap, Amm, KeyedAccount, Quote, QuoteParams, SwapParams}; use lazy_static::lazy_static; -use sanctum_lst_list::{PoolInfo, SanctumLst, SanctumLstList, SplPoolAccounts}; +use sanctum_lst_list::{PoolInfo, SanctumLst, SanctumLstList}; use solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey, system_program}; use spl_token::native_mint; use stakedex_interface::{ @@ -82,27 +82,22 @@ fn init_from_keyed_account_no_params( P::from_keyed_account(&keyed_acc) } -fn sanctum_lst_list_map_all_spl_like T, T>( - mut f: F, -) -> impl Iterator { - SANCTUM_LST_LIST - .sanctum_lst_list - .iter() - .filter_map(move |lst| match lst.pool { - PoolInfo::SanctumSpl(accounts) - | PoolInfo::Spl(accounts) - | PoolInfo::SanctumSplMulti(accounts) => Some(f(lst, accounts)), - PoolInfo::Lido | PoolInfo::Marinade | PoolInfo::ReservePool | PoolInfo::SPool(..) => { - None - } - }) -} - impl Stakedex { /// Gets the list of accounts that must be fetched first to initialize /// Stakedex by passing the result into from_fetched_accounts() - pub fn init_accounts() -> Vec { - sanctum_lst_list_map_all_spl_like(|_lst, SplPoolAccounts { pool, .. }| pool) + pub fn init_accounts<'a, I: Iterator + 'a>( + sanctum_lsts: I, + ) -> Vec { + sanctum_lsts + .filter_map(|lst| match lst.pool { + PoolInfo::SanctumSpl(accounts) + | PoolInfo::Spl(accounts) + | PoolInfo::SanctumSplMulti(accounts) => Some(accounts.pool), + PoolInfo::Lido + | PoolInfo::Marinade + | PoolInfo::ReservePool + | PoolInfo::SPool(..) => None, + }) .chain([ unstake_it_program::SOL_RESERVES_ID, marinade_state::ID, @@ -111,8 +106,10 @@ impl Stakedex { .collect() } - pub fn from_fetched_accounts( - accounts: &HashMap, + /// `sanctum_lsts` must be the same iterator passed to [`Self::init_accounts()`] + pub fn from_fetched_accounts<'a>( + sanctum_lsts: impl Iterator + 'a, + accounts: &'a HashMap, ) -> (Self, Vec) { // So that stakedex is still useable even if some pools fail to load let mut errs = Vec::new(); @@ -137,20 +134,31 @@ impl Stakedex { LidoStakedex::default() }); - let spls = sanctum_lst_list_map_all_spl_like( - |SanctumLst { name, .. }, SplPoolAccounts { pool, .. }| { - get_keyed_account(accounts, &pool) - .map_or_else(Err, |mut ka| { - ka.params = Some(name.as_str().into()); - SplStakePoolStakedex::from_keyed_account(&ka) - }) - .unwrap_or_else(|e| { - errs.push(e); - SplStakePoolStakedex::default() - }) - }, - ) - .collect(); + let spls = sanctum_lsts + .filter_map(|lst| match lst.pool { + PoolInfo::SanctumSpl(spl_accs) + | PoolInfo::Spl(spl_accs) + | PoolInfo::SanctumSplMulti(spl_accs) => { + let name = &lst.name; + let pool = spl_accs.pool; + Some( + get_keyed_account(accounts, &pool) + .map_or_else(Err, |mut ka| { + ka.params = Some(name.as_str().into()); + SplStakePoolStakedex::from_keyed_account(&ka) + }) + .unwrap_or_else(|e| { + errs.push(e); + SplStakePoolStakedex::default() + }), + ) + } + PoolInfo::Lido + | PoolInfo::Marinade + | PoolInfo::ReservePool + | PoolInfo::SPool(..) => None, + }) + .collect(); ( Self { diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index 2dc97a2..5b54135 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -1,5 +1,6 @@ use jupiter_amm_interface::{Quote, QuoteParams, SwapMode, SwapParams}; use lazy_static::lazy_static; +use sanctum_lst_list::SanctumLstList; use solana_account_decoder::UiAccountEncoding; use solana_client::{ rpc_client::RpcClient, @@ -36,8 +37,9 @@ pub mod jupiter_program { lazy_static! { static ref RPC: RpcClient = RpcClient::new(std::env::var("SOLANA_RPC_URL").unwrap()); static ref STAKEDEX: Stakedex = { - let init_accounts = fetch_accounts(&Stakedex::init_accounts()); - let (mut stakedex, errs) = Stakedex::from_fetched_accounts(&init_accounts); + let sll = SanctumLstList::load().sanctum_lst_list; + let init_accounts = fetch_accounts(&Stakedex::init_accounts(sll.iter())); + let (mut stakedex, errs) = Stakedex::from_fetched_accounts(sll.iter(), &init_accounts); if !errs.is_empty() { eprintln!("init errs {:?}", errs); } From dffa97c852d9ff6f6661118cc26e243816602b69 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 29 Apr 2024 16:50:09 +0800 Subject: [PATCH 10/33] dont quote deposit stake for newly added validators --- .../src/stakedex_traits/deposit_stake.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs index 5e4eda7..7764232 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs @@ -5,7 +5,10 @@ use stakedex_deposit_stake_interface::{ spl_stake_pool_deposit_stake_ix, SplStakePoolDepositStakeKeys, SPL_STAKE_POOL_DEPOSIT_STAKE_IX_ACCOUNTS_LEN, }; -use stakedex_sdk_common::{DepositStake, DepositStakeInfo, DepositStakeQuote, WithdrawStakeQuote}; +use stakedex_sdk_common::{ + DepositStake, DepositStakeInfo, DepositStakeQuote, WithdrawStakeQuote, + STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS, +}; use crate::SplStakePoolStakedex; @@ -35,6 +38,13 @@ impl DepositStake for SplStakePoolStakedex { if validator_list_entry.status != StakeStatus::Active.into() { return DepositStakeQuote::default(); } + // This is a newly added validator, so the vsa is not yet active. + // We don't handle depositing to merge with the transient stake account for now. + if u64::from(validator_list_entry.active_stake_lamports) + <= STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS + { + return DepositStakeQuote::default(); + } // Reference: https://github.com/solana-labs/solana-program-library/blob/stake-pool-v0.6.4/stake-pool/program/src/processor.rs#L1971 let total_deposit_lamports = withdraw_stake_quote.lamports_out; let stake_deposit_lamports = withdraw_stake_quote.lamports_staked; From 10d000709fb3d796c312774f1833ea50bfafea77 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 29 Apr 2024 16:51:36 +0800 Subject: [PATCH 11/33] not rdy for solana-readonly-account refactor yet --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cf4c2c4..cff476d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ rust_decimal = ">=1.0,<=1.32.0" # anything >1.32 uses borsh ^1 sanctum-macros = "^1.2" serde = "^1" serde_json = "^1" -solana-readonly-account = "^1" spl-associated-token-account = { version = ">=1", features = ["no-entrypoint"] } spl-math = { version = "0.1.0", features = ["no-entrypoint"]} spl-stake-pool = { version = "^1", features = ["no-entrypoint"] } From 249300368ef2e34ab5aa773fc590fc30434bd97e Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 29 Apr 2024 17:09:33 +0800 Subject: [PATCH 12/33] less restrictive lifetimes --- stakedex_sdk/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index fd38afa..e682e29 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -85,9 +85,7 @@ fn init_from_keyed_account_no_params( impl Stakedex { /// Gets the list of accounts that must be fetched first to initialize /// Stakedex by passing the result into from_fetched_accounts() - pub fn init_accounts<'a, I: Iterator + 'a>( - sanctum_lsts: I, - ) -> Vec { + pub fn init_accounts<'a, I: Iterator>(sanctum_lsts: I) -> Vec { sanctum_lsts .filter_map(|lst| match lst.pool { PoolInfo::SanctumSpl(accounts) @@ -108,8 +106,8 @@ impl Stakedex { /// `sanctum_lsts` must be the same iterator passed to [`Self::init_accounts()`] pub fn from_fetched_accounts<'a>( - sanctum_lsts: impl Iterator + 'a, - accounts: &'a HashMap, + sanctum_lsts: impl Iterator, + accounts: &HashMap, ) -> (Self, Vec) { // So that stakedex is still useable even if some pools fail to load let mut errs = Vec::new(); From 6f609ff8ee4af0098f5749713e1c4e5a5dfa4716 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 29 Apr 2024 17:33:31 +0800 Subject: [PATCH 13/33] new uninitialized --- libs/spl_stake_pool/src/lib.rs | 24 ++++++++++++++++++- .../src/stakedex_traits/base.rs | 9 ++----- stakedex_sdk/src/lib.rs | 12 ++++++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index f7cd1ec..a3f71c2 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -2,13 +2,19 @@ use anyhow::Result; use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch}; use spl_stake_pool::{ error::StakePoolError, - find_withdraw_authority_program_address, + find_deposit_authority_program_address, find_withdraw_authority_program_address, state::{StakePool, StakeStatus, ValidatorList}, }; use stakedex_sdk_common::{WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS}; mod stakedex_traits; +#[derive(Clone, Copy, Debug, Default)] +pub struct SplStakePoolStakedexInitKeys { + pub stake_pool_program: Pubkey, + pub stake_pool_addr: Pubkey, +} + /// A SPL stake pool with possibly custom program ID. /// Works for different deploys of spl stake pool prog - spl, sanctum spl, sanctum spl multi #[derive(Clone, Default)] @@ -23,6 +29,22 @@ pub struct SplStakePoolStakedex { } impl SplStakePoolStakedex { + pub fn new_uninitialized( + SplStakePoolStakedexInitKeys { + stake_pool_program, + stake_pool_addr, + }: SplStakePoolStakedexInitKeys, + ) -> Self { + let (deposit_authority_program_address, _bump) = + find_deposit_authority_program_address(&stake_pool_program, &stake_pool_addr); + Self { + stake_pool_addr, + stake_pool_program, + deposit_authority_program_address, + ..Default::default() + } + } + pub fn update_stake_pool(&mut self, data: &[u8]) -> Result<()> { self.stake_pool = try_from_slice_unchecked::(data)?; Ok(()) diff --git a/libs/spl_stake_pool/src/stakedex_traits/base.rs b/libs/spl_stake_pool/src/stakedex_traits/base.rs index b779292..564ec77 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/base.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/base.rs @@ -1,7 +1,6 @@ use anyhow::Result; use jupiter_amm_interface::{AccountMap, 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}; use crate::SplStakePoolStakedex; @@ -15,14 +14,10 @@ impl InitFromKeyedAccount for SplStakePoolStakedex { params, }: &KeyedAccount, ) -> Result { - let deposit_authority_program_address = - find_deposit_authority_program_address(&account.owner, key).0; - let mut res = Self { + let mut res = Self::new_uninitialized(crate::SplStakePoolStakedexInitKeys { stake_pool_program: account.owner, stake_pool_addr: *key, - deposit_authority_program_address, - ..Default::default() - }; + }); res.update_stake_pool(&account.data)?; diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index e682e29..3a53c83 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -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; +use stakedex_spl_stake_pool::{SplStakePoolStakedex, SplStakePoolStakedexInitKeys}; use stakedex_unstake_it::{UnstakeItStakedex, UnstakeItStakedexPrefund}; pub use stakedex_interface::ID as stakedex_program_id; @@ -147,7 +147,15 @@ impl Stakedex { }) .unwrap_or_else(|e| { errs.push(e); - SplStakePoolStakedex::default() + SplStakePoolStakedex { + stake_pool_label: format!("{name} stake pool"), + ..SplStakePoolStakedex::new_uninitialized( + SplStakePoolStakedexInitKeys { + stake_pool_program: lst.pool.pool_program().into(), + stake_pool_addr: pool, + }, + ) + } }), ) } From 8a0f869c512b5abb0a7ad5b13d33d5a6236ca2aa Mon Sep 17 00:00:00 2001 From: Johnnycus Date: Thu, 2 May 2024 01:49:24 +0500 Subject: [PATCH 14/33] update lst list --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fca5fc..2fea0b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3124,7 +3124,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "sanctum-lst-list" version = "0.2.0" -source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#b4f05b27086fcdf98c3cdf16d3c9531b6a98160b" +source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#a5f36af3724658289e8f7d0033c46bba9ab5effe" dependencies = [ "sanctum-macros", "serde", diff --git a/Cargo.toml b/Cargo.toml index cff476d..7bea507 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-sola # sanctum-lst-list # keep branch = "master" for flexibility of downstream crates -sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = b4f05b2 +sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = a5f36af # solana core crates solana-program = "^1" From a3ccd30416ba2d6b85f2b31cd625360fe6eec11b Mon Sep 17 00:00:00 2001 From: Johnnycus Date: Thu, 2 May 2024 02:34:48 +0500 Subject: [PATCH 15/33] update sanctum lst list again --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2fea0b8..dbd0446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3124,7 +3124,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "sanctum-lst-list" version = "0.2.0" -source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#a5f36af3724658289e8f7d0033c46bba9ab5effe" +source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#93fdec2802abeabec4e956cde7f7552f41db4d3a" dependencies = [ "sanctum-macros", "serde", diff --git a/Cargo.toml b/Cargo.toml index 7bea507..1d2f7b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-sola # sanctum-lst-list # keep branch = "master" for flexibility of downstream crates -sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = a5f36af +sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = 93fdec2 # solana core crates solana-program = "^1" From 4a381352593bbecc6fe8b6fb4d8c794b6a59e8a4 Mon Sep 17 00:00:00 2001 From: Johnnycus Date: Thu, 6 Jun 2024 19:16:56 +0500 Subject: [PATCH 16/33] update sanctum lst list commit hash --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dbd0446..e483293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3124,7 +3124,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "sanctum-lst-list" version = "0.2.0" -source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#93fdec2802abeabec4e956cde7f7552f41db4d3a" +source = "git+https://github.com/igneous-labs/sanctum-lst-list.git?branch=master#ebecde4b4b879b50852fdbc133ffd343bd0a525d" dependencies = [ "sanctum-macros", "serde", diff --git a/Cargo.toml b/Cargo.toml index 1d2f7b9..4899ccb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-sola # sanctum-lst-list # keep branch = "master" for flexibility of downstream crates -sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = 93fdec2 +sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = ebecde4 # solana core crates solana-program = "^1" From 75d3e65d463ad27907a5b473ff1c92a14b0f8b7b Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 17 Jun 2024 21:27:55 +0800 Subject: [PATCH 17/33] extend dedup, cb --- .gitignore | 2 ++ cli/srlut/src/subcmd/extend.rs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e08c794..41b3a53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ target/ .DS_Store + +keys.json diff --git a/cli/srlut/src/subcmd/extend.rs b/cli/srlut/src/subcmd/extend.rs index c1a3927..bf4f343 100644 --- a/cli/srlut/src/subcmd/extend.rs +++ b/cli/srlut/src/subcmd/extend.rs @@ -4,6 +4,7 @@ use clap::Args; use sanctum_solana_cli_utils::{parse_signer, TxSendingNonblockingRpcClient}; use solana_sdk::{ address_lookup_table::{instruction::extend_lookup_table, state::AddressLookupTable}, + compute_budget::ComputeBudgetInstruction, message::{v0::Message, VersionedMessage}, pubkey::Pubkey, transaction::VersionedTransaction, @@ -70,6 +71,8 @@ impl ExtendArgs { let lut = AddressLookupTable::deserialize(&lut_acc_data).unwrap(); lut_list.retain(|addr| !lut.addresses.contains(addr)); + lut_list.sort(); + lut_list.dedup(); if lut_list.is_empty() { eprintln!("LUT already synced, nothing to be done"); @@ -89,7 +92,19 @@ impl ExtendArgs { let rbh = rpc.get_latest_blockhash().await.unwrap(); let tx = VersionedTransaction::try_new( VersionedMessage::V0( - Message::try_compile(&payer.pubkey(), &[ix], &[], rbh).unwrap(), + Message::try_compile( + &payer.pubkey(), + &[ + // hardcode CUs to set to 5k lamports prio fees for now. + // simulation shows extend lut always takes 600 CUs + 600 CUs for CU ixs = 1200 CUs + ComputeBudgetInstruction::set_compute_unit_limit(1_500), + ComputeBudgetInstruction::set_compute_unit_price(3_334), + ix, + ], + &[], + rbh, + ) + .unwrap(), ), &signers, ) From 2fedea87c81ee802cf6ee9be936e65c4bfd1ecfe Mon Sep 17 00:00:00 2001 From: billythedummy Date: Mon, 17 Jun 2024 21:30:20 +0800 Subject: [PATCH 18/33] oops --- cli/srlut/src/subcmd/extend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/srlut/src/subcmd/extend.rs b/cli/srlut/src/subcmd/extend.rs index bf4f343..a709e57 100644 --- a/cli/srlut/src/subcmd/extend.rs +++ b/cli/srlut/src/subcmd/extend.rs @@ -98,7 +98,7 @@ impl ExtendArgs { // hardcode CUs to set to 5k lamports prio fees for now. // simulation shows extend lut always takes 600 CUs + 600 CUs for CU ixs = 1200 CUs ComputeBudgetInstruction::set_compute_unit_limit(1_500), - ComputeBudgetInstruction::set_compute_unit_price(3_334), + ComputeBudgetInstruction::set_compute_unit_price(3_333_334), ix, ], &[], From 902f808f063aff90fedbb21162e9861b5cdfa1d7 Mon Sep 17 00:00:00 2001 From: billythedummy Date: Fri, 13 Sep 2024 15:12:58 +0800 Subject: [PATCH 19/33] add support for deposit cap guard program --- Cargo.lock | 16 +- common/src/address/mod.rs | 2 + common/src/address/spl_deposit_cap_guard.rs | 3 + common/src/base_amm.rs | 4 + .../stakedex_deposit_sol_interface/idl.json | 45 +++ .../src/instructions.rs | 272 +++++++++++++ .../stakedex_deposit_stake_interface/idl.json | 80 ++++ .../src/instructions.rs | 370 ++++++++++++++++++ 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 | 18 +- libs/marinade/src/validator_system.rs | 5 +- .../src/deposit_cap_guard/mod.rs | 58 +++ libs/spl_stake_pool/src/lib.rs | 37 +- .../src/stakedex_traits/base.rs | 16 +- .../src/stakedex_traits/deposit_sol.rs | 38 +- .../src/stakedex_traits/deposit_stake.rs | 67 +++- 17 files changed, 1005 insertions(+), 42 deletions(-) create mode 100644 common/src/address/spl_deposit_cap_guard.rs create mode 100644 libs/spl_stake_pool/src/deposit_cap_guard/mod.rs diff --git a/Cargo.lock b/Cargo.lock index e483293..56ccf10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2225,6 +2225,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-derive" version = "0.3.3" @@ -4904,12 +4910,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -4924,10 +4931,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] diff --git a/common/src/address/mod.rs b/common/src/address/mod.rs index c696394..1981de6 100644 --- a/common/src/address/mod.rs +++ b/common/src/address/mod.rs @@ -2,12 +2,14 @@ mod lido; mod marinade; +mod spl_deposit_cap_guard; mod spl_stake_pool_like; mod stakedex; mod unstake_it; pub use lido::*; pub use marinade::*; +pub use spl_deposit_cap_guard::*; pub use spl_stake_pool_like::*; pub use stakedex::*; pub use unstake_it::*; diff --git a/common/src/address/spl_deposit_cap_guard.rs b/common/src/address/spl_deposit_cap_guard.rs new file mode 100644 index 0000000..d1197fe --- /dev/null +++ b/common/src/address/spl_deposit_cap_guard.rs @@ -0,0 +1,3 @@ +pub mod spl_deposit_cap_guard_program { + sanctum_macros::declare_program_keys!("sdcQPewqY4aVLrXRj5meSPWyE2Hi39tufwMY5XbKGYg", []); +} diff --git a/common/src/base_amm.rs b/common/src/base_amm.rs index 6f66ff1..5b75c50 100644 --- a/common/src/base_amm.rs +++ b/common/src/base_amm.rs @@ -4,6 +4,10 @@ use jupiter_amm_interface::AccountMap; use solana_program::pubkey::Pubkey; pub trait BaseStakePoolAmm { + /// stake pool program ID + /// NB: this is not necessarily the program to invoke to execute the deposit/withdraw: + /// e.g. a spl pool behind the deposit cap guard program + /// will invoke the deposit cap guard program instead fn program_id(&self) -> Pubkey; fn stake_pool_label(&self) -> &str; diff --git a/interfaces/stakedex_deposit_sol_interface/idl.json b/interfaces/stakedex_deposit_sol_interface/idl.json index 69a868e..9c51089 100644 --- a/interfaces/stakedex_deposit_sol_interface/idl.json +++ b/interfaces/stakedex_deposit_sol_interface/idl.json @@ -151,6 +151,51 @@ "type": "u8", "value": 4 } + }, + { + "name": "SplStakePoolDepositCapGuardDepositSol", + "accounts": [ + { + "name": "depositCapGuardProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "depositCapGuardState", + "isMut": false, + "isSigner": false + }, + { + "name": "splStakePoolProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "stakePoolWithdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "stakePoolReserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "stakePoolManagerFee", + "isMut": true, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 5 + } } ], "metadata": { diff --git a/interfaces/stakedex_deposit_sol_interface/src/instructions.rs b/interfaces/stakedex_deposit_sol_interface/src/instructions.rs index 3cf5613..06563ef 100644 --- a/interfaces/stakedex_deposit_sol_interface/src/instructions.rs +++ b/interfaces/stakedex_deposit_sol_interface/src/instructions.rs @@ -13,6 +13,7 @@ pub enum StakedexDepositSolProgramIx { SplStakePoolDepositSol, SanctumSplStakePoolDepositSol, SanctumSplMultiStakePoolDepositSol, + SplStakePoolDepositCapGuardDepositSol, } impl StakedexDepositSolProgramIx { pub fn deserialize(buf: &[u8]) -> std::io::Result { @@ -27,6 +28,9 @@ impl StakedexDepositSolProgramIx { SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM => { Ok(Self::SanctumSplMultiStakePoolDepositSol) } + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM => { + Ok(Self::SplStakePoolDepositCapGuardDepositSol) + } _ => Err(std::io::Error::new( std::io::ErrorKind::Other, format!("discm {:?} not found", maybe_discm), @@ -45,6 +49,9 @@ impl StakedexDepositSolProgramIx { Self::SanctumSplMultiStakePoolDepositSol => { writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_SOL_IX_DISCM]) } + Self::SplStakePoolDepositCapGuardDepositSol => { + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM]) + } } } pub fn try_to_vec(&self) -> std::io::Result> { @@ -982,3 +989,268 @@ pub fn sanctum_spl_multi_stake_pool_deposit_sol_verify_account_privileges<'me, ' sanctum_spl_multi_stake_pool_deposit_sol_verify_writable_privileges(accounts)?; Ok(()) } +pub const SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN: usize = 7; +#[derive(Copy, Clone, Debug)] +pub struct SplStakePoolDepositCapGuardDepositSolAccounts<'me, 'info> { + pub deposit_cap_guard_program: &'me AccountInfo<'info>, + pub deposit_cap_guard_state: &'me AccountInfo<'info>, + pub spl_stake_pool_program: &'me AccountInfo<'info>, + pub stake_pool: &'me AccountInfo<'info>, + pub stake_pool_withdraw_authority: &'me AccountInfo<'info>, + pub stake_pool_reserve_stake: &'me AccountInfo<'info>, + pub stake_pool_manager_fee: &'me AccountInfo<'info>, +} +#[derive(Copy, Clone, Debug)] +pub struct SplStakePoolDepositCapGuardDepositSolKeys { + pub deposit_cap_guard_program: Pubkey, + pub deposit_cap_guard_state: Pubkey, + pub spl_stake_pool_program: Pubkey, + pub stake_pool: Pubkey, + pub stake_pool_withdraw_authority: Pubkey, + pub stake_pool_reserve_stake: Pubkey, + pub stake_pool_manager_fee: Pubkey, +} +impl From> + for SplStakePoolDepositCapGuardDepositSolKeys +{ + fn from(accounts: SplStakePoolDepositCapGuardDepositSolAccounts) -> Self { + Self { + deposit_cap_guard_program: *accounts.deposit_cap_guard_program.key, + deposit_cap_guard_state: *accounts.deposit_cap_guard_state.key, + spl_stake_pool_program: *accounts.spl_stake_pool_program.key, + stake_pool: *accounts.stake_pool.key, + stake_pool_withdraw_authority: *accounts.stake_pool_withdraw_authority.key, + stake_pool_reserve_stake: *accounts.stake_pool_reserve_stake.key, + stake_pool_manager_fee: *accounts.stake_pool_manager_fee.key, + } + } +} +impl From + for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +{ + fn from(keys: SplStakePoolDepositCapGuardDepositSolKeys) -> Self { + [ + AccountMeta { + pubkey: keys.deposit_cap_guard_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_cap_guard_state, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.spl_stake_pool_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_pool, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.stake_pool_withdraw_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_pool_reserve_stake, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.stake_pool_manager_fee, + is_signer: false, + is_writable: true, + }, + ] + } +} +impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositCapGuardDepositSolKeys +{ + fn from( + pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + deposit_cap_guard_program: pubkeys[0], + deposit_cap_guard_state: pubkeys[1], + spl_stake_pool_program: pubkeys[2], + stake_pool: pubkeys[3], + stake_pool_withdraw_authority: pubkeys[4], + stake_pool_reserve_stake: pubkeys[5], + stake_pool_manager_fee: pubkeys[6], + } + } +} +impl<'info> From> + for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN] +{ + fn from(accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, 'info>) -> Self { + [ + accounts.deposit_cap_guard_program.clone(), + accounts.deposit_cap_guard_state.clone(), + accounts.spl_stake_pool_program.clone(), + accounts.stake_pool.clone(), + accounts.stake_pool_withdraw_authority.clone(), + accounts.stake_pool_reserve_stake.clone(), + accounts.stake_pool_manager_fee.clone(), + ] + } +} +impl<'me, 'info> + From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositCapGuardDepositSolAccounts<'me, 'info> +{ + fn from( + arr: &'me [AccountInfo<'info>; + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + deposit_cap_guard_program: &arr[0], + deposit_cap_guard_state: &arr[1], + spl_stake_pool_program: &arr[2], + stake_pool: &arr[3], + stake_pool_withdraw_authority: &arr[4], + stake_pool_reserve_stake: &arr[5], + stake_pool_manager_fee: &arr[6], + } + } +} +pub const SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM: u8 = 5u8; +#[derive(Clone, Debug, PartialEq)] +pub struct SplStakePoolDepositCapGuardDepositSolIxData; +impl SplStakePoolDepositCapGuardDepositSolIxData { + pub fn deserialize(buf: &[u8]) -> std::io::Result { + let mut reader = buf; + let mut maybe_discm_buf = [0u8; 1]; + reader.read_exact(&mut maybe_discm_buf)?; + let maybe_discm = maybe_discm_buf[0]; + if maybe_discm != SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!( + "discm does not match. Expected: {:?}. Received: {:?}", + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM, maybe_discm + ), + )); + } + Ok(Self) + } + pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_DISCM]) + } + pub fn try_to_vec(&self) -> std::io::Result> { + let mut data = Vec::new(); + self.serialize(&mut data)?; + Ok(data) + } +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_ix_with_program_id( + program_id: Pubkey, + keys: SplStakePoolDepositCapGuardDepositSolKeys, +) -> std::io::Result { + let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_SOL_IX_ACCOUNTS_LEN] = + keys.into(); + Ok(Instruction { + program_id, + accounts: Vec::from(metas), + data: SplStakePoolDepositCapGuardDepositSolIxData.try_to_vec()?, + }) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_ix( + keys: SplStakePoolDepositCapGuardDepositSolKeys, +) -> std::io::Result { + spl_stake_pool_deposit_cap_guard_deposit_sol_ix_with_program_id(crate::ID, keys) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_invoke_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, '_>, +) -> ProgramResult { + let keys: SplStakePoolDepositCapGuardDepositSolKeys = accounts.into(); + let ix = spl_stake_pool_deposit_cap_guard_deposit_sol_ix_with_program_id(program_id, keys)?; + invoke_instruction(&ix, accounts) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_invoke( + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, '_>, +) -> ProgramResult { + spl_stake_pool_deposit_cap_guard_deposit_sol_invoke_with_program_id(crate::ID, accounts) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_invoke_signed_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + let keys: SplStakePoolDepositCapGuardDepositSolKeys = accounts.into(); + let ix = spl_stake_pool_deposit_cap_guard_deposit_sol_ix_with_program_id(program_id, keys)?; + invoke_instruction_signed(&ix, accounts, seeds) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_invoke_signed( + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + spl_stake_pool_deposit_cap_guard_deposit_sol_invoke_signed_with_program_id( + crate::ID, + accounts, + seeds, + ) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_verify_account_keys( + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'_, '_>, + keys: SplStakePoolDepositCapGuardDepositSolKeys, +) -> Result<(), (Pubkey, Pubkey)> { + for (actual, expected) in [ + ( + accounts.deposit_cap_guard_program.key, + &keys.deposit_cap_guard_program, + ), + ( + accounts.deposit_cap_guard_state.key, + &keys.deposit_cap_guard_state, + ), + ( + accounts.spl_stake_pool_program.key, + &keys.spl_stake_pool_program, + ), + (accounts.stake_pool.key, &keys.stake_pool), + ( + accounts.stake_pool_withdraw_authority.key, + &keys.stake_pool_withdraw_authority, + ), + ( + accounts.stake_pool_reserve_stake.key, + &keys.stake_pool_reserve_stake, + ), + ( + accounts.stake_pool_manager_fee.key, + &keys.stake_pool_manager_fee, + ), + ] { + if actual != expected { + return Err((*actual, *expected)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_verify_writable_privileges<'me, 'info>( + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + for should_be_writable in [ + accounts.stake_pool, + accounts.stake_pool_reserve_stake, + accounts.stake_pool_manager_fee, + ] { + if !should_be_writable.is_writable { + return Err((should_be_writable, ProgramError::InvalidAccountData)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_sol_verify_account_privileges<'me, 'info>( + accounts: SplStakePoolDepositCapGuardDepositSolAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + spl_stake_pool_deposit_cap_guard_deposit_sol_verify_writable_privileges(accounts)?; + Ok(()) +} diff --git a/interfaces/stakedex_deposit_stake_interface/idl.json b/interfaces/stakedex_deposit_stake_interface/idl.json index aad877c..df902ef 100644 --- a/interfaces/stakedex_deposit_stake_interface/idl.json +++ b/interfaces/stakedex_deposit_stake_interface/idl.json @@ -341,6 +341,86 @@ "type": "u8", "value": 5 } + }, + { + "name": "SplStakePoolDepositCapGuardDepositStake", + "accounts": [ + { + "name": "depositCapGuardProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "depositCapGuardState", + "isMut": false, + "isSigner": false + }, + { + "name": "splStakePoolProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "depositStakeSplStakePool", + "isMut": true, + "isSigner": false + }, + { + "name": "depositStakeValidatorList", + "isMut": true, + "isSigner": false + }, + { + "name": "depositStakeDepositAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "depositStakeWithdrawAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "depositStakeValidatorStake", + "isMut": true, + "isSigner": false + }, + { + "name": "depositStakeReserveStake", + "isMut": true, + "isSigner": false + }, + { + "name": "depositStakeManagerFee", + "isMut": true, + "isSigner": false + }, + { + "name": "clock", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeHistory", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "stakeProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 6 + } } ], "metadata": { diff --git a/interfaces/stakedex_deposit_stake_interface/src/instructions.rs b/interfaces/stakedex_deposit_stake_interface/src/instructions.rs index f0494f6..5c1e23a 100644 --- a/interfaces/stakedex_deposit_stake_interface/src/instructions.rs +++ b/interfaces/stakedex_deposit_stake_interface/src/instructions.rs @@ -14,6 +14,7 @@ pub enum StakedexDepositStakeProgramIx { UnstakeItDepositStake, SanctumSplStakePoolDepositStake, SanctumSplMultiStakePoolDepositStake, + SplStakePoolDepositCapGuardDepositStake, } impl StakedexDepositStakeProgramIx { pub fn deserialize(buf: &[u8]) -> std::io::Result { @@ -31,6 +32,9 @@ impl StakedexDepositStakeProgramIx { SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM => { Ok(Self::SanctumSplMultiStakePoolDepositStake) } + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM => { + Ok(Self::SplStakePoolDepositCapGuardDepositStake) + } _ => Err(std::io::Error::new( std::io::ErrorKind::Other, format!("discm {:?} not found", maybe_discm), @@ -50,6 +54,9 @@ impl StakedexDepositStakeProgramIx { Self::SanctumSplMultiStakePoolDepositStake => { writer.write_all(&[SANCTUM_SPL_MULTI_STAKE_POOL_DEPOSIT_STAKE_IX_DISCM]) } + Self::SplStakePoolDepositCapGuardDepositStake => { + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM]) + } } } pub fn try_to_vec(&self) -> std::io::Result> { @@ -1635,3 +1642,366 @@ pub fn sanctum_spl_multi_stake_pool_deposit_stake_verify_account_privileges<'me, sanctum_spl_multi_stake_pool_deposit_stake_verify_writable_privileges(accounts)?; Ok(()) } +pub const SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN: usize = 14; +#[derive(Copy, Clone, Debug)] +pub struct SplStakePoolDepositCapGuardDepositStakeAccounts<'me, 'info> { + pub deposit_cap_guard_program: &'me AccountInfo<'info>, + pub deposit_cap_guard_state: &'me AccountInfo<'info>, + pub spl_stake_pool_program: &'me AccountInfo<'info>, + pub deposit_stake_spl_stake_pool: &'me AccountInfo<'info>, + pub deposit_stake_validator_list: &'me AccountInfo<'info>, + pub deposit_stake_deposit_authority: &'me AccountInfo<'info>, + pub deposit_stake_withdraw_authority: &'me AccountInfo<'info>, + pub deposit_stake_validator_stake: &'me AccountInfo<'info>, + pub deposit_stake_reserve_stake: &'me AccountInfo<'info>, + pub deposit_stake_manager_fee: &'me AccountInfo<'info>, + pub clock: &'me AccountInfo<'info>, + pub stake_history: &'me AccountInfo<'info>, + pub token_program: &'me AccountInfo<'info>, + pub stake_program: &'me AccountInfo<'info>, +} +#[derive(Copy, Clone, Debug)] +pub struct SplStakePoolDepositCapGuardDepositStakeKeys { + pub deposit_cap_guard_program: Pubkey, + pub deposit_cap_guard_state: Pubkey, + pub spl_stake_pool_program: Pubkey, + pub deposit_stake_spl_stake_pool: Pubkey, + pub deposit_stake_validator_list: Pubkey, + pub deposit_stake_deposit_authority: Pubkey, + pub deposit_stake_withdraw_authority: Pubkey, + pub deposit_stake_validator_stake: Pubkey, + pub deposit_stake_reserve_stake: Pubkey, + pub deposit_stake_manager_fee: Pubkey, + pub clock: Pubkey, + pub stake_history: Pubkey, + pub token_program: Pubkey, + pub stake_program: Pubkey, +} +impl From> + for SplStakePoolDepositCapGuardDepositStakeKeys +{ + fn from(accounts: SplStakePoolDepositCapGuardDepositStakeAccounts) -> Self { + Self { + deposit_cap_guard_program: *accounts.deposit_cap_guard_program.key, + deposit_cap_guard_state: *accounts.deposit_cap_guard_state.key, + spl_stake_pool_program: *accounts.spl_stake_pool_program.key, + deposit_stake_spl_stake_pool: *accounts.deposit_stake_spl_stake_pool.key, + deposit_stake_validator_list: *accounts.deposit_stake_validator_list.key, + deposit_stake_deposit_authority: *accounts.deposit_stake_deposit_authority.key, + deposit_stake_withdraw_authority: *accounts.deposit_stake_withdraw_authority.key, + deposit_stake_validator_stake: *accounts.deposit_stake_validator_stake.key, + deposit_stake_reserve_stake: *accounts.deposit_stake_reserve_stake.key, + deposit_stake_manager_fee: *accounts.deposit_stake_manager_fee.key, + clock: *accounts.clock.key, + stake_history: *accounts.stake_history.key, + token_program: *accounts.token_program.key, + stake_program: *accounts.stake_program.key, + } + } +} +impl From + for [AccountMeta; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +{ + fn from(keys: SplStakePoolDepositCapGuardDepositStakeKeys) -> Self { + [ + AccountMeta { + pubkey: keys.deposit_cap_guard_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_cap_guard_state, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.spl_stake_pool_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_stake_spl_stake_pool, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.deposit_stake_validator_list, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.deposit_stake_deposit_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_stake_withdraw_authority, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.deposit_stake_validator_stake, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.deposit_stake_reserve_stake, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.deposit_stake_manager_fee, + is_signer: false, + is_writable: true, + }, + AccountMeta { + pubkey: keys.clock, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_history, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.token_program, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: keys.stake_program, + is_signer: false, + is_writable: false, + }, + ] + } +} +impl From<[Pubkey; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositCapGuardDepositStakeKeys +{ + fn from( + pubkeys: [Pubkey; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + deposit_cap_guard_program: pubkeys[0], + deposit_cap_guard_state: pubkeys[1], + spl_stake_pool_program: pubkeys[2], + deposit_stake_spl_stake_pool: pubkeys[3], + deposit_stake_validator_list: pubkeys[4], + deposit_stake_deposit_authority: pubkeys[5], + deposit_stake_withdraw_authority: pubkeys[6], + deposit_stake_validator_stake: pubkeys[7], + deposit_stake_reserve_stake: pubkeys[8], + deposit_stake_manager_fee: pubkeys[9], + clock: pubkeys[10], + stake_history: pubkeys[11], + token_program: pubkeys[12], + stake_program: pubkeys[13], + } + } +} +impl<'info> From> + for [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] +{ + fn from(accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, 'info>) -> Self { + [ + accounts.deposit_cap_guard_program.clone(), + accounts.deposit_cap_guard_state.clone(), + accounts.spl_stake_pool_program.clone(), + accounts.deposit_stake_spl_stake_pool.clone(), + accounts.deposit_stake_validator_list.clone(), + accounts.deposit_stake_deposit_authority.clone(), + accounts.deposit_stake_withdraw_authority.clone(), + accounts.deposit_stake_validator_stake.clone(), + accounts.deposit_stake_reserve_stake.clone(), + accounts.deposit_stake_manager_fee.clone(), + accounts.clock.clone(), + accounts.stake_history.clone(), + accounts.token_program.clone(), + accounts.stake_program.clone(), + ] + } +} +impl<'me, 'info> + From<&'me [AccountInfo<'info>; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN]> + for SplStakePoolDepositCapGuardDepositStakeAccounts<'me, 'info> +{ + fn from( + arr: &'me [AccountInfo<'info>; + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN], + ) -> Self { + Self { + deposit_cap_guard_program: &arr[0], + deposit_cap_guard_state: &arr[1], + spl_stake_pool_program: &arr[2], + deposit_stake_spl_stake_pool: &arr[3], + deposit_stake_validator_list: &arr[4], + deposit_stake_deposit_authority: &arr[5], + deposit_stake_withdraw_authority: &arr[6], + deposit_stake_validator_stake: &arr[7], + deposit_stake_reserve_stake: &arr[8], + deposit_stake_manager_fee: &arr[9], + clock: &arr[10], + stake_history: &arr[11], + token_program: &arr[12], + stake_program: &arr[13], + } + } +} +pub const SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM: u8 = 6u8; +#[derive(Clone, Debug, PartialEq)] +pub struct SplStakePoolDepositCapGuardDepositStakeIxData; +impl SplStakePoolDepositCapGuardDepositStakeIxData { + pub fn deserialize(buf: &[u8]) -> std::io::Result { + let mut reader = buf; + let mut maybe_discm_buf = [0u8; 1]; + reader.read_exact(&mut maybe_discm_buf)?; + let maybe_discm = maybe_discm_buf[0]; + if maybe_discm != SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!( + "discm does not match. Expected: {:?}. Received: {:?}", + SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM, maybe_discm + ), + )); + } + Ok(Self) + } + pub fn serialize(&self, mut writer: W) -> std::io::Result<()> { + writer.write_all(&[SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_DISCM]) + } + pub fn try_to_vec(&self) -> std::io::Result> { + let mut data = Vec::new(); + self.serialize(&mut data)?; + Ok(data) + } +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_ix_with_program_id( + program_id: Pubkey, + keys: SplStakePoolDepositCapGuardDepositStakeKeys, +) -> std::io::Result { + let metas: [AccountMeta; SPL_STAKE_POOL_DEPOSIT_CAP_GUARD_DEPOSIT_STAKE_IX_ACCOUNTS_LEN] = + keys.into(); + Ok(Instruction { + program_id, + accounts: Vec::from(metas), + data: SplStakePoolDepositCapGuardDepositStakeIxData.try_to_vec()?, + }) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_ix( + keys: SplStakePoolDepositCapGuardDepositStakeKeys, +) -> std::io::Result { + spl_stake_pool_deposit_cap_guard_deposit_stake_ix_with_program_id(crate::ID, keys) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_invoke_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, '_>, +) -> ProgramResult { + let keys: SplStakePoolDepositCapGuardDepositStakeKeys = accounts.into(); + let ix = spl_stake_pool_deposit_cap_guard_deposit_stake_ix_with_program_id(program_id, keys)?; + invoke_instruction(&ix, accounts) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_invoke( + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, '_>, +) -> ProgramResult { + spl_stake_pool_deposit_cap_guard_deposit_stake_invoke_with_program_id(crate::ID, accounts) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_invoke_signed_with_program_id( + program_id: Pubkey, + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + let keys: SplStakePoolDepositCapGuardDepositStakeKeys = accounts.into(); + let ix = spl_stake_pool_deposit_cap_guard_deposit_stake_ix_with_program_id(program_id, keys)?; + invoke_instruction_signed(&ix, accounts, seeds) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_invoke_signed( + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, '_>, + seeds: &[&[&[u8]]], +) -> ProgramResult { + spl_stake_pool_deposit_cap_guard_deposit_stake_invoke_signed_with_program_id( + crate::ID, + accounts, + seeds, + ) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_verify_account_keys( + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'_, '_>, + keys: SplStakePoolDepositCapGuardDepositStakeKeys, +) -> Result<(), (Pubkey, Pubkey)> { + for (actual, expected) in [ + ( + accounts.deposit_cap_guard_program.key, + &keys.deposit_cap_guard_program, + ), + ( + accounts.deposit_cap_guard_state.key, + &keys.deposit_cap_guard_state, + ), + ( + accounts.spl_stake_pool_program.key, + &keys.spl_stake_pool_program, + ), + ( + accounts.deposit_stake_spl_stake_pool.key, + &keys.deposit_stake_spl_stake_pool, + ), + ( + accounts.deposit_stake_validator_list.key, + &keys.deposit_stake_validator_list, + ), + ( + accounts.deposit_stake_deposit_authority.key, + &keys.deposit_stake_deposit_authority, + ), + ( + accounts.deposit_stake_withdraw_authority.key, + &keys.deposit_stake_withdraw_authority, + ), + ( + accounts.deposit_stake_validator_stake.key, + &keys.deposit_stake_validator_stake, + ), + ( + accounts.deposit_stake_reserve_stake.key, + &keys.deposit_stake_reserve_stake, + ), + ( + accounts.deposit_stake_manager_fee.key, + &keys.deposit_stake_manager_fee, + ), + (accounts.clock.key, &keys.clock), + (accounts.stake_history.key, &keys.stake_history), + (accounts.token_program.key, &keys.token_program), + (accounts.stake_program.key, &keys.stake_program), + ] { + if actual != expected { + return Err((*actual, *expected)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_verify_writable_privileges<'me, 'info>( + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + for should_be_writable in [ + accounts.deposit_stake_spl_stake_pool, + accounts.deposit_stake_validator_list, + accounts.deposit_stake_validator_stake, + accounts.deposit_stake_reserve_stake, + accounts.deposit_stake_manager_fee, + ] { + if !should_be_writable.is_writable { + return Err((should_be_writable, ProgramError::InvalidAccountData)); + } + } + Ok(()) +} +pub fn spl_stake_pool_deposit_cap_guard_deposit_stake_verify_account_privileges<'me, 'info>( + accounts: SplStakePoolDepositCapGuardDepositStakeAccounts<'me, 'info>, +) -> Result<(), (&'me AccountInfo<'info>, ProgramError)> { + spl_stake_pool_deposit_cap_guard_deposit_stake_verify_writable_privileges(accounts)?; + Ok(()) +} diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index dee71a0..9829d5d 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -5,8 +5,8 @@ use jupiter_amm_interface::{ use solana_sdk::{clock::Clock, pubkey::Pubkey, sysvar}; use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN; use stakedex_sdk_common::{ - account_missing_err, find_stake_pool_pair_amm_key, unstake_it_program, DepositStake, - WithdrawStake, TEMPORARY_JUP_AMM_LABEL, + account_missing_err, find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program, + unstake_it_program, DepositStake, WithdrawStake, TEMPORARY_JUP_AMM_LABEL, }; use std::collections::HashSet; @@ -181,6 +181,10 @@ where self.deposit.stake_pool_label().to_lowercase(), ), (unstake_it_program::ID, "unstake.it".to_owned()), + ( + spl_deposit_cap_guard_program::ID, + "spl-deposit-cap-guard".to_owned(), + ), ] } } diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index 8bfa04c..fbdc54a 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -5,8 +5,8 @@ use jupiter_amm_interface::{ use solana_sdk::{clock::Clock, pubkey::Pubkey, sysvar}; use stakedex_interface::PREFUND_SWAP_VIA_STAKE_IX_ACCOUNTS_LEN; use stakedex_sdk_common::{ - account_missing_err, find_stake_pool_pair_amm_key, unstake_it_program, DepositStake, - WithdrawStake, TEMPORARY_JUP_AMM_LABEL, + account_missing_err, find_stake_pool_pair_amm_key, spl_deposit_cap_guard_program, + unstake_it_program, DepositStake, WithdrawStake, TEMPORARY_JUP_AMM_LABEL, }; use std::collections::HashSet; @@ -204,6 +204,10 @@ where self.p2.stake_pool_label().to_lowercase(), ), (unstake_it_program::ID, "unstake.it".to_owned()), + ( + spl_deposit_cap_guard_program::ID, + "spl-deposit-cap-guard".to_owned(), + ), ] } } diff --git a/jup_interface/src/pool_sol/deposit_sol.rs b/jup_interface/src/pool_sol/deposit_sol.rs index 5cc39af..b633bc5 100644 --- a/jup_interface/src/pool_sol/deposit_sol.rs +++ b/jup_interface/src/pool_sol/deposit_sol.rs @@ -6,8 +6,8 @@ use solana_sdk::{account::Account, instruction::AccountMeta, pubkey::Pubkey, sys use spl_token::native_mint; use stakedex_interface::{StakeWrappedSolKeys, STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN}; use stakedex_sdk_common::{ - find_deposit_stake_amm_key, find_fee_token_acc, stakedex_program, wsol_bridge_in, DepositSol, - InitFromKeyedAccount, TEMPORARY_JUP_AMM_LABEL, + find_deposit_stake_amm_key, find_fee_token_acc, spl_deposit_cap_guard_program, + stakedex_program, wsol_bridge_in, DepositSol, InitFromKeyedAccount, TEMPORARY_JUP_AMM_LABEL, }; use std::collections::HashMap; @@ -104,9 +104,15 @@ where } fn program_dependencies(&self) -> Vec<(Pubkey, String)> { - vec![( - self.0.program_id(), - self.0.stake_pool_label().to_lowercase(), - )] + vec![ + ( + self.0.program_id(), + self.0.stake_pool_label().to_lowercase(), + ), + ( + spl_deposit_cap_guard_program::ID, + "spl-deposit-cap-guard".to_owned(), + ), + ] } } diff --git a/libs/marinade/src/validator_system.rs b/libs/marinade/src/validator_system.rs index 5526b6e..917967a 100644 --- a/libs/marinade/src/validator_system.rs +++ b/libs/marinade/src/validator_system.rs @@ -1,10 +1,9 @@ -use marinade_finance_interface::ValidatorRecord; use solana_program::pubkey::Pubkey; use stakedex_sdk_common::marinade_program; -pub struct ValidatorRecordWrapper<'a>(pub &'a ValidatorRecord); +pub struct ValidatorRecordWrapper; -impl<'a> ValidatorRecordWrapper<'a> { +impl ValidatorRecordWrapper { pub const DUPLICATE_FLAG_SEED: &'static [u8] = b"unique_validator"; pub fn find_duplication_flag(state: &Pubkey, validator_account: &Pubkey) -> (Pubkey, u8) { diff --git a/libs/spl_stake_pool/src/deposit_cap_guard/mod.rs b/libs/spl_stake_pool/src/deposit_cap_guard/mod.rs new file mode 100644 index 0000000..164dc1b --- /dev/null +++ b/libs/spl_stake_pool/src/deposit_cap_guard/mod.rs @@ -0,0 +1,58 @@ +use anyhow::{anyhow, Result}; +use solana_program::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, +}; +use stakedex_sdk_common::spl_deposit_cap_guard_program; + +pub fn find_spl_deposit_cap_guard_state( + program_id: &Pubkey, + spl_stake_pool: &Pubkey, +) -> (Pubkey, u8) { + Pubkey::find_program_address(&[spl_stake_pool.as_ref()], program_id) +} + +const LAMPORTS_TY_DISCM: u8 = 1; + +const LST_ATOMICS_TY_DISCM: u8 = 2; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum DepositCap { + Lamports(u64), + LstAtomics(u64), +} + +impl DepositCap { + pub fn try_from_buf(buf: &[u8; 9]) -> Result { + let (ty, amt) = buf.split_last().unwrap(); + let amt: &[u8; 8] = amt.try_into().unwrap(); + let amt = u64::from_le_bytes(*amt); + Ok(match *ty { + LAMPORTS_TY_DISCM => Self::Lamports(amt), + LST_ATOMICS_TY_DISCM => Self::LstAtomics(amt), + _ => Err(anyhow!("invalid deposit cap"))?, + }) + } +} + +pub fn to_deposit_cap_guard_ix( + mut spl_deposit_ix: Instruction, + deposit_cap_guard_state: Pubkey, +) -> Instruction { + spl_deposit_ix.accounts.splice( + 0..0, + [ + AccountMeta { + pubkey: spl_deposit_cap_guard_program::ID, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: deposit_cap_guard_state, + is_signer: false, + is_writable: false, + }, + ], + ); + spl_deposit_ix +} diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index a3f71c2..60216cc 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -1,12 +1,16 @@ -use anyhow::Result; +use anyhow::{anyhow, Result}; +use deposit_cap_guard::{find_spl_deposit_cap_guard_state, DepositCap}; use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch}; use spl_stake_pool::{ error::StakePoolError, find_deposit_authority_program_address, find_withdraw_authority_program_address, state::{StakePool, StakeStatus, ValidatorList}, }; -use stakedex_sdk_common::{WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS}; +use stakedex_sdk_common::{ + spl_deposit_cap_guard_program, WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS, +}; +mod deposit_cap_guard; mod stakedex_traits; #[derive(Clone, Copy, Debug, Default)] @@ -26,6 +30,8 @@ pub struct SplStakePoolStakedex { pub validator_list: ValidatorList, pub curr_epoch: Epoch, pub deposit_authority_program_address: Pubkey, + pub spl_deposit_cap_guard_program_address: Pubkey, + pub deposit_cap_state: Option, } impl SplStakePoolStakedex { @@ -37,10 +43,13 @@ impl SplStakePoolStakedex { ) -> Self { let (deposit_authority_program_address, _bump) = find_deposit_authority_program_address(&stake_pool_program, &stake_pool_addr); + let (spl_deposit_cap_guard_program_address, _bump) = + find_spl_deposit_cap_guard_state(&spl_deposit_cap_guard_program::ID, &stake_pool_addr); Self { stake_pool_addr, stake_pool_program, deposit_authority_program_address, + spl_deposit_cap_guard_program_address, ..Default::default() } } @@ -55,6 +64,20 @@ impl SplStakePoolStakedex { Ok(()) } + pub fn update_deposit_cap_state( + &mut self, + deposit_cap_state_account_data: &[u8], + ) -> Result<()> { + const STATE_DEPOSIT_CAP_OFFSET: usize = 0; + let deposit_cap: &[u8; 9] = deposit_cap_state_account_data + .get(STATE_DEPOSIT_CAP_OFFSET..STATE_DEPOSIT_CAP_OFFSET + 9) + .ok_or_else(|| anyhow!("Invalid deposit cap state account data"))? + .try_into() + .unwrap(); + self.deposit_cap_state = Some(DepositCap::try_from_buf(deposit_cap)?); + Ok(()) + } + pub fn is_updated_this_epoch(&self) -> bool { self.stake_pool.last_update_epoch >= self.curr_epoch } @@ -117,6 +140,16 @@ impl SplStakePoolStakedex { voter: validator_list_entry.vote_account_address, }) } + + #[inline] + pub fn is_sol_deposit_capped(&self) -> bool { + self.stake_pool.sol_deposit_authority == Some(self.spl_deposit_cap_guard_program_address) + } + + #[inline] + pub fn is_stake_deposit_capped(&self) -> bool { + self.stake_pool.stake_deposit_authority == self.spl_deposit_cap_guard_program_address + } } #[cfg(test)] diff --git a/libs/spl_stake_pool/src/stakedex_traits/base.rs b/libs/spl_stake_pool/src/stakedex_traits/base.rs index 564ec77..c32f60f 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/base.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/base.rs @@ -52,11 +52,15 @@ impl BaseStakePoolAmm for SplStakePoolStakedex { } fn get_accounts_to_update(&self) -> Vec { - Vec::from([ + let mut res = Vec::from([ self.stake_pool_addr, self.stake_pool.validator_list, sysvar::clock::ID, - ]) + ]); + if self.is_sol_deposit_capped() || self.is_stake_deposit_capped() { + res.push(self.spl_deposit_cap_guard_program_address); + } + res } fn update(&mut self, accounts_map: &AccountMap) -> Result<()> { @@ -79,6 +83,14 @@ impl BaseStakePoolAmm for SplStakePoolStakedex { .as_ref(); let clock: Clock = bincode::deserialize(clock_data)?; self.curr_epoch = clock.epoch; + if self.is_sol_deposit_capped() || self.is_stake_deposit_capped() { + let deposit_cap_data = accounts_map + .get(&self.spl_deposit_cap_guard_program_address) + .ok_or_else(|| account_missing_err(&self.spl_deposit_cap_guard_program_address))? + .data + .as_ref(); + self.update_deposit_cap_state(deposit_cap_data)?; + } Ok(()) } } diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs index 3eec6e3..3dcb803 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_sol.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use anyhow::{anyhow, Result}; use solana_program::instruction::Instruction; use spl_stake_pool::error::StakePoolError; use stakedex_deposit_sol_interface::{ @@ -7,7 +7,10 @@ use stakedex_deposit_sol_interface::{ }; use stakedex_sdk_common::{DepositSol, DepositSolQuote}; -use crate::SplStakePoolStakedex; +use crate::{ + deposit_cap_guard::{to_deposit_cap_guard_ix, DepositCap}, + SplStakePoolStakedex, +}; impl DepositSol for SplStakePoolStakedex { fn can_accept_sol_deposits(&self) -> bool { @@ -23,6 +26,28 @@ impl DepositSol for SplStakePoolStakedex { .stake_pool .calc_pool_tokens_for_deposit(lamports) .ok_or(StakePoolError::CalculationFailure)?; + if self.is_sol_deposit_capped() { + let deposit_cap = self + .deposit_cap_state + .as_ref() + .ok_or_else(|| anyhow!("deposit cap state not yet fetched"))?; + let will_exceed_deposit_cap = match deposit_cap { + DepositCap::Lamports(max_lamports) => { + let new_pool_lamports = self.stake_pool.total_lamports.saturating_add(lamports); + new_pool_lamports > *max_lamports + } + DepositCap::LstAtomics(max_lst_atomics) => { + let new_lst_atomics = self + .stake_pool + .pool_token_supply + .saturating_add(new_pool_tokens); + new_lst_atomics > *max_lst_atomics + } + }; + if will_exceed_deposit_cap { + return Err(anyhow!("deposit will exceed cap")); + } + } let pool_tokens_sol_deposit_fee = self .stake_pool .calc_pool_tokens_sol_deposit_fee(new_pool_tokens) @@ -51,13 +76,18 @@ impl DepositSol for SplStakePoolStakedex { fn virtual_ix(&self) -> Result { // spl_stake_pool_deposit_sol_ix works for all spl-stake-pool like // (spl, sanctum-spl, sanctum-spl-multi) because the accounts interface is the exact same - Ok(spl_stake_pool_deposit_sol_ix(SplStakePoolDepositSolKeys { + let ix = spl_stake_pool_deposit_sol_ix(SplStakePoolDepositSolKeys { spl_stake_pool_program: self.stake_pool_program, stake_pool: self.stake_pool_addr, stake_pool_withdraw_authority: self.withdraw_authority_addr(), stake_pool_manager_fee: self.stake_pool.manager_fee_account, stake_pool_reserve_stake: self.stake_pool.reserve_stake, - })?) + })?; + Ok(if self.is_sol_deposit_capped() { + to_deposit_cap_guard_ix(ix, self.spl_deposit_cap_guard_program_address) + } else { + ix + }) } fn accounts_len(&self) -> usize { diff --git a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs index 7764232..f028df5 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs @@ -10,7 +10,10 @@ use stakedex_sdk_common::{ STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS, }; -use crate::SplStakePoolStakedex; +use crate::{ + deposit_cap_guard::{to_deposit_cap_guard_ix, DepositCap}, + SplStakePoolStakedex, +}; impl DepositStake for SplStakePoolStakedex { fn can_accept_stake_deposits(&self) -> bool { @@ -56,6 +59,33 @@ impl DepositStake for SplStakePoolStakedex { Some(r) => r, None => return DepositStakeQuote::default(), }; + + if self.is_stake_deposit_capped() { + let deposit_cap = match self.deposit_cap_state.as_ref() { + Some(d) => d, + None => return DepositStakeQuote::default(), + }; + let will_exceed_deposit_cap = match deposit_cap { + DepositCap::Lamports(max_lamports) => { + let new_pool_lamports = self + .stake_pool + .total_lamports + .saturating_add(total_deposit_lamports); + new_pool_lamports > *max_lamports + } + DepositCap::LstAtomics(max_lst_atomics) => { + let new_lst_atomics = self + .stake_pool + .pool_token_supply + .saturating_add(new_pool_tokens); + new_lst_atomics > *max_lst_atomics + } + }; + if will_exceed_deposit_cap { + return DepositStakeQuote::default(); + } + } + let new_pool_tokens_from_stake = match self .stake_pool .calc_pool_tokens_for_deposit(stake_deposit_lamports) @@ -129,22 +159,25 @@ impl DepositStake for SplStakePoolStakedex { .0; // spl_stake_pool_deposit_stake_ix works for all spl-stake-pool like // (spl, sanctum-spl, sanctum-spl-multi) because the accounts interface is the exact same - Ok(spl_stake_pool_deposit_stake_ix( - SplStakePoolDepositStakeKeys { - spl_stake_pool_program: self.stake_pool_program, - deposit_stake_spl_stake_pool: self.stake_pool_addr, - deposit_stake_validator_list: self.stake_pool.validator_list, - deposit_stake_deposit_authority: self.stake_pool.stake_deposit_authority, - deposit_stake_withdraw_authority: self.withdraw_authority_addr(), - deposit_stake_reserve_stake: self.stake_pool.reserve_stake, - deposit_stake_manager_fee: self.stake_pool.manager_fee_account, - deposit_stake_validator_stake, - clock: sysvar::clock::ID, - stake_history: sysvar::stake_history::ID, - token_program: spl_token::ID, - stake_program: stake::program::ID, - }, - )?) + let ix = spl_stake_pool_deposit_stake_ix(SplStakePoolDepositStakeKeys { + spl_stake_pool_program: self.stake_pool_program, + deposit_stake_spl_stake_pool: self.stake_pool_addr, + deposit_stake_validator_list: self.stake_pool.validator_list, + deposit_stake_deposit_authority: self.stake_pool.stake_deposit_authority, + deposit_stake_withdraw_authority: self.withdraw_authority_addr(), + deposit_stake_reserve_stake: self.stake_pool.reserve_stake, + deposit_stake_manager_fee: self.stake_pool.manager_fee_account, + deposit_stake_validator_stake, + clock: sysvar::clock::ID, + stake_history: sysvar::stake_history::ID, + token_program: spl_token::ID, + stake_program: stake::program::ID, + })?; + Ok(if self.is_stake_deposit_capped() { + to_deposit_cap_guard_ix(ix, self.spl_deposit_cap_guard_program_address) + } else { + ix + }) } fn accounts_len(&self) -> usize { From ac6f33ce152c9b801c542d37f62a1704eecf84a0 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Mon, 17 Jul 2023 14:17:09 +1000 Subject: [PATCH 20/33] Jupiter changes for jupiter-core compat --- Cargo.lock | 274 +++++++++++++----- Cargo.toml | 7 +- .../stakedex_interface/src/instructions.rs | 102 ++----- libs/marinade/src/lib.rs | 26 +- stakedex_sdk/Cargo.toml | 1 + stakedex_sdk/tests/test_main.rs | 30 +- 6 files changed, 255 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56ccf10..3e7e35d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2021,7 +2021,7 @@ dependencies = [ [[package]] name = "lido" version = "1.3.6" -source = "git+https://github.com/jup-ag/solido?branch=jupiter#ec25a9b9f3415bf5fd0354cf3ae6d239c28e2c87" +source = "git+https://github.com/jup-ag/solido?rev=2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967#2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967" dependencies = [ "arrayref", "borsh 0.10.3", @@ -2069,14 +2069,11 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "marinade_finance_interface" -version = "0.1.0" -source = "git+https://github.com/igneous-labs/marinade_finance_interface?branch=master#4d1895b6b1c34d731c1589e6d8a6c8feb6258152" +version = "0.0.0" +source = "git+https://github.com/jup-ag/marinade_finance_interface?rev=5747b5350c5505fc2ea597c3f8ae1f8cf71c363d#5747b5350c5505fc2ea597c3f8ae1f8cf71c363d" dependencies = [ "borsh 0.10.3", - "num-derive 0.4.1", - "num-traits", "solana-program", - "thiserror", ] [[package]] @@ -3510,10 +3507,10 @@ dependencies = [ "serde_json", "solana-config-program", "solana-sdk", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-token-2022 1.0.0", "spl-token-group-interface", - "spl-token-metadata-interface", + "spl-token-metadata-interface 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror", "zstd", ] @@ -4136,8 +4133,8 @@ dependencies = [ "solana-account-decoder", "solana-sdk", "spl-associated-token-account", - "spl-memo", - "spl-token 4.0.0", + "spl-memo 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-token-2022 1.0.0", "thiserror", ] @@ -4276,7 +4273,7 @@ dependencies = [ "num-derive 0.4.1", "num-traits", "solana-program", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-token-2022 1.0.0", "thiserror", ] @@ -4289,7 +4286,27 @@ checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator-derive", + "spl-discriminator-derive 0.1.1", +] + +[[package]] +name = "spl-discriminator" +version = "0.1.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator-derive 0.1.0", +] + +[[package]] +name = "spl-discriminator-derive" +version = "0.1.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "quote", + "spl-discriminator-syn 0.1.0", + "syn 2.0.41", ] [[package]] @@ -4299,8 +4316,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fadbefec4f3c678215ca72bd71862697bb06b41fd77c0088902dd3203354387b" dependencies = [ "quote", - "spl-discriminator-syn", + "spl-discriminator-syn 0.1.1", + "syn 2.0.41", +] + +[[package]] +name = "spl-discriminator-syn" +version = "0.1.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "proc-macro2", + "quote", + "solana-program", "syn 2.0.41", + "thiserror", ] [[package]] @@ -4345,6 +4374,19 @@ dependencies = [ "uint 0.9.5", ] +[[package]] +name = "spl-math" +version = "0.2.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "borsh 0.10.3", + "num-derive 0.4.1", + "num-traits", + "solana-program", + "thiserror", + "uint 0.9.5", +] + [[package]] name = "spl-memo" version = "4.0.0" @@ -4354,6 +4396,14 @@ dependencies = [ "solana-program", ] +[[package]] +name = "spl-memo" +version = "4.0.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "solana-program", +] + [[package]] name = "spl-pod" version = "0.1.0" @@ -4364,7 +4414,19 @@ dependencies = [ "bytemuck", "solana-program", "solana-zk-token-sdk", - "spl-program-error", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "spl-pod" +version = "0.1.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "borsh 0.10.3", + "bytemuck", + "solana-program", + "solana-zk-token-sdk", + "spl-program-error 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", ] [[package]] @@ -4376,10 +4438,33 @@ dependencies = [ "num-derive 0.4.1", "num-traits", "solana-program", - "spl-program-error-derive", + "spl-program-error-derive 0.3.1", + "thiserror", +] + +[[package]] +name = "spl-program-error" +version = "0.3.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "num-derive 0.4.1", + "num-traits", + "solana-program", + "spl-program-error-derive 0.3.0", "thiserror", ] +[[package]] +name = "spl-program-error-derive" +version = "0.3.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "proc-macro2", + "quote", + "solana-program", + "syn 2.0.41", +] + [[package]] name = "spl-program-error-derive" version = "0.3.1" @@ -4394,39 +4479,35 @@ dependencies = [ [[package]] name = "spl-stake-pool" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f973333ac37c47dac368cc13088ebebaa7d67e50a7f56a2a83f090bc32c2cb" +version = "0.7.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" dependencies = [ "arrayref", "bincode", "borsh 0.10.3", - "bytemuck", "num-derive 0.4.1", "num-traits", "num_enum 0.7.2", "serde", "serde_derive", "solana-program", - "solana-security-txt", - "spl-math 0.2.0", - "spl-pod", - "spl-token-2022 0.9.0", + "spl-math 0.2.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-token-2022 0.8.0", "thiserror", ] [[package]] name = "spl-tlv-account-resolution" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062e148d3eab7b165582757453632ffeef490c02c86a48bfdb4988f63eefb3b9" +version = "0.3.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", - "spl-type-length-value", + "spl-discriminator 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-program-error 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-type-length-value 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", ] [[package]] @@ -4437,10 +4518,10 @@ checksum = "615d381f48ddd2bb3c57c7f7fb207591a2a05054639b18a62e785117dd7a8683" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", - "spl-type-length-value", + "spl-discriminator 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-type-length-value 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4473,11 +4554,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "spl-token" +version = "4.0.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.1", + "num-traits", + "num_enum 0.7.2", + "solana-program", + "thiserror", +] + [[package]] name = "spl-token-2022" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4abf34a65ba420584a0c35f3903f8d727d1f13ababbdc3f714c6b065a686e86" +version = "0.8.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" dependencies = [ "arrayref", "bytemuck", @@ -4486,12 +4580,12 @@ dependencies = [ "num_enum 0.7.2", "solana-program", "solana-zk-token-sdk", - "spl-memo", - "spl-pod", - "spl-token 4.0.0", - "spl-token-metadata-interface", - "spl-transfer-hook-interface 0.3.0", - "spl-type-length-value", + "spl-memo 4.0.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-token 4.0.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-token-metadata-interface 0.2.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-transfer-hook-interface 0.2.0", + "spl-type-length-value 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", "thiserror", ] @@ -4509,13 +4603,13 @@ dependencies = [ "solana-program", "solana-security-txt", "solana-zk-token-sdk", - "spl-memo", - "spl-pod", - "spl-token 4.0.0", + "spl-memo 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-token-group-interface", - "spl-token-metadata-interface", + "spl-token-metadata-interface 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-transfer-hook-interface 0.4.1", - "spl-type-length-value", + "spl-type-length-value 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror", ] @@ -4527,9 +4621,9 @@ checksum = "b889509d49fa74a4a033ca5dae6c2307e9e918122d97e58562f5c4ffa795c75d" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", + "spl-discriminator 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4540,26 +4634,38 @@ checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" dependencies = [ "borsh 0.10.3", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", - "spl-type-length-value", + "spl-discriminator 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-type-length-value 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "spl-token-metadata-interface" +version = "0.2.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "borsh 0.10.3", + "solana-program", + "spl-discriminator 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-program-error 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-type-length-value 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", ] [[package]] name = "spl-transfer-hook-interface" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051d31803f873cabe71aec3c1b849f35248beae5d19a347d93a5c9cccc5d5a9b" +version = "0.2.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" dependencies = [ "arrayref", "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", - "spl-tlv-account-resolution 0.4.0", - "spl-type-length-value", + "spl-discriminator 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-program-error 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-tlv-account-resolution 0.3.0", + "spl-type-length-value 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", ] [[package]] @@ -4571,11 +4677,11 @@ dependencies = [ "arrayref", "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", + "spl-discriminator 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "spl-tlv-account-resolution 0.5.1", - "spl-type-length-value", + "spl-type-length-value 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4586,9 +4692,21 @@ checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator", - "spl-pod", - "spl-program-error", + "spl-discriminator 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-pod 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spl-program-error 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "spl-type-length-value" +version = "0.3.0" +source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9#a3996814cb44eab2834f72113b742c875ac7b1b9" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-pod 0.1.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", + "spl-program-error 0.3.0 (git+https://github.com/solana-labs/solana-program-library.git?rev=a3996814cb44eab2834f72113b742c875ac7b1b9)", ] [[package]] @@ -4603,7 +4721,7 @@ dependencies = [ "solana-program", "solana-sdk", "spl-associated-token-account", - "spl-token 3.5.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_sdk_common", "tokio", ] @@ -4648,7 +4766,7 @@ dependencies = [ "rand 0.8.5", "rust_decimal", "solana-sdk", - "spl-token 3.5.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_interface", "stakedex_sdk_common", "unstake-lib", @@ -4666,7 +4784,7 @@ dependencies = [ "lido", "solana-client", "solana-program", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_deposit_sol_interface", "stakedex_sdk_common", "stakedex_withdraw_stake_interface", @@ -4681,7 +4799,7 @@ dependencies = [ "jupiter-amm-interface", "marinade_finance_interface", "solana-program", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_deposit_sol_interface", "stakedex_deposit_stake_interface", "stakedex_sdk_common", @@ -4700,7 +4818,7 @@ dependencies = [ "solana-client", "solana-sdk", "spl-associated-token-account", - "spl-token 3.5.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_interface", "stakedex_jup_interface", "stakedex_lido", @@ -4733,7 +4851,7 @@ dependencies = [ "jupiter-amm-interface", "solana-program", "spl-stake-pool", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_deposit_sol_interface", "stakedex_deposit_stake_interface", "stakedex_jup_interface", @@ -4749,7 +4867,7 @@ dependencies = [ "jupiter-amm-interface", "solana-program", "spl-math 0.1.0", - "spl-token 4.0.0", + "spl-token 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "stakedex_deposit_stake_interface", "stakedex_jup_interface", "stakedex_sdk_common", @@ -5248,7 +5366,7 @@ name = "unstake-lib" version = "0.1.0" source = "git+https://github.com/igneous-labs/sanctum-unstake-program.git?rev=069f941#069f941d275cc41b2ec0e3c2dbfae78cae63d786" dependencies = [ - "spl-math 0.2.0", + "spl-math 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unstake_interface", ] diff --git a/Cargo.toml b/Cargo.toml index 4899ccb..cbce37a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ itertools = ">=0.1" jupiter-amm-interface = "~0.3.2" 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", branch = "jupiter", features = ["no-entrypoint"] } # rev = "ec25a9b" -marinade_finance_interface = { git = "https://github.com/igneous-labs/marinade_finance_interface", branch = "master" } # rev = "4d1895b" +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" rand = "0.8.5" @@ -30,7 +30,8 @@ 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 = { version = "^1", 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" tokio = "^1.0" diff --git a/interfaces/stakedex_interface/src/instructions.rs b/interfaces/stakedex_interface/src/instructions.rs index a901d73..a0380e5 100644 --- a/interfaces/stakedex_interface/src/instructions.rs +++ b/interfaces/stakedex_interface/src/instructions.rs @@ -158,56 +158,16 @@ impl From> for StakeWrappedSolKeys { impl From for [AccountMeta; STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN] { fn from(keys: StakeWrappedSolKeys) -> Self { [ - AccountMeta { - pubkey: keys.user, - is_signer: true, - is_writable: false, - }, - AccountMeta { - pubkey: keys.wsol_from, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_to, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.wsol_bridge_in, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.sol_bridge_out, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_fee_token_account, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_mint, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.wsol_mint, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.token_program, - is_signer: false, - is_writable: false, - }, - AccountMeta { - pubkey: keys.system_program, - is_signer: false, - is_writable: false, - }, + AccountMeta::new_readonly(keys.user, false), + AccountMeta::new(keys.wsol_from, false), + AccountMeta::new(keys.dest_token_to, false), + AccountMeta::new(keys.wsol_bridge_in, false), + AccountMeta::new(keys.sol_bridge_out, false), + AccountMeta::new(keys.dest_token_fee_token_account, false), + AccountMeta::new(keys.dest_token_mint, false), + AccountMeta::new_readonly(keys.wsol_mint, false), + AccountMeta::new_readonly(keys.token_program, false), + AccountMeta::new_readonly(keys.system_program, false), ] } } @@ -464,41 +424,13 @@ impl From> for SwapViaStakeKeys { impl From for [AccountMeta; SWAP_VIA_STAKE_IX_ACCOUNTS_LEN] { fn from(keys: SwapViaStakeKeys) -> Self { [ - AccountMeta { - pubkey: keys.user, - is_signer: true, - is_writable: true, - }, - AccountMeta { - pubkey: keys.src_token_from, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_to, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.bridge_stake, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_fee_token_account, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.src_token_mint, - is_signer: false, - is_writable: true, - }, - AccountMeta { - pubkey: keys.dest_token_mint, - is_signer: false, - is_writable: true, - }, + AccountMeta::new(keys.user, false), + AccountMeta::new(keys.src_token_from, false), + AccountMeta::new(keys.dest_token_to, false), + AccountMeta::new(keys.bridge_stake, false), + AccountMeta::new(keys.dest_token_fee_token_account, false), + AccountMeta::new(keys.src_token_mint, false), + AccountMeta::new(keys.dest_token_mint, false), ] } } diff --git a/libs/marinade/src/lib.rs b/libs/marinade/src/lib.rs index 61dbe63..cbd26d9 100644 --- a/libs/marinade/src/lib.rs +++ b/libs/marinade/src/lib.rs @@ -8,7 +8,7 @@ use anyhow::{anyhow, Result}; use borsh::BorshDeserialize; use consts::VALIDATOR_RECORD_BYTE_LENGTH; use marinade_finance_interface::{ - Fee, FeeCents, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem, + Fee, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem, }; use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey}; @@ -26,11 +26,13 @@ impl Default for MarinadeStakedex { account: Pubkey::default(), item_size: 0, count: 0, - reserved1: Pubkey::default(), - reserved2: 0, + new_account: Pubkey::default(), + copied_count: 0, + // reserved1: Pubkey::default(), + // reserved2: 0, }; let zero_fee = Fee { basis_points: 0 }; - let zero_fee_cents = FeeCents { bp_cents: 0 }; + // let zero_fee_cents = FeeCents { bp_cents: 0 }; Self { state: State { msol_mint: Pubkey::default(), @@ -82,14 +84,14 @@ impl Default for MarinadeStakedex { min_withdraw: 0, staking_sol_cap: 0, emergency_cooling_down: 0, - pause_authority: Pubkey::default(), - paused: false, - delayed_unstake_fee: zero_fee_cents.clone(), - withdraw_stake_account_fee: zero_fee_cents, - withdraw_stake_account_enabled: false, - last_stake_move_epoch: 0, - stake_moved: 0, - max_stake_moved_per_epoch: zero_fee, + // pause_authority: Pubkey::default(), + // paused: false, + // delayed_unstake_fee: zero_fee_cents.clone(), + // withdraw_stake_account_fee: zero_fee_cents, + // withdraw_stake_account_enabled: false, + // last_stake_move_epoch: 0, + // stake_moved: 0, + // max_stake_moved_per_epoch: zero_fee, }, validator_records: Vec::new(), } diff --git a/stakedex_sdk/Cargo.toml b/stakedex_sdk/Cargo.toml index bbee73b..c0c2246 100644 --- a/stakedex_sdk/Cargo.toml +++ b/stakedex_sdk/Cargo.toml @@ -28,3 +28,4 @@ stakedex_unstake_it = { workspace = true } [dev-dependencies] solana-client = { workspace = true } +lazy_static = { workspace = true } diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index 5b54135..9e04e83 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -76,13 +76,25 @@ fn fetch_accounts(accounts_pubkeys: &[Pubkey]) -> HashMap { } #[test] -fn test_swap_via_stake_unknown_token() { +fn test_quote_swap_via_stake_jitosol_bsol() { + STAKEDEX + .quote_swap_via_stake(&QuoteParams { + amount: 1_000_000_000, + input_mint: jitosol::ID, + output_mint: bsol::ID, + swap_mode: jupiter_amm_interface::SwapMode::ExactIn, + }) + .unwrap(); +} + +#[test] +fn test_quote_swap_via_stake_unknown_token() { let unknown_token = Pubkey::new_unique(); let res = STAKEDEX.quote_swap_via_stake(&QuoteParams { amount: 1_000_000_000, input_mint: unknown_token, output_mint: bsol::ID, - swap_mode: SwapMode::default(), + swap_mode: jupiter_amm_interface::SwapMode::ExactIn, }); assert!(res.is_err()); } @@ -309,13 +321,17 @@ fn test_jsol_drain_vsa_edge_case() { .validator_list .validators .iter() - .max_by_key(|v| v.active_stake_lamports) + .max_by_key(|v| u64::from(v.active_stake_lamports)) .unwrap(); let max_withdraw_lamports = largest_active_stake_vsi.active_stake_lamports; let parts_after_fees = (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator - STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.numerator) as u128; +<<<<<<< HEAD let max_withdraw_lamports_bef_fees = u128::from(max_withdraw_lamports) +======= + let max_withdraw_lamports_bef_fees = (u128::from(u64::from(max_withdraw_lamports)) +>>>>>>> 6314bd6 (Jupiter changes for jupiter-core compat) * (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator as u128) + parts_after_fees - 1) @@ -327,17 +343,17 @@ fn test_jsol_drain_vsa_edge_case() { .unwrap(); let max_possible_quote = STAKEDEX .quote_swap_via_stake(&QuoteParams { - amount: max_withdraw_jsol, - input_mint: jsol::ID, + amount: 100_000_000_000, + input_mint: stsol::ID, output_mint: msol::ID, - swap_mode: SwapMode::default(), + swap_mode: jupiter_amm_interface::SwapMode::ExactIn, }) .unwrap(); let should_fail = STAKEDEX.quote_swap_via_stake(&QuoteParams { amount: max_withdraw_jsol + 1, input_mint: jsol::ID, output_mint: msol::ID, - swap_mode: SwapMode::default(), + swap_mode: SwapMode::ExactIn, }); assert!(should_fail.is_err()); From 43eb6bdde47111f70e48fae8c6a48808da155540 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Mon, 11 Mar 2024 18:14:27 +1100 Subject: [PATCH 21/33] minor fixes for jupiter usage --- interfaces/stakedex_interface/src/instructions.rs | 2 +- jup_interface/src/pool_pair/two_way.rs | 2 +- stakedex_sdk/tests/test_main.rs | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/interfaces/stakedex_interface/src/instructions.rs b/interfaces/stakedex_interface/src/instructions.rs index a0380e5..328a5b1 100644 --- a/interfaces/stakedex_interface/src/instructions.rs +++ b/interfaces/stakedex_interface/src/instructions.rs @@ -2030,7 +2030,7 @@ impl From for [AccountMeta; PREFUND_SWAP_VIA_STAKE_IX_A [ AccountMeta { pubkey: keys.user, - is_signer: true, + is_signer: false, // Jupiter needs to disable signers since shared accounts are PDAs is_writable: true, }, AccountMeta { diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index fbdc54a..74ba4cc 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -168,7 +168,7 @@ where account_metas.extend(other_account_metas); account_metas.push(swap_params.placeholder_account_meta()); Ok(SwapAndAccountMetas { - swap: Swap::StakeDexSwapViaStake { bridge_stake_seed }, + swap: Swap::StakeDexPrefundSwapViaStake { bridge_stake_seed }, account_metas, }) } diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index 9e04e83..fb5a6f1 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -327,11 +327,7 @@ fn test_jsol_drain_vsa_edge_case() { let parts_after_fees = (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator - STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.numerator) as u128; -<<<<<<< HEAD let max_withdraw_lamports_bef_fees = u128::from(max_withdraw_lamports) -======= - let max_withdraw_lamports_bef_fees = (u128::from(u64::from(max_withdraw_lamports)) ->>>>>>> 6314bd6 (Jupiter changes for jupiter-core compat) * (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator as u128) + parts_after_fees - 1) From c82a5c08ca73537ec9c52e8b0743c72e7f7bbeea Mon Sep 17 00:00:00 2001 From: Arrowana Date: Thu, 14 Mar 2024 11:36:59 +1100 Subject: [PATCH 22/33] disable everything else than deposit sol when not ignoring limitation --- stakedex_sdk/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index 3a53c83..d22e31e 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -531,7 +531,7 @@ impl Stakedex { } /// Creates all possible Amms from the underlying available Stakedexes - pub fn get_amms(self) -> Vec> { + pub fn get_amms(self, ignore_cpi_limitation: bool) -> Vec> { #[derive(Clone)] enum Stakedex { SplStakePool(SplStakePoolStakedex), @@ -572,6 +572,10 @@ impl Stakedex { } } + if !ignore_cpi_limitation { + return amms; + } + // SplStakePool WithdrawStake + DepositStake // UnstakeIt DepositStake // Marinade DepositStake From 987a73844a3c077552ddf072f2e2c07d254278a4 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Fri, 15 Mar 2024 16:52:11 +1100 Subject: [PATCH 23/33] the usual hack for jup usage --- interfaces/stakedex_interface/src/instructions.rs | 4 ++-- jup_interface/src/pool_pair/two_way.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/stakedex_interface/src/instructions.rs b/interfaces/stakedex_interface/src/instructions.rs index 328a5b1..7f298aa 100644 --- a/interfaces/stakedex_interface/src/instructions.rs +++ b/interfaces/stakedex_interface/src/instructions.rs @@ -1317,7 +1317,7 @@ impl From for [AccountMeta; DEPOSIT_STAKE_IX_ACCOUNTS_LEN] { [ AccountMeta { pubkey: keys.user, - is_signer: true, + is_signer: false, is_writable: true, }, AccountMeta { @@ -1600,7 +1600,7 @@ impl From for [AccountMeta; PREFUND_WITHDRAW_STAKE_IX_ [ AccountMeta { pubkey: keys.user, - is_signer: true, + is_signer: false, is_writable: true, }, AccountMeta { diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index 74ba4cc..1a0db38 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -168,7 +168,7 @@ where account_metas.extend(other_account_metas); account_metas.push(swap_params.placeholder_account_meta()); Ok(SwapAndAccountMetas { - swap: Swap::StakeDexPrefundSwapViaStake { bridge_stake_seed }, + swap: Swap::StakeDexPrefundWithdrawStakeAndDepositStake { bridge_stake_seed }, account_metas, }) } From 8811bd39bc65717fbbd23a3d0a5ebb87f7ad2999 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Fri, 15 Mar 2024 17:01:21 +1100 Subject: [PATCH 24/33] revert the disabling hack --- stakedex_sdk/src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index d22e31e..3a53c83 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -531,7 +531,7 @@ impl Stakedex { } /// Creates all possible Amms from the underlying available Stakedexes - pub fn get_amms(self, ignore_cpi_limitation: bool) -> Vec> { + pub fn get_amms(self) -> Vec> { #[derive(Clone)] enum Stakedex { SplStakePool(SplStakePoolStakedex), @@ -572,10 +572,6 @@ impl Stakedex { } } - if !ignore_cpi_limitation { - return amms; - } - // SplStakePool WithdrawStake + DepositStake // UnstakeIt DepositStake // Marinade DepositStake From 76381f03b376d0dc024df2c37ba851a1cf53a7fe Mon Sep 17 00:00:00 2001 From: Siong Ong Date: Sat, 16 Mar 2024 03:17:47 +0800 Subject: [PATCH 25/33] allow it to compile. --- Cargo.lock | 92 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 2 +- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e7e35d..f9828dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,7 +363,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -756,7 +756,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1088,7 +1088,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1099,7 +1099,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1229,7 +1229,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1252,7 +1252,7 @@ checksum = "a6cbae11b3de8fce2a456e8ea3dada226b35fe791f0dc1d360c0941f0bb681f3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1334,7 +1334,7 @@ checksum = "03cdc46ec28bd728e67540c528013c6a10eb69a02eb31078a1bda695438cbfb8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1471,7 +1471,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -1925,9 +1925,9 @@ dependencies = [ [[package]] name = "jupiter-amm-interface" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad613279e534eba2c9d95ef6f2d2c7e170f6647ce50216301741ed3e73a79bb" +checksum = "d3d08fe25539f5064257e7f372e8a172099656c248891c09c59318870de7e21a" dependencies = [ "anyhow", "borsh 0.10.3", @@ -2247,7 +2247,7 @@ checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -2350,7 +2350,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -2362,7 +2362,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -2604,9 +2604,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -2648,7 +2648,7 @@ checksum = "9e2e25ee72f5b24d773cae88422baddefff7714f97aab68d96fe2b6fc4a28fb2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -2701,9 +2701,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3146,7 +3146,7 @@ dependencies = [ "proc-macro2", "quote", "solana-program", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -3197,7 +3197,7 @@ checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -3247,9 +3247,9 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] @@ -3265,20 +3265,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -3333,7 +3333,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -3345,7 +3345,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -3656,7 +3656,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4034,7 +4034,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4306,7 +4306,7 @@ source = "git+https://github.com/solana-labs/solana-program-library.git?rev=a399 dependencies = [ "quote", "spl-discriminator-syn 0.1.0", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4317,7 +4317,7 @@ checksum = "fadbefec4f3c678215ca72bd71862697bb06b41fd77c0088902dd3203354387b" dependencies = [ "quote", "spl-discriminator-syn 0.1.1", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4328,7 +4328,7 @@ dependencies = [ "proc-macro2", "quote", "solana-program", - "syn 2.0.41", + "syn 2.0.52", "thiserror", ] @@ -4341,7 +4341,7 @@ dependencies = [ "proc-macro2", "quote", "sha2 0.10.8", - "syn 2.0.41", + "syn 2.0.52", "thiserror", ] @@ -4462,7 +4462,7 @@ dependencies = [ "proc-macro2", "quote", "solana-program", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4474,7 +4474,7 @@ dependencies = [ "proc-macro2", "quote", "sha2 0.10.8", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -4921,9 +4921,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -5023,7 +5023,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -5118,7 +5118,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -5234,7 +5234,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -5487,7 +5487,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", "wasm-bindgen-shared", ] @@ -5521,7 +5521,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5867,7 +5867,7 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] @@ -5887,7 +5887,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.52", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index cbce37a..1265826 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ bincode = "^1.0" borsh = ">=0.9,<1.0.0" clap = "^3" itertools = ">=0.1" -jupiter-amm-interface = "~0.3.2" +jupiter-amm-interface = "~0.3.3" 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"] } From 4a5a653f03147187fea7f7c70dddac348407c709 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Mon, 18 Mar 2024 06:33:56 +1100 Subject: [PATCH 26/33] fix wrong swap enum for one way --- jup_interface/src/pool_pair/one_way.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index 9829d5d..1b4c34f 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -143,7 +143,7 @@ where )?); account_metas.push(swap_params.placeholder_account_meta()); Ok(SwapAndAccountMetas { - swap: Swap::StakeDexSwapViaStake { bridge_stake_seed }, + swap: Swap::StakeDexPrefundWithdrawStakeAndDepositStake { bridge_stake_seed }, account_metas, }) } From f39c7365f68cf96240c832fc3e55f9d0e15ce1a7 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 27/33] 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 f9828dd..c64ec72 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 1265826..0d59bb1 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 1b4c34f..bac6fc0 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 1a0db38..197e06f 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 b633bc5..efc8c2c 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 c32f60f..7dd406b 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::new_uninitialized(crate::SplStakePoolStakedexInitKeys { 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 3a53c83..dad2684 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}; 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(), + }, + ) } impl Stakedex { @@ -143,7 +151,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(), // Ok because unused internally + }, + ) }) .unwrap_or_else(|e| { errs.push(e); From b636f3e54b1ab115382c49be35b932533d63b415 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Tue, 7 May 2024 10:29:35 +1000 Subject: [PATCH 28/33] Reexport SanctumLstList --- stakedex_sdk/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index dad2684..30906b0 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -6,7 +6,7 @@ use jupiter_amm_interface::{ AccountMap, Amm, AmmContext, ClockRef, KeyedAccount, Quote, QuoteParams, SwapParams, }; use lazy_static::lazy_static; -use sanctum_lst_list::{PoolInfo, SanctumLst, SanctumLstList}; +use sanctum_lst_list::{PoolInfo, SanctumLst}; use solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey, system_program}; use spl_token::native_mint; use stakedex_interface::{ @@ -29,6 +29,7 @@ use stakedex_sdk_common::{ use stakedex_spl_stake_pool::{SplStakePoolStakedex, SplStakePoolStakedexInitKeys}; use stakedex_unstake_it::{UnstakeItStakedex, UnstakeItStakedexPrefund}; +pub use sanctum_lst_list::SanctumLstList; pub use stakedex_interface::ID as stakedex_program_id; /// mainnet LUT that contains prefund accounts and other common accounts From 489f7cddb9980d6030b396ebee7d5fd619e58cb9 Mon Sep 17 00:00:00 2001 From: zyzy Date: Mon, 29 Jul 2024 16:27:38 +0800 Subject: [PATCH 29/33] fix: use accountMap --- jup_interface/src/pool_sol/deposit_sol.rs | 8 ++++---- stakedex_sdk/src/lib.rs | 8 ++++---- stakedex_sdk/tests/test_main.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/jup_interface/src/pool_sol/deposit_sol.rs b/jup_interface/src/pool_sol/deposit_sol.rs index efc8c2c..fa3d74d 100644 --- a/jup_interface/src/pool_sol/deposit_sol.rs +++ b/jup_interface/src/pool_sol/deposit_sol.rs @@ -1,15 +1,15 @@ use anyhow::{anyhow, Result}; use jupiter_amm_interface::{ - Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, SwapParams, + AccountMap, Amm, AmmContext, KeyedAccount, Quote, QuoteParams, Swap, SwapAndAccountMetas, + SwapParams, }; -use solana_sdk::{account::Account, instruction::AccountMeta, pubkey::Pubkey, system_program}; +use solana_sdk::{instruction::AccountMeta, pubkey::Pubkey, system_program}; use spl_token::native_mint; use stakedex_interface::{StakeWrappedSolKeys, STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN}; use stakedex_sdk_common::{ find_deposit_stake_amm_key, find_fee_token_acc, spl_deposit_cap_guard_program, stakedex_program, wsol_bridge_in, DepositSol, InitFromKeyedAccount, TEMPORARY_JUP_AMM_LABEL, }; -use std::collections::HashMap; use crate::jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META; @@ -43,7 +43,7 @@ where self.0.get_accounts_to_update() } - fn update(&mut self, accounts_map: &HashMap) -> Result<()> { + fn update(&mut self, accounts_map: &AccountMap) -> Result<()> { self.0.update(accounts_map) } diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index 30906b0..59845f4 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -66,7 +66,7 @@ pub struct Stakedex { pub lido: LidoStakedex, } -fn get_keyed_account(accounts: &HashMap, key: &Pubkey) -> Result { +fn get_keyed_account(accounts: &AccountMap, key: &Pubkey) -> Result { Ok(KeyedAccount { key: *key, account: accounts @@ -78,7 +78,7 @@ fn get_keyed_account(accounts: &HashMap, key: &Pubkey) -> Resul } fn init_from_keyed_account_no_params( - accounts: &HashMap, + accounts: &AccountMap, key: &Pubkey, ) -> Result

{ let keyed_acc = get_keyed_account(accounts, key)?; @@ -116,7 +116,7 @@ impl Stakedex { /// `sanctum_lsts` must be the same iterator passed to [`Self::init_accounts()`] pub fn from_fetched_accounts<'a>( sanctum_lsts: impl Iterator, - accounts: &HashMap, + accounts: &AccountMap, ) -> (Self, Vec) { // So that stakedex is still useable even if some pools fail to load let mut errs = Vec::new(); @@ -220,7 +220,7 @@ impl Stakedex { }) } - pub fn update(&mut self, account_map: &HashMap) -> Vec { + pub fn update(&mut self, account_map: &AccountMap) -> Vec { // 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, diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index fb5a6f1..117f334 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -1,4 +1,4 @@ -use jupiter_amm_interface::{Quote, QuoteParams, SwapMode, SwapParams}; +use jupiter_amm_interface::{AccountMap, Quote, QuoteParams, SwapMode, SwapParams}; use lazy_static::lazy_static; use sanctum_lst_list::SanctumLstList; use solana_account_decoder::UiAccountEncoding; @@ -62,7 +62,7 @@ lazy_static! { }; } -fn fetch_accounts(accounts_pubkeys: &[Pubkey]) -> HashMap { +fn fetch_accounts(accounts_pubkeys: &[Pubkey]) -> AccountMap { let fetched = RPC.get_multiple_accounts(accounts_pubkeys).unwrap(); zip(accounts_pubkeys, fetched) .filter_map(|(pubkey, opt)| match opt { From a8d22627b76632a72419f9229b1fdbb839b9be4b Mon Sep 17 00:00:00 2001 From: zyzy Date: Tue, 3 Sep 2024 14:51:26 +0800 Subject: [PATCH 30/33] 1.18 --- Cargo.lock | 458 ++++++++++++++++++------------------- Cargo.toml | 14 +- libs/unstake_it/src/lib.rs | 2 +- 3 files changed, 226 insertions(+), 248 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c64ec72..f99dfc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.4" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72832d73be48bac96a5d7944568f305d829ed55b0ce3b483647089dfaf6cf704" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom 0.2.11", @@ -357,9 +357,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", @@ -412,9 +412,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -439,9 +439,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" dependencies = [ "serde", ] @@ -535,6 +535,16 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "borsh" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d4d6dafc1a3bb54687538972158f07b2c948bc57d5890df22c0739098b3028" +dependencies = [ + "borsh-derive 1.3.0", + "cfg_aliases", +] + [[package]] name = "borsh-derive" version = "0.7.2" @@ -586,6 +596,20 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4918709cc4dd777ad2b6303ed03cb37f3ca0ccede8c1b0d28ac6db8f4710e0" +dependencies = [ + "once_cell", + "proc-macro-crate 2.0.1", + "proc-macro2", + "quote", + "syn 2.0.52", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" version = "0.7.2" @@ -797,6 +821,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -899,15 +929,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -978,11 +1008,10 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.9" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ - "cfg-if", "crossbeam-utils", ] @@ -1011,12 +1040,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" -dependencies = [ - "cfg-if", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -1104,12 +1130,15 @@ dependencies = [ [[package]] name = "dashmap" -version = "4.0.2" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "num_cpus", + "hashbrown 0.14.3", + "lock_api", + "once_cell", + "parking_lot_core", ] [[package]] @@ -1417,9 +1446,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1432,9 +1461,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1442,15 +1471,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1459,15 +1488,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", @@ -1476,21 +1505,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -1620,7 +1649,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.4", + "ahash 0.8.11", ] [[package]] @@ -1901,9 +1930,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -1955,9 +1984,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libredox" @@ -1965,7 +1994,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "libc", "redox_syscall", ] @@ -2021,7 +2050,7 @@ dependencies = [ [[package]] name = "lido" version = "1.3.6" -source = "git+https://github.com/jup-ag/solido?rev=2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967#2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967" +source = "git+https://github.com/jup-ag/solido?rev=a0de12d06502680277405c7e795ffa82f30af38c#a0de12d06502680277405c7e795ffa82f30af38c" dependencies = [ "arrayref", "borsh 0.10.3", @@ -2796,9 +2825,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -2806,9 +2835,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -2891,7 +2920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ "async-compression", - "base64 0.21.5", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -3006,12 +3035,12 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.32.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c4216490d5a413bc6d10fa4742bd7d4955941d062c0ef873141d6b0e7b30fd" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", - "borsh 0.10.3", + "borsh 1.3.0", "bytes", "num-traits", "rand 0.8.5", @@ -3062,7 +3091,7 @@ version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -3071,9 +3100,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.7", @@ -3099,7 +3128,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", ] [[package]] @@ -3241,9 +3270,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" @@ -3256,9 +3285,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] @@ -3313,7 +3342,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "chrono", "hex", "indexmap 1.9.3", @@ -3350,9 +3379,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.29" +version = "0.9.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15e0ef66bf939a7c890a0bf6d5a733c70202225f9888a89ed5c62298b019129" +checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" dependencies = [ "indexmap 2.1.0", "itoa", @@ -3445,6 +3474,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "sized-chunks" version = "0.6.5" @@ -3466,9 +3501,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -3492,12 +3527,12 @@ dependencies = [ [[package]] name = "solana-account-decoder" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bc7bb65888ae7e13180dcd6a74d3233fcc57b627e138e34f2ac01601e92e6a2" +checksum = "f5e54ec43b0262c19a3c87bf2dbd52c6bc6d4f9307246fe4b666fd87f06305e5" dependencies = [ "Inflector", - "base64 0.21.5", + "base64 0.21.7", "bincode", "bs58", "bv", @@ -3517,9 +3552,9 @@ dependencies = [ [[package]] name = "solana-clap-utils" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b29a50c8ac6cb7cdefa3da425bad3122d14a7b9f5e1a6e1e4e64eb53c778c1ff" +checksum = "117bf11e4d15b529dd9dfa2680abaf8bd3c1d8f7cb0586a5accdac5a2ecc7cc5" dependencies = [ "chrono", "clap 2.34.0", @@ -3534,9 +3569,9 @@ dependencies = [ [[package]] name = "solana-cli-config" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47c88fefb22ac1f9f8e0f2d33da1b3f6ebc7411e112a26d6490f03d50254c493" +checksum = "884f604b0ebb6572103b92b043cfe977ad13137f54c307e9d2c14b8b5079d150" dependencies = [ "dirs-next", "lazy_static", @@ -3550,9 +3585,9 @@ dependencies = [ [[package]] name = "solana-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93b28ec883a4bb22289ef31851abe5f2c9247748cf79580aef954ec9759b84ca" +checksum = "1501330d85c1a790f45f11330616bd6f0b9acd2193477268a65a38ce3b7cfdd0" dependencies = [ "async-trait", "bincode", @@ -3583,9 +3618,9 @@ dependencies = [ [[package]] name = "solana-config-program" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5fa041dc7ebb8079fb15a4691b2822d8a67a615f90a838e43aa556eaab6178" +checksum = "d00d0d031f3d97e3f59305c4aabf9da7359fad86dbaeb43b61a1ea13224e0b8a" dependencies = [ "bincode", "chrono", @@ -3597,9 +3632,9 @@ dependencies = [ [[package]] name = "solana-connection-cache" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f933d76a147dc6bb37daff4314c7b63a8a4778be259d8cbe8126294d97b328d" +checksum = "90fa9ff6c33772441670e446b1d43e787aa315e95f2f9c14e3e9508b814bc8e5" dependencies = [ "async-trait", "bincode", @@ -3619,17 +3654,13 @@ dependencies = [ [[package]] name = "solana-frozen-abi" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a64bc1df0fcda5884f6cf6eb50f8aa283dbf767e984fcbbb53e344859b597f" +checksum = "4bfcde2fc6946c99c7e3400fadd04d1628d675bfd66cb34d461c0f3224bd27d1" dependencies = [ - "ahash 0.8.4", - "blake3", "block-buffer 0.10.4", "bs58", "bv", - "byteorder", - "cc", "either", "generic-array", "im", @@ -3640,7 +3671,6 @@ dependencies = [ "serde", "serde_bytes", "serde_derive", - "serde_json", "sha2 0.10.8", "solana-frozen-abi-macro", "subtle", @@ -3649,9 +3679,9 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8e0e27e6639f23a7d23e0ae7b92b8ab5d848bb649e962f6528a795988ca161" +checksum = "d5024d241425f4e99f112ee03bfa89e526c86c7ca9bd7e13448a7f2dffb7e060" dependencies = [ "proc-macro2", "quote", @@ -3661,9 +3691,9 @@ dependencies = [ [[package]] name = "solana-logger" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b868a3b8148d7ab3e44a6b40530843903bedaaf8c6a2aa3d797eb01b3435538d" +checksum = "10948c30d138d6fbfc2ae78a4882be5a9ebffa4bb1239c4efc386104ebc35b7f" dependencies = [ "env_logger", "lazy_static", @@ -3672,9 +3702,9 @@ dependencies = [ [[package]] name = "solana-measure" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd5a243ef9e5f0364a3625a74ac701ff15d28d57f997cfcfc5b27badb0f0f36d" +checksum = "379355a731abf50bb5ef1e4afba02ac8c835c25bb18e32229bb481657d5c9eca" dependencies = [ "log", "solana-sdk", @@ -3682,9 +3712,9 @@ dependencies = [ [[package]] name = "solana-metrics" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b007b5f98cf2f3760fd28b3e9131e68ba9e55a9b164be966fc108e859999c1f8" +checksum = "82a6f767cf39d69104bff52602f3141d6abfbdd55b4eb310f8fbbbf862b27e6f" dependencies = [ "crossbeam-channel", "gethostname", @@ -3697,9 +3727,9 @@ dependencies = [ [[package]] name = "solana-net-utils" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6de74b7158359b85c773436284cd0bf68f925434888d2681d3db68dc1a1e4460" +checksum = "c81ade42b553c7de08fb97cf3cfe44545f59a247e90042a67d224d62a8a189d7" dependencies = [ "bincode", "clap 3.2.25", @@ -3719,11 +3749,11 @@ dependencies = [ [[package]] name = "solana-perf" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a837e4272603ec6b73e72db330f3b1b3b03174b6f2f57d28daf8d702adaa35" +checksum = "9ecdf31e535743515d31392f210d132463300b5d3de7c3e26f6b344b6c941c42" dependencies = [ - "ahash 0.8.4", + "ahash 0.8.11", "bincode", "bv", "caps", @@ -3748,20 +3778,21 @@ dependencies = [ [[package]] name = "solana-program" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1ec090add6d789cd498291fbbcbc4207ec5d8f4df4e93cf9bd30feed14474a1" +checksum = "76056fecde0fe0ece8b457b719729c17173333471c72ad41969982975a10d6e0" dependencies = [ "ark-bn254", "ark-ec", "ark-ff", "ark-serialize", - "base64 0.21.5", + "base64 0.21.7", "bincode", - "bitflags 2.4.1", + "bitflags 2.6.0", "blake3", "borsh 0.10.3", "borsh 0.9.3", + "borsh 1.3.0", "bs58", "bv", "bytemuck", @@ -3779,7 +3810,7 @@ dependencies = [ "log", "memoffset 0.9.0", "num-bigint 0.4.4", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", "parking_lot", "rand 0.8.5", @@ -3802,18 +3833,18 @@ dependencies = [ [[package]] name = "solana-program-runtime" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b0b2035bff6725d6792c2709871b3df58517e5b064fe8ae9a00aa9ec7c2804" +checksum = "e566a9e61ecdc250824314864654dd370abf561fa8328f6e08b3bc96ccc5b80d" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bincode", "eager", "enum-iterator", "itertools", "libc", "log", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", "percentage", "rand 0.8.5", @@ -3830,9 +3861,9 @@ dependencies = [ [[package]] name = "solana-pubsub-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb2e34874dc723285d1eedeb5d6c9b51e4b19e0b71434b5121019d21d4e5553" +checksum = "a5d997840e6d033edc4fca8f06b920726dc18d3a5bbc1e538b2154cc3b71acd1" dependencies = [ "crossbeam-channel", "futures-util", @@ -3855,9 +3886,9 @@ dependencies = [ [[package]] name = "solana-quic-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0a48caf146b1f226b0a049053ae77034df28818413c20528834b11d61e3c6a" +checksum = "6e689a97cefa6a005cd305210234f3dc78aacc934c0f76d210a264fae36ee432" dependencies = [ "async-mutex", "async-trait", @@ -3882,9 +3913,9 @@ dependencies = [ [[package]] name = "solana-rayon-threadlimit" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b9aa7bb42651394ac4f087df364bfcf801d8d9f249e94721e1ef15240c5887" +checksum = "bbf70f0441603e553fc3db30c1eec9f10cecc27849e7dc74d5f692d5a41a56ca" dependencies = [ "lazy_static", "num_cpus", @@ -3892,14 +3923,14 @@ dependencies = [ [[package]] name = "solana-remote-wallet" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68904b56c0457dd688300069f825c169d30acfa4eddfd5662b0ca700437c5d78" +checksum = "9651b3f2c3df39a1a6fc87fe792bdb3ec3d84a8169c0a57c86335b48d6cb1491" dependencies = [ "console", "dialoguer", "log", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", "parking_lot", "qstring", @@ -3911,12 +3942,12 @@ dependencies = [ [[package]] name = "solana-rpc-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee48b323271070ea8e2902c101d808d54c7d910d573b02a646e0c462aa6de2dc" +checksum = "d753d116aacc43ef64a2bc8d25f8b20af47c366b29aa859186124e226d6e3819" dependencies = [ "async-trait", - "base64 0.21.5", + "base64 0.21.7", "bincode", "bs58", "indicatif", @@ -3937,11 +3968,11 @@ dependencies = [ [[package]] name = "solana-rpc-client-api" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa40fc52832e790c53e27baf771926542b5b9a370c5dad59cbc31055b1e52a2b" +checksum = "617df2c53f948c821cefca6824e376aac04ff0d844bb27f4d3ada9e211bcffe7" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bs58", "jsonrpc-core", "reqwest", @@ -3959,9 +3990,9 @@ dependencies = [ [[package]] name = "solana-rpc-client-nonce-utils" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd6be836c589018ad607193ccf27677ac8e97125c40642ab2183f23deb95a5f" +checksum = "c2d34cf36289cc35a0b18cd518a256312090368a37f40b448520e260923558a9" dependencies = [ "clap 2.34.0", "solana-clap-utils", @@ -3972,15 +4003,15 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2817e4e1190e3539c989b3b350ee306b91e63959e19638e2632cc92ac9041527" +checksum = "b4b3f2080eddef6552fde7f149c429cf05b9bb0605a068b0d28e19d793e24df4" dependencies = [ "assert_matches", - "base64 0.21.5", + "base64 0.21.7", "bincode", - "bitflags 2.4.1", - "borsh 0.10.3", + "bitflags 2.6.0", + "borsh 1.3.0", "bs58", "bytemuck", "byteorder", @@ -3997,9 +4028,9 @@ dependencies = [ "libsecp256k1", "log", "memmap2", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", - "num_enum 0.6.1", + "num_enum 0.7.2", "pbkdf2 0.11.0", "qstring", "qualifier_attr", @@ -4014,6 +4045,7 @@ dependencies = [ "serde_with 2.3.3", "sha2 0.10.8", "sha3 0.10.8", + "siphasher", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", @@ -4026,9 +4058,9 @@ dependencies = [ [[package]] name = "solana-sdk-macro" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04051488f4275df58be7abf34dc0583f4d38df72000a047c85a549c6a996acc0" +checksum = "2a8613ca80150f7e277e773620ba65d2c5fcc3a08eb8026627d601421ab43aef" dependencies = [ "bs58", "proc-macro2", @@ -4045,9 +4077,9 @@ checksum = "468aa43b7edb1f9b7b7b686d5c3aeb6630dc1708e86e31343499dd5c4d775183" [[package]] name = "solana-streamer" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e4a9a97a9e559d4b1eaeb6a5700c9c9c109a15fdac1f7253af529677a69b39c" +checksum = "979d470dd7c589679a2e036078921989a2563f333b73b31e2fdceb09a6d55a29" dependencies = [ "async-channel", "bytes", @@ -4067,6 +4099,7 @@ dependencies = [ "rand 0.8.5", "rcgen", "rustls", + "smallvec", "solana-metrics", "solana-perf", "solana-sdk", @@ -4077,9 +4110,9 @@ dependencies = [ [[package]] name = "solana-thin-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "603ed51b04bbe7645c2f8a532adc1cf30e74b92d321171fc381caf29836f6fe0" +checksum = "851b9ae239d098c766aee3558330cc16edd0524c9cf3f9cf7c64f53b1024d507" dependencies = [ "bincode", "log", @@ -4092,9 +4125,9 @@ dependencies = [ [[package]] name = "solana-tpu-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbd9242b9df608c1e4d8ed0a22e68e864313678aa2d6f78e3a6bb75b42859a08" +checksum = "6a7a7e5a522fe5333fcb47e02fb7da73ff614d917754167937b5523c383ce161" dependencies = [ "async-trait", "bincode", @@ -4116,12 +4149,12 @@ dependencies = [ [[package]] name = "solana-transaction-status" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53ebc2543fe6066cc3b530fce572d1a204a207fa801b258682efcf1955da683" +checksum = "51be349fb9301d2a0fdd0b9ba5341e5f72bf4900ca4c0ede04748bc9038d15e8" dependencies = [ "Inflector", - "base64 0.21.5", + "base64 0.21.7", "bincode", "borsh 0.10.3", "bs58", @@ -4141,9 +4174,9 @@ dependencies = [ [[package]] name = "solana-udp-client" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e49d8462ebedc0524d5c287dd7feea3ac13622b424deba4459813fff1748a9bb" +checksum = "3274b4bfccd57ecffcf4037cd09fc61777633e0d0c5f8b76abcaa10ee83f3ae5" dependencies = [ "async-trait", "solana-connection-cache", @@ -4156,9 +4189,9 @@ dependencies = [ [[package]] name = "solana-version" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ac486deb05a0c4164e892091c6c817c9f9a54d658721e316f49040ab2f2df9" +checksum = "aaf45873439f73420f60a5e0f87b529923c3489d24a228d5eb8f5ce6955bdc1b" dependencies = [ "log", "rustc_version", @@ -4172,13 +4205,13 @@ dependencies = [ [[package]] name = "solana-vote-program" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b87fe95b52594e21a410ec5ab00c3266ebf41997c8c28ca6765b123eaf5a475" +checksum = "0e7c7525bda137bbb9bc0dc967a4ffca82786147eb2d1efbf76a8dc52978f0b8" dependencies = [ "bincode", "log", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", "rustc_version", "serde", @@ -4194,12 +4227,12 @@ dependencies = [ [[package]] name = "solana-zk-token-sdk" -version = "1.17.16" +version = "1.18.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d860992705578848d2a04e8a2a5b2b2d380b0be5db8cf9d0744a166e269c0ceb" +checksum = "39a57b2f269f24088b6b8e426de05e5c1faa6b5d6f26175c06eb80df96ec685e" dependencies = [ "aes-gcm-siv", - "base64 0.21.5", + "base64 0.21.7", "bincode", "bytemuck", "byteorder", @@ -4208,7 +4241,7 @@ dependencies = [ "itertools", "lazy_static", "merlin", - "num-derive 0.3.3", + "num-derive 0.4.1", "num-traits", "rand 0.7.3", "serde", @@ -4223,9 +4256,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d457cc2ba742c120492a64b7fa60e22c575e891f6b55039f4d736568fb112a3" +checksum = "da5d083187e3b3f453e140f292c09186881da8a02a7b5e27f645ee26de3d9cc5" dependencies = [ "byteorder", "combine", @@ -4930,6 +4963,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "synstructure" version = "0.12.6" @@ -5008,18 +5053,18 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -5375,7 +5420,7 @@ name = "unstake_interface" version = "2.0.0" source = "git+https://github.com/igneous-labs/sanctum-unstake-program.git?rev=069f941#069f941d275cc41b2ec0e3c2dbfae78cae63d786" dependencies = [ - "borsh 0.10.3", + "borsh 1.3.0", "num-derive 0.4.1", "num-traits", "solana-program", @@ -5468,19 +5513,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -5505,9 +5551,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5515,9 +5561,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -5528,9 +5574,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "web-sys" @@ -5597,15 +5643,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -5624,21 +5661,6 @@ dependencies = [ "windows-targets 0.52.0", ] -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-targets" version = "0.48.5" @@ -5669,12 +5691,6 @@ dependencies = [ "windows_x86_64_msvc 0.52.0", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -5687,12 +5703,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -5705,12 +5715,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -5723,12 +5727,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -5741,12 +5739,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -5759,12 +5751,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -5777,12 +5763,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 0d59bb1..d11a95e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,14 +19,12 @@ itertools = ">=0.1" 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 = "a0de12d06502680277405c7e795ffa82f30af38c", features = ["no-entrypoint"] } # rev = "ec25a9b" marinade_finance_interface = { git = "https://github.com/jup-ag/marinade_finance_interface", rev = "5747b5350c5505fc2ea597c3f8ae1f8cf71c363d" } # rev = "4d1895b" num-derive = ">=0.1" num-traits = ">=0.1" rand = "0.8.5" -rust_decimal = ">=1.0,<=1.32.0" # anything >1.32 uses borsh ^1 +rust_decimal = "1.36" # anything >1.32 uses borsh ^1 sanctum-macros = "^1.2" serde = "^1" serde_json = "^1" @@ -50,10 +48,10 @@ sanctum-solana-cli-utils = { git = "https://github.com/igneous-labs/sanctum-sola sanctum-lst-list = { git = "https://github.com/igneous-labs/sanctum-lst-list.git", branch = "master" } # rev = ebecde4 # solana core crates -solana-program = "^1" -solana-sdk = "^1" -solana-account-decoder = "^1" -solana-client = "^1" +solana-program = "1.18" +solana-sdk = "1.18" +solana-account-decoder = "1.18" +solana-client = "1.18" # workspace members stakedex_deposit_sol_interface = { path = "./interfaces/stakedex_deposit_sol_interface" } diff --git a/libs/unstake_it/src/lib.rs b/libs/unstake_it/src/lib.rs index 40092a6..a3b95be 100644 --- a/libs/unstake_it/src/lib.rs +++ b/libs/unstake_it/src/lib.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey}; +use solana_program::{borsh1::try_from_slice_unchecked, pubkey::Pubkey}; use unstake_interface::{Fee, FeeEnum, Pool, ProtocolFee, Rational}; mod pda; From b1c7ce6f6a7af67eae3b232519cbec035651841e Mon Sep 17 00:00:00 2001 From: Arrowana Date: Wed, 18 Sep 2024 16:17:10 +1000 Subject: [PATCH 31/33] Change to underscores --- jup_interface/src/pool_pair/one_way.rs | 2 +- jup_interface/src/pool_pair/two_way.rs | 2 +- jup_interface/src/pool_sol/deposit_sol.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index bac6fc0..b87122a 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -187,7 +187,7 @@ where (unstake_it_program::ID, "unstake.it".to_owned()), ( spl_deposit_cap_guard_program::ID, - "spl-deposit-cap-guard".to_owned(), + "spl_deposit_cap_guard".to_owned(), ), ] } diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index 197e06f..bf04ce2 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -210,7 +210,7 @@ where (unstake_it_program::ID, "unstake.it".to_owned()), ( spl_deposit_cap_guard_program::ID, - "spl-deposit-cap-guard".to_owned(), + "spl_deposit_cap_guard".to_owned(), ), ] } diff --git a/jup_interface/src/pool_sol/deposit_sol.rs b/jup_interface/src/pool_sol/deposit_sol.rs index fa3d74d..e135536 100644 --- a/jup_interface/src/pool_sol/deposit_sol.rs +++ b/jup_interface/src/pool_sol/deposit_sol.rs @@ -111,7 +111,7 @@ where ), ( spl_deposit_cap_guard_program::ID, - "spl-deposit-cap-guard".to_owned(), + "spl_deposit_cap_guard".to_owned(), ), ] } From 2deb20a54edb6861a8cc2269c417f15ef19a8f92 Mon Sep 17 00:00:00 2001 From: Arrowana Date: Sat, 21 Sep 2024 12:08:19 +1000 Subject: [PATCH 32/33] feat: Remove clock account updates --- jup_interface/src/pool_pair/one_way.rs | 10 +----- jup_interface/src/pool_pair/two_way.rs | 12 ++----- libs/lido/src/lib.rs | 14 +++----- libs/lido/src/stakedex_traits/base.rs | 17 +++------ .../src/stakedex_traits/withdraw_stake.rs | 4 +-- libs/lido/tests/test_mainnet.rs | 10 ++++-- libs/marinade/src/stakedex_traits/base.rs | 1 + libs/spl_stake_pool/src/lib.rs | 11 ++++-- .../src/stakedex_traits/base.rs | 28 ++++++--------- .../src/stakedex_traits/withdraw_stake.rs | 4 ++- stakedex_sdk/src/lib.rs | 36 +++++-------------- stakedex_sdk/tests/test_main.rs | 2 ++ 12 files changed, 54 insertions(+), 95 deletions(-) diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index b87122a..715800e 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -23,7 +23,6 @@ pub struct OneWayPoolPair< > { pub withdraw: W, pub deposit: D, - clock: Clock, prefund_repay_params: Option, underlying_liquidities: Option>, } @@ -41,7 +40,6 @@ where Self { withdraw, deposit, - clock: Clock::default(), prefund_repay_params: None, underlying_liquidities, } @@ -89,7 +87,6 @@ where [ self.withdraw.get_accounts_to_update().as_slice(), self.deposit.get_accounts_to_update().as_slice(), - &[sysvar::clock::ID], PrefundRepayParams::ACCOUNTS_TO_UPDATE.as_slice(), ] .concat() @@ -99,11 +96,6 @@ where // TODO: not sure if should short-circuit and early return if first update() fails let rw = self.withdraw.update(account_map); let rd = self.deposit.update(account_map); - let rc = account_map - .get(&sysvar::clock::ID) - .ok_or_else(|| account_missing_err(&sysvar::clock::ID)) - .map_or_else(Err, |acc| Ok(bincode::deserialize(&acc.data)?)) - .map(|new_clock| self.clock = new_clock); let rp = match self.prefund_repay_params.as_mut() { None => { let init_res = PrefundRepayParams::try_init(account_map); @@ -113,7 +105,7 @@ where } Some(p) => p.update(account_map), }; - rw.and(rd).and(rc).and(rp) + rw.and(rd).and(rp) } fn quote(&self, quote_params: &QuoteParams) -> Result { diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index bf04ce2..ed6f8b3 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -3,7 +3,7 @@ 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, sysvar}; 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, @@ -23,7 +23,6 @@ pub struct TwoWayPoolPair< > { pub p1: P1, pub p2: P2, - clock: Clock, prefund_repay_params: Option, underlying_liquidities: Option>, } @@ -43,7 +42,6 @@ where Self { p1, p2, - clock: Clock::default(), prefund_repay_params: None, underlying_liquidities, } @@ -84,7 +82,6 @@ where [ self.p1.get_accounts_to_update().as_slice(), self.p2.get_accounts_to_update().as_slice(), - &[sysvar::clock::ID], PrefundRepayParams::ACCOUNTS_TO_UPDATE.as_slice(), ] .concat() @@ -94,11 +91,6 @@ where // TODO: not sure if should short-circuit and early return if first update() fails let r1 = self.p1.update(account_map); let r2 = self.p2.update(account_map); - let rc = account_map - .get(&sysvar::clock::ID) - .ok_or_else(|| account_missing_err(&sysvar::clock::ID)) - .map_or_else(Err, |acc| Ok(bincode::deserialize(&acc.data)?)) - .map(|new_clock| self.clock = new_clock); let rp = match self.prefund_repay_params.as_mut() { None => { let init_res = PrefundRepayParams::try_init(account_map); @@ -108,7 +100,7 @@ where } Some(p) => p.update(account_map), }; - r1.and(r2).and(rc).and(rp) + r1.and(r2).and(rp) } fn quote(&self, quote_params: &QuoteParams) -> Result { diff --git a/libs/lido/src/lib.rs b/libs/lido/src/lib.rs index c34a24e..71b6ceb 100644 --- a/libs/lido/src/lib.rs +++ b/libs/lido/src/lib.rs @@ -1,11 +1,11 @@ +use std::sync::{atomic::AtomicU64, Arc}; + use anyhow::Result; use lido::state::{AccountType, Lido, Validator}; mod stakedex_traits; -use solana_program::{ - borsh0_10::try_from_slice_unchecked, clock::Clock, program_pack::Pack, stake_history::Epoch, -}; +use solana_program::{borsh0_10::try_from_slice_unchecked, program_pack::Pack}; pub use stakedex_traits::*; pub const LIDO_LABEL: &str = "Lido"; @@ -18,7 +18,7 @@ pub const LIST_HEADER_LEN: usize = pub struct LidoStakedex { lido_state: Lido, validator_list: Vec, - curr_epoch: Epoch, + curr_epoch: Arc, } impl LidoStakedex { @@ -47,10 +47,4 @@ impl LidoStakedex { self.validator_list = validator_list; Ok(()) } - - pub fn update_curr_epoch(&mut self, clock_data: &[u8]) -> Result<()> { - let clock: Clock = bincode::deserialize(clock_data)?; - self.curr_epoch = clock.epoch; - Ok(()) - } } diff --git a/libs/lido/src/stakedex_traits/base.rs b/libs/lido/src/stakedex_traits/base.rs index c7b563a..03c5654 100644 --- a/libs/lido/src/stakedex_traits/base.rs +++ b/libs/lido/src/stakedex_traits/base.rs @@ -1,6 +1,6 @@ use anyhow::Result; use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; -use solana_program::{pubkey::Pubkey, sysvar}; +use solana_program::pubkey::Pubkey; use stakedex_sdk_common::{ account_missing_err, lido_program, lido_state, stsol, BaseStakePoolAmm, InitFromKeyedAccount, }; @@ -9,9 +9,10 @@ use crate::{LidoStakedex, LIDO_LABEL}; impl InitFromKeyedAccount for LidoStakedex { /// Initialize from lido - fn from_keyed_account(keyed_account: &KeyedAccount, _amm_context: &AmmContext) -> 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)?; + res.curr_epoch = amm_context.clock_ref.epoch.clone(); // NOTE: validator_list is not initialized until self.update() is // called for the first time with fetched on-chain data Ok(res) @@ -36,11 +37,7 @@ impl BaseStakePoolAmm for LidoStakedex { } fn get_accounts_to_update(&self) -> Vec { - vec![ - lido_state::ID, - self.lido_state.validator_list, - sysvar::clock::ID, - ] + vec![lido_state::ID, self.lido_state.validator_list] } fn update(&mut self, accounts_map: &AccountMap) -> Result<()> { @@ -56,12 +53,6 @@ impl BaseStakePoolAmm for LidoStakedex { .data .as_ref(); self.update_validator_list(validator_list_data)?; - let clock_data = accounts_map - .get(&sysvar::clock::ID) - .ok_or_else(|| account_missing_err(&sysvar::clock::ID))? - .data - .as_ref(); - self.update_curr_epoch(clock_data)?; Ok(()) } } diff --git a/libs/lido/src/stakedex_traits/withdraw_stake.rs b/libs/lido/src/stakedex_traits/withdraw_stake.rs index ed79dde..db9a1d9 100644 --- a/libs/lido/src/stakedex_traits/withdraw_stake.rs +++ b/libs/lido/src/stakedex_traits/withdraw_stake.rs @@ -16,7 +16,7 @@ use stakedex_sdk_common::{ use stakedex_withdraw_stake_interface::{ lido_withdraw_stake_ix, LidoWithdrawStakeKeys, LIDO_WITHDRAW_STAKE_IX_ACCOUNTS_LEN, }; -use std::ops::Add; +use std::{ops::Add, sync::atomic::Ordering}; use crate::LidoStakedex; @@ -132,7 +132,7 @@ impl WithdrawStakeIter for LidoStakedex { impl WithdrawStakeBase for LidoStakedex { fn can_accept_stake_withdrawals(&self) -> bool { - self.lido_state.exchange_rate.computed_in_epoch >= self.curr_epoch + self.lido_state.exchange_rate.computed_in_epoch >= self.curr_epoch.load(Ordering::Relaxed) } fn virtual_ix(&self, quote: &WithdrawStakeQuote) -> Result { diff --git a/libs/lido/tests/test_mainnet.rs b/libs/lido/tests/test_mainnet.rs index 0098a19..4407598 100644 --- a/libs/lido/tests/test_mainnet.rs +++ b/libs/lido/tests/test_mainnet.rs @@ -1,6 +1,6 @@ use std::iter::zip; -use jupiter_amm_interface::KeyedAccount; +use jupiter_amm_interface::{AmmContext, ClockRef, KeyedAccount}; use solana_client::rpc_client::RpcClient; use solana_program::sysvar; use stakedex_lido::LidoStakedex; @@ -19,6 +19,12 @@ fn test_mainnet() { params: None, }; let accounts_map = zip(keys, accounts.into_iter().map(|o| o.unwrap())).collect(); - let mut lido = LidoStakedex::from_keyed_account(&keyed_state).unwrap(); + let mut lido = LidoStakedex::from_keyed_account( + &keyed_state, + &AmmContext { + clock_ref: ClockRef::default(), + }, + ) + .unwrap(); lido.update(&accounts_map).unwrap(); } diff --git a/libs/marinade/src/stakedex_traits/base.rs b/libs/marinade/src/stakedex_traits/base.rs index 6496241..1d5f2c6 100644 --- a/libs/marinade/src/stakedex_traits/base.rs +++ b/libs/marinade/src/stakedex_traits/base.rs @@ -13,6 +13,7 @@ impl InitFromKeyedAccount for MarinadeStakedex { 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 // called for the first time with fetched on-chain data Ok(res) diff --git a/libs/spl_stake_pool/src/lib.rs b/libs/spl_stake_pool/src/lib.rs index 60216cc..4d2e084 100644 --- a/libs/spl_stake_pool/src/lib.rs +++ b/libs/spl_stake_pool/src/lib.rs @@ -1,6 +1,8 @@ +use std::sync::{atomic::AtomicU64, Arc}; + use anyhow::{anyhow, Result}; use deposit_cap_guard::{find_spl_deposit_cap_guard_state, DepositCap}; -use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch}; +use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey}; use spl_stake_pool::{ error::StakePoolError, find_deposit_authority_program_address, find_withdraw_authority_program_address, @@ -28,7 +30,7 @@ pub struct SplStakePoolStakedex { pub stake_pool_label: String, pub stake_pool: StakePool, pub validator_list: ValidatorList, - pub curr_epoch: Epoch, + pub curr_epoch: Arc, pub deposit_authority_program_address: Pubkey, pub spl_deposit_cap_guard_program_address: Pubkey, pub deposit_cap_state: Option, @@ -40,6 +42,7 @@ impl SplStakePoolStakedex { stake_pool_program, stake_pool_addr, }: SplStakePoolStakedexInitKeys, + curr_epoch: Arc, ) -> Self { let (deposit_authority_program_address, _bump) = find_deposit_authority_program_address(&stake_pool_program, &stake_pool_addr); @@ -50,6 +53,7 @@ impl SplStakePoolStakedex { stake_pool_program, deposit_authority_program_address, spl_deposit_cap_guard_program_address, + curr_epoch, ..Default::default() } } @@ -79,7 +83,8 @@ impl SplStakePoolStakedex { } pub fn is_updated_this_epoch(&self) -> bool { - self.stake_pool.last_update_epoch >= self.curr_epoch + self.stake_pool.last_update_epoch + >= self.curr_epoch.load(std::sync::atomic::Ordering::Relaxed) } /// Computes and returns the stake withdraw authority PDA diff --git a/libs/spl_stake_pool/src/stakedex_traits/base.rs b/libs/spl_stake_pool/src/stakedex_traits/base.rs index 7dd406b..6252f9d 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/base.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/base.rs @@ -1,6 +1,6 @@ use anyhow::Result; use jupiter_amm_interface::{AccountMap, AmmContext, KeyedAccount}; -use solana_program::{clock::Clock, pubkey::Pubkey, sysvar}; +use solana_program::pubkey::Pubkey; use stakedex_sdk_common::{account_missing_err, BaseStakePoolAmm, InitFromKeyedAccount}; use crate::SplStakePoolStakedex; @@ -13,12 +13,15 @@ impl InitFromKeyedAccount for SplStakePoolStakedex { account, params, }: &KeyedAccount, - _amm_context: &AmmContext, + amm_context: &AmmContext, ) -> Result { - let mut res = Self::new_uninitialized(crate::SplStakePoolStakedexInitKeys { - stake_pool_program: account.owner, - stake_pool_addr: *key, - }); + let mut res = Self::new_uninitialized( + crate::SplStakePoolStakedexInitKeys { + stake_pool_program: account.owner, + stake_pool_addr: *key, + }, + amm_context.clock_ref.epoch.clone(), + ); res.update_stake_pool(&account.data)?; @@ -53,11 +56,7 @@ impl BaseStakePoolAmm for SplStakePoolStakedex { } fn get_accounts_to_update(&self) -> Vec { - let mut res = Vec::from([ - self.stake_pool_addr, - self.stake_pool.validator_list, - sysvar::clock::ID, - ]); + let mut res = Vec::from([self.stake_pool_addr, self.stake_pool.validator_list]); if self.is_sol_deposit_capped() || self.is_stake_deposit_capped() { res.push(self.spl_deposit_cap_guard_program_address); } @@ -77,13 +76,6 @@ impl BaseStakePoolAmm for SplStakePoolStakedex { .data .as_ref(); self.update_validator_list(validator_list_data)?; - let clock_data = accounts_map - .get(&sysvar::clock::ID) - .ok_or_else(|| account_missing_err(&sysvar::clock::ID))? - .data - .as_ref(); - let clock: Clock = bincode::deserialize(clock_data)?; - self.curr_epoch = clock.epoch; if self.is_sol_deposit_capped() || self.is_stake_deposit_capped() { let deposit_cap_data = accounts_map .get(&self.spl_deposit_cap_guard_program_address) diff --git a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs index bcfa0c1..83343d8 100644 --- a/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs +++ b/libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs @@ -1,3 +1,5 @@ +use std::sync::atomic::Ordering; + use anyhow::Result; use solana_program::{instruction::Instruction, pubkey::Pubkey, stake, system_program, sysvar}; use spl_stake_pool::{find_stake_program_address, MINIMUM_ACTIVE_STAKE}; @@ -101,7 +103,7 @@ impl WithdrawStakeIter for SplStakePoolStakedex { impl WithdrawStakeBase for SplStakePoolStakedex { fn can_accept_stake_withdrawals(&self) -> bool { - self.stake_pool.last_update_epoch >= self.curr_epoch + self.stake_pool.last_update_epoch >= self.curr_epoch.load(Ordering::Relaxed) } fn virtual_ix(&self, quote: &WithdrawStakeQuote) -> Result { diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index 59845f4..ca07fee 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - use anyhow::{anyhow, Result}; use itertools::Itertools; use jupiter_amm_interface::{ @@ -7,7 +5,7 @@ use jupiter_amm_interface::{ }; use lazy_static::lazy_static; use sanctum_lst_list::{PoolInfo, SanctumLst}; -use solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey, system_program}; +use solana_sdk::{instruction::Instruction, pubkey::Pubkey, system_program}; use spl_token::native_mint; use stakedex_interface::{ DepositStakeKeys, PrefundSwapViaStakeIxArgs, PrefundSwapViaStakeKeys, @@ -117,6 +115,7 @@ impl Stakedex { pub fn from_fetched_accounts<'a>( sanctum_lsts: impl Iterator, accounts: &AccountMap, + amm_context: &AmmContext, ) -> (Self, Vec) { // So that stakedex is still useable even if some pools fail to load let mut errs = Vec::new(); @@ -148,30 +147,13 @@ impl Stakedex { | PoolInfo::SanctumSplMulti(spl_accs) => { let name = &lst.name; let pool = spl_accs.pool; - Some( - get_keyed_account(accounts, &pool) - .map_or_else(Err, |mut ka| { - ka.params = Some(name.as_str().into()); - SplStakePoolStakedex::from_keyed_account( - &ka, - &AmmContext { - clock_ref: ClockRef::default(), // Ok because unused internally - }, - ) - }) - .unwrap_or_else(|e| { - errs.push(e); - SplStakePoolStakedex { - stake_pool_label: format!("{name} stake pool"), - ..SplStakePoolStakedex::new_uninitialized( - SplStakePoolStakedexInitKeys { - stake_pool_program: lst.pool.pool_program().into(), - stake_pool_addr: pool, - }, - ) - } - }), - ) + + get_keyed_account(accounts, &pool) + .map_or_else(Err, |mut ka| { + ka.params = Some(name.as_str().into()); + SplStakePoolStakedex::from_keyed_account(&ka, &amm_context) + }) + .ok() } PoolInfo::Lido | PoolInfo::Marinade diff --git a/stakedex_sdk/tests/test_main.rs b/stakedex_sdk/tests/test_main.rs index 117f334..f39e678 100644 --- a/stakedex_sdk/tests/test_main.rs +++ b/stakedex_sdk/tests/test_main.rs @@ -578,6 +578,7 @@ pub fn test_sim_prefund_swap_via_stake(stakedex: &Stakedex, args: TestSwapViaSta token_transfer_authority: signer, open_order_address: None, quote_mint_to_referrer: None, + missing_dynamic_accounts_as_default: None, }, 0, ) @@ -625,6 +626,7 @@ pub fn test_sim_manual_concat_prefund_swap_via_stake( token_transfer_authority: signer, open_order_address: None, quote_mint_to_referrer: None, + missing_dynamic_accounts_as_default: None, }, 0, ) From 017a22000f6fa5ed88cfca58c6df273de1a47cfc Mon Sep 17 00:00:00 2001 From: Arrowana Date: Tue, 24 Sep 2024 20:17:12 +1000 Subject: [PATCH 33/33] fix init_from_keyed_account_no_params --- jup_interface/src/pool_pair/one_way.rs | 6 +-- jup_interface/src/pool_pair/prefund.rs | 2 +- jup_interface/src/pool_pair/two_way.rs | 6 +-- stakedex_sdk/src/lib.rs | 63 +++++++++++++------------- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/jup_interface/src/pool_pair/one_way.rs b/jup_interface/src/pool_pair/one_way.rs index 715800e..09984ea 100644 --- a/jup_interface/src/pool_pair/one_way.rs +++ b/jup_interface/src/pool_pair/one_way.rs @@ -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; diff --git a/jup_interface/src/pool_pair/prefund.rs b/jup_interface/src/pool_pair/prefund.rs index 0e2b920..34029f5 100644 --- a/jup_interface/src/pool_pair/prefund.rs +++ b/jup_interface/src/pool_pair/prefund.rs @@ -112,7 +112,7 @@ fn extract_incoming_stake(accounts_map: &AccountMap) -> Result { Ok(incoming_stake) } -fn extract_sol_reserves_lamports(accounts_map: &AccountMap) -> Result { +pub fn extract_sol_reserves_lamports(accounts_map: &AccountMap) -> Result { let Account { lamports: sol_reserves_lamports, .. diff --git a/jup_interface/src/pool_pair/two_way.rs b/jup_interface/src/pool_pair/two_way.rs index ed6f8b3..e875858 100644 --- a/jup_interface/src/pool_pair/two_way.rs +++ b/jup_interface/src/pool_pair/two_way.rs @@ -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; diff --git a/stakedex_sdk/src/lib.rs b/stakedex_sdk/src/lib.rs index ca07fee..5daf5f6 100644 --- a/stakedex_sdk/src/lib.rs +++ b/stakedex_sdk/src/lib.rs @@ -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}; @@ -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; @@ -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; @@ -78,15 +78,11 @@ fn get_keyed_account(accounts: &AccountMap, key: &Pubkey) -> Result( accounts: &AccountMap, key: &Pubkey, + amm_context: &AmmContext, ) -> Result

{ 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 { @@ -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() }); @@ -204,19 +205,17 @@ impl Stakedex { pub fn update(&mut self, account_map: &AccountMap) -> Vec { // 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