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,20 +720,23 @@ 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);
|
||||||
|
|
||||||
ValidationLogic.validateHealthFactor(
|
|
||||||
from,
|
|
||||||
_reserves,
|
|
||||||
_usersConfig[from],
|
|
||||||
_reservesList,
|
|
||||||
_reservesCount,
|
|
||||||
_addressesProvider.getPriceOracle()
|
|
||||||
);
|
|
||||||
|
|
||||||
uint256 reserveId = _reserves[asset].id;
|
uint256 reserveId = _reserves[asset].id;
|
||||||
|
|
||||||
if (from != to) {
|
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) {
|
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,15 +960,16 @@ 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,
|
||||||
userConfig,
|
userConfig,
|
||||||
_reservesList,
|
_reservesList,
|
||||||
_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