feat: added borrow cap to config

This commit is contained in:
Hadrien Charlanes 2021-04-23 17:32:07 +02:00
parent 2ae2680834
commit 4ce1bfcb8c
9 changed files with 59 additions and 17 deletions

View File

@ -73,6 +73,7 @@ contract AaveProtocolDataProvider {
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 reserveFactor,
uint256 borrowCap,
bool usageAsCollateralEnabled,
bool borrowingEnabled,
bool stableBorrowRateEnabled,
@ -80,13 +81,14 @@ contract AaveProtocolDataProvider {
bool isFrozen
)
{
DataTypes.ReserveConfigurationMap memory configuration =
ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getConfiguration(asset);
(ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor) = configuration
(ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor, ) =
ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
.getConfiguration(asset)
.getParamsMemory();
(isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) = configuration
(isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) =
ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
.getConfiguration(asset)
.getFlagsMemory();
usageAsCollateralEnabled = liquidationThreshold > 0;

View File

@ -104,7 +104,8 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
reserveData.reserveLiquidationThreshold,
reserveData.reserveLiquidationBonus,
reserveData.decimals,
reserveData.reserveFactor
reserveData.reserveFactor,
reserveData.borrowCap
) = baseData.configuration.getParamsMemory();
(
reserveData.isActive,

View File

@ -14,6 +14,7 @@ interface IUiPoolDataProvider {
uint256 reserveLiquidationThreshold;
uint256 reserveLiquidationBonus;
uint256 reserveFactor;
uint256 borrowCap;
bool usageAsCollateralEnabled;
bool borrowingEnabled;
bool stableBorrowRateEnabled;

View File

@ -286,7 +286,7 @@ contract LendingPoolCollateralManager is
vars.collateralPrice = oracle.getAssetPrice(collateralAsset);
vars.debtAssetPrice = oracle.getAssetPrice(debtAsset);
(, , vars.liquidationBonus, vars.collateralDecimals, ) = collateralReserve
(, , vars.liquidationBonus, vars.collateralDecimals, , ) = collateralReserve
.configuration
.getParams();
vars.debtAssetDecimals = debtReserve.configuration.getDecimals();

View File

@ -149,7 +149,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, , ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector(
IInitializableAToken.initialize.selector,
@ -180,7 +180,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, , ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector,
@ -217,7 +217,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
(, , , uint256 decimals, , ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector,

View File

@ -19,6 +19,7 @@ library ReserveConfiguration {
uint256 constant BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant STABLE_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFF; // prettier-ignore
uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFF; // 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;
@ -29,12 +30,14 @@ library ReserveConfiguration {
uint256 constant BORROWING_ENABLED_START_BIT_POSITION = 58;
uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59;
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 constant BORROW_CAP_START_BIT_POSITION = 80;
uint256 constant MAX_VALID_LTV = 65535;
uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
uint256 constant MAX_VALID_LIQUIDATION_BONUS = 65535;
uint256 constant MAX_VALID_DECIMALS = 255;
uint256 constant MAX_VALID_RESERVE_FACTOR = 65535;
uint256 constant MAX_VALID_BORROW_CAP = 65535;
/**
* @dev Sets the Loan to Value of the reserve
@ -264,6 +267,35 @@ library ReserveConfiguration {
return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION;
}
/**
* @dev Sets the borrow cap of the reserve
* @param self The reserve configuration
* @param borrowCap The borrow cap
**/
function setBorrowCap(DataTypes.ReserveConfigurationMap memory self, uint256 borrowCap)
internal
pure
{
require(borrowCap <= MAX_VALID_BORROW_CAP, Errors.RC_INVALID_BORROW_CAP);
self.data =
(self.data & BORROW_CAP_MASK) |
(borrowCap << BORROW_CAP_START_BIT_POSITION);
}
/**
* @dev Gets the borrow cap of the reserve
* @param self The reserve configuration
* @return The borrow cap
**/
function getBorrowCap(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (uint256)
{
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
}
/**
* @dev Gets the configuration flags of the reserve
* @param self The reserve configuration
@ -290,9 +322,9 @@ library ReserveConfiguration {
}
/**
* @dev Gets the configuration paramters of the reserve
* @dev Gets the configuration paramters of the reserve from storage
* @param self The reserve configuration
* @return The state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals
* @return The state params representing ltv, liquidation threshold, liquidation bonus, reserve decimals, reserve factor and borrow cap.
**/
function getParams(DataTypes.ReserveConfigurationMap storage self)
internal
@ -302,6 +334,7 @@ library ReserveConfiguration {
uint256,
uint256,
uint256,
uint256,
uint256
)
{
@ -312,14 +345,15 @@ library ReserveConfiguration {
(dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
(dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
(dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
(dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION,
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION
);
}
/**
* @dev Gets the configuration paramters of the reserve from a memory object
* @param self The reserve configuration
* @return The state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals
* @return The state params representing ltv, liquidation threshold, liquidation bonus, reserve decimals, reserve factor, borrow cap
**/
function getParamsMemory(DataTypes.ReserveConfigurationMap memory self)
internal
@ -329,6 +363,7 @@ library ReserveConfiguration {
uint256,
uint256,
uint256,
uint256,
uint256
)
{
@ -337,7 +372,8 @@ library ReserveConfiguration {
(self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION,
(self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION,
(self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION,
(self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION
(self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION,
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION
);
}

View File

@ -103,6 +103,7 @@ library Errors {
string public constant LP_NOT_CONTRACT = '78';
string public constant SDT_STABLE_DEBT_OVERFLOW = '79';
string public constant SDT_BURN_EXCEEDS_BALANCE = '80';
string public constant RC_INVALID_BORROW_CAP = '82';
enum CollateralManagerErrors {
NO_ERROR,

View File

@ -68,7 +68,7 @@ library GenericLogic {
balanceDecreaseAllowedLocalVars memory vars;
(, vars.liquidationThreshold, , vars.decimals, ) = reservesData[asset]
(, vars.liquidationThreshold, , vars.decimals, , ) = reservesData[asset]
.configuration
.getParams();
@ -178,7 +178,7 @@ library GenericLogic {
vars.currentReserveAddress = reserves[vars.i];
DataTypes.ReserveData storage currentReserve = reservesData[vars.currentReserveAddress];
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
(vars.ltv, vars.liquidationThreshold, , vars.decimals, , ) = currentReserve
.configuration
.getParams();

View File

@ -38,6 +38,7 @@ library DataTypes {
//bit 59: stable rate borrowing enabled
//bit 60-63: reserved
//bit 64-79: reserve factor
//bit 80-95 borrow cap
uint256 data;
}