diff --git a/token-lending/program/src/state/obligation.rs b/token-lending/program/src/state/obligation.rs index 8da002f7..80bd8bb7 100644 --- a/token-lending/program/src/state/obligation.rs +++ b/token-lending/program/src/state/obligation.rs @@ -115,9 +115,10 @@ impl Obligation { } /// Liquidate part of obligation - pub fn liquidate(&mut self, settle_amount: Decimal, withdraw_amount: u64) -> ProgramResult { - self.borrowed_liquidity_wads = self.borrowed_liquidity_wads.try_sub(settle_amount)?; - self.deposited_collateral_tokens + pub fn liquidate(&mut self, repay_amount: Decimal, withdraw_amount: u64) -> ProgramResult { + self.borrowed_liquidity_wads = self.borrowed_liquidity_wads.try_sub(repay_amount)?; + self.deposited_collateral_tokens = self + .deposited_collateral_tokens .checked_sub(withdraw_amount) .ok_or(LendingError::MathOverflow)?; Ok(()) @@ -147,12 +148,7 @@ impl Obligation { obligation_token_supply, )?; - self.borrowed_liquidity_wads = - self.borrowed_liquidity_wads.try_sub(decimal_repay_amount)?; - self.deposited_collateral_tokens = self - .deposited_collateral_tokens - .checked_sub(collateral_withdraw_amount) - .ok_or(LendingError::MathOverflow)?; + self.liquidate(decimal_repay_amount, collateral_withdraw_amount)?; Ok(RepayResult { decimal_repay_amount,