Skip to content

Commit

Permalink
fix: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Aug 21, 2024
1 parent 2f4eeb7 commit a229cc1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 144 deletions.
117 changes: 29 additions & 88 deletions src/contracts/misc/GhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.10;

import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {IPoolDataProvider} from 'aave-address-book/AaveV3.sol';
import {IPoolDataProvider} from '@aave/core-v3/contracts/interfaces/IPoolDataProvider.sol';
import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
Expand All @@ -23,7 +23,6 @@ import {RiskCouncilControlled} from './RiskCouncilControlled.sol';
*/
contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using Address for address;

/// @inheritdoc IGhoAaveSteward
uint256 public constant GHO_BORROW_RATE_MAX = 0.25e4; // 25.00%
Expand Down Expand Up @@ -61,7 +60,7 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
* @param poolDataProvider The pool data provider of the pool to be controlled by the steward
* @param ghoToken The address of the GhoToken
* @param riskCouncil The address of the risk council
* @param borrowRateConfig The initial borrow rate configuration for the Gho reserve
* @param borrowRateConfig The configuration conditions for GHO borrow rate changes
*/
constructor(
address owner,
Expand Down Expand Up @@ -97,9 +96,19 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
variableRateSlope1,
variableRateSlope2
);
_updateRates(optimalUsageRatio, baseVariableBorrowRate, variableRateSlope1, variableRateSlope2);

IDefaultInterestRateStrategyV2.InterestRateData
memory rateParams = IDefaultInterestRateStrategyV2.InterestRateData({
optimalUsageRatio: uint16(optimalUsageRatio),
baseVariableBorrowRate: uint32(baseVariableBorrowRate),
variableRateSlope1: uint32(variableRateSlope1),
variableRateSlope2: uint32(variableRateSlope2)
});

_ghoTimelocks.ghoBorrowRateLastUpdate = uint40(block.timestamp);

IPoolConfigurator(IPoolAddressesProvider(POOL_ADDRESSES_PROVIDER).getPoolConfigurator())
.setReserveInterestRateData(GHO_TOKEN, abi.encode(rateParams));
}

/// @inheritdoc IGhoAaveSteward
Expand Down Expand Up @@ -148,20 +157,11 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
uint256 baseVariableBorrowRateMaxChange,
uint256 variableRateSlope1MaxChange,
uint256 variableRateSlope2MaxChange
) external onlyOwner notTimelocked(_ghoTimelocks.riskConfigLastUpdate) {
) external onlyOwner {
_borrowRateConfig.optimalUsageRatioMaxChange = optimalUsageRatioMaxChange;
_borrowRateConfig.baseVariableBorrowRateMaxChange = baseVariableBorrowRateMaxChange;
_borrowRateConfig.variableRateSlope1MaxChange = variableRateSlope1MaxChange;
_borrowRateConfig.variableRateSlope2MaxChange = variableRateSlope2MaxChange;

_ghoTimelocks.riskConfigLastUpdate = uint40(block.timestamp);

emit BorrowRateConfigSet(
optimalUsageRatioMaxChange,
baseVariableBorrowRateMaxChange,
variableRateSlope1MaxChange,
variableRateSlope2MaxChange
);
}

/// @inheritdoc IGhoAaveSteward
Expand All @@ -176,36 +176,11 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {

/// @inheritdoc IGhoAaveSteward
function RISK_COUNCIL() public view override returns (address) {
return COUNCIL;
return riskCouncil;
}

/**
* @notice method to update the interest rates params using the config engine and updates the debounce
* @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 _updateRates(
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
) internal {
IDefaultInterestRateStrategyV2.InterestRateData
memory rateParams = IDefaultInterestRateStrategyV2.InterestRateData({
optimalUsageRatio: uint16(optimalUsageRatio),
baseVariableBorrowRate: uint32(baseVariableBorrowRate),
variableRateSlope1: uint32(variableRateSlope1),
variableRateSlope2: uint32(variableRateSlope2)
});

IPoolConfigurator(IPoolAddressesProvider(POOL_ADDRESSES_PROVIDER).getPoolConfigurator())
.setReserveInterestRateData(GHO_TOKEN, abi.encode(rateParams));
}

/**
* @notice method to validate the interest rates update
* @dev Validates the interest rates update
* @param optimalUsageRatio The new optimal usage ratio to validate
* @param baseVariableBorrowRate The new base variable borrow rate to validate
* @param variableRateSlope1 The new variable rate slope 1 to validate
Expand All @@ -217,24 +192,23 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
uint256 variableRateSlope1,
uint256 variableRateSlope2
) internal view {
(
uint256 currentOptimalUsageRatio,
uint256 currentBaseVariableBorrowRate,
uint256 currentVariableRateSlope1,
uint256 currentVariableRateSlope2
) = _getInterestRatesForAsset(GHO_TOKEN);
address rateStrategyAddress = IPoolDataProvider(POOL_DATA_PROVIDER)
.getInterestRateStrategyAddress(GHO_TOKEN);
IDefaultInterestRateStrategyV2.InterestRateData
memory currentRates = IDefaultInterestRateStrategyV2(rateStrategyAddress)
.getInterestRateDataBps(GHO_TOKEN);

require(
optimalUsageRatio != currentOptimalUsageRatio ||
baseVariableBorrowRate != currentBaseVariableBorrowRate ||
variableRateSlope1 != currentVariableRateSlope1 ||
variableRateSlope2 != currentVariableRateSlope2,
optimalUsageRatio != currentRates.optimalUsageRatio ||
baseVariableBorrowRate != currentRates.baseVariableBorrowRate ||
variableRateSlope1 != currentRates.variableRateSlope1 ||
variableRateSlope2 != currentRates.variableRateSlope2,
'NO_CHANGE_IN_RATES'
);

require(
_updateWithinAllowedRange(
currentOptimalUsageRatio,
currentRates.optimalUsageRatio,
optimalUsageRatio,
_borrowRateConfig.optimalUsageRatioMaxChange,
false
Expand All @@ -243,7 +217,7 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
);
require(
_updateWithinAllowedRange(
currentBaseVariableBorrowRate,
currentRates.baseVariableBorrowRate,
baseVariableBorrowRate,
_borrowRateConfig.baseVariableBorrowRateMaxChange,
false
Expand All @@ -252,7 +226,7 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
);
require(
_updateWithinAllowedRange(
currentVariableRateSlope1,
currentRates.variableRateSlope1,
variableRateSlope1,
_borrowRateConfig.variableRateSlope1MaxChange,
false
Expand All @@ -261,7 +235,7 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
);
require(
_updateWithinAllowedRange(
currentVariableRateSlope2,
currentRates.variableRateSlope2,
variableRateSlope2,
_borrowRateConfig.variableRateSlope2MaxChange,
false
Expand All @@ -276,39 +250,6 @@ contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
);
}

/**
* @notice method to fetch the current interest rate params of the asset
* @param asset the address of the underlying asset
* @return optimalUsageRatio the current optimal usage ratio of the asset
* @return baseVariableBorrowRate the current base variable borrow rate of the asset
* @return variableRateSlope1 the current variable rate slope 1 of the asset
* @return variableRateSlope2 the current variable rate slope 2 of the asset
*/
function _getInterestRatesForAsset(
address asset
)
internal
view
returns (
uint256 optimalUsageRatio,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2
)
{
address rateStrategyAddress = IPoolDataProvider(POOL_DATA_PROVIDER)
.getInterestRateStrategyAddress(asset);
IDefaultInterestRateStrategyV2.InterestRateData
memory interestRateData = IDefaultInterestRateStrategyV2(rateStrategyAddress)
.getInterestRateDataBps(asset);
return (
interestRateData.optimalUsageRatio,
interestRateData.baseVariableBorrowRate,
interestRateData.variableRateSlope1,
interestRateData.variableRateSlope2
);
}

/**
* @dev Ensures that the change difference is lower than max.
* @param from current value
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/misc/GhoBucketSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract GhoBucketSteward is Ownable, RiskCouncilControlled, IGhoBucketSteward {

/// @inheritdoc IGhoBucketSteward
function RISK_COUNCIL() public view override returns (address) {
return COUNCIL;
return riskCouncil;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/misc/GhoCcipSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ contract GhoCcipSteward is RiskCouncilControlled, IGhoCcipSteward {
'INVALID_BRIDGE_LIMIT_UPDATE'
);

IUpgradeableLockReleaseTokenPool(GHO_TOKEN_POOL).setBridgeLimit(newBridgeLimit);

_ccipTimelocks.bridgeLimitLastUpdate = uint40(block.timestamp);

IUpgradeableLockReleaseTokenPool(GHO_TOKEN_POOL).setBridgeLimit(newBridgeLimit);
}

/// @inheritdoc IGhoCcipSteward
Expand Down Expand Up @@ -117,6 +117,8 @@ contract GhoCcipSteward is RiskCouncilControlled, IGhoCcipSteward {
'INVALID_RATE_LIMIT_UPDATE'
);

_ccipTimelocks.rateLimitLastUpdate = uint40(block.timestamp);

IUpgradeableLockReleaseTokenPool(GHO_TOKEN_POOL).setChainRateLimiterConfig(
remoteChainSelector,
RateLimiter.Config({
Expand All @@ -126,13 +128,11 @@ contract GhoCcipSteward is RiskCouncilControlled, IGhoCcipSteward {
}),
RateLimiter.Config({isEnabled: inboundEnabled, capacity: inboundCapacity, rate: inboundRate})
);

_ccipTimelocks.rateLimitLastUpdate = uint40(block.timestamp);
}

/// @inheritdoc IGhoCcipSteward
function RISK_COUNCIL() public view override returns (address) {
return COUNCIL;
return riskCouncil;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/misc/GhoGsmSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.10;

import {IGsm} from '../facilitators/gsm/interfaces/IGsm.sol';
import {IGsmFeeStrategy} from '../facilitators/gsm/feeStrategy/interfaces/IGsmFeeStrategy.sol';
import {IFixedFeeStrategyFactory} from '../facilitators/gsm/feeStrategy/interfaces/IFixedFeeStrategyFactory.sol';
import {IGhoGsmSteward} from './interfaces/IGhoGsmSteward.sol';
import {RiskCouncilControlled} from './RiskCouncilControlled.sol';
import {IFixedFeeStrategyFactory} from '../facilitators/gsm/feeStrategy/interfaces/IFixedFeeStrategyFactory.sol';

/**
* @title GhoGsmSteward
Expand Down Expand Up @@ -106,7 +106,7 @@ contract GhoGsmSteward is RiskCouncilControlled, IGhoGsmSteward {

/// @inheritdoc IGhoGsmSteward
function RISK_COUNCIL() public view override returns (address) {
return COUNCIL;
return riskCouncil;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/contracts/misc/RiskCouncilControlled.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ pragma solidity ^0.8.10;
* @notice Helper contract for controlling access to Steward and other functions restricted to Risk Council
*/
abstract contract RiskCouncilControlled {
address public immutable COUNCIL;
address internal immutable riskCouncil;

/**
* @dev Constructor
* @param riskCouncil The address of the risk council
* @param _riskCouncil The address of the risk council
*/
constructor(address riskCouncil) {
require(riskCouncil != address(0), 'INVALID_RISK_COUNCIL');
COUNCIL = riskCouncil;
constructor(address _riskCouncil) {
require(_riskCouncil != address(0), 'INVALID_RISK_COUNCIL');
riskCouncil = _riskCouncil;
}

/**
* @dev Only Risk Council can call functions marked by this modifier.
*/
modifier onlyRiskCouncil() {
require(COUNCIL == msg.sender, 'INVALID_CALLER');
require(riskCouncil == msg.sender, 'INVALID_CALLER');
_;
}
}
21 changes: 3 additions & 18 deletions src/contracts/misc/interfaces/IGhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@ pragma solidity ^0.8.10;
* @notice Defines the basic interface of the GhoAaveSteward
*/
interface IGhoAaveSteward {
/**
* @notice Emitted when the borrow rate configuration has been updated
* @param optimalUsageRatioMaxChange The new allowed max percentage change for optimal usage ratio
* @param baseVariableBorrowRateMaxChange The new allowed max percentage change for base variable borrow rate
* @param variableRateSlope1MaxChange The new allowed max percentage change for variable rate slope 1
* @param variableRateSlope2MaxChange The new allowed max percentage change for variable rate slope 2
*/
event BorrowRateConfigSet(
uint256 optimalUsageRatioMaxChange,
uint256 baseVariableBorrowRateMaxChange,
uint256 variableRateSlope1MaxChange,
uint256 variableRateSlope2MaxChange
);

/**
* @notice Struct storing the last update by the steward of each borrow rate param
*/
struct GhoDebounce {
uint40 ghoBorrowCapLastUpdate;
uint40 ghoSupplyCapLastUpdate;
uint40 ghoBorrowRateLastUpdate;
uint40 riskConfigLastUpdate;
}

/**
Expand All @@ -44,7 +29,7 @@ interface IGhoAaveSteward {
/**
* @notice Updates the borrow rate of GHO, only if:
* - respects `MINIMUM_DELAY`, the minimum time delay between updates
* - the update changes up to 5% upwards or downwards
* - the update changes parameters up to the maximum allowed change according to risk config
* - the update is lower than `GHO_BORROW_RATE_MAX`
* @dev Only callable by Risk Council
* @param optimalUsageRatio The new optimal usage ratio
Expand Down Expand Up @@ -78,7 +63,7 @@ interface IGhoAaveSteward {
function updateGhoSupplyCap(uint256 newSupplyCap) external;

/**
* @notice method called by the Risk Council to set the borrow rate configuration params
* @notice Updates the configuration conditions for borrow rate changes
* @param optimalUsageRatioMaxChange The new allowed max percentage change for optimal usage ratio
* @param baseVariableBorrowRateMaxChange The new allowed max percentage change for base variable borrow rate
* @param variableRateSlope1MaxChange The new allowed max percentage change for variable rate slope 1
Expand All @@ -92,7 +77,7 @@ interface IGhoAaveSteward {
) external;

/**
* @notice method to get the borrow rate configuration
* @notice Returns the configuration conditions for a GHO borrow rate change
* @return struct containing the borrow rate configuration
*/
function getBorrowRateConfig() external view returns (BorrowRateConfig memory);
Expand Down
12 changes: 6 additions & 6 deletions src/contracts/misc/interfaces/IGhoBucketSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ interface IGhoBucketSteward {
*/
function getFacilitatorBucketCapacityTimelock(address facilitator) external view returns (uint40);

/**
* @notice Returns the address of the risk council
* @return The address of the RiskCouncil
*/
function RISK_COUNCIL() external view returns (address);

/**
* @notice Returns the minimum delay that must be respected between parameters update.
* @return The minimum delay between parameter updates (in seconds)
Expand All @@ -56,4 +50,10 @@ interface IGhoBucketSteward {
* @return The address of the GhoToken
*/
function GHO_TOKEN() external view returns (address);

/**
* @notice Returns the address of the risk council
* @return The address of the RiskCouncil
*/
function RISK_COUNCIL() external view returns (address);
}
Loading

0 comments on commit a229cc1

Please sign in to comment.