Skip to content

Commit

Permalink
Merge pull request #27 from solendprotocol/max_fixes
Browse files Browse the repository at this point in the history
fixes for max stuff
  • Loading branch information
nope-finance authored Aug 1, 2021
2 parents 34a0c7c + f391a84 commit a6b1ce1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,10 +1344,11 @@ fn process_borrow_obligation_liquidity(
msg!("Borrow reserve is stale and must be refreshed in the current slot");
return Err(LendingError::ReserveStale.into());
}
if Decimal::from(liquidity_amount)
.try_add(borrow_reserve.liquidity.borrowed_amount_wads)?
.try_floor_u64()?
> borrow_reserve.config.borrow_limit
if liquidity_amount != u64::MAX
&& Decimal::from(liquidity_amount)
.try_add(borrow_reserve.liquidity.borrowed_amount_wads)?
.try_floor_u64()?
> borrow_reserve.config.borrow_limit
{
msg!("Cannot borrow above the borrow limit");
return Err(LendingError::InvalidAmount.into());
Expand Down Expand Up @@ -1474,7 +1475,6 @@ fn process_repay_obligation_liquidity(
msg!("Liquidity amount provided cannot be zero");
return Err(LendingError::InvalidAmount.into());
}

let account_info_iter = &mut accounts.iter();
let source_liquidity_info = next_account_info(account_info_iter)?;
let destination_liquidity_info = next_account_info(account_info_iter)?;
Expand Down
3 changes: 2 additions & 1 deletion token-lending/program/src/state/reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ impl ReserveLiquidity {
.available_amount
.checked_add(repay_amount)
.ok_or(LendingError::MathOverflow)?;
self.borrowed_amount_wads = self.borrowed_amount_wads.try_sub(settle_amount)?;
let safe_settle_amount = settle_amount.min(self.borrowed_amount_wads);
self.borrowed_amount_wads = self.borrowed_amount_wads.try_sub(safe_settle_amount)?;

Ok(())
}
Expand Down

0 comments on commit a6b1ce1

Please sign in to comment.