From dd15e237034d26007711d9297b4670f5d68ac719 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 13 Dec 2022 18:02:27 +0100 Subject: [PATCH] fix: Complete interfaces of IReserveInterestRateStrategy and IPoolDataProvider (#763) * feat: complete interface & use inheritdoc * Added missing functions on IReserveInterestRateStrategy and inheritdoc on DefaultInterestRateStrategy * fix: added missing overrides, docs for constructor and added ADDRESSES_PROVIDER to interface * fix: sepparated interest rate strategy interface into default and rate interfaces * fix: added visibility to false rule * fix: minor fixes * fix: fixed natspec. Fixed import order * Update contracts/interfaces/IDefaultInterestRateStrategy.sol * Apply suggestions from code review * Apply suggestions from code review * fix: fixed correct import order Co-authored-by: eboado Co-authored-by: sendra Co-authored-by: sendra Co-authored-by: miguelmtz <36620902+miguelmtzinf@users.noreply.github.com> --- .../IDefaultInterestRateStrategy.sol | 97 +++++++++ contracts/interfaces/IPoolDataProvider.sol | 190 +++++++++++++++++- .../IReserveInterestRateStrategy.sol | 14 +- contracts/misc/AaveProtocolDataProvider.sol | 177 ++++------------ .../tests/MockReserveInterestRateStrategy.sol | 19 +- .../DefaultReserveInterestRateStrategy.sol | 68 ++----- 6 files changed, 357 insertions(+), 208 deletions(-) create mode 100644 contracts/interfaces/IDefaultInterestRateStrategy.sol diff --git a/contracts/interfaces/IDefaultInterestRateStrategy.sol b/contracts/interfaces/IDefaultInterestRateStrategy.sol new file mode 100644 index 000000000..22770226a --- /dev/null +++ b/contracts/interfaces/IDefaultInterestRateStrategy.sol @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity ^0.8.0; + +import {IReserveInterestRateStrategy} from './IReserveInterestRateStrategy.sol'; +import {IPoolAddressesProvider} from './IPoolAddressesProvider.sol'; + +/** + * @title IDefaultInterestRateStrategy + * @author Aave + * @notice Defines the basic interface of the DefaultReserveInterestRateStrategy + */ +interface IDefaultInterestRateStrategy is IReserveInterestRateStrategy { + /** + * @notice Returns the usage ratio at which the pool aims to obtain most competitive borrow rates. + * @return The optimal usage ratio, expressed in ray. + */ + function OPTIMAL_USAGE_RATIO() external view returns (uint256); + + /** + * @notice Returns the optimal stable to total debt ratio of the reserve. + * @return The optimal stable to total debt ratio, expressed in ray. + */ + function OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO() external view returns (uint256); + + /** + * @notice Returns the excess usage ratio above the optimal. + * @dev It's always equal to 1-optimal usage ratio (added as constant for gas optimizations) + * @return The max excess usage ratio, expressed in ray. + */ + function MAX_EXCESS_USAGE_RATIO() external view returns (uint256); + + /** + * @notice Returns the excess stable debt ratio above the optimal. + * @dev It's always equal to 1-optimal stable to total debt ratio (added as constant for gas optimizations) + * @return The max excess stable to total debt ratio, expressed in ray. + */ + function MAX_EXCESS_STABLE_TO_TOTAL_DEBT_RATIO() external view returns (uint256); + + /** + * @notice Returns the address of the PoolAddressesProvider + * @return The address of the PoolAddressesProvider contract + */ + function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider); + + /** + * @notice Returns the variable rate slope below optimal usage ratio + * @dev It's the variable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO + * @return The variable rate slope, expressed in ray + */ + function getVariableRateSlope1() external view returns (uint256); + + /** + * @notice Returns the variable rate slope above optimal usage ratio + * @dev It's the variable rate when usage ratio > OPTIMAL_USAGE_RATIO + * @return The variable rate slope, expressed in ray + */ + function getVariableRateSlope2() external view returns (uint256); + + /** + * @notice Returns the stable rate slope below optimal usage ratio + * @dev It's the stable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO + * @return The stable rate slope, expressed in ray + */ + function getStableRateSlope1() external view returns (uint256); + + /** + * @notice Returns the stable rate slope above optimal usage ratio + * @dev It's the variable rate when usage ratio > OPTIMAL_USAGE_RATIO + * @return The stable rate slope, expressed in ray + */ + function getStableRateSlope2() external view returns (uint256); + + /** + * @notice Returns the stable rate excess offset + * @dev It's an additional premium applied to the stable when stable debt > OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO + * @return The stable rate excess offset, expressed in ray + */ + function getStableRateExcessOffset() external view returns (uint256); + + /** + * @notice Returns the base stable borrow rate + * @return The base stable borrow rate, expressed in ray + */ + function getBaseStableBorrowRate() external view returns (uint256); + + /** + * @notice Returns the base variable borrow rate + * @return The base variable borrow rate, expressed in ray + */ + function getBaseVariableBorrowRate() external view returns (uint256); + + /** + * @notice Returns the maximum variable borrow rate + * @return The maximum variable borrow rate, expressed in ray + */ + function getMaxVariableBorrowRate() external view returns (uint256); +} diff --git a/contracts/interfaces/IPoolDataProvider.sol b/contracts/interfaces/IPoolDataProvider.sol index 0c7b34c35..1755553cf 100644 --- a/contracts/interfaces/IPoolDataProvider.sol +++ b/contracts/interfaces/IPoolDataProvider.sol @@ -1,7 +1,128 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; +import { IPoolAddressesProvider } from './IPoolAddressesProvider.sol'; + + /** + * @title IPoolDataProvider + * @author Aave + * @notice Defines the basic interface of a PoolDataProvider + */ interface IPoolDataProvider { + struct TokenData { + string symbol; + address tokenAddress; + } + + /** + * @notice Returns the address for the PoolAddressesProvider contract. + * @return The address for the PoolAddressesProvider contract + */ + function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider); + + /** + * @notice Returns the list of the existing reserves in the pool. + * @dev Handling MKR and ETH in a different way since they do not have standard `symbol` functions. + * @return The list of reserves, pairs of symbols and addresses + */ + function getAllReservesTokens() external view returns (TokenData[] memory); + + /** + * @notice Returns the list of the existing ATokens in the pool. + * @return The list of ATokens, pairs of symbols and addresses + */ + function getAllATokens() external view returns (TokenData[] memory); + + /** + * @notice Returns the configuration data of the reserve + * @dev Not returning borrow and supply caps for compatibility, nor pause flag + * @param asset The address of the underlying asset of the reserve + * @return decimals The number of decimals of the reserve + * @return ltv The ltv of the reserve + * @return liquidationThreshold The liquidationThreshold of the reserve + * @return liquidationBonus The liquidationBonus of the reserve + * @return reserveFactor The reserveFactor of the reserve + * @return usageAsCollateralEnabled True if the usage as collateral is enabled, false otherwise + * @return borrowingEnabled True if borrowing is enabled, false otherwise + * @return stableBorrowRateEnabled True if stable rate borrowing is enabled, false otherwise + * @return isActive True if it is active, false otherwise + * @return isFrozen True if it is frozen, false otherwise + */ + function getReserveConfigurationData(address asset) + external + view + returns ( + uint256 decimals, + uint256 ltv, + uint256 liquidationThreshold, + uint256 liquidationBonus, + uint256 reserveFactor, + bool usageAsCollateralEnabled, + bool borrowingEnabled, + bool stableBorrowRateEnabled, + bool isActive, + bool isFrozen + ); + + /** + * @notice Returns the efficiency mode category of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The eMode id of the reserve + */ + function getReserveEModeCategory(address asset) external view returns (uint256); + + /** + * @notice Returns the caps parameters of the reserve + * @param asset The address of the underlying asset of the reserve + * @return borrowCap The borrow cap of the reserve + * @return supplyCap The supply cap of the reserve + **/ + function getReserveCaps(address asset) + external + view + returns (uint256 borrowCap, uint256 supplyCap); + + /** + * @notice Returns if the pool is paused + * @param asset The address of the underlying asset of the reserve + * @return isPaused True if the pool is paused, false otherwise + */ + function getPaused(address asset) external view returns (bool isPaused); + + /** + * @notice Returns the siloed borrowing flag + * @param asset The address of the underlying asset of the reserve + * @return True if the asset is siloed for borrowing + */ + function getSiloedBorrowing(address asset) external view returns (bool); + + /** + * @notice Returns the protocol fee on the liquidation bonus + * @param asset The address of the underlying asset of the reserve + * @return The protocol fee on liquidation + */ + function getLiquidationProtocolFee(address asset) external view returns (uint256); + + /** + * @notice Returns the unbacked mint cap of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The unbacked mint cap of the reserve + */ + function getUnbackedMintCap(address asset) external view returns (uint256); + + /** + * @notice Returns the debt ceiling of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The debt ceiling of the reserve + */ + function getDebtCeiling(address asset) external view returns (uint256); + + /** + * @notice Returns the debt ceiling decimals + * @return The debt ceiling decimals + */ + function getDebtCeilingDecimals() external pure returns (uint256); + /** * @notice Returns the reserve data * @param asset The address of the underlying asset of the reserve @@ -17,7 +138,7 @@ interface IPoolDataProvider { * @return liquidityIndex The liquidity index of the reserve * @return variableBorrowIndex The variable borrow index of the reserve * @return lastUpdateTimestamp The timestamp of the last update of the reserve - **/ + */ function getReserveData(address asset) external view @@ -40,13 +161,76 @@ interface IPoolDataProvider { * @notice Returns the total supply of aTokens for a given asset * @param asset The address of the underlying asset of the reserve * @return The total supply of the aToken - **/ + */ function getATokenTotalSupply(address asset) external view returns (uint256); /** * @notice Returns the total debt for a given asset * @param asset The address of the underlying asset of the reserve * @return The total debt for asset - **/ + */ function getTotalDebt(address asset) external view returns (uint256); + + /** + * @notice Returns the user data in a reserve + * @param asset The address of the underlying asset of the reserve + * @param user The address of the user + * @return currentATokenBalance The current AToken balance of the user + * @return currentStableDebt The current stable debt of the user + * @return currentVariableDebt The current variable debt of the user + * @return principalStableDebt The principal stable debt of the user + * @return scaledVariableDebt The scaled variable debt of the user + * @return stableBorrowRate The stable borrow rate of the user + * @return liquidityRate The liquidity rate of the reserve + * @return stableRateLastUpdated The timestamp of the last update of the user stable rate + * @return usageAsCollateralEnabled True if the user is using the asset as collateral, false + * otherwise + */ + function getUserReserveData(address asset, address user) + external + view + returns ( + uint256 currentATokenBalance, + uint256 currentStableDebt, + uint256 currentVariableDebt, + uint256 principalStableDebt, + uint256 scaledVariableDebt, + uint256 stableBorrowRate, + uint256 liquidityRate, + uint40 stableRateLastUpdated, + bool usageAsCollateralEnabled + ); + + /** + * @notice Returns the token addresses of the reserve + * @param asset The address of the underlying asset of the reserve + * @return aTokenAddress The AToken address of the reserve + * @return stableDebtTokenAddress The StableDebtToken address of the reserve + * @return variableDebtTokenAddress The VariableDebtToken address of the reserve + */ + function getReserveTokensAddresses(address asset) + external + view + returns ( + address aTokenAddress, + address stableDebtTokenAddress, + address variableDebtTokenAddress + ); + + /** + * @notice Returns the address of the Interest Rate strategy + * @param asset The address of the underlying asset of the reserve + * @return irStrategyAddress The address of the Interest Rate strategy + */ + function getInterestRateStrategyAddress(address asset) + external + view + returns (address irStrategyAddress); + + /** + * @notice Returns whether the reserve has FlashLoans enabled or disabled + * @param asset The address of the underlying asset of the reserve + * @return True if FlashLoans are enabled, false otherwise + */ + function getFlashLoanEnabled(address asset) external view returns (bool); } diff --git a/contracts/interfaces/IReserveInterestRateStrategy.sol b/contracts/interfaces/IReserveInterestRateStrategy.sol index 1aaf63343..65eefa50a 100644 --- a/contracts/interfaces/IReserveInterestRateStrategy.sol +++ b/contracts/interfaces/IReserveInterestRateStrategy.sol @@ -9,25 +9,13 @@ import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; * @notice Interface for the calculation of the interest rates */ interface IReserveInterestRateStrategy { - /** - * @notice Returns the base variable borrow rate - * @return The base variable borrow rate, expressed in ray - **/ - function getBaseVariableBorrowRate() external view returns (uint256); - - /** - * @notice Returns the maximum variable borrow rate - * @return The maximum variable borrow rate, expressed in ray - **/ - function getMaxVariableBorrowRate() external view returns (uint256); - /** * @notice Calculates the interest rates depending on the reserve's state and configurations * @param params The parameters needed to calculate interest rates * @return liquidityRate The liquidity rate expressed in rays * @return stableBorrowRate The stable borrow rate expressed in rays * @return variableBorrowRate The variable borrow rate expressed in rays - **/ + */ function calculateInterestRates(DataTypes.CalculateInterestRatesParams memory params) external view diff --git a/contracts/misc/AaveProtocolDataProvider.sol b/contracts/misc/AaveProtocolDataProvider.sol index c7284ab12..03d14a36f 100644 --- a/contracts/misc/AaveProtocolDataProvider.sol +++ b/contracts/misc/AaveProtocolDataProvider.sol @@ -25,23 +25,19 @@ contract AaveProtocolDataProvider is IPoolDataProvider { address constant MKR = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2; address constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - struct TokenData { - string symbol; - address tokenAddress; - } - + /// @inheritdoc IPoolDataProvider IPoolAddressesProvider public immutable ADDRESSES_PROVIDER; + /** + * @notice Constructor + * @param addressesProvider The address of the PoolAddressesProvider contract + */ constructor(IPoolAddressesProvider addressesProvider) { ADDRESSES_PROVIDER = addressesProvider; } - /** - * @notice Returns the list of the existing reserves in the pool. - * @dev Handling MKR and ETH in a different way since they do not have standard `symbol` functions. - * @return The list of reserves, pairs of symbols and addresses - */ - function getAllReservesTokens() external view returns (TokenData[] memory) { + /// @inheritdoc IPoolDataProvider + function getAllReservesTokens() external view override returns (TokenData[] memory) { IPool pool = IPool(ADDRESSES_PROVIDER.getPool()); address[] memory reserves = pool.getReservesList(); TokenData[] memory reservesTokens = new TokenData[](reserves.length); @@ -61,12 +57,9 @@ contract AaveProtocolDataProvider is IPoolDataProvider { } return reservesTokens; } - - /** - * @notice Returns the list of the existing ATokens in the pool. - * @return The list of ATokens, pairs of symbols and addresses - */ - function getAllATokens() external view returns (TokenData[] memory) { + + /// @inheritdoc IPoolDataProvider + function getAllATokens() external view override returns (TokenData[] memory) { IPool pool = IPool(ADDRESSES_PROVIDER.getPool()); address[] memory reserves = pool.getReservesList(); TokenData[] memory aTokens = new TokenData[](reserves.length); @@ -80,24 +73,11 @@ contract AaveProtocolDataProvider is IPoolDataProvider { return aTokens; } - /** - * @notice Returns the configuration data of the reserve - * @dev Not returning borrow and supply caps for compatibility, nor pause flag - * @param asset The address of the underlying asset of the reserve - * @return decimals The number of decimals of the reserve - * @return ltv The ltv of the reserve - * @return liquidationThreshold The liquidationThreshold of the reserve - * @return liquidationBonus The liquidationBonus of the reserve - * @return reserveFactor The reserveFactor of the reserve - * @return usageAsCollateralEnabled True if the usage as collateral is enabled, false otherwise - * @return borrowingEnabled True if borrowing is enabled, false otherwise - * @return stableBorrowRateEnabled True if stable rate borrowing is enabled, false otherwise - * @return isActive True if it is active, false otherwise - * @return isFrozen True if it is frozen, false otherwise - **/ + /// @inheritdoc IPoolDataProvider function getReserveConfigurationData(address asset) external view + override returns ( uint256 decimals, uint256 ltv, @@ -122,100 +102,54 @@ contract AaveProtocolDataProvider is IPoolDataProvider { usageAsCollateralEnabled = liquidationThreshold != 0; } - /** - * Returns the efficiency mode category of the reserve - * @param asset The address of the underlying asset of the reserve - * @return The eMode id of the reserve - */ - function getReserveEModeCategory(address asset) external view returns (uint256) { + /// @inheritdoc IPoolDataProvider + function getReserveEModeCategory(address asset) external view override returns (uint256) { DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool()) .getConfiguration(asset); return configuration.getEModeCategory(); } - /** - * @notice Returns the caps parameters of the reserve - * @param asset The address of the underlying asset of the reserve - * @return borrowCap The borrow cap of the reserve - * @return supplyCap The supply cap of the reserve - **/ + /// @inheritdoc IPoolDataProvider function getReserveCaps(address asset) external view + override returns (uint256 borrowCap, uint256 supplyCap) { (borrowCap, supplyCap) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getCaps(); } - /** - * @notice Returns if the pool is paused - * @param asset The address of the underlying asset of the reserve - * @return isPaused True if the pool is paused, false otherwise - **/ - function getPaused(address asset) external view returns (bool isPaused) { + /// @inheritdoc IPoolDataProvider + function getPaused(address asset) external view override returns (bool isPaused) { (, , , , isPaused) = IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getFlags(); } - /** - * @notice Returns the siloed borrowing flag - * @param asset The address of the underlying asset of the reserve - * @return True if the asset is siloed for borrowing - **/ - function getSiloedBorrowing(address asset) external view returns (bool) { + /// @inheritdoc IPoolDataProvider + function getSiloedBorrowing(address asset) external view override returns (bool) { return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getSiloedBorrowing(); } - /** - * @notice Returns the protocol fee on the liquidation bonus - * @param asset The address of the underlying asset of the reserve - * @return The protocol fee on liquidation - **/ - function getLiquidationProtocolFee(address asset) external view returns (uint256) { + /// @inheritdoc IPoolDataProvider + function getLiquidationProtocolFee(address asset) external view override returns (uint256) { return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getLiquidationProtocolFee(); } - /** - * @notice Returns the unbacked mint cap of the reserve - * @param asset The address of the underlying asset of the reserve - * @return The unbacked mint cap of the reserve - **/ - function getUnbackedMintCap(address asset) external view returns (uint256) { + /// @inheritdoc IPoolDataProvider + function getUnbackedMintCap(address asset) external view override returns (uint256) { return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getUnbackedMintCap(); } - /** - * @notice Returns the debt ceiling of the reserve - * @param asset The address of the underlying asset of the reserve - * @return The debt ceiling of the reserve - **/ - function getDebtCeiling(address asset) external view returns (uint256) { + /// @inheritdoc IPoolDataProvider + function getDebtCeiling(address asset) external view override returns (uint256) { return IPool(ADDRESSES_PROVIDER.getPool()).getConfiguration(asset).getDebtCeiling(); } - /** - * @notice Returns the debt ceiling decimals - * @return The debt ceiling decimals - **/ - function getDebtCeilingDecimals() external pure returns (uint256) { + /// @inheritdoc IPoolDataProvider + function getDebtCeilingDecimals() external pure override returns (uint256) { return ReserveConfiguration.DEBT_CEILING_DECIMALS; } - /** - * @notice Returns the reserve data - * @param asset The address of the underlying asset of the reserve - * @return unbacked The amount of unbacked tokens - * @return accruedToTreasuryScaled The scaled amount of tokens accrued to treasury that is to be minted - * @return totalAToken The total supply of the aToken - * @return totalStableDebt The total stable debt of the reserve - * @return totalVariableDebt The total variable debt of the reserve - * @return liquidityRate The liquidity rate of the reserve - * @return variableBorrowRate The variable borrow rate of the reserve - * @return stableBorrowRate The stable borrow rate of the reserve - * @return averageStableBorrowRate The average stable borrow rate of the reserve - * @return liquidityIndex The liquidity index of the reserve - * @return variableBorrowIndex The variable borrow index of the reserve - * @return lastUpdateTimestamp The timestamp of the last update of the reserve - **/ + /// @inheritdoc IPoolDataProvider function getReserveData(address asset) external view @@ -255,11 +189,7 @@ contract AaveProtocolDataProvider is IPoolDataProvider { ); } - /** - * @notice Returns the total supply of aTokens for a given asset - * @param asset The address of the underlying asset of the reserve - * @return The total supply of the aToken - **/ + /// @inheritdoc IPoolDataProvider function getATokenTotalSupply(address asset) external view override returns (uint256) { DataTypes.ReserveData memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData( asset @@ -267,11 +197,7 @@ contract AaveProtocolDataProvider is IPoolDataProvider { return IERC20Detailed(reserve.aTokenAddress).totalSupply(); } - /** - * @notice Returns the total debt for a given asset - * @param asset The address of the underlying asset of the reserve - * @return The total debt for asset - **/ + /// @inheritdoc IPoolDataProvider function getTotalDebt(address asset) external view override returns (uint256) { DataTypes.ReserveData memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData( asset @@ -281,24 +207,11 @@ contract AaveProtocolDataProvider is IPoolDataProvider { IERC20Detailed(reserve.variableDebtTokenAddress).totalSupply(); } - /** - * @notice Returns the user data in a reserve - * @param asset The address of the underlying asset of the reserve - * @param user The address of the user - * @return currentATokenBalance The current AToken balance of the user - * @return currentStableDebt The current stable debt of the user - * @return currentVariableDebt The current variable debt of the user - * @return principalStableDebt The principal stable debt of the user - * @return scaledVariableDebt The scaled variable debt of the user - * @return stableBorrowRate The stable borrow rate of the user - * @return liquidityRate The liquidity rate of the reserve - * @return stableRateLastUpdated The timestamp of the last update of the user stable rate - * @return usageAsCollateralEnabled True if the user is using the asset as collateral, false - * otherwise - **/ + /// @inheritdoc IPoolDataProvider function getUserReserveData(address asset, address user) external view + override returns ( uint256 currentATokenBalance, uint256 currentStableDebt, @@ -331,16 +244,11 @@ contract AaveProtocolDataProvider is IPoolDataProvider { usageAsCollateralEnabled = userConfig.isUsingAsCollateral(reserve.id); } - /** - * @notice Returns the token addresses of the reserve - * @param asset The address of the underlying asset of the reserve - * @return aTokenAddress The AToken address of the reserve - * @return stableDebtTokenAddress The StableDebtToken address of the reserve - * @return variableDebtTokenAddress The VariableDebtToken address of the reserve - */ + /// @inheritdoc IPoolDataProvider function getReserveTokensAddresses(address asset) external view + override returns ( address aTokenAddress, address stableDebtTokenAddress, @@ -358,14 +266,11 @@ contract AaveProtocolDataProvider is IPoolDataProvider { ); } - /** - * @notice Returns the address of the Interest Rate strategy - * @param asset The address of the underlying asset of the reserve - * @return irStrategyAddress The address of the Interest Rate strategy - */ + /// @inheritdoc IPoolDataProvider function getInterestRateStrategyAddress(address asset) external view + override returns (address irStrategyAddress) { DataTypes.ReserveData memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData( @@ -375,12 +280,8 @@ contract AaveProtocolDataProvider is IPoolDataProvider { return (reserve.interestRateStrategyAddress); } - /** - * @notice Returns whether the reserve has FlashLoans enabled or disabled - * @param asset The address of the underlying asset of the reserve - * @return True if FlashLoans are enabled, false otherwise - * */ - function getFlashLoanEnabled(address asset) external view returns (bool) { + /// @inheritdoc IPoolDataProvider + function getFlashLoanEnabled(address asset) external view override returns (bool) { DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool()) .getConfiguration(asset); diff --git a/contracts/mocks/tests/MockReserveInterestRateStrategy.sol b/contracts/mocks/tests/MockReserveInterestRateStrategy.sol index 973ed7976..a868540f6 100644 --- a/contracts/mocks/tests/MockReserveInterestRateStrategy.sol +++ b/contracts/mocks/tests/MockReserveInterestRateStrategy.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.10; -import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol'; import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol'; import {WadRayMath} from '../../protocol/libraries/math/WadRayMath.sol'; import {DataTypes} from '../../protocol/libraries/types/DataTypes.sol'; +import {IDefaultInterestRateStrategy} from "../../interfaces/IDefaultInterestRateStrategy.sol"; -contract MockReserveInterestRateStrategy is IReserveInterestRateStrategy { +contract MockReserveInterestRateStrategy is IDefaultInterestRateStrategy { uint256 public immutable OPTIMAL_USAGE_RATIO; IPoolAddressesProvider public immutable ADDRESSES_PROVIDER; uint256 internal immutable _baseVariableBorrowRate; @@ -15,6 +15,11 @@ contract MockReserveInterestRateStrategy is IReserveInterestRateStrategy { uint256 internal immutable _stableRateSlope1; uint256 internal immutable _stableRateSlope2; + // Not used, only defined for interface compatibility + uint256 public constant MAX_EXCESS_STABLE_TO_TOTAL_DEBT_RATIO = 0; + uint256 public constant MAX_EXCESS_USAGE_RATIO = 0; + uint256 public constant OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = 0; + uint256 internal _liquidityRate; uint256 internal _stableBorrowRate; uint256 internal _variableBorrowRate; @@ -85,4 +90,14 @@ contract MockReserveInterestRateStrategy is IReserveInterestRateStrategy { function getMaxVariableBorrowRate() external view override returns (uint256) { return _baseVariableBorrowRate + _variableRateSlope1 + _variableRateSlope2; } + + // Not used, only defined for interface compatibility + function getBaseStableBorrowRate() external pure override returns (uint256) { + return 0; + } + + // Not used, only defined for interface compatibility + function getStableRateExcessOffset() external pure override returns (uint256) { + return 0; + } } diff --git a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol index 9937ce237..1191457d1 100644 --- a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol @@ -5,9 +5,10 @@ import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; -import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol'; -import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; +import {IDefaultInterestRateStrategy} from "../../interfaces/IDefaultInterestRateStrategy.sol"; +import {IReserveInterestRateStrategy} from "../../interfaces/IReserveInterestRateStrategy.sol"; +import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol'; /** * @title DefaultReserveInterestRateStrategy contract @@ -18,34 +19,20 @@ import {Errors} from '../libraries/helpers/Errors.sol'; * - An instance of this same contract, can't be used across different Aave markets, due to the caching * of the PoolAddressesProvider **/ -contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { +contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { using WadRayMath for uint256; using PercentageMath for uint256; - /** - * @dev This constant represents the usage ratio at which the pool aims to obtain most competitive borrow rates. - * Expressed in ray - **/ + /// @inheritdoc IDefaultInterestRateStrategy uint256 public immutable OPTIMAL_USAGE_RATIO; - /** - * @dev This constant represents the optimal stable debt to total debt ratio of the reserve. - * Expressed in ray - */ + /// @inheritdoc IDefaultInterestRateStrategy uint256 public immutable OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO; - /** - * @dev This constant represents the excess usage ratio above the optimal. It's always equal to - * 1-optimal usage ratio. Added as a constant here for gas optimizations. - * Expressed in ray - **/ + /// @inheritdoc IDefaultInterestRateStrategy uint256 public immutable MAX_EXCESS_USAGE_RATIO; - /** - * @dev This constant represents the excess stable debt ratio above the optimal. It's always equal to - * 1-optimal stable to total debt ratio. Added as a constant here for gas optimizations. - * Expressed in ray - **/ + /// @inheritdoc IDefaultInterestRateStrategy uint256 public immutable MAX_EXCESS_STABLE_TO_TOTAL_DEBT_RATIO; IPoolAddressesProvider public immutable ADDRESSES_PROVIDER; @@ -115,65 +102,42 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { _stableRateExcessOffset = stableRateExcessOffset; } - /** - * @notice Returns the variable rate slope below optimal usage ratio - * @dev Its the variable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO - * @return The variable rate slope - **/ + /// @inheritdoc IDefaultInterestRateStrategy function getVariableRateSlope1() external view returns (uint256) { return _variableRateSlope1; } - /** - * @notice Returns the variable rate slope above optimal usage ratio - * @dev Its the variable rate when usage ratio > OPTIMAL_USAGE_RATIO - * @return The variable rate slope - **/ + /// @inheritdoc IDefaultInterestRateStrategy function getVariableRateSlope2() external view returns (uint256) { return _variableRateSlope2; } - /** - * @notice Returns the stable rate slope below optimal usage ratio - * @dev Its the stable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO - * @return The stable rate slope - **/ + /// @inheritdoc IDefaultInterestRateStrategy function getStableRateSlope1() external view returns (uint256) { return _stableRateSlope1; } - /** - * @notice Returns the stable rate slope above optimal usage ratio - * @dev Its the variable rate when usage ratio > OPTIMAL_USAGE_RATIO - * @return The stable rate slope - **/ + /// @inheritdoc IDefaultInterestRateStrategy function getStableRateSlope2() external view returns (uint256) { return _stableRateSlope2; } - /** - * @notice Returns the stable rate excess offset - * @dev An additional premium applied to the stable when stable debt > OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO - * @return The stable rate excess offset - */ + /// @inheritdoc IDefaultInterestRateStrategy function getStableRateExcessOffset() external view returns (uint256) { return _stableRateExcessOffset; } - /** - * @notice Returns the base stable borrow rate - * @return The base stable borrow rate - **/ + /// @inheritdoc IDefaultInterestRateStrategy function getBaseStableBorrowRate() public view returns (uint256) { return _variableRateSlope1 + _baseStableRateOffset; } - /// @inheritdoc IReserveInterestRateStrategy + /// @inheritdoc IDefaultInterestRateStrategy function getBaseVariableBorrowRate() external view override returns (uint256) { return _baseVariableBorrowRate; } - /// @inheritdoc IReserveInterestRateStrategy + /// @inheritdoc IDefaultInterestRateStrategy function getMaxVariableBorrowRate() external view override returns (uint256) { return _baseVariableBorrowRate + _variableRateSlope1 + _variableRateSlope2; }