mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
refactor: added validation on withdraw/finalizeTransfer - only check the HF if the user is using the asset as collateral or is borrowing
This commit is contained in:
parent
2507a2220b
commit
235f2d80ec
|
@ -720,6 +720,12 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
) external override whenNotPaused {
|
) external override whenNotPaused {
|
||||||
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
||||||
|
|
||||||
|
uint256 reserveId = _reserves[asset].id;
|
||||||
|
|
||||||
|
if (from != to) {
|
||||||
|
DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from];
|
||||||
|
|
||||||
|
if (fromConfig.isUsingAsCollateral(reserveId) && fromConfig.isBorrowingAny()) {
|
||||||
ValidationLogic.validateHealthFactor(
|
ValidationLogic.validateHealthFactor(
|
||||||
from,
|
from,
|
||||||
_reserves,
|
_reserves,
|
||||||
|
@ -728,12 +734,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
_reservesCount,
|
_reservesCount,
|
||||||
_addressesProvider.getPriceOracle()
|
_addressesProvider.getPriceOracle()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
uint256 reserveId = _reserves[asset].id;
|
|
||||||
|
|
||||||
if (from != to) {
|
|
||||||
if (balanceFromBefore.sub(amount) == 0) {
|
if (balanceFromBefore.sub(amount) == 0) {
|
||||||
DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from];
|
|
||||||
fromConfig.setUsingAsCollateral(reserveId, false);
|
fromConfig.setUsingAsCollateral(reserveId, false);
|
||||||
emit ReserveUsedAsCollateralDisabled(asset, from);
|
emit ReserveUsedAsCollateralDisabled(asset, from);
|
||||||
}
|
}
|
||||||
|
@ -957,7 +960,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex);
|
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex);
|
||||||
|
|
||||||
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
||||||
|
if (userConfig.isBorrowingAny()) {
|
||||||
ValidationLogic.validateHealthFactor(
|
ValidationLogic.validateHealthFactor(
|
||||||
msg.sender,
|
msg.sender,
|
||||||
_reserves,
|
_reserves,
|
||||||
|
@ -966,6 +969,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
_reservesCount,
|
_reservesCount,
|
||||||
_addressesProvider.getPriceOracle()
|
_addressesProvider.getPriceOracle()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (amountToWithdraw == userBalance) {
|
if (amountToWithdraw == userBalance) {
|
||||||
userConfig.setUsingAsCollateral(reserve.id, false);
|
userConfig.setUsingAsCollateral(reserve.id, false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user