- Added set of usage as collateral to true on liquidator receiving aToken.

This commit is contained in:
eboado 2020-11-26 16:44:32 +01:00
parent e9a94b29a9
commit 3f070d67ec
3 changed files with 50 additions and 30 deletions

View File

@ -2,19 +2,19 @@
pragma solidity 0.6.12; pragma solidity 0.6.12;
/** /**
* @title ILendingPoolCollateralManager interface * @title ILendingPoolCollateralManager
* @author Aave * @author Aave
* @notice Defines the actions involving management of collateral in the protocol. * @notice Defines the actions involving management of collateral in the protocol.
**/ **/
interface ILendingPoolCollateralManager { interface ILendingPoolCollateralManager {
/** /**
* @dev emitted when a borrower is liquidated * @dev Emitted when a borrower is liquidated
* @param collateral the address of the collateral being liquidated * @param collateral The address of the collateral being liquidated
* @param principal the address of the reserve * @param principal The address of the reserve
* @param user the address of the user being liquidated * @param user The address of the user being liquidated
* @param debtToCover the total amount liquidated * @param debtToCover The total amount liquidated
* @param liquidatedCollateralAmount the amount of collateral being liquidated * @param liquidatedCollateralAmount The amount of collateral being liquidated
* @param liquidator the address of the liquidator * @param liquidator The address of the liquidator
* @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise
**/ **/
event LiquidationCall( event LiquidationCall(
@ -28,18 +28,25 @@ interface ILendingPoolCollateralManager {
); );
/** /**
* @dev emitted when a user disables a reserve as collateral * @dev Emitted when a reserve is disabled as collateral for an user
* @param reserve the address of the reserve * @param reserve The address of the reserve
* @param user the address of the user * @param user The address of the user
**/ **/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
/** /**
* @dev users can invoke this function to liquidate an undercollateralized position. * @dev Emitted when a reserve is enabled as collateral for an user
* @param collateral the address of the collateral to liquidated * @param reserve The address of the reserve
* @param principal the address of the principal reserve * @param user The address of the user
* @param user the address of the borrower **/
* @param debtToCover the amount of principal that the liquidator wants to repay event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);
/**
* @dev Users can invoke this function to liquidate an undercollateralized position.
* @param collateral The address of the collateral to liquidated
* @param principal The address of the principal reserve
* @param user The address of the borrower
* @param debtToCover The amount of principal that the liquidator wants to repay
* @param receiveAToken true if the liquidators wants to receive the aTokens, false if * @param receiveAToken true if the liquidators wants to receive the aTokens, false if
* he wants to receive the underlying asset directly * he wants to receive the underlying asset directly
**/ **/

View File

@ -50,6 +50,7 @@ contract LendingPoolCollateralManager is
uint256 maxCollateralToLiquidate; uint256 maxCollateralToLiquidate;
uint256 debtAmountNeeded; uint256 debtAmountNeeded;
uint256 healthFactor; uint256 healthFactor;
uint256 liquidatorPreviousATokenBalance;
IAToken collateralAtoken; IAToken collateralAtoken;
bool isCollateralEnabled; bool isCollateralEnabled;
DataTypes.InterestRateMode borrowRateMode; DataTypes.InterestRateMode borrowRateMode;
@ -190,7 +191,14 @@ contract LendingPoolCollateralManager is
); );
if (receiveAToken) { if (receiveAToken) {
vars.liquidatorPreviousATokenBalance = IERC20(vars.collateralAtoken).balanceOf(msg.sender);
vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate); vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate);
if (vars.liquidatorPreviousATokenBalance == 0) {
DataTypes.UserConfigurationMap storage liquidatorConfig = _usersConfig[msg.sender];
liquidatorConfig.setUsingAsCollateral(collateralReserve.id, true);
emit ReserveUsedAsCollateralEnabled(collateralAsset, msg.sender);
}
} else { } else {
collateralReserve.updateState(); collateralReserve.updateState();
collateralReserve.updateInterestRates( collateralReserve.updateInterestRates(

View File

@ -117,7 +117,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
}); });
it('LIQUIDATION - Liquidates the borrow', async () => { it('LIQUIDATION - Liquidates the borrow', async () => {
const {pool, dai, weth, users, oracle, helpersContract} = testEnv; const { pool, dai, weth, aWETH, aDai, users, oracle, helpersContract, deployer } = testEnv;
const borrower = users[1]; const borrower = users[1];
//mints dai to the caller //mints dai to the caller
@ -223,6 +223,11 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0), new BigNumber(ethReserveDataBefore.availableLiquidity.toString()).toFixed(0),
'Invalid collateral available liquidity' 'Invalid collateral available liquidity'
); );
expect(
(await helpersContract.getUserReserveData(weth.address, deployer.address))
.usageAsCollateralEnabled
).to.be.true;
}); });
it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => { it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => {