Skip to content

Commit a438436

Browse files
committed
revert total borrows handling on liquidation
1 parent a857a9c commit a438436

4 files changed

Lines changed: 4 additions & 28 deletions

File tree

x/lending/keeper/liquidation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (k Keeper) HandleLiquidatedDebt(ctx sdk.Context, liquidationId uint64, loan
118118
}
119119
}
120120

121-
k.AfterPoolRepaid(ctx, loan.PoolId, loan.Maturity, debtAmount.SubAmount(interest), interest, protocolFee, actualProtocolFee, false)
121+
k.AfterPoolRepaid(ctx, loan.PoolId, loan.Maturity, debtAmount.SubAmount(interest), interest, protocolFee, actualProtocolFee)
122122

123123
return nil
124124
}

x/lending/keeper/pool.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,17 @@ func (k Keeper) AfterPoolBorrowed(ctx sdk.Context, poolId string, maturity int64
9898
}
9999

100100
// AfterPoolRepaid is the hook which is invoked after the loan is repaid
101-
func (k Keeper) AfterPoolRepaid(ctx sdk.Context, poolId string, maturity int64, amount sdk.Coin, interest sdkmath.Int, protocolFee sdkmath.Int, actualProtocolFee sdkmath.Int, updateTotalBorrowed bool) {
101+
func (k Keeper) AfterPoolRepaid(ctx sdk.Context, poolId string, maturity int64, amount sdk.Coin, interest sdkmath.Int, protocolFee sdkmath.Int, actualProtocolFee sdkmath.Int) {
102102
pool := k.GetPool(ctx, poolId)
103103

104104
totalRepaid := amount.Amount.Add(interest).Sub(protocolFee)
105105

106106
pool.Supply = pool.Supply.AddAmount(interest).SubAmount(protocolFee)
107107
pool.AvailableAmount = pool.AvailableAmount.Add(totalRepaid)
108108
pool.BorrowedAmount = pool.BorrowedAmount.Sub(amount.Amount)
109+
pool.TotalBorrowed = pool.TotalBorrowed.Sub(totalRepaid)
109110
pool.ReserveAmount = pool.ReserveAmount.Add(actualProtocolFee)
110111

111-
if updateTotalBorrowed {
112-
pool.TotalBorrowed = pool.TotalBorrowed.Sub(totalRepaid)
113-
}
114-
115112
for i, tranche := range pool.Tranches {
116113
if tranche.Maturity == maturity {
117114
pool.Tranches[i].TotalBorrowed = pool.Tranches[i].TotalBorrowed.Sub(totalRepaid)
@@ -124,24 +121,6 @@ func (k Keeper) AfterPoolRepaid(ctx sdk.Context, poolId string, maturity int64,
124121
k.SetPool(ctx, pool)
125122
}
126123

127-
// DecreaseTotalBorrowed decreases total borrowed by the given amount for the specified pool
128-
func (k Keeper) DecreaseTotalBorrowed(ctx sdk.Context, poolId string, maturity int64, amount sdkmath.Int) {
129-
pool := k.GetPool(ctx, poolId)
130-
131-
pool.TotalBorrowed = pool.TotalBorrowed.Sub(amount)
132-
133-
for i, tranche := range pool.Tranches {
134-
if tranche.Maturity == maturity {
135-
pool.Tranches[i].TotalBorrowed = pool.Tranches[i].TotalBorrowed.Sub(amount)
136-
break
137-
}
138-
}
139-
140-
k.NormalizePool(ctx, pool)
141-
142-
k.SetPool(ctx, pool)
143-
}
144-
145124
// UpdatePoolTranches updates total borrowed amount for each tranche at the beginning of each block
146125
//
147126
// Formula:

x/lending/keeper/repayment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (k Keeper) CompleteRepayment(ctx sdk.Context, loan *types.Loan) error {
7070
}
7171

7272
// update pool
73-
k.AfterPoolRepaid(ctx, loan.PoolId, loan.Maturity, loan.BorrowAmount, interest.Amount, protocolFee.Amount, actualProtocolFee.Amount, true)
73+
k.AfterPoolRepaid(ctx, loan.PoolId, loan.Maturity, loan.BorrowAmount, interest.Amount, protocolFee.Amount, actualProtocolFee.Amount)
7474

7575
loan.Status = types.LoanStatus_Closed
7676
k.SetLoan(ctx, loan)

x/lending/module/abci.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ func handleActiveLoans(ctx sdk.Context, k keeper.Keeper) {
120120

121121
// update loan
122122
k.SetLoan(ctx, loan)
123-
124-
// update pool
125-
k.DecreaseTotalBorrowed(ctx, loan.PoolId, loan.Maturity, liquidation.DebtAmount.Amount.Sub(types.GetProtocolFee(liquidationInterest, pool.Config.ReserveFactor)))
126123
}
127124
}
128125
}

0 commit comments

Comments
 (0)