Fixes issue on LiquidationManager

This commit is contained in:
The3D 2020-07-15 16:44:20 +02:00
parent 7b66a05c5d
commit 2add014fe5
2 changed files with 35 additions and 6 deletions

View File

@ -201,16 +201,12 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
//of _collateral to cover the actual amount that is being liquidated, hence we liquidate
//a smaller amount
vars.collateralAtoken = AToken(payable(collateralReserve.aTokenAddress));
//if principalAmountNeeded < vars.ActualAmountToLiquidate, there isn't enough
//of _collateral to cover the actual amount that is being liquidated, hence we liquidate
//a smaller amount
if (vars.principalAmountNeeded < vars.actualAmountToLiquidate) {
vars.actualAmountToLiquidate = vars.principalAmountNeeded;
}
vars.collateralAtoken = AToken(payable(collateralReserve.aTokenAddress));
//if liquidator reclaims the underlying asset, we make sure there is enough available collateral in the reserve
if (!_receiveAToken) {
uint256 currentAvailableCollateral = IERC20(_collateral).universalBalanceOf(
@ -224,6 +220,10 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
}
}
//update the principal reserve
principalReserve.updateCumulativeIndexesAndTimestamp();
principalReserve.updateInterestRates(_reserve, vars.actualAmountToLiquidate, 0);
if (vars.userVariableDebt >= vars.actualAmountToLiquidate) {
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
_user,
@ -245,6 +245,11 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
vars.collateralAtoken.transferOnLiquidation(_user, msg.sender, vars.maxCollateralToLiquidate);
} else {
//otherwise receives the underlying asset
//updating collateral reserve
collateralReserve.updateCumulativeIndexesAndTimestamp();
collateralReserve.updateInterestRates(_collateral, 0, vars.maxCollateralToLiquidate);
//burn the equivalent amount of atoken
vars.collateralAtoken.burnOnLiquidation(_user, vars.maxCollateralToLiquidate);
vars.collateralAtoken.transferUnderlyingTo(msg.sender, vars.maxCollateralToLiquidate);

View File

@ -197,6 +197,18 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
'Invalid principal available liquidity'
);
//the liquidity index of the principal reserve needs to be bigger than the index before
expect(daiReserveDataAfter.liquidityIndex.toString()).to.be.bignumber.gt(
daiReserveDataBefore.liquidityIndex.toString(),
'Invalid liquidity index'
);
//the principal APY after a liquidation needs to be lower than the APY before
expect(daiReserveDataAfter.liquidityRate.toString()).to.be.bignumber.lt(
daiReserveDataBefore.liquidityRate.toString(),
'Invalid liquidity APY'
);
expect(ethReserveDataAfter.availableLiquidity).to.be.bignumber.almostEqual(
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
'Invalid collateral available liquidity'
@ -317,6 +329,18 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
'Invalid principal available liquidity'
);
//the liquidity index of the principal reserve needs to be bigger than the index before
expect(usdcReserveDataAfter.liquidityIndex.toString()).to.be.bignumber.gt(
usdcReserveDataBefore.liquidityIndex.toString(),
'Invalid liquidity index'
);
//the principal APY after a liquidation needs to be lower than the APY before
expect(usdcReserveDataAfter.liquidityRate.toString()).to.be.bignumber.lt(
usdcReserveDataBefore.liquidityRate.toString(),
'Invalid liquidity APY'
);
expect(ethReserveDataAfter.availableLiquidity).to.be.bignumber.almostEqual(
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
'Invalid collateral available liquidity'