Skip to content

Commit

Permalink
feat: Add GhoStewardV2 (#388)
Browse files Browse the repository at this point in the history
* feat: basic gho steward

* feat: init tests for gho steward

* feat:updateBorrowCap tests

* feat: polish tests for GhoStewardV2

* feat: new parameters requeriments and natspec for GhoStewardV2

* feat: initial test suit for GhoStewardV2

* feat: refactor to updateFacilitator instead of GHO and GSM by separate

* feat: natspec polish

* feat: fixed tests

* feat: PR feedback + new tests for GhoStewardV2

* feat: deleted not used libraries and added setFacilitators tests

* feat: fixed PR feedback

* feat: format fix

* feat: PR reviews 3

* feat: added updateGhoBorrowCap

* feat: pr reviews and added test for roles removed

* feat: added fixed rate strategy factory and deleted requeriment for borrow rate only increase

* feat: fixed natspec

* feat: more natspec cleaning

* feat: deleted old test

* feat: added tests for decrease gho borrow rate

* feat: added test for missing constructor

* feat: added FixedRateStrategyFactory tests

* feat: made strategy factory initializable and moved it to correct directory

* feat: PR feedback

* feat: moved event test to common cases instead of separate test

* fix: Update values for input validation

---------

Co-authored-by: miguelmtzinf <[email protected]>
  • Loading branch information
JoaquinBattilana and miguelmtzinf authored Mar 15, 2024
1 parent 3b6810c commit 77dd627
Show file tree
Hide file tree
Showing 11 changed files with 1,597 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IDefaultInterestRateStrategy} from '@aave/core-v3/contracts/interfaces/IDefaultInterestRateStrategy.sol';
import {VersionedInitializable} from '@aave/core-v3/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol';
import {IFixedRateStrategyFactory} from './interfaces/IFixedRateStrategyFactory.sol';
import {GhoInterestRateStrategy} from './GhoInterestRateStrategy.sol';

/**
* @title FixedRateStrategyFactory
* @author Aave Labs
* @notice Factory contract to create and keep record of Aave v3 fixed rate strategy contracts
* @dev `GhoInterestRateStrategy` is used to provide a fixed interest rate strategy.
*/
contract FixedRateStrategyFactory is VersionedInitializable, IFixedRateStrategyFactory {
///@inheritdoc IFixedRateStrategyFactory
address public immutable POOL_ADDRESSES_PROVIDER;

mapping(uint256 => address) internal _strategiesByRate;
address[] internal _strategies;

/**
* @dev Constructor
* @param addressesProvider The address of the PoolAddressesProvider of Aave V3 Pool
*/
constructor(address addressesProvider) {
require(addressesProvider != address(0), 'INVALID_ADDRESSES_PROVIDER');
POOL_ADDRESSES_PROVIDER = addressesProvider;
}

/**
* @notice FixedRateStrategyFactory initializer
* @dev asumes that the addresses provided are fixed rate deployed strategies.
* @param fixedRateStrategiesList List of fixed rate strategies
*/
function initialize(address[] memory fixedRateStrategiesList) external initializer {
for (uint256 i = 0; i < fixedRateStrategiesList.length; i++) {
address fixedRateStrategy = fixedRateStrategiesList[i];
uint256 rate = IDefaultInterestRateStrategy(fixedRateStrategy).getBaseVariableBorrowRate();

_strategiesByRate[rate] = fixedRateStrategy;
_strategies.push(fixedRateStrategy);

emit RateStrategyCreated(fixedRateStrategy, rate);
}
}

///@inheritdoc IFixedRateStrategyFactory
function createStrategies(uint256[] memory fixedRateList) public returns (address[] memory) {
address[] memory strategies = new address[](fixedRateList.length);
for (uint256 i = 0; i < fixedRateList.length; i++) {
uint256 rate = fixedRateList[i];
address cachedStrategy = _strategiesByRate[rate];

if (cachedStrategy == address(0)) {
cachedStrategy = address(new GhoInterestRateStrategy(POOL_ADDRESSES_PROVIDER, rate));
_strategiesByRate[rate] = cachedStrategy;
_strategies.push(cachedStrategy);

emit RateStrategyCreated(cachedStrategy, rate);
}

strategies[i] = cachedStrategy;
}

return strategies;
}

///@inheritdoc IFixedRateStrategyFactory
function getAllStrategies() external view returns (address[] memory) {
return _strategies;
}

///@inheritdoc IFixedRateStrategyFactory
function getStrategyByRate(uint256 borrowRate) external view returns (address) {
return _strategiesByRate[borrowRate];
}

/// @inheritdoc IFixedRateStrategyFactory
function REVISION() public pure virtual override returns (uint256) {
return 1;
}

/// @inheritdoc VersionedInitializable
function getRevision() internal pure virtual override returns (uint256) {
return REVISION();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IFixedRateStrategyFactory {
/**
* @dev Emitted when a new strategy is created
* @param strategy The address of the new fixed rate strategy
* @param rate The rate of the new strategy, expressed in ray (e.g. 0.0150e27 results in 1.50%)
*/
event RateStrategyCreated(address indexed strategy, uint256 indexed rate);

/**
* @notice Creates new fixed rate strategy contracts from a list of rates.
* @dev Returns the address of a cached contract if a strategy with same rate already exists
* @param fixedRateList The list of rates for interest rates strategies, expressed in ray (e.g. 0.0150e27 results in 1.50%)
* @return The list of fixed interest rate strategy contracts
*/
function createStrategies(uint256[] memory fixedRateList) external returns (address[] memory);

/**
* @notice Returns the address of the Pool Addresses Provider of Aave
* @return The address of the PoolAddressesProvider of Aave
*/
function POOL_ADDRESSES_PROVIDER() external view returns (address);

/**
* @notice Returns all the fixed interest rate strategy contracts of the factory
* @return The list of fixed interest rate strategy contracts
*/
function getAllStrategies() external view returns (address[] memory);

/**
* @notice Returns the fixed interest rate strategy contract which corresponds to the given rate.
* @dev Returns `address(0)` if there is no interest rate strategy for the given rate
* @param rate The rate of the fixed interest rate strategy contract
* @return The address of the fixed interest rate strategy contract
*/
function getStrategyByRate(uint256 rate) external view returns (address);

/**
* @notice Returns the FixedRateStrategyFactory revision number
* @return The revision number
*/
function REVISION() external pure returns (uint256);
}
Loading

0 comments on commit 77dd627

Please sign in to comment.