From 46b6849e421d4fe3c5d525ff297afa2af07f52e3 Mon Sep 17 00:00:00 2001 From: NOPE finance Date: Tue, 10 Aug 2021 05:27:08 -0700 Subject: [PATCH] fix tests --- token-lending/program/src/processor.rs | 9 +++------ token-lending/program/src/state/obligation.rs | 7 ++++--- token-lending/program/tests/helpers/mod.rs | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/token-lending/program/src/processor.rs b/token-lending/program/src/processor.rs index d5eaaab26d4..6b73074d518 100644 --- a/token-lending/program/src/processor.rs +++ b/token-lending/program/src/processor.rs @@ -1398,18 +1398,15 @@ fn process_borrow_obligation_liquidity( return Err(LendingError::BorrowTooSmall.into()); } - // logically i think this should be below but is equiv because how borrow doesn't update rate let cumulative_borrow_rate_wads = borrow_reserve.liquidity.cumulative_borrow_rate_wads; borrow_reserve.liquidity.borrow(borrow_amount)?; borrow_reserve.last_update.mark_stale(); Reserve::pack(borrow_reserve, &mut borrow_reserve_info.data.borrow_mut())?; - let obligation_liquidity = - obligation.find_or_add_liquidity_to_borrows(*borrow_reserve_info.key)?; - if obligation_liquidity.cumulative_borrow_rate_wads == Decimal::zero() { - obligation_liquidity.cumulative_borrow_rate_wads = cumulative_borrow_rate_wads; - } + let obligation_liquidity = obligation + .find_or_add_liquidity_to_borrows(*borrow_reserve_info.key, cumulative_borrow_rate_wads)?; + obligation_liquidity.borrow(borrow_amount)?; obligation.last_update.mark_stale(); Obligation::pack(obligation, &mut obligation_info.data.borrow_mut())?; diff --git a/token-lending/program/src/state/obligation.rs b/token-lending/program/src/state/obligation.rs index 938ca9d2b57..6586967686d 100644 --- a/token-lending/program/src/state/obligation.rs +++ b/token-lending/program/src/state/obligation.rs @@ -180,6 +180,7 @@ impl Obligation { pub fn find_or_add_liquidity_to_borrows( &mut self, borrow_reserve: Pubkey, + cumulative_borrow_rate_wads: Decimal, ) -> Result<&mut ObligationLiquidity, ProgramError> { if let Some(liquidity_index) = self._find_liquidity_index_in_borrows(borrow_reserve) { return Ok(&mut self.borrows[liquidity_index]); @@ -191,7 +192,7 @@ impl Obligation { ); return Err(LendingError::ObligationReserveLimit.into()); } - let liquidity = ObligationLiquidity::new(borrow_reserve); + let liquidity = ObligationLiquidity::new(borrow_reserve, cumulative_borrow_rate_wads); self.borrows.push(liquidity); Ok(self.borrows.last_mut().unwrap()) } @@ -279,10 +280,10 @@ pub struct ObligationLiquidity { impl ObligationLiquidity { /// Create new obligation liquidity - pub fn new(borrow_reserve: Pubkey) -> Self { + pub fn new(borrow_reserve: Pubkey, cumulative_borrow_rate_wads: Decimal) -> Self { Self { borrow_reserve, - cumulative_borrow_rate_wads: Decimal::zero(), + cumulative_borrow_rate_wads: cumulative_borrow_rate_wads, borrowed_amount_wads: Decimal::zero(), market_value: Decimal::zero(), } diff --git a/token-lending/program/tests/helpers/mod.rs b/token-lending/program/tests/helpers/mod.rs index d517cf958b4..d4b47f65cfe 100644 --- a/token-lending/program/tests/helpers/mod.rs +++ b/token-lending/program/tests/helpers/mod.rs @@ -174,7 +174,7 @@ pub fn add_obligation( .map(|(borrow_reserve, liquidity_amount)| { let borrowed_amount_wads = Decimal::from(*liquidity_amount); - let mut liquidity = ObligationLiquidity::new(borrow_reserve.pubkey); + let mut liquidity = ObligationLiquidity::new(borrow_reserve.pubkey, Decimal::one()); liquidity.borrowed_amount_wads = borrowed_amount_wads; (