mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/9' into 'master'
Resolve "Fix liquidationCall() function" Closes #9 See merge request aave-tech/protocol-v2!7
This commit is contained in:
commit
57f2965cbd
|
@ -201,16 +201,12 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
|
||||||
//of _collateral to cover the actual amount that is being liquidated, hence we liquidate
|
//of _collateral to cover the actual amount that is being liquidated, hence we liquidate
|
||||||
//a smaller amount
|
//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) {
|
if (vars.principalAmountNeeded < vars.actualAmountToLiquidate) {
|
||||||
vars.actualAmountToLiquidate = vars.principalAmountNeeded;
|
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 liquidator reclaims the underlying asset, we make sure there is enough available collateral in the reserve
|
||||||
if (!_receiveAToken) {
|
if (!_receiveAToken) {
|
||||||
uint256 currentAvailableCollateral = IERC20(_collateral).universalBalanceOf(
|
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) {
|
if (vars.userVariableDebt >= vars.actualAmountToLiquidate) {
|
||||||
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
|
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
|
||||||
_user,
|
_user,
|
||||||
|
@ -245,6 +245,11 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
|
||||||
vars.collateralAtoken.transferOnLiquidation(_user, msg.sender, vars.maxCollateralToLiquidate);
|
vars.collateralAtoken.transferOnLiquidation(_user, msg.sender, vars.maxCollateralToLiquidate);
|
||||||
} else {
|
} else {
|
||||||
//otherwise receives the underlying asset
|
//otherwise receives the underlying asset
|
||||||
|
|
||||||
|
//updating collateral reserve
|
||||||
|
collateralReserve.updateCumulativeIndexesAndTimestamp();
|
||||||
|
collateralReserve.updateInterestRates(_collateral, 0, vars.maxCollateralToLiquidate);
|
||||||
|
|
||||||
//burn the equivalent amount of atoken
|
//burn the equivalent amount of atoken
|
||||||
vars.collateralAtoken.burnOnLiquidation(_user, vars.maxCollateralToLiquidate);
|
vars.collateralAtoken.burnOnLiquidation(_user, vars.maxCollateralToLiquidate);
|
||||||
vars.collateralAtoken.transferUnderlyingTo(msg.sender, vars.maxCollateralToLiquidate);
|
vars.collateralAtoken.transferUnderlyingTo(msg.sender, vars.maxCollateralToLiquidate);
|
||||||
|
|
|
@ -300,25 +300,6 @@ library ReserveLogic {
|
||||||
updateInterestRates(_reserve, _reserveAddress, _income, 0);
|
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
|
* @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
|
* @param _reserve the reserve address
|
||||||
|
|
|
@ -197,6 +197,18 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
||||||
'Invalid principal available liquidity'
|
'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(
|
expect(ethReserveDataAfter.availableLiquidity).to.be.bignumber.almostEqual(
|
||||||
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
|
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
|
||||||
'Invalid collateral available liquidity'
|
'Invalid collateral available liquidity'
|
||||||
|
@ -317,6 +329,18 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
||||||
'Invalid principal available liquidity'
|
'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(
|
expect(ethReserveDataAfter.availableLiquidity).to.be.bignumber.almostEqual(
|
||||||
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
|
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
|
||||||
'Invalid collateral available liquidity'
|
'Invalid collateral available liquidity'
|
||||||
|
|
|
@ -182,6 +182,18 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
|
||||||
'Invalid user debt after liquidation'
|
'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(
|
expect(daiReserveDataAfter.availableLiquidity.toString()).to.be.bignumber.almostEqual(
|
||||||
new BigNumber(daiReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
|
new BigNumber(daiReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
|
||||||
'Invalid principal available liquidity'
|
'Invalid principal available liquidity'
|
||||||
|
@ -309,6 +321,18 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
|
||||||
'Invalid user borrow balance after liquidation'
|
'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(
|
expect(usdcReserveDataAfter.availableLiquidity.toString()).to.be.bignumber.almostEqual(
|
||||||
new BigNumber(usdcReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
|
new BigNumber(usdcReserveDataBefore.availableLiquidity).plus(amountToLiquidate).toFixed(0),
|
||||||
'Invalid principal available liquidity'
|
'Invalid principal available liquidity'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user