Skip to content

Commit 46b6849

Browse files
committed
fix tests
1 parent 512c129 commit 46b6849

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

token-lending/program/src/processor.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,18 +1398,15 @@ fn process_borrow_obligation_liquidity(
13981398
return Err(LendingError::BorrowTooSmall.into());
13991399
}
14001400

1401-
// logically i think this should be below but is equiv because how borrow doesn't update rate
14021401
let cumulative_borrow_rate_wads = borrow_reserve.liquidity.cumulative_borrow_rate_wads;
14031402

14041403
borrow_reserve.liquidity.borrow(borrow_amount)?;
14051404
borrow_reserve.last_update.mark_stale();
14061405
Reserve::pack(borrow_reserve, &mut borrow_reserve_info.data.borrow_mut())?;
14071406

1408-
let obligation_liquidity =
1409-
obligation.find_or_add_liquidity_to_borrows(*borrow_reserve_info.key)?;
1410-
if obligation_liquidity.cumulative_borrow_rate_wads == Decimal::zero() {
1411-
obligation_liquidity.cumulative_borrow_rate_wads = cumulative_borrow_rate_wads;
1412-
}
1407+
let obligation_liquidity = obligation
1408+
.find_or_add_liquidity_to_borrows(*borrow_reserve_info.key, cumulative_borrow_rate_wads)?;
1409+
14131410
obligation_liquidity.borrow(borrow_amount)?;
14141411
obligation.last_update.mark_stale();
14151412
Obligation::pack(obligation, &mut obligation_info.data.borrow_mut())?;

token-lending/program/src/state/obligation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl Obligation {
180180
pub fn find_or_add_liquidity_to_borrows(
181181
&mut self,
182182
borrow_reserve: Pubkey,
183+
cumulative_borrow_rate_wads: Decimal,
183184
) -> Result<&mut ObligationLiquidity, ProgramError> {
184185
if let Some(liquidity_index) = self._find_liquidity_index_in_borrows(borrow_reserve) {
185186
return Ok(&mut self.borrows[liquidity_index]);
@@ -191,7 +192,7 @@ impl Obligation {
191192
);
192193
return Err(LendingError::ObligationReserveLimit.into());
193194
}
194-
let liquidity = ObligationLiquidity::new(borrow_reserve);
195+
let liquidity = ObligationLiquidity::new(borrow_reserve, cumulative_borrow_rate_wads);
195196
self.borrows.push(liquidity);
196197
Ok(self.borrows.last_mut().unwrap())
197198
}
@@ -279,10 +280,10 @@ pub struct ObligationLiquidity {
279280

280281
impl ObligationLiquidity {
281282
/// Create new obligation liquidity
282-
pub fn new(borrow_reserve: Pubkey) -> Self {
283+
pub fn new(borrow_reserve: Pubkey, cumulative_borrow_rate_wads: Decimal) -> Self {
283284
Self {
284285
borrow_reserve,
285-
cumulative_borrow_rate_wads: Decimal::zero(),
286+
cumulative_borrow_rate_wads: cumulative_borrow_rate_wads,
286287
borrowed_amount_wads: Decimal::zero(),
287288
market_value: Decimal::zero(),
288289
}

token-lending/program/tests/helpers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn add_obligation(
174174
.map(|(borrow_reserve, liquidity_amount)| {
175175
let borrowed_amount_wads = Decimal::from(*liquidity_amount);
176176

177-
let mut liquidity = ObligationLiquidity::new(borrow_reserve.pubkey);
177+
let mut liquidity = ObligationLiquidity::new(borrow_reserve.pubkey, Decimal::one());
178178
liquidity.borrowed_amount_wads = borrowed_amount_wads;
179179

180180
(

0 commit comments

Comments
 (0)