mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: added exposure cap logic in calculateUserAccountData
This commit is contained in:
parent
5a8572d568
commit
68ff74a3a6
|
@ -110,6 +110,7 @@ library Errors {
|
|||
string public constant VL_RESERVE_PAUSED = '86';
|
||||
string public constant LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87';
|
||||
string public constant RC_INVALID_EXPOSURE_CAP = '88';
|
||||
string public constant VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '89';
|
||||
|
||||
enum CollateralManagerErrors {
|
||||
NO_ERROR,
|
||||
|
|
|
@ -47,10 +47,12 @@ library GenericLogic {
|
|||
uint256 reservesLength;
|
||||
uint256 normalizedIncome;
|
||||
uint256 normalizedDebt;
|
||||
uint256 exposureCap;
|
||||
bool healthFactorBelowThreshold;
|
||||
address currentReserveAddress;
|
||||
bool usageAsCollateralEnabled;
|
||||
bool userUsesReserveAsCollateral;
|
||||
bool exposureCapped;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,8 +114,14 @@ library GenericLogic {
|
|||
vars.userBalanceETH = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
|
||||
|
||||
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
|
||||
|
||||
vars.avgLtv = vars.avgLtv.add(vars.userBalanceETH.mul(vars.ltv));
|
||||
vars.exposureCap = currentReserve.configuration.getExposureCap();
|
||||
vars.exposureCapped =
|
||||
IERC20(currentReserve.stableDebtTokenAddress)
|
||||
.totalSupply()
|
||||
.add(IERC20(currentReserve.variableDebtTokenAddress).totalSupply())
|
||||
.div(10**vars.decimals) >
|
||||
vars.exposureCap;
|
||||
vars.avgLtv = vars.avgLtv.add(vars.exposureCapped ? 0 : vars.userBalanceETH.mul(vars.ltv));
|
||||
vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add(
|
||||
vars.userBalanceETH.mul(vars.liquidationThreshold)
|
||||
);
|
||||
|
@ -132,7 +140,7 @@ library GenericLogic {
|
|||
IERC20(currentReserve.stableDebtTokenAddress).balanceOf(user)
|
||||
);
|
||||
vars.userDebtETH = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit);
|
||||
vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH);
|
||||
vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -480,7 +480,7 @@ library ValidationLogic {
|
|||
exposureCap == 0 ||
|
||||
ltv == 0 ||
|
||||
totalSupplyStableDebt.add(totalSupplyVariableDebt).div(10**reserveDecimals) < exposureCap,
|
||||
Errors.VL_SUPPLY_CAP_EXCEEDED
|
||||
Errors.VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -184,6 +184,8 @@ export enum ProtocolErrors {
|
|||
LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85',
|
||||
VL_RESERVE_PAUSED = '86',
|
||||
LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87',
|
||||
RC_INVALID_EXPOSURE_CAP = '88',
|
||||
VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '89',
|
||||
|
||||
// old
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user