fix: remove exposure cap specific code and configuration

This commit is contained in:
The3D 2021-07-05 19:54:59 +02:00
parent 76a141cd36
commit a98956f8b2
11 changed files with 30 additions and 157 deletions

View File

@ -33,7 +33,6 @@ contract ATokensAndRatesHelper is Ownable {
uint256 reserveFactor;
uint256 borrowCap;
uint256 supplyCap;
uint256 exposureCap;
bool stableBorrowingEnabled;
bool borrowingEnabled;
}
@ -74,8 +73,7 @@ contract ATokensAndRatesHelper is Ownable {
inputParams[i].asset,
inputParams[i].baseLTV,
inputParams[i].liquidationThreshold,
inputParams[i].liquidationBonus,
inputParams[i].exposureCap
inputParams[i].liquidationBonus
);
if (inputParams[i].borrowingEnabled) {

View File

@ -159,13 +159,6 @@ interface ILendingPoolConfigurator {
**/
event SupplyCapChanged(address indexed asset, uint256 supplyCap);
/**
* @dev Emitted when the exposure cap of a reserve is updated
* @param asset The address of the underlying asset of the reserve
* @param exposureCap The new exposure cap
**/
event ExposureCapChanged(address indexed asset, uint256 exposureCap);
/**
* @dev Emitted when the reserve decimals are updated
* @param asset The address of the underlying asset of the reserve
@ -301,15 +294,13 @@ interface ILendingPoolConfigurator {
* @param ltv The loan to value of the asset when used as collateral
* @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized
* @param liquidationBonus The bonus liquidators receive to liquidate this asset. The values is always above 100%. A value of 105%
* @param exposureCap The exposure cap for the collateral reserve. If cap is reached, effective LTV = 0
* means the liquidator will receive a 5% bonus
**/
function configureReserveAsCollateral(
address asset,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 exposureCap
uint256 liquidationBonus
) external;
/**
@ -392,13 +383,6 @@ interface ILendingPoolConfigurator {
**/
function setSupplyCap(address asset, uint256 supplyCap) external;
/**
* @dev Updates the exposure cap of a reserve
* @param asset The address of the underlying asset of the reserve
* @param exposureCap The new exposure of the reserve
**/
function setExposureCap(address asset, uint256 exposureCap) external;
/**
* @dev Registers a new admin with rights on risk related configurations
* @param admin The address of the admin to register

View File

@ -98,11 +98,10 @@ contract AaveProtocolDataProvider {
view
returns (
uint256 borrowCap,
uint256 supplyCap,
uint256 exposureCap
uint256 supplyCap
)
{
(borrowCap, supplyCap, exposureCap) = ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
(borrowCap, supplyCap) = ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
.getConfiguration(asset)
.getCapsMemory();
}

View File

@ -114,7 +114,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
reserveData.decimals,
reserveData.reserveFactor
) = baseData.configuration.getParamsMemory();
(reserveData.borrowCap, reserveData.supplyCap, reserveData.exposureCap) = baseData
(reserveData.borrowCap, reserveData.supplyCap) = baseData
.configuration
.getCapsMemory();
(

View File

@ -17,7 +17,6 @@ interface IUiPoolDataProvider {
uint256 reserveFactor;
uint256 borrowCap;
uint256 supplyCap;
uint256 exposureCap;
bool usageAsCollateralEnabled;
bool borrowingEnabled;
bool stableBorrowRateEnabled;

View File

@ -278,9 +278,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (useAsCollateral) {
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
} else {
ValidationLogic.validateHFAndExposureCap(
ValidationLogic.validateHFAndLtv(
asset,
userBalance,
msg.sender,
_reserves,
_usersConfig[msg.sender],
@ -620,9 +619,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (fromConfig.isUsingAsCollateral(reserveId)) {
if (fromConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndExposureCap(
ValidationLogic.validateHFAndLtv(
asset,
amount,
from,
_reserves,
_usersConfig[from],
@ -864,9 +862,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (userConfig.isUsingAsCollateral(reserve.id)) {
if (userConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndExposureCap(
ValidationLogic.validateHFAndLtv(
asset,
0,
msg.sender,
_reserves,
userConfig,

View File

@ -296,8 +296,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
address asset,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 exposureCap
uint256 liquidationBonus
) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
@ -331,7 +330,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
currentConfig.setLtv(ltv);
currentConfig.setLiquidationThreshold(liquidationThreshold);
currentConfig.setLiquidationBonus(liquidationBonus);
currentConfig.setExposureCap(exposureCap);
_pool.setConfiguration(asset, currentConfig.data);
@ -458,21 +456,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
emit SupplyCapChanged(asset, supplyCap);
}
///@inheritdoc ILendingPoolConfigurator
function setExposureCap(address asset, uint256 exposureCap)
external
override
onlyRiskOrPoolAdmins
{
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setExposureCap(exposureCap);
_pool.setConfiguration(asset, currentConfig.data);
emit ExposureCapChanged(asset, exposureCap);
}
///@inheritdoc ILendingPoolConfigurator
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external

View File

@ -22,7 +22,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant EXPOSURE_CAP_MASK = 0xFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
@ -37,7 +36,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 constant BORROW_CAP_START_BIT_POSITION = 80;
uint256 constant SUPPLY_CAP_START_BIT_POSITION = 116;
uint256 constant EXPOSURE_CAP_START_BIT_POSITION = 152;
uint256 constant MAX_VALID_LTV = 65535;
uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
@ -46,7 +44,6 @@ library ReserveConfiguration {
uint256 constant MAX_VALID_RESERVE_FACTOR = 65535;
uint256 constant MAX_VALID_BORROW_CAP = 68719476735;
uint256 constant MAX_VALID_SUPPLY_CAP = 68719476735;
uint256 constant MAX_VALID_EXPOSURE_CAP = 68719476735;
/**
* @dev Sets the Loan to Value of the reserve
@ -386,33 +383,6 @@ library ReserveConfiguration {
return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION;
}
/**
* @dev Sets the exposure cap of the reserve
* @param self The reserve configuration
* @param exposureCap The exposure cap
**/
function setExposureCap(DataTypes.ReserveConfigurationMap memory self, uint256 exposureCap)
internal
pure
{
require(exposureCap <= MAX_VALID_EXPOSURE_CAP, Errors.RC_INVALID_EXPOSURE_CAP);
self.data = (self.data & EXPOSURE_CAP_MASK) | (exposureCap << EXPOSURE_CAP_START_BIT_POSITION);
}
/**
* @dev Gets the exposure cap of the reserve
* @param self The reserve configuration
* @return The exposure cap
**/
function getExposureCap(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (uint256)
{
return (self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION;
}
/**
* @dev Gets the configuration flags of the reserve
* @param self The reserve configuration
@ -476,7 +446,6 @@ library ReserveConfiguration {
internal
view
returns (
uint256,
uint256,
uint256
)
@ -485,8 +454,7 @@ library ReserveConfiguration {
return (
(dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION,
(dataLocal & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}
@ -524,15 +492,13 @@ library ReserveConfiguration {
internal
pure
returns (
uint256,
uint256,
uint256
)
{
return (
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION,
(self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}
@ -586,17 +552,4 @@ library ReserveConfiguration {
{
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
}
/**
* @dev Gets the exposure cap of the reserve from a memory object
* @param self The reserve configuration
* @return The exposure cap
**/
function getExposureCapMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
{
return (self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION;
}
}

View File

@ -114,7 +114,7 @@ library Errors {
string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90';
string public constant LP_CALLER_NOT_EOA = '91';
string public constant RC_INVALID_EXPOSURE_CAP = '92';
string public constant VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '93';
string public constant VL_LTV_VALIDATION_FAILED = '93';
string public constant VL_SAME_BLOCK_BORROW_REPAY = '94';
string public constant LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95';
string public constant LPC_FLASHLOAN_PREMIUM_INVALID = '96';

View File

@ -44,18 +44,11 @@ library GenericLogic {
uint256 totalCollateralInETH;
uint256 totalDebtInETH;
uint256 avgLtv;
uint256 avgUncappedLtv;
uint256 avgLiquidationThreshold;
uint256 reservesLength;
uint256 normalizedIncome;
uint256 normalizedDebt;
uint256 exposureCap;
uint256 aTokenSupply;
bool healthFactorBelowThreshold;
address currentReserveAddress;
bool usageAsCollateralEnabled;
bool userUsesReserveAsCollateral;
bool exposureCapCrossed;
bool hasZeroLtvCollateral;
}
/**
@ -85,13 +78,13 @@ library GenericLogic {
uint256,
uint256,
uint256,
uint256
bool
)
{
CalculateUserAccountDataVars memory vars;
if (userConfig.isEmpty()) {
return (0, 0, 0, 0, uint256(-1), 0);
return (0, 0, 0, 0, uint256(-1), false);
}
for (vars.i = 0; vars.i < reservesCount; vars.i++) {
if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) {
@ -107,38 +100,20 @@ library GenericLogic {
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
.configuration
.getParams();
vars.exposureCap = currentReserve.configuration.getExposureCap();
vars.assetUnit = 10**vars.decimals;
vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress);
if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) {
vars.normalizedIncome = currentReserve.getNormalizedIncome();
if (vars.exposureCap != 0) {
(vars.userBalance, vars.aTokenSupply) = IScaledBalanceToken(currentReserve.aTokenAddress)
.getScaledUserBalanceAndSupply(user);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
vars.aTokenSupply = vars.aTokenSupply.rayMul(vars.normalizedIncome);
} else {
vars.userBalance = IScaledBalanceToken(currentReserve.aTokenAddress).scaledBalanceOf(
user
);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
vars.aTokenSupply = 0;
}
vars.userBalance = IScaledBalanceToken(currentReserve.aTokenAddress).scaledBalanceOf(user);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
vars.userBalanceETH = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
vars.exposureCapCrossed =
vars.exposureCap != 0 &&
vars.aTokenSupply.div(10**vars.decimals) > vars.exposureCap;
vars.avgLtv = vars.avgLtv.add(
vars.exposureCapCrossed ? 0 : vars.userBalanceETH.mul(vars.ltv)
);
vars.avgUncappedLtv = vars.avgUncappedLtv.add(vars.userBalanceETH.mul(vars.ltv));
vars.avgLtv = vars.avgLtv.add(vars.userBalanceETH.mul(vars.ltv));
vars.hasZeroLtvCollateral = vars.ltv == 0;
vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add(
vars.userBalanceETH.mul(vars.liquidationThreshold)
);
@ -160,9 +135,6 @@ library GenericLogic {
}
vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0;
vars.avgUncappedLtv = vars.totalCollateralInETH > 0
? vars.avgUncappedLtv.div(vars.totalCollateralInETH)
: 0;
vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0
? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH)
: 0;
@ -178,7 +150,7 @@ library GenericLogic {
vars.avgLtv,
vars.avgLiquidationThreshold,
vars.healthFactor,
vars.avgUncappedLtv
vars.hasZeroLtvCollateral
);
}
@ -249,7 +221,7 @@ library GenericLogic {
uint256,
uint256,
uint256,
uint256
bool
)
{
return

View File

@ -507,19 +507,17 @@ library ValidationLogic {
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
}
struct validateHFAndExposureCapLocalVars {
struct validateHFAndLtvLocalVars {
uint256 healthFactor;
uint256 ltv;
uint256 uncappedLtv;
uint256 exposureCap;
uint256 assetLtv;
uint256 reserveDecimals;
uint256 totalSupplyAtoken;
bool hasZeroLtvCollateral;
}
/**
* @dev Validates the health factor of a user and the exposure cap for the asset being withdrawn
* @dev Validates the health factor of a user and the ltv of the asset being withdrawn
* @param asset The asset for which the exposure cap will be validated
* @param expCapOffset The offset to consider on the total atoken supply of asset when validating the exposure cap
* @param from The user from which the aTokens are being transferred
* @param reservesData The state of all the reserves
* @param userConfig The state of the user for the specific reserve
@ -527,9 +525,8 @@ library ValidationLogic {
* @param reservesCount The number of available reserves
* @param oracle The price oracle
*/
function validateHFAndExposureCap(
function validateHFAndLtv(
address asset,
uint256 expCapOffset,
address from,
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig,
@ -537,9 +534,9 @@ library ValidationLogic {
uint256 reservesCount,
address oracle
) external view {
validateHFAndExposureCapLocalVars memory vars;
validateHFAndLtvLocalVars memory vars;
DataTypes.ReserveData memory reserve = reservesData[asset];
(, , vars.ltv, , vars.healthFactor, vars.uncappedLtv) = GenericLogic.calculateUserAccountData(
(, , , , vars.healthFactor, vars.hasZeroLtvCollateral) = GenericLogic.calculateUserAccountData(
from,
reservesData,
userConfig,
@ -553,18 +550,9 @@ library ValidationLogic {
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
);
vars.exposureCap = reserve.configuration.getExposureCapMemory();
vars.assetLtv = reserve.configuration.getLtvMemory();
if (vars.exposureCap != 0) {
if (vars.ltv < vars.uncappedLtv) {
vars.totalSupplyAtoken = IERC20(reserve.aTokenAddress).totalSupply();
(, , , vars.reserveDecimals, ) = reserve.configuration.getParamsMemory();
bool isAssetCapped =
vars.totalSupplyAtoken.sub(expCapOffset).div(10**vars.reserveDecimals) >=
vars.exposureCap;
require(isAssetCapped, Errors.VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
}
}
require(vars.assetLtv == 0 || !vars.hasZeroLtvCollateral, Errors.VL_LTV_VALIDATION_FAILED);
}
/**