Skip to content

Commit

Permalink
Update contracts/protocol/libraries/logic/LiquidationLogic.sol
Browse files Browse the repository at this point in the history
Co-authored-by: Ernesto Boado <[email protected]>
  • Loading branch information
zhoujia6139 and eboadom authored Nov 11, 2022
1 parent 623730b commit e99112c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions contracts/protocol/libraries/logic/LiquidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ library LiquidationLogic {

// Transfer fee to treasury if it is non-zero
if (vars.liquidationProtocolFeeAmount != 0) {
uint256 index = collateralReserve.getNormalizedIncome();
uint256 aTokenAmount = vars.liquidationProtocolFeeAmount.rayDiv(index);
uint256 aTokenBalance = vars.collateralAToken.scaledBalanceOf(params.user);
if (aTokenAmount > aTokenBalance) {
vars.liquidationProtocolFeeAmount = aTokenBalance.rayMul(index);
uint256 liquidityIndex = collateralReserve.getNormalizedIncome();
uint256 scaledDownLiquidationProtocolFee = vars.liquidationProtocolFeeAmount.rayDiv(liquidityIndex);
uint256 scaledDownUserBalance = vars.collateralAToken.scaledBalanceOf(params.user);
// To avoid trying to send more aTokens than available on balance, due to 1 wei imprecision
if (scaledDownLiquidationProtocolFee > scaledDownUserBalance) {
vars.liquidationProtocolFeeAmount = scaledDownUserBalance.rayMul(liquidityIndex);
}
vars.collateralAToken.transferOnLiquidation(
params.user,
Expand Down

0 comments on commit e99112c

Please sign in to comment.