From 49db36726bb120473eb6f1016a363a1fd08569f6 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 14 May 2021 20:00:37 +0200 Subject: [PATCH] fix: update behavior of finalizeTransfer() to proper emit the ReserveUsedAsCollateralDisabled event --- .../protocol/lendingpool/LendingPool.sol | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 11e727a4..f61826f0 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -725,20 +725,21 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage if (from != to) { DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from]; - if (fromConfig.isUsingAsCollateral(reserveId) && fromConfig.isBorrowingAny()) { - ValidationLogic.validateHealthFactor( - from, - _reserves, - _usersConfig[from], - _reservesList, - _reservesCount, - _addressesProvider.getPriceOracle() - ); - } - - if (balanceFromBefore.sub(amount) == 0) { - fromConfig.setUsingAsCollateral(reserveId, false); - emit ReserveUsedAsCollateralDisabled(asset, from); + if (fromConfig.isUsingAsCollateral(reserveId)) { + if (fromConfig.isBorrowingAny()) { + ValidationLogic.validateHealthFactor( + from, + _reserves, + _usersConfig[from], + _reservesList, + _reservesCount, + _addressesProvider.getPriceOracle() + ); + } + if (balanceFromBefore.sub(amount) == 0) { + fromConfig.setUsingAsCollateral(reserveId, false); + emit ReserveUsedAsCollateralDisabled(asset, from); + } } if (balanceToBefore == 0 && amount != 0) {