From a3ee5d2ce695f3fb668c9622c5e16facc3ca8424 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 10 Nov 2020 16:18:31 +0100 Subject: [PATCH] Added tracking of the usage as collateral to the liquidationCall --- .../LendingPoolCollateralManager.sol | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contracts/lendingpool/LendingPoolCollateralManager.sol b/contracts/lendingpool/LendingPoolCollateralManager.sol index 993f7fe5..729895de 100644 --- a/contracts/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/lendingpool/LendingPoolCollateralManager.sol @@ -57,6 +57,13 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor 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 { uint256 userCollateralBalance; uint256 userStableDebt; @@ -120,7 +127,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor (, , , , vars.healthFactor) = GenericLogic.calculateUserAccountData( user, _reserves, - _usersConfig[user], + userConfig, _reservesList, _reservesCount, _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 IERC20(principal).safeTransferFrom( msg.sender,