mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
fix: fixed behavior in case the asset withdrawn was already being used as collateral
This commit is contained in:
parent
50ea61fe70
commit
2dac7fbd80
|
@ -936,6 +936,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
address to
|
address to
|
||||||
) internal returns (uint256) {
|
) internal returns (uint256) {
|
||||||
DataTypes.ReserveData storage reserve = _reserves[asset];
|
DataTypes.ReserveData storage reserve = _reserves[asset];
|
||||||
|
DataTypes.UserConfigurationMap storage userConfig = _usersConfig[msg.sender];
|
||||||
|
|
||||||
address aToken = reserve.aTokenAddress;
|
address aToken = reserve.aTokenAddress;
|
||||||
|
|
||||||
|
@ -953,21 +954,24 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw);
|
reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw);
|
||||||
|
|
||||||
if (amountToWithdraw == userBalance) {
|
|
||||||
_usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false);
|
|
||||||
emit ReserveUsedAsCollateralDisabled(asset, msg.sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex);
|
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex);
|
||||||
|
|
||||||
ValidationLogic.validateHealthFactor(
|
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
||||||
msg.sender,
|
|
||||||
_reserves,
|
ValidationLogic.validateHealthFactor(
|
||||||
_usersConfig[msg.sender],
|
msg.sender,
|
||||||
_reservesList,
|
_reserves,
|
||||||
_reservesCount,
|
userConfig,
|
||||||
_addressesProvider.getPriceOracle()
|
_reservesList,
|
||||||
);
|
_reservesCount,
|
||||||
|
_addressesProvider.getPriceOracle()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (amountToWithdraw == userBalance) {
|
||||||
|
userConfig.setUsingAsCollateral(reserve.id, false);
|
||||||
|
emit ReserveUsedAsCollateralDisabled(asset, msg.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit Withdraw(asset, msg.sender, to, amountToWithdraw);
|
emit Withdraw(asset, msg.sender, to, amountToWithdraw);
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ library ValidationLogic {
|
||||||
IERC20 stableDebtToken,
|
IERC20 stableDebtToken,
|
||||||
IERC20 variableDebtToken,
|
IERC20 variableDebtToken,
|
||||||
address aTokenAddress
|
address aTokenAddress
|
||||||
) internal view {
|
) external view {
|
||||||
(bool isActive, , , ) = reserve.configuration.getFlags();
|
(bool isActive, , , ) = reserve.configuration.getFlags();
|
||||||
|
|
||||||
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
|
@ -315,7 +315,7 @@ library ValidationLogic {
|
||||||
*/
|
*/
|
||||||
function validateSetUseReserveAsCollateral(
|
function validateSetUseReserveAsCollateral(
|
||||||
DataTypes.ReserveData storage reserve
|
DataTypes.ReserveData storage reserve
|
||||||
) internal view {
|
) external view {
|
||||||
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
|
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
|
||||||
|
|
||||||
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
|
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user