Added tracking of the usage as collateral to the liquidationCall

This commit is contained in:
The3D 2020-11-10 16:18:31 +01:00
parent c8e59ca950
commit a3ee5d2ce6

View File

@ -57,6 +57,13 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
bool receiveAToken bool receiveAToken
); );
/**
* @dev emitted when a user disables a reserve as collateral
* @param reserve the address of the reserve
* @param user the address of the user
**/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
struct LiquidationCallLocalVars { struct LiquidationCallLocalVars {
uint256 userCollateralBalance; uint256 userCollateralBalance;
uint256 userStableDebt; uint256 userStableDebt;
@ -120,7 +127,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
(, , , , vars.healthFactor) = GenericLogic.calculateUserAccountData( (, , , , vars.healthFactor) = GenericLogic.calculateUserAccountData(
user, user,
_reserves, _reserves,
_usersConfig[user], userConfig,
_reservesList, _reservesList,
_reservesCount, _reservesCount,
_addressesProvider.getPriceOracle() _addressesProvider.getPriceOracle()
@ -246,6 +253,14 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
); );
} }
//if the collateral being liquidated is equal to the user balance,
//we set the currency as not being used as collateral anymore
if (vars.maxCollateralToLiquidate == vars.userCollateralBalance) {
userConfig.setUsingAsCollateral(collateralReserve.id, false);
emit ReserveUsedAsCollateralDisabled(collateral, user);
}
//transfers the principal currency to the aToken //transfers the principal currency to the aToken
IERC20(principal).safeTransferFrom( IERC20(principal).safeTransferFrom(
msg.sender, msg.sender,