Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Sep 24, 2024
1 parent f6c6ecb commit 8620038
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
71 changes: 71 additions & 0 deletions token-lending/program/tests/donate_to_reserve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#![cfg(feature = "test-bpf")]
use crate::solend_program_test::custom_scenario;

use crate::solend_program_test::User;

use crate::solend_program_test::BalanceChecker;

use crate::solend_program_test::PriceArgs;
use crate::solend_program_test::ReserveArgs;
use crate::solend_program_test::TokenBalanceChange;

mod helpers;

use helpers::*;
use solana_program_test::*;

use std::collections::HashSet;

#[tokio::test]
async fn test_donate_to_reserve() {
let (mut test, lending_market, reserves, _obligations, _users, _) = custom_scenario(
&[ReserveArgs {
mint: usdc_mint::id(),
config: test_reserve_config(),
liquidity_amount: 100_000 * FRACTIONAL_TO_USDC,
price: PriceArgs {
price: 10,
conf: 0,
expo: -1,
ema_price: 10,
ema_conf: 1,
},
}],
&[],
)
.await;

let whale = User::new_with_balances(
&mut test,
&[(&usdc_mint::id(), 100_000 * FRACTIONAL_TO_USDC)],
)
.await;

let balance_checker = BalanceChecker::start(&mut test, &[&whale, &reserves[0]]).await;

lending_market
.donate_to_reserve(
&mut test,
&reserves[0],
&whale,
100_000 * FRACTIONAL_TO_USDC,
)
.await
.unwrap();

let (balance_changes, _) = balance_checker.find_balance_changes(&mut test).await;
let expected_balance_changes = HashSet::from([
TokenBalanceChange {
token_account: whale.get_account(&usdc_mint::id()).unwrap(),
mint: usdc_mint::id(),
diff: -(100_000 * FRACTIONAL_TO_USDC as i128),
},
TokenBalanceChange {
token_account: reserves[0].account.liquidity.supply_pubkey,
mint: usdc_mint::id(),
diff: 100_000 * FRACTIONAL_TO_USDC as i128,
},
]);

assert_eq!(balance_changes, expected_balance_changes);
}
25 changes: 25 additions & 0 deletions token-lending/program/tests/helpers/solend_program_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,31 @@ impl Info<LendingMarket> {
.await
}

pub async fn donate_to_reserve(
&self,
test: &mut SolendProgramTest,
reserve: &Info<Reserve>,
user: &User,
liquidity_amount: u64,
) -> Result<(), BanksClientError> {
let instructions = [
ComputeBudgetInstruction::set_compute_unit_limit(50_000),
donate_to_reserve(
solend_program::id(),
liquidity_amount,
user.get_account(&reserve.account.liquidity.mint_pubkey)
.unwrap(),
reserve.account.liquidity.supply_pubkey,
reserve.pubkey,
self.pubkey,
user.keypair.pubkey(),
),
];

test.process_transaction(&instructions, Some(&[&user.keypair]))
.await
}

pub async fn update_reserve_config(
&self,
test: &mut SolendProgramTest,
Expand Down
4 changes: 4 additions & 0 deletions token-lending/sdk/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ impl LendingInstruction {

Self::SetObligationCloseabilityStatus { closeable }
}
24 => {
let (liquidity_amount, _rest) = Self::unpack_u64(rest)?;
Self::DonateToReserve { liquidity_amount }
}
_ => {
msg!("Instruction cannot be unpacked");
return Err(LendingError::InstructionUnpackError.into());
Expand Down

0 comments on commit 8620038

Please sign in to comment.