Skip to content

Commit

Permalink
fix: remove gho borrow rate change
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Jul 26, 2024
1 parent 9d83320 commit db4aa51
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 449 deletions.
39 changes: 0 additions & 39 deletions src/contracts/misc/GhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import {RiskCouncilControlled} from './RiskCouncilControlled.sol';
contract GhoAaveSteward is Ownable, IGhoAaveSteward, RiskCouncilControlled {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;

/// @inheritdoc IGhoAaveSteward
uint256 public constant GHO_BORROW_RATE_CHANGE_MAX = 0.0500e27; // 5.00%

/// @inheritdoc IGhoAaveSteward
uint256 public constant GHO_BORROW_RATE_MAX = 0.2500e27; // 25.00%

/// @inheritdoc IGhoAaveSteward
uint256 public constant MINIMUM_DELAY = 2 days;

Expand Down Expand Up @@ -100,39 +94,6 @@ contract GhoAaveSteward is Ownable, IGhoAaveSteward, RiskCouncilControlled {
.setBorrowCap(GHO_TOKEN, newBorrowCap);
}

/// @inheritdoc IGhoAaveSteward
function updateGhoBorrowRate(
uint256 newBorrowRate
) external onlyRiskCouncil notTimelocked(_ghoTimelocks.ghoBorrowRateLastUpdate) {
DataTypes.ReserveData memory ghoReserveData = IPool(
IPoolAddressesProvider(POOL_ADDRESSES_PROVIDER).getPool()
).getReserveData(GHO_TOKEN);
require(
ghoReserveData.interestRateStrategyAddress != address(0),
'GHO_INTEREST_RATE_STRATEGY_NOT_FOUND'
);

uint256 currentBorrowRate = GhoInterestRateStrategy(ghoReserveData.interestRateStrategyAddress)
.getBaseVariableBorrowRate();
require(newBorrowRate <= GHO_BORROW_RATE_MAX, 'BORROW_RATE_HIGHER_THAN_MAX');
require(
_isDifferenceLowerThanMax(currentBorrowRate, newBorrowRate, GHO_BORROW_RATE_CHANGE_MAX),
'INVALID_BORROW_RATE_UPDATE'
);

IFixedRateStrategyFactory strategyFactory = IFixedRateStrategyFactory(
FIXED_RATE_STRATEGY_FACTORY
);
uint256[] memory borrowRateList = new uint256[](1);
borrowRateList[0] = newBorrowRate;
address strategy = strategyFactory.createStrategies(borrowRateList)[0];

_ghoTimelocks.ghoBorrowRateLastUpdate = uint40(block.timestamp);

IPoolConfigurator(IPoolAddressesProvider(POOL_ADDRESSES_PROVIDER).getPoolConfigurator())
.setReserveInterestRateStrategyAddress(GHO_TOKEN, strategy);
}

/// @inheritdoc IGhoAaveSteward
function getGhoTimelocks() external view returns (GhoDebounce memory) {
return _ghoTimelocks;
Expand Down
23 changes: 0 additions & 23 deletions src/contracts/misc/interfaces/IGhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pragma solidity ^0.8.10;
interface IGhoAaveSteward {
struct GhoDebounce {
uint40 ghoBorrowCapLastUpdate;
uint40 ghoBorrowRateLastUpdate;
}

/**
Expand All @@ -33,28 +32,6 @@ interface IGhoAaveSteward {
*/
function updateGhoBorrowCap(uint256 newBorrowCap) external;

/**
* @notice Updates the borrow rate of GHO, only if:
* - respects `MINIMUM_DELAY`, the minimum time delay between updates
* - 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%)
*/
function updateGhoBorrowRate(uint256 newBorrowRate) external;

/**
* @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%)
*/
function GHO_BORROW_RATE_CHANGE_MAX() external view returns (uint256);

/**
* @notice Returns maximum value that can be assigned to GHO borrow rate.
* @return The maximum value that can be assigned to GHO borrow rate in ray (e.g. 0.01e27 results in 1.0%)
*/
function GHO_BORROW_RATE_MAX() external view returns (uint256);

/**
* @notice Returns the minimum delay that must be respected between parameters update.
* @return The minimum delay between parameter updates (in seconds)
Expand Down
175 changes: 0 additions & 175 deletions src/test/TestGhoAaveSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ contract TestGhoAaveSteward is TestGhoBase {
}

function testConstructor() public {
assertEq(GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX(), GHO_BORROW_RATE_CHANGE_MAX);
assertEq(GHO_AAVE_STEWARD.GHO_BORROW_RATE_MAX(), GHO_BORROW_RATE_MAX);
assertEq(GHO_AAVE_STEWARD.MINIMUM_DELAY(), MINIMUM_DELAY_V2);

assertEq(GHO_AAVE_STEWARD.owner(), SHORT_EXECUTOR);
Expand All @@ -29,7 +27,6 @@ contract TestGhoAaveSteward is TestGhoBase {

IGhoAaveSteward.GhoDebounce memory ghoTimelocks = GHO_AAVE_STEWARD.getGhoTimelocks();
assertEq(ghoTimelocks.ghoBorrowCapLastUpdate, 0);
assertEq(ghoTimelocks.ghoBorrowRateLastUpdate, 0);
}

function testRevertConstructorInvalidExecutor() public {
Expand Down Expand Up @@ -130,182 +127,10 @@ contract TestGhoAaveSteward is TestGhoBase {
GHO_AAVE_STEWARD.updateGhoBorrowCap(oldBorrowCap * 2 + 1);
}

function testUpdateGhoBorrowRateUpwards() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate + 1;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);
}

function testUpdateGhoBorrowRateDownwards() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate - 1;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);
}

function testUpdateGhoBorrowRateMaxValue() public {
uint256 ghoBorrowRateMax = GHO_AAVE_STEWARD.GHO_BORROW_RATE_MAX();
(, uint256 oldBorrowRate) = _setGhoBorrowRateViaConfigurator(ghoBorrowRateMax - 1);
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(ghoBorrowRateMax);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, ghoBorrowRateMax);
}

function testUpdateGhoBorrowRateMaxIncrement() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate + GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX();
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);
}

function testUpdateGhoBorrowRateDecrement() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate - 1;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);
}

function testUpdateGhoBorrowRateMaxDecrement() public {
vm.startPrank(RISK_COUNCIL);

// set a high borrow rate
GHO_AAVE_STEWARD.updateGhoBorrowRate(GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX() + 1);
vm.warp(block.timestamp + GHO_AAVE_STEWARD.MINIMUM_DELAY() + 1);

uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate - GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX();
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);

vm.stopPrank();
}

function testUpdateGhoBorrowRateTimelock() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(oldBorrowRate + 1);
IGhoAaveSteward.GhoDebounce memory ghoTimelocks = GHO_AAVE_STEWARD.getGhoTimelocks();
assertEq(ghoTimelocks.ghoBorrowRateLastUpdate, block.timestamp);
}

function testUpdateGhoBorrowRateAfterTimelock() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(oldBorrowRate + 1);
skip(GHO_AAVE_STEWARD.MINIMUM_DELAY() + 1);
uint256 newBorrowRate = oldBorrowRate + 2;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
uint256 currentBorrowRate = _getGhoBorrowRate();
assertEq(currentBorrowRate, newBorrowRate);
}

function testRevertUpdateGhoBorrowRateIfUnauthorized() public {
vm.expectRevert('INVALID_CALLER');
vm.prank(ALICE);
GHO_AAVE_STEWARD.updateGhoBorrowRate(0.07e4);
}

function testRevertUpdateGhoBorrowRateIfUpdatedTooSoon() public {
address oldInterestStrategy = POOL.getReserveInterestRateStrategyAddress(address(GHO_TOKEN));
uint256 oldBorrowRate = GhoInterestRateStrategy(oldInterestStrategy)
.getBaseVariableBorrowRate();
vm.prank(RISK_COUNCIL);
uint256 newBorrowRate = oldBorrowRate + 1;
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
vm.prank(RISK_COUNCIL);
vm.expectRevert('DEBOUNCE_NOT_RESPECTED');
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
}

function testRevertUpdateGhoBorrowRateIfInterestRateNotFound() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
DataTypes.ReserveData memory mockData = POOL.getReserveData(address(GHO_TOKEN));
mockData.interestRateStrategyAddress = address(0);
vm.mockCall(
address(POOL),
abi.encodeWithSelector(IPool.getReserveData.selector, address(GHO_TOKEN)),
abi.encode(mockData)
);
vm.expectRevert('GHO_INTEREST_RATE_STRATEGY_NOT_FOUND');
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowRate(oldBorrowRate + 1);
}

function testRevertUpdateGhoBorrowRateIfValueMoreThanMax() public {
uint256 maxGhoBorrowRate = GHO_AAVE_STEWARD.GHO_BORROW_RATE_MAX();
_setGhoBorrowRateViaConfigurator(maxGhoBorrowRate);
vm.prank(RISK_COUNCIL);
vm.expectRevert('BORROW_RATE_HIGHER_THAN_MAX');
GHO_AAVE_STEWARD.updateGhoBorrowRate(maxGhoBorrowRate + 1);
}

function testRevertUpdateGhoBorrowRateIfMaxExceededUpwards() public {
uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate + GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX() + 1;
vm.prank(RISK_COUNCIL);
vm.expectRevert('INVALID_BORROW_RATE_UPDATE');
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);
}

function testRevertUpdateGhoBorrowRateIfMaxExceededDownwards() public {
vm.startPrank(RISK_COUNCIL);

// set a high borrow rate
GHO_AAVE_STEWARD.updateGhoBorrowRate(GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX() + 1);
vm.warp(block.timestamp + GHO_AAVE_STEWARD.MINIMUM_DELAY() + 1);

uint256 oldBorrowRate = _getGhoBorrowRate();
uint256 newBorrowRate = oldBorrowRate - GHO_AAVE_STEWARD.GHO_BORROW_RATE_CHANGE_MAX() - 1;
vm.expectRevert('INVALID_BORROW_RATE_UPDATE');
GHO_AAVE_STEWARD.updateGhoBorrowRate(newBorrowRate);

vm.stopPrank();
}

function _setGhoBorrowCapViaConfigurator(uint256 newBorrowCap) internal {
CONFIGURATOR.setBorrowCap(address(GHO_TOKEN), newBorrowCap);
}

function _setGhoBorrowRateViaConfigurator(
uint256 newBorrowRate
) internal returns (GhoInterestRateStrategy, uint256) {
GhoInterestRateStrategy newRateStrategy = new GhoInterestRateStrategy(
address(PROVIDER),
newBorrowRate
);
CONFIGURATOR.setReserveInterestRateStrategyAddress(
address(GHO_TOKEN),
address(newRateStrategy)
);
address currentInterestRateStrategy = POOL.getReserveInterestRateStrategyAddress(
address(GHO_TOKEN)
);
uint256 currentBorrowRate = GhoInterestRateStrategy(currentInterestRateStrategy)
.getBaseVariableBorrowRate();
assertEq(currentInterestRateStrategy, address(newRateStrategy));
assertEq(currentBorrowRate, newBorrowRate);
return (newRateStrategy, newBorrowRate);
}

function _getGhoBorrowRate() internal view returns (uint256) {
address currentInterestRateStrategy = POOL.getReserveInterestRateStrategyAddress(
address(GHO_TOKEN)
);
return GhoInterestRateStrategy(currentInterestRateStrategy).getBaseVariableBorrowRate();
}

function _getGhoBorrowCap() internal view returns (uint256) {
DataTypes.ReserveConfigurationMap memory configuration = POOL.getConfiguration(
address(GHO_TOKEN)
Expand Down
Loading

0 comments on commit db4aa51

Please sign in to comment.