Skip to content

Commit

Permalink
require fee claims before full reserve repays
Browse files Browse the repository at this point in the history
  • Loading branch information
nope-finance committed Jun 7, 2022
1 parent f81a9ed commit c77f102
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions token-lending/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ pub enum LendingError {
/// Not enough liquidity after flash loan
#[error("Not enough liquidity after flash loan")]
NotEnoughLiquidityAfterFlashLoan,

// 45
/// Null oracle config
#[error("Null oracle config")]
NullOracleConfig,
/// Over repay when pending protocol fees
#[error("Over repay when pending protocol fees")]
OverRepayWithPendingFees,
}

impl From<LendingError> for ProgramError {
Expand Down
6 changes: 6 additions & 0 deletions token-lending/program/src/state/reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ impl ReserveLiquidity {
.checked_add(repay_amount)
.ok_or(LendingError::MathOverflow)?;
let safe_settle_amount = settle_amount.min(self.borrowed_amount_wads);
// if you are fulling repaying the reserve protocol fees must be claimed
if safe_settle_amount == self.borrowed_amount_wads
&& self.accumulated_protocol_fees_wads.try_floor_u64()? > 0
{
return Err(LendingError::OverRepayWithPendingFees.into());
}
self.borrowed_amount_wads = self.borrowed_amount_wads.try_sub(safe_settle_amount)?;

Ok(())
Expand Down

0 comments on commit c77f102

Please sign in to comment.