mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: added collateral withdrawal check regarding exposure cap
This commit is contained in:
parent
3b0f7b18c0
commit
5a8572d568
|
@ -372,7 +372,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
|||
if (useAsCollateral) {
|
||||
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
|
||||
} else {
|
||||
ValidationLogic.validateHealthFactor(
|
||||
ValidationLogic.validateWithdrawCollateral(
|
||||
asset,
|
||||
msg.sender,
|
||||
_reserves,
|
||||
_usersConfig[msg.sender],
|
||||
|
@ -729,7 +730,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
|||
|
||||
if (fromConfig.isUsingAsCollateral(reserveId)) {
|
||||
if (fromConfig.isBorrowingAny()) {
|
||||
ValidationLogic.validateHealthFactor(
|
||||
ValidationLogic.validateWithdrawCollateral(
|
||||
asset,
|
||||
from,
|
||||
_reserves,
|
||||
_usersConfig[from],
|
||||
|
@ -966,7 +968,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
|||
|
||||
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
||||
if (userConfig.isBorrowingAny()) {
|
||||
ValidationLogic.validateHealthFactor(
|
||||
ValidationLogic.validateWithdrawCollateral(
|
||||
asset,
|
||||
msg.sender,
|
||||
_reserves,
|
||||
userConfig,
|
||||
|
|
|
@ -446,7 +446,8 @@ library ValidationLogic {
|
|||
* @param reservesCount The number of available reserves
|
||||
* @param oracle The price oracle
|
||||
*/
|
||||
function validateHealthFactor(
|
||||
function validateWithdrawCollateral(
|
||||
address collateral,
|
||||
address from,
|
||||
mapping(address => DataTypes.ReserveData) storage reservesData,
|
||||
DataTypes.UserConfigurationMap storage userConfig,
|
||||
|
@ -454,7 +455,8 @@ library ValidationLogic {
|
|||
uint256 reservesCount,
|
||||
address oracle
|
||||
) internal view {
|
||||
(, , , , uint256 healthFactor) =
|
||||
DataTypes.ReserveData memory reserve = reservesData[collateral];
|
||||
(, , uint256 ltv, , uint256 healthFactor) =
|
||||
GenericLogic.calculateUserAccountData(
|
||||
from,
|
||||
reservesData,
|
||||
|
@ -464,10 +466,22 @@ library ValidationLogic {
|
|||
oracle
|
||||
);
|
||||
|
||||
uint256 exposureCap = reserve.configuration.getExposureCapMemory();
|
||||
uint256 totalSupplyStableDebt = IERC20(reserve.stableDebtTokenAddress).totalSupply();
|
||||
uint256 totalSupplyVariableDebt = IERC20(reserve.variableDebtTokenAddress).totalSupply();
|
||||
(, , , uint256 reserveDecimals, ) = reserve.configuration.getParamsMemory();
|
||||
|
||||
require(
|
||||
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
||||
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
||||
);
|
||||
|
||||
require(
|
||||
exposureCap == 0 ||
|
||||
ltv == 0 ||
|
||||
totalSupplyStableDebt.add(totalSupplyVariableDebt).div(10**reserveDecimals) < exposureCap,
|
||||
Errors.VL_SUPPLY_CAP_EXCEEDED
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user