fix: token lending; repay and liquidate should set deposited collateral tokens (#1383)

This commit is contained in:
Jordan Sexton 2021-03-06 11:24:44 -06:00 committed by GitHub
parent 27c94293ce
commit f24d375b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 9 deletions

View File

@ -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,