diff --git a/token-lending/program/tests/donate_to_reserve.rs b/token-lending/program/tests/donate_to_reserve.rs new file mode 100644 index 00000000000..314dc768071 --- /dev/null +++ b/token-lending/program/tests/donate_to_reserve.rs @@ -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); +} diff --git a/token-lending/program/tests/helpers/solend_program_test.rs b/token-lending/program/tests/helpers/solend_program_test.rs index 0a391455496..05e1705d350 100644 --- a/token-lending/program/tests/helpers/solend_program_test.rs +++ b/token-lending/program/tests/helpers/solend_program_test.rs @@ -862,6 +862,31 @@ impl Info { .await } + pub async fn donate_to_reserve( + &self, + test: &mut SolendProgramTest, + reserve: &Info, + 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, diff --git a/token-lending/sdk/src/instruction.rs b/token-lending/sdk/src/instruction.rs index a83ee22e470..4340458ad0f 100644 --- a/token-lending/sdk/src/instruction.rs +++ b/token-lending/sdk/src/instruction.rs @@ -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());