Merge branch 'fix/9' into 'master'

Resolve "Fix liquidationCall() function"

Closes 

See merge request 
This commit is contained in:
The-3D 2020-07-17 10:29:51 +00:00
commit 57f2965cbd
4 changed files with 59 additions and 25 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

@ -300,25 +300,6 @@ library ReserveLogic {
updateInterestRates(_reserve, _reserveAddress, _income, 0);
}
/**
* @dev updates the state of the core as a consequence of a liquidation action.
* @param _collateralReserve the collateral reserve that is being liquidated
* @param _collateralToLiquidate the amount of collateral being liquidated
* @param _liquidatorReceivesAToken true if the liquidator will receive aTokens, false otherwise
**/
function updateStateOnLiquidationAsCollateral(
ReserveData storage _collateralReserve,
address _collateralReserveAddress,
uint256 _collateralToLiquidate,
bool _liquidatorReceivesAToken
) external {
_collateralReserve.updateCumulativeIndexesAndTimestamp();
if (!_liquidatorReceivesAToken) {
updateInterestRates(_collateralReserve, _collateralReserveAddress, 0, _collateralToLiquidate);
}
}
/**
* @dev gets the total liquidity in the reserve. The total liquidity is the balance of the core contract + total borrows
* @param _reserve the reserve address

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'

View File

@ -182,6 +182,18 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
'Invalid user debt after liquidation'
);
//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(daiReserveDataAfter.availableLiquidity.toString()).to.be.bignumber.almostEqual(
new BigNumber(daiReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
'Invalid principal available liquidity'
@ -309,6 +321,18 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
'Invalid user borrow balance after liquidation'
);
//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(usdcReserveDataAfter.availableLiquidity.toString()).to.be.bignumber.almostEqual(
new BigNumber(usdcReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
'Invalid principal available liquidity'