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) {
|
if (useAsCollateral) {
|
||||||
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
|
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
|
||||||
} else {
|
} else {
|
||||||
ValidationLogic.validateHealthFactor(
|
ValidationLogic.validateWithdrawCollateral(
|
||||||
|
asset,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
_reserves,
|
_reserves,
|
||||||
_usersConfig[msg.sender],
|
_usersConfig[msg.sender],
|
||||||
|
@ -729,7 +730,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
if (fromConfig.isUsingAsCollateral(reserveId)) {
|
if (fromConfig.isUsingAsCollateral(reserveId)) {
|
||||||
if (fromConfig.isBorrowingAny()) {
|
if (fromConfig.isBorrowingAny()) {
|
||||||
ValidationLogic.validateHealthFactor(
|
ValidationLogic.validateWithdrawCollateral(
|
||||||
|
asset,
|
||||||
from,
|
from,
|
||||||
_reserves,
|
_reserves,
|
||||||
_usersConfig[from],
|
_usersConfig[from],
|
||||||
|
@ -966,7 +968,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
||||||
if (userConfig.isBorrowingAny()) {
|
if (userConfig.isBorrowingAny()) {
|
||||||
ValidationLogic.validateHealthFactor(
|
ValidationLogic.validateWithdrawCollateral(
|
||||||
|
asset,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
_reserves,
|
_reserves,
|
||||||
userConfig,
|
userConfig,
|
||||||
|
|
|
@ -446,7 +446,8 @@ library ValidationLogic {
|
||||||
* @param reservesCount The number of available reserves
|
* @param reservesCount The number of available reserves
|
||||||
* @param oracle The price oracle
|
* @param oracle The price oracle
|
||||||
*/
|
*/
|
||||||
function validateHealthFactor(
|
function validateWithdrawCollateral(
|
||||||
|
address collateral,
|
||||||
address from,
|
address from,
|
||||||
mapping(address => DataTypes.ReserveData) storage reservesData,
|
mapping(address => DataTypes.ReserveData) storage reservesData,
|
||||||
DataTypes.UserConfigurationMap storage userConfig,
|
DataTypes.UserConfigurationMap storage userConfig,
|
||||||
|
@ -454,7 +455,8 @@ library ValidationLogic {
|
||||||
uint256 reservesCount,
|
uint256 reservesCount,
|
||||||
address oracle
|
address oracle
|
||||||
) internal view {
|
) internal view {
|
||||||
(, , , , uint256 healthFactor) =
|
DataTypes.ReserveData memory reserve = reservesData[collateral];
|
||||||
|
(, , uint256 ltv, , uint256 healthFactor) =
|
||||||
GenericLogic.calculateUserAccountData(
|
GenericLogic.calculateUserAccountData(
|
||||||
from,
|
from,
|
||||||
reservesData,
|
reservesData,
|
||||||
|
@ -464,10 +466,22 @@ library ValidationLogic {
|
||||||
oracle
|
oracle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
uint256 exposureCap = reserve.configuration.getExposureCapMemory();
|
||||||
|
uint256 totalSupplyStableDebt = IERC20(reserve.stableDebtTokenAddress).totalSupply();
|
||||||
|
uint256 totalSupplyVariableDebt = IERC20(reserve.variableDebtTokenAddress).totalSupply();
|
||||||
|
(, , , uint256 reserveDecimals, ) = reserve.configuration.getParamsMemory();
|
||||||
|
|
||||||
require(
|
require(
|
||||||
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
||||||
Errors.VL_HEALTH_FACTOR_LOWER_THAN_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