Skip to content

Commit

Permalink
test: gho aave steward
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Jul 25, 2024
1 parent 20ba63f commit c850a0d
Showing 1 changed file with 258 additions and 0 deletions.
258 changes: 258 additions & 0 deletions src/test/TestGhoAaveSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import './TestGhoBase.t.sol';
import {IGhoAaveSteward} from '../contracts/misc/interfaces/IGhoAaveSteward.sol';

contract TestGhoAaveSteward is TestGhoBase {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;

function setUp() public {
/// @dev Since block.timestamp starts at 0 this is a necessary condition (block.timestamp > `MINIMUM_DELAY`) for the timelocked contract methods to work.
vm.warp(GHO_AAVE_STEWARD.MINIMUM_DELAY() + 1);
Expand Down Expand Up @@ -53,4 +55,260 @@ contract TestGhoAaveSteward is TestGhoBase {
vm.expectRevert('INVALID_RISK_COUNCIL');
new GhoAaveSteward(address(0x001), address(0x002), address(0x003), address(0x004), address(0));
}

function testUpdateGhoBorrowCap() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
uint256 newBorrowCap = oldBorrowCap + 1;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(newBorrowCap);
uint256 currentBorrowCap = _getGhoBorrowCap();
assertEq(newBorrowCap, currentBorrowCap);
}

function testUpdateGhoBorrowCapMaxIncrease() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
uint256 newBorrowCap = oldBorrowCap * 2;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(newBorrowCap);
uint256 currentBorrowCap = _getGhoBorrowCap();
assertEq(newBorrowCap, currentBorrowCap);
}

function testUpdateGhoBorrowCapMaxDecrease() public {
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(0);
uint256 currentBorrowCap = _getGhoBorrowCap();
assertEq(currentBorrowCap, 0);
}

function testUpdateGhoBorrowCapTimelock() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(oldBorrowCap + 1);
IGhoAaveSteward.GhoDebounce memory ghoTimelocks = GHO_AAVE_STEWARD.getGhoTimelocks();
assertEq(ghoTimelocks.ghoBorrowCapLastUpdate, block.timestamp);
}

function testUpdateGhoBorrowCapAfterTimelock() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(oldBorrowCap + 1);
skip(GHO_AAVE_STEWARD.MINIMUM_DELAY() + 1);
uint256 newBorrowCap = oldBorrowCap + 2;
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(newBorrowCap);
uint256 currentBorrowCap = _getGhoBorrowCap();
assertEq(newBorrowCap, currentBorrowCap);
}

function testRevertUpdateGhoBorrowCapIfUnauthorized() public {
vm.prank(ALICE);
vm.expectRevert('INVALID_CALLER');
GHO_AAVE_STEWARD.updateGhoBorrowCap(50e6);
}

function testRevertUpdateGhoBorrowCapIfUpdatedTooSoon() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
vm.prank(RISK_COUNCIL);
GHO_AAVE_STEWARD.updateGhoBorrowCap(oldBorrowCap + 1);
vm.prank(RISK_COUNCIL);
vm.expectRevert('DEBOUNCE_NOT_RESPECTED');
GHO_AAVE_STEWARD.updateGhoBorrowCap(oldBorrowCap + 2);
}

function testRevertUpdateGhoBorrowCapIfValueMoreThanDouble() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
vm.prank(RISK_COUNCIL);
vm.expectRevert('INVALID_BORROW_CAP_UPDATE');
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)
);
return configuration.getBorrowCap();
}
}

0 comments on commit c850a0d

Please sign in to comment.