- Reviewed comments on DefaultReserveInterestRateStrategy and interface.

This commit is contained in:
eboado 2020-11-19 14:48:15 +01:00
parent 97aa76b13c
commit 0c6ec03cec
2 changed files with 37 additions and 52 deletions

View File

@ -2,26 +2,15 @@
pragma solidity ^0.6.8; pragma solidity ^0.6.8;
/** /**
@title IReserveInterestRateStrategyInterface interface * @title IReserveInterestRateStrategyInterface interface
@notice Interface for the calculation of the interest rates. * @dev Interface for the calculation of the interest rates
* @author Aave
*/ */
interface IReserveInterestRateStrategy { interface IReserveInterestRateStrategy {
/**
* @dev returns the base variable borrow rate, in rays
*/
function baseVariableBorrowRate() external view returns (uint256); function baseVariableBorrowRate() external view returns (uint256);
/**
* @dev returns the maximum variable borrow rate
*/
function getMaxVariableBorrowRate() external view returns (uint256); function getMaxVariableBorrowRate() external view returns (uint256);
/**
* @dev calculates the liquidity, stable, and variable rates depending on the current utilization rate
* and the base parameters
*
*/
function calculateInterestRates( function calculateInterestRates(
address reserve, address reserve,
uint256 utilizationRate, uint256 utilizationRate,

View File

@ -5,53 +5,55 @@ import {SafeMath} from '../dependencies/openzeppelin/contracts/SafeMath.sol';
import {IReserveInterestRateStrategy} from '../interfaces/IReserveInterestRateStrategy.sol'; import {IReserveInterestRateStrategy} from '../interfaces/IReserveInterestRateStrategy.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingRateOracle} from '../interfaces/ILendingRateOracle.sol'; import {ILendingRateOracle} from '../interfaces/ILendingRateOracle.sol';
/** /**
* @title DefaultReserveInterestRateStrategy contract * @title DefaultReserveInterestRateStrategy contract
* @notice implements the calculation of the interest rates depending on the reserve parameters. * @notice Implements the calculation of the interest rates depending on the reserve state
* @dev if there is need to update the calculation of the interest rates for a specific reserve, * @dev The model of interest rate is based on 2 slopes, one before the `OPTIMAL_UTILIZATION_RATE`
* a new version of this contract will be deployed. * point of utilization and another from that one to 100%
* - An instance of this same contract, can't be used across different Aave markets, due to the caching
* of the LendingPoolAddressesProvider
* @author Aave * @author Aave
**/ **/
contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
using WadRayMath for uint256; using WadRayMath for uint256;
using SafeMath for uint256; using SafeMath for uint256;
using PercentageMath for uint256; using PercentageMath for uint256;
/** /**
* @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates * @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates.
* expressed in ray * Expressed in ray
**/ **/
uint256 public constant OPTIMAL_UTILIZATION_RATE = 0.8 * 1e27; uint256 public constant OPTIMAL_UTILIZATION_RATE = 0.8 * 1e27;
/** /**
* @dev this constant represents the excess utilization rate above the optimal. It's always equal to * @dev This constant represents the excess utilization rate above the optimal. It's always equal to
* 1-optimal utilization rate. Added as a constant here for gas optimizations * 1-optimal utilization rate. Added as a constant here for gas optimizations.
* expressed in ray * Expressed in ray
**/ **/
uint256 public constant EXCESS_UTILIZATION_RATE = 0.2 * 1e27; uint256 public constant EXCESS_UTILIZATION_RATE = 0.2 * 1e27;
LendingPoolAddressesProvider public immutable addressesProvider; ILendingPoolAddressesProvider public immutable addressesProvider;
//base variable borrow rate when Utilization rate = 0. Expressed in ray // Base variable borrow rate when Utilization rate = 0. Expressed in ray
uint256 internal immutable _baseVariableBorrowRate; uint256 internal immutable _baseVariableBorrowRate;
//slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray // Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _variableRateSlope1; uint256 internal immutable _variableRateSlope1;
//slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray // Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _variableRateSlope2; uint256 internal immutable _variableRateSlope2;
//slope of the stable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray // Slope of the stable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _stableRateSlope1; uint256 internal immutable _stableRateSlope1;
//slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray // Slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _stableRateSlope2; uint256 internal immutable _stableRateSlope2;
constructor( constructor(
LendingPoolAddressesProvider provider, ILendingPoolAddressesProvider provider,
uint256 baseVariableBorrowRate, uint256 baseVariableBorrowRate,
uint256 variableRateSlope1, uint256 variableRateSlope1,
uint256 variableRateSlope2, uint256 variableRateSlope2,
@ -66,10 +68,6 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
_stableRateSlope2 = stableRateSlope2; _stableRateSlope2 = stableRateSlope2;
} }
/**
* @dev accessors
*/
function variableRateSlope1() external view returns (uint256) { function variableRateSlope1() external view returns (uint256) {
return _variableRateSlope1; return _variableRateSlope1;
} }
@ -103,16 +101,14 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
} }
/** /**
* @dev calculates the interest rates depending on the available liquidity and the total borrowed. * @dev Calculates the interest rates depending on the reserve's state and configurations
* @param reserve the address of the reserve * @param reserve The address of the reserve
* @param availableLiquidity the liquidity available in the reserve * @param availableLiquidity The liquidity available in the reserve
* @param totalStableDebt the total borrowed from the reserve a stable rate * @param totalStableDebt The total borrowed from the reserve a stable rate
* @param totalVariableDebt the total borrowed from the reserve at a variable rate * @param totalVariableDebt The total borrowed from the reserve at a variable rate
* @param averageStableBorrowRate the weighted average of all the stable rate borrows * @param averageStableBorrowRate The weighted average of all the stable rate loans
* @param reserveFactor the reserve portion of the interest to redirect to the reserve treasury * @param reserveFactor The reserve portion of the interest that goes to the treasury of the market
* @return currentLiquidityRate the liquidity rate * @return The liquidity rate, the stable borrow rate and the variable borrow rate
* @return currentStableBorrowRate stable borrow rate
* @return currentVariableBorrowRate variable borrow rate
**/ **/
function calculateInterestRates( function calculateInterestRates(
address reserve, address reserve,
@ -184,12 +180,12 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
} }
/** /**
* @dev calculates the overall borrow rate as the weighted average between the total variable borrows and total stable borrows. * @dev Calculates the overall borrow rate as the weighted average between the total variable borrows and total stable borrows
* @param totalStableDebt the total borrowed from the reserve a stable rate * @param totalStableDebt The total borrowed from the reserve a stable rate
* @param totalVariableDebt the total borrowed from the reserve at a variable rate * @param totalVariableDebt The total borrowed from the reserve at a variable rate
* @param currentVariableBorrowRate the current variable borrow rate * @param currentVariableBorrowRate The current variable borrow rate of the reserve
* @param currentAverageStableBorrowRate the weighted average of all the stable rate borrows * @param currentAverageStableBorrowRate The current weighted average of all the stable rate loans
* @return the weighted averaged borrow rate * @return The weighted averaged borrow rate
**/ **/
function _getOverallBorrowRate( function _getOverallBorrowRate(
uint256 totalStableDebt, uint256 totalStableDebt,