mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: allowed people to withdraw colleteral that exceeded the exposure cap if their ltv still superior to their liq threshold
This commit is contained in:
parent
485a41a0ef
commit
7a80d5cd14
|
@ -100,6 +100,7 @@ library GenericLogic {
|
||||||
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
|
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
|
||||||
.configuration
|
.configuration
|
||||||
.getParams();
|
.getParams();
|
||||||
|
vars.exposureCap = currentReserve.configuration.getExposureCap();
|
||||||
|
|
||||||
vars.assetUnit = 10**vars.decimals;
|
vars.assetUnit = 10**vars.decimals;
|
||||||
vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress);
|
vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress);
|
||||||
|
@ -114,7 +115,6 @@ library GenericLogic {
|
||||||
vars.userBalanceETH = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
|
vars.userBalanceETH = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
|
||||||
|
|
||||||
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
|
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
|
||||||
vars.exposureCap = currentReserve.configuration.getExposureCap();
|
|
||||||
vars.exposureCapped =
|
vars.exposureCapped =
|
||||||
vars.exposureCap != 0 &&
|
vars.exposureCap != 0 &&
|
||||||
IERC20(currentReserve.aTokenAddress).totalSupply().div(10**vars.decimals) >
|
IERC20(currentReserve.aTokenAddress).totalSupply().div(10**vars.decimals) >
|
||||||
|
|
|
@ -456,7 +456,7 @@ library ValidationLogic {
|
||||||
address oracle
|
address oracle
|
||||||
) internal view {
|
) internal view {
|
||||||
DataTypes.ReserveData memory reserve = reservesData[collateral];
|
DataTypes.ReserveData memory reserve = reservesData[collateral];
|
||||||
(, , uint256 ltv, , uint256 healthFactor) =
|
(, , uint256 ltv, uint256 liquidationThreshold, uint256 healthFactor) =
|
||||||
GenericLogic.calculateUserAccountData(
|
GenericLogic.calculateUserAccountData(
|
||||||
from,
|
from,
|
||||||
reservesData,
|
reservesData,
|
||||||
|
@ -475,8 +475,17 @@ library ValidationLogic {
|
||||||
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// exposureCap == 0 means no cap => can withdraw
|
||||||
|
// ltv > liquidationThreshold means that there is enough collateral margin => can withdraw
|
||||||
|
// ltv == 0 means all current collaterals have exceeded the exposure cap => can withdraw
|
||||||
|
// last means that for this asset the cap is not yet exceeded => can withdraw
|
||||||
|
// else this means the user is trying to withdraw a collateral that has exceeded the exposure cap, and that it
|
||||||
|
// as other collaterals available to withdraw: he must withdraw from other collateral reserves first
|
||||||
require(
|
require(
|
||||||
exposureCap == 0 || ltv == 0 || totalSupplyAtoken.div(10**reserveDecimals) < exposureCap,
|
exposureCap == 0 ||
|
||||||
|
ltv > liquidationThreshold ||
|
||||||
|
ltv == 0 ||
|
||||||
|
totalSupplyAtoken.div(10**reserveDecimals) < exposureCap,
|
||||||
Errors.VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED
|
Errors.VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user