Skip to content

Commit

Permalink
fixes to support 2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed May 6, 2024
1 parent 5d41db7 commit 35de05b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 47 deletions.
29 changes: 1 addition & 28 deletions token-lending/program/tests/wrapper_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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,
));
Expand Down
50 changes: 31 additions & 19 deletions token-lending/wrapper/src/processor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()?
Expand All @@ -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(
Expand Down Expand Up @@ -468,35 +474,41 @@ pub fn withdraw_exact(
reserve_liquidity_supply_pubkey: Pubkey,
obligation_owner_pubkey: Pubkey,
user_transfer_authority_pubkey: Pubkey,
collateral_reserves: Vec<Pubkey>,
liquidity_amount: u64,
) -> Instruction {
let (lending_market_authority_pubkey, _bump_seed) = Pubkey::find_program_address(
&[&lending_market_pubkey.to_bytes()[..PUBKEY_BYTES]],
&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(),
}
}



0 comments on commit 35de05b

Please sign in to comment.