Skip to content

Commit

Permalink
feat: add all 4 params for borrow rate update
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Aug 6, 2024
1 parent df771f1 commit 158e021
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 58 deletions.
95 changes: 74 additions & 21 deletions src/contracts/misc/GhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {

uint256 internal constant BPS_MAX = 100_00;

Config internal _riskConfig;

GhoDebounce internal _ghoTimelocks;

/**
Expand All @@ -77,7 +79,8 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
address engine,
address ghoToken,
address fixedRateStrategyFactory,
address riskCouncil
address riskCouncil,
Config memory riskConfig
) RiskCouncilControlled(riskCouncil) {
require(addressesProvider != address(0), 'INVALID_ADDRESSES_PROVIDER');
require(poolDataProvider != address(0), 'INVALID_DATA_PROVIDER');
Expand All @@ -90,15 +93,23 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
CONFIG_ENGINE = engine;
GHO_TOKEN = ghoToken;
FIXED_RATE_STRATEGY_FACTORY = fixedRateStrategyFactory;
_riskConfig = riskConfig;
}

/// @inheritdoc IGhoAaveSteward
function updateGhoBorrowRate(
/* TODO: Add all 4 parameters back */
uint256 baseVariableBorrowRate
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
) external onlyRiskCouncil notTimelocked(_ghoTimelocks.ghoBorrowRateLastUpdate) {
_validateRatesUpdate(baseVariableBorrowRate);
_updateRates(baseVariableBorrowRate);
_validateRatesUpdate(
optimalUsageRatio,
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2
);
_updateRates(optimalUsageRatio, baseVariableBorrowRate, variableRateSlope1, variableRateSlope2);

_ghoTimelocks.ghoBorrowRateLastUpdate = uint40(block.timestamp);
}
Expand Down Expand Up @@ -141,6 +152,17 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
.setSupplyCap(GHO_TOKEN, newSupplyCap);
}

/// @inheritdoc IGhoAaveSteward
function setRiskConfig(Config calldata riskConfig) external onlyRiskCouncil {
_riskConfig = riskConfig;
emit RiskConfigSet(riskConfig);
}

/// @inheritdoc IGhoAaveSteward
function getRiskConfig() external view returns (Config memory) {
return _riskConfig;
}

/// @inheritdoc IGhoAaveSteward
function getGhoTimelocks() external view returns (GhoDebounce memory) {
return _ghoTimelocks;
Expand All @@ -166,22 +188,20 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
return from < to ? to - from <= max : from - to <= max;
}

function _updateRates(uint256 baseVariableBorrowRate) internal {
(
uint256 currentOptimalUsageRatio,
,
uint256 currentVariableRateSlope1,
uint256 currentVariableRateSlope2
) = _getInterestRatesForAsset(GHO_TOKEN);

function _updateRates(
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
) internal {
IEngine.RateStrategyUpdate[] memory ratesUpdate = new IEngine.RateStrategyUpdate[](1);
ratesUpdate[0] = IEngine.RateStrategyUpdate({
asset: GHO_TOKEN,
params: IEngine.InterestRateInputData({
optimalUsageRatio: currentOptimalUsageRatio,
optimalUsageRatio: optimalUsageRatio,
baseVariableBorrowRate: baseVariableBorrowRate,
variableRateSlope1: currentVariableRateSlope1,
variableRateSlope2: currentVariableRateSlope2
variableRateSlope1: variableRateSlope1,
variableRateSlope2: variableRateSlope2
})
});

Expand All @@ -190,7 +210,12 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
);
}

function _validateRatesUpdate(uint256 baseVariableBorrowRate) internal view {
function _validateRatesUpdate(
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
) internal view {
DataTypes.ReserveData memory ghoReserveData = IPool(
IPoolAddressesProvider(POOL_ADDRESSES_PROVIDER).getPool()
).getReserveData(GHO_TOKEN);
Expand All @@ -200,20 +225,48 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
);

(
uint256 optimalUsageRatio,
uint256 currentOptimalUsageRatio,
uint256 currentBaseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
uint256 currentVariableRateSlope1,
uint256 currentVariableRateSlope2
) = _getInterestRatesForAsset(GHO_TOKEN);

require(
_updateWithinAllowedRange(
currentOptimalUsageRatio,
optimalUsageRatio,
_riskConfig.optimalUsageRatio.maxPercentChange,
false
),
'INVALID_OPTIMAL_USAGE_RATIO'
);
require(
_updateWithinAllowedRange(
currentBaseVariableBorrowRate,
baseVariableBorrowRate,
0.05e4,
_riskConfig.baseVariableBorrowRate.maxPercentChange,
false
),
'INVALID_BORROW_RATE_UPDATE'
);
require(
_updateWithinAllowedRange(
currentVariableRateSlope1,
variableRateSlope1,
_riskConfig.variableRateSlope1.maxPercentChange,
false
),
'INVALID_VARIABLE_RATE_SLOPE1'
);
require(
_updateWithinAllowedRange(
currentVariableRateSlope2,
variableRateSlope2,
_riskConfig.variableRateSlope2.maxPercentChange,
false
),
'INVALID_VARIABLE_RATE_SLOPE2'
);

uint256 maxBorrowRate = IDefaultInterestRateStrategyV2(
ghoReserveData.interestRateStrategyAddress
Expand Down
40 changes: 29 additions & 11 deletions src/contracts/misc/interfaces/IGhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pragma solidity ^0.8.10;
* @notice Defines the basic interface of the GhoAaveSteward
*/
interface IGhoAaveSteward {
/**
* @notice Emitted when the risk configuration for the risk params has been set
* @param riskConfig struct containing the risk configurations
*/
event RiskConfigSet(Config indexed riskConfig);

/**
* @notice Struct storing the last update by the steward of each risk param
*/
Expand All @@ -28,18 +34,10 @@ interface IGhoAaveSteward {
* @notice Struct storing the risk configuration for all the risk param
*/
struct Config {
RiskParamConfig ltv;
RiskParamConfig liquidationThreshold;
RiskParamConfig liquidationBonus;
RiskParamConfig supplyCap;
RiskParamConfig borrowCap;
RiskParamConfig debtCeiling;
RiskParamConfig optimalUsageRatio;
RiskParamConfig baseVariableBorrowRate;
RiskParamConfig variableRateSlope1;
RiskParamConfig variableRateSlope2;
RiskParamConfig optimalUsageRatio;
RiskParamConfig priceCapLst;
RiskParamConfig priceCapStable;
}

/**
Expand All @@ -48,9 +46,17 @@ interface IGhoAaveSteward {
* - the update changes up to `GHO_BORROW_RATE_CHANGE_MAX` upwards or downwards
* - the update is lower than `GHO_BORROW_RATE_MAX`
* @dev Only callable by Risk Council
* @param newBorrowRate The new variable borrow rate (expressed in ray) (e.g. 0.0150e27 results in 1.50%)
* @param optimalUsageRatio The new optimal usage ratio
* @param baseVariableBorrowRate The new base variable borrow rate
* @param variableRateSlope1 The new variable rate slope 1
* @param variableRateSlope2 The new variable rate slope 2
*/
function updateGhoBorrowRate(uint256 newBorrowRate) external;
function updateGhoBorrowRate(
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
) external;

/**
* @notice Updates the GHO borrow cap, only if:
Expand All @@ -70,6 +76,18 @@ interface IGhoAaveSteward {
*/
function updateGhoSupplyCap(uint256 newSupplyCap) external;

/**
* @notice method called by the Risk Council to set the risk configuration for the risk params
* @param riskConfig struct containing the risk configurations
*/
function setRiskConfig(Config calldata riskConfig) external;

/**
* @notice method to get the risk configuration set for all the risk params
* @return struct containing the risk configurations
*/
function getRiskConfig() external view returns (Config memory);

/**
* @notice Returns the maximum increase/decrease for GHO borrow rate updates.
* @return The maximum increase change for borrow rate updates in ray (e.g. 0.010e27 results in 1.00%)
Expand Down
Loading

0 comments on commit 158e021

Please sign in to comment.