Skip to content

Commit

Permalink
feat: only owner can set borrow rate config
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Aug 19, 2024
1 parent 255ddfa commit 90770bd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/contracts/misc/GhoAaveSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
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 {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IPoolConfigurator} from './deps/IPoolConfigurator.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {ReserveConfiguration} from '@aave/core-v3/contracts/protocol/libraries/configuration/ReserveConfiguration.sol';
import {IPoolConfigurator} from './deps/IPoolConfigurator.sol';
import {IDefaultInterestRateStrategyV2} from './deps/Dependencies.sol';
import {DefaultReserveInterestRateStrategyV2} from './deps/Dependencies.sol';
import {IGhoAaveSteward} from './interfaces/IGhoAaveSteward.sol';
Expand All @@ -20,7 +21,7 @@ import {RiskCouncilControlled} from './RiskCouncilControlled.sol';
* @dev Only the Risk Council is able to action contract's functions, based on specific conditions that have been agreed upon with the community.
* @dev Requires role RiskAdmin on the Aave V3 Ethereum Pool
*/
contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
contract GhoAaveSteward is Ownable, RiskCouncilControlled, IGhoAaveSteward {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using Address for address;

Expand Down Expand Up @@ -55,19 +56,22 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {

/**
* @dev Constructor
* @param owner The address of the contract's owner
* @param addressesProvider The address of the PoolAddressesProvider of Aave V3 Ethereum Pool
* @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
*/
constructor(
address owner,
address addressesProvider,
address poolDataProvider,
address ghoToken,
address riskCouncil,
BorrowRateConfig memory borrowRateConfig
) RiskCouncilControlled(riskCouncil) {
require(owner != address(0), 'INVALID_OWNER');
require(addressesProvider != address(0), 'INVALID_ADDRESSES_PROVIDER');
require(poolDataProvider != address(0), 'INVALID_DATA_PROVIDER');
require(ghoToken != address(0), 'INVALID_GHO_TOKEN');
Expand All @@ -76,6 +80,8 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
POOL_DATA_PROVIDER = poolDataProvider;
GHO_TOKEN = ghoToken;
_borrowRateConfig = borrowRateConfig;

_transferOwnership(owner);
}

/// @inheritdoc IGhoAaveSteward
Expand Down Expand Up @@ -142,7 +148,7 @@ contract GhoAaveSteward is RiskCouncilControlled, IGhoAaveSteward {
uint256 baseVariableBorrowRateMaxChange,
uint256 variableRateSlope1MaxChange,
uint256 variableRateSlope2MaxChange
) external onlyRiskCouncil notTimelocked(_ghoTimelocks.riskConfigLastUpdate) {
) external onlyOwner notTimelocked(_ghoTimelocks.riskConfigLastUpdate) {
_borrowRateConfig.optimalUsageRatioMaxChange = optimalUsageRatioMaxChange;
_borrowRateConfig.baseVariableBorrowRateMaxChange = baseVariableBorrowRateMaxChange;
_borrowRateConfig.variableRateSlope1MaxChange = variableRateSlope1MaxChange;
Expand Down
44 changes: 38 additions & 6 deletions src/test/TestGhoAaveSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract TestGhoAaveSteward is TestGhoBase {
function setUp() public {
// Deploy Gho Aave Steward
GHO_AAVE_STEWARD = new GhoAaveSteward(
SHORT_EXECUTOR,
address(PROVIDER),
address(MOCK_POOL_DATA_PROVIDER),
address(GHO_TOKEN),
Expand All @@ -50,6 +51,7 @@ contract TestGhoAaveSteward is TestGhoBase {
}

function testConstructor() public {
assertEq(GHO_AAVE_STEWARD.owner(), SHORT_EXECUTOR);
assertEq(GHO_AAVE_STEWARD.MINIMUM_DELAY(), MINIMUM_DELAY_V2);

assertEq(GHO_AAVE_STEWARD.POOL_ADDRESSES_PROVIDER(), address(PROVIDER));
Expand All @@ -61,13 +63,26 @@ contract TestGhoAaveSteward is TestGhoBase {
assertEq(ghoTimelocks.ghoBorrowCapLastUpdate, 0);
}

function testRevertConstructorInvalidOwner() public {
vm.expectRevert('INVALID_OWNER');
new GhoAaveSteward(
address(0),
address(0x002),
address(0x003),
address(0x004),
address(0x005),
defaultBorrowRateConfig
);
}

function testRevertConstructorInvalidAddressesProvider() public {
vm.expectRevert('INVALID_ADDRESSES_PROVIDER');
new GhoAaveSteward(
address(0x001),
address(0),
address(0x002),
address(0x003),
address(0x004),
address(0x005),
defaultBorrowRateConfig
);
}
Expand All @@ -76,9 +91,10 @@ contract TestGhoAaveSteward is TestGhoBase {
vm.expectRevert('INVALID_DATA_PROVIDER');
new GhoAaveSteward(
address(0x001),
address(0x002),
address(0),
address(0x003),
address(0x004),
address(0x005),
defaultBorrowRateConfig
);
}
Expand All @@ -88,8 +104,9 @@ contract TestGhoAaveSteward is TestGhoBase {
new GhoAaveSteward(
address(0x001),
address(0x002),
address(0x003),
address(0),
address(0x004),
address(0x005),
defaultBorrowRateConfig
);
}
Expand All @@ -100,11 +117,26 @@ contract TestGhoAaveSteward is TestGhoBase {
address(0x001),
address(0x002),
address(0x003),
address(0x004),
address(0),
defaultBorrowRateConfig
);
}

function testChangeOwnership() public {
address newOwner = makeAddr('newOwner');
assertEq(GHO_AAVE_STEWARD.owner(), SHORT_EXECUTOR);
vm.prank(SHORT_EXECUTOR);
GHO_AAVE_STEWARD.transferOwnership(newOwner);
assertEq(GHO_AAVE_STEWARD.owner(), newOwner);
}

function testChangeOwnershipRevert() public {
vm.expectRevert('Ownable: new owner is the zero address');
vm.prank(SHORT_EXECUTOR);
GHO_AAVE_STEWARD.transferOwnership(address(0));
}

function testUpdateGhoBorrowCap() public {
uint256 oldBorrowCap = 1e6;
_setGhoBorrowCapViaConfigurator(oldBorrowCap);
Expand Down Expand Up @@ -532,7 +564,7 @@ contract TestGhoAaveSteward is TestGhoBase {

function testSetRiskConfig() public {
defaultBorrowRateConfig.optimalUsageRatioMaxChange += 1;
vm.prank(RISK_COUNCIL);
vm.prank(SHORT_EXECUTOR);
GHO_AAVE_STEWARD.setBorrowRateConfig(
defaultBorrowRateConfig.optimalUsageRatioMaxChange,
defaultBorrowRateConfig.baseVariableBorrowRateMaxChange,
Expand All @@ -548,15 +580,15 @@ contract TestGhoAaveSteward is TestGhoBase {
}

function testSetRiskConfigIfUpdatedTooSoon() public {
vm.prank(RISK_COUNCIL);
vm.prank(SHORT_EXECUTOR);
GHO_AAVE_STEWARD.setBorrowRateConfig(
defaultBorrowRateConfig.optimalUsageRatioMaxChange,
defaultBorrowRateConfig.baseVariableBorrowRateMaxChange,
defaultBorrowRateConfig.variableRateSlope1MaxChange,
defaultBorrowRateConfig.variableRateSlope2MaxChange
);
vm.expectRevert('DEBOUNCE_NOT_RESPECTED');
vm.prank(RISK_COUNCIL);
vm.prank(SHORT_EXECUTOR);
GHO_AAVE_STEWARD.setBorrowRateConfig(
defaultBorrowRateConfig.optimalUsageRatioMaxChange,
defaultBorrowRateConfig.baseVariableBorrowRateMaxChange,
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestGhoBucketSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TestGhoBucketSteward is TestGhoBase {
assertEq(facilitatorTimelock, 0);
}

function testRevertConstructorInvalidExecutor() public {
function testRevertConstructorInvalidOwner() public {
vm.expectRevert('INVALID_OWNER');
new GhoBucketSteward(address(0), address(0x002), address(0x003));
}
Expand Down

0 comments on commit 90770bd

Please sign in to comment.