diff --git a/token-lending/program/tests/wrapper_program.rs b/token-lending/program/tests/wrapper_program.rs index e9840749cbe..fa8ffa6710b 100644 --- a/token-lending/program/tests/wrapper_program.rs +++ b/token-lending/program/tests/wrapper_program.rs @@ -31,34 +31,6 @@ use helpers::*; use solana_program_test::*; use wrapper::processor::liquidate_without_receiving_ctokens; -pub fn reserve_config_no_fees() -> ReserveConfig { - ReserveConfig { - optimal_utilization_rate: 80, - max_utilization_rate: 80, - loan_to_value_ratio: 50, - liquidation_bonus: 0, - max_liquidation_bonus: 0, - liquidation_threshold: 55, - max_liquidation_threshold: 65, - min_borrow_rate: 0, - optimal_borrow_rate: 0, - max_borrow_rate: 0, - super_max_borrow_rate: 0, - fees: ReserveFees { - borrow_fee_wad: 0, - flash_loan_fee_wad: 0, - host_fee_percentage: 0, - }, - deposit_limit: u64::MAX, - borrow_limit: u64::MAX, - fee_receiver: Keypair::new().pubkey(), - protocol_liquidation_fee: 0, - protocol_take_rate: 0, - added_borrow_weight_bps: 0, - reserve_type: ReserveType::Regular, - } -} - #[tokio::test] async fn test_liquidate() { let (mut test, lending_market, reserves, obligations, _users, lending_market_owner) = @@ -490,6 +462,7 @@ async fn test_withdraw_exact() { obligations[0].account.owner, // user_transfer_authority_pubkey, users[0].keypair.pubkey(), + obligations[0].account.deposits.iter().map(|d| d.deposit_reserve).collect(), // liquidity amount 4 * FRACTIONAL_TO_USDC, )); diff --git a/token-lending/wrapper/src/processor.rs b/token-lending/wrapper/src/processor.rs index 59ff066ab4d..b3bc8dbf284 100644 --- a/token-lending/wrapper/src/processor.rs +++ b/token-lending/wrapper/src/processor.rs @@ -1,6 +1,5 @@ //! Program state processor -use solend_sdk::math::TrySub; use borsh::{BorshDeserialize, BorshSerialize}; use num_derive::FromPrimitive; use solana_program::pubkey::PUBKEY_BYTES; @@ -20,6 +19,7 @@ use solend_sdk::instruction::{ withdraw_obligation_collateral_and_redeem_reserve_collateral, }; use solend_sdk::math::Decimal; +use solend_sdk::math::TrySub; use solend_sdk::state::Reserve; use thiserror::Error; @@ -264,6 +264,11 @@ pub fn process_instruction( let user_transfer_authority_info = next_account_info(account_info_iter)?; let token_program_id = next_account_info(account_info_iter)?; + // while account info iter has pubkeys, add them to collateral reserves + let collateral_reserves = account_info_iter + .map(|account_info| *account_info.key) + .collect(); + let reserve = Reserve::unpack(&reserve_info.try_borrow_data()?)?; let mut ctoken_amount = reserve .collateral_exchange_rate()? @@ -289,6 +294,7 @@ pub fn process_instruction( *reserve_liquidity_supply_info.key, *obligation_owner_info.key, *user_transfer_authority_info.key, + collateral_reserves, ); invoke( @@ -468,6 +474,7 @@ pub fn withdraw_exact( reserve_liquidity_supply_pubkey: Pubkey, obligation_owner_pubkey: Pubkey, user_transfer_authority_pubkey: Pubkey, + collateral_reserves: Vec, liquidity_amount: u64, ) -> Instruction { let (lending_market_authority_pubkey, _bump_seed) = Pubkey::find_program_address( @@ -475,28 +482,33 @@ pub fn withdraw_exact( &solend_program_id, ); + let mut accounts = vec![ + AccountMeta::new_readonly(solend_program_id, false), + AccountMeta::new(reserve_collateral_pubkey, false), + AccountMeta::new(user_collateral_pubkey, false), + AccountMeta::new(reserve_pubkey, false), + AccountMeta::new(obligation_pubkey, false), + AccountMeta::new(lending_market_pubkey, false), + AccountMeta::new_readonly(lending_market_authority_pubkey, false), + AccountMeta::new(user_liquidity_pubkey, false), + AccountMeta::new(reserve_collateral_mint_pubkey, false), + AccountMeta::new(reserve_liquidity_supply_pubkey, false), + AccountMeta::new(obligation_owner_pubkey, true), + AccountMeta::new_readonly(user_transfer_authority_pubkey, true), + AccountMeta::new_readonly(spl_token::id(), false), + ]; + + accounts.extend( + collateral_reserves + .iter() + .map(|reserve| AccountMeta::new(*reserve, false)), + ); + Instruction { program_id, - accounts: vec![ - AccountMeta::new_readonly(solend_program_id, false), - AccountMeta::new(reserve_collateral_pubkey, false), - AccountMeta::new(user_collateral_pubkey, false), - AccountMeta::new(reserve_pubkey, false), - AccountMeta::new(obligation_pubkey, false), - AccountMeta::new(lending_market_pubkey, false), - AccountMeta::new_readonly(lending_market_authority_pubkey, false), - AccountMeta::new(user_liquidity_pubkey, false), - AccountMeta::new(reserve_collateral_mint_pubkey, false), - AccountMeta::new(reserve_liquidity_supply_pubkey, false), - AccountMeta::new(obligation_owner_pubkey, true), - AccountMeta::new_readonly(user_transfer_authority_pubkey, true), - AccountMeta::new_readonly(spl_token::id(), false), - ], + accounts, data: WrapperInstruction::WithdrawExact { liquidity_amount } .try_to_vec() .unwrap(), } } - - -