From 489f7cddb9980d6030b396ebee7d5fd619e58cb9 Mon Sep 17 00:00:00 2001 From: zyzy Date: Mon, 29 Jul 2024 16:27:38 +0800 Subject: [PATCH] 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 {