Verified contractExactagpl-3.0
DefaultReserveInterestRateStrategy
Address0xec2416bf49ee3cf57eb2cb6b55061e9c9d691390
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.6.12
- Same code
46 more contracts
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- istanbul
- License
- agpl-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 18,028,810
- Creation transaction
- 0x5b154914b2…5f02ec3471
- Main copy (most transactions)
- 0x025d9d36…73170947
113 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.solmain9.81 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.7 KB
- contracts/adapters/BaseParaSwapAdapter.sol4.1 KB
- contracts/adapters/BaseParaSwapSellAdapter.sol4.63 KB
- contracts/adapters/BaseUniswapAdapter.sol19.28 KB
- contracts/adapters/FlashLiquidationAdapter.sol7.73 KB
- contracts/adapters/ParaSwapLiquiditySwapAdapter.sol8.46 KB
- contracts/adapters/UniswapLiquiditySwapAdapter.sol10.99 KB
- contracts/adapters/UniswapRepayAdapter.sol9.94 KB
- contracts/adapters/interfaces/IBaseUniswapAdapter.sol2.73 KB
- contracts/dependencies/openzeppelin/contracts/Address.sol2.53 KB
- contracts/dependencies/openzeppelin/contracts/Context.sol912 B
- contracts/dependencies/openzeppelin/contracts/ERC20.sol10.36 KB
- contracts/dependencies/openzeppelin/contracts/IERC20.sol2.59 KB
- contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol310 B
- contracts/dependencies/openzeppelin/contracts/Ownable.sol2.11 KB
- contracts/dependencies/openzeppelin/contracts/ReentrancyGuard.sol2.61 KB
- contracts/dependencies/openzeppelin/contracts/SafeERC20.sol2.03 KB
- contracts/dependencies/openzeppelin/contracts/SafeMath.sol4.97 KB
- contracts/dependencies/openzeppelin/upgradeability/AdminUpgradeabilityProxy.sol1.4 KB
- contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol3.85 KB
- contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol1.96 KB
- contracts/dependencies/openzeppelin/upgradeability/InitializableAdminUpgradeabilityProxy.sol1.57 KB
- contracts/dependencies/openzeppelin/upgradeability/InitializableUpgradeabilityProxy.sol1.23 KB
- contracts/dependencies/openzeppelin/upgradeability/Proxy.sol2.19 KB
- contracts/dependencies/openzeppelin/upgradeability/UpgradeabilityProxy.sol1.15 KB
- contracts/deployments/ATokensAndRatesHelper.sol2.74 KB
- contracts/deployments/StableAndVariableTokensHelper.sol1.87 KB
- contracts/deployments/StringLib.sol223 B
- contracts/flashloan/base/FlashLoanReceiverBase.sol962 B
- contracts/flashloan/interfaces/IFlashLoanReceiver.sol830 B
- contracts/interfaces/IAToken.sol3.89 KB
- contracts/interfaces/IAaveIncentivesController.sol4.64 KB
- contracts/interfaces/IChainlinkAggregator.sol640 B
- contracts/interfaces/IChefIncentivesController.sol414 B
- contracts/interfaces/ICreditDelegationToken.sol970 B
- contracts/interfaces/IDelegationToken.sol273 B
- contracts/interfaces/IERC20WithPermit.sol334 B
- contracts/interfaces/IExchangeAdapter.sol512 B
- contracts/interfaces/IInitializableAToken.sol2 KB
- contracts/interfaces/IInitializableDebtToken.sol1.89 KB
- contracts/interfaces/ILendingPool.sol17.36 KB
- contracts/interfaces/ILendingPoolAddressesProvider.sol2.26 KB
- contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol998 B
- contracts/interfaces/ILendingPoolCollateralManager.sol2.21 KB
- contracts/interfaces/ILendingPoolConfigurator.sol5.92 KB
- contracts/interfaces/ILendingRateOracle.sol588 B
- contracts/interfaces/IMultiFeeDistribution.sol394 B
- contracts/interfaces/IParaSwapAugustus.sol196 B
- contracts/interfaces/IParaSwapAugustusRegistry.sol211 B
- contracts/interfaces/IPriceOracle.sol443 B
- contracts/interfaces/IPriceOracleGetter.sol402 B
- contracts/interfaces/IReserveInterestRateStrategy.sol1.09 KB
- contracts/interfaces/IScaledBalanceToken.sol1.02 KB
- contracts/interfaces/IStableDebtToken.sol4.37 KB
- contracts/interfaces/IUniswapV2Router02.sol758 B
- contracts/interfaces/IVariableDebtToken.sol2.11 KB
- contracts/misc/AaveOracle.sol5.15 KB
- contracts/misc/AaveProtocolDataProvider.sol6.51 KB
- contracts/misc/UiIncentiveDataProviderV2.sol12.4 KB
- contracts/misc/UiIncentiveDataProviderV2V3.sol14.68 KB
- contracts/misc/UiPoolDataProvider.sol15.8 KB
- contracts/misc/UiPoolDataProviderV2.sol9.3 KB
- contracts/misc/UiPoolDataProviderV2V3.sol9.38 KB
- contracts/misc/WETHGateway.sol6.8 KB
- contracts/misc/WalletBalanceProvider.sol3.95 KB
- contracts/misc/interfaces/IAaveOracle.sol484 B
- contracts/misc/interfaces/IERC20DetailedBytes.sol342 B
- contracts/misc/interfaces/IUiIncentiveDataProviderV2.sol1.75 KB
- contracts/misc/interfaces/IUiIncentiveDataProviderV3.sol2.14 KB
- contracts/misc/interfaces/IUiPoolDataProvider.sol3.18 KB
- contracts/misc/interfaces/IUiPoolDataProviderV2.sol2.26 KB
- contracts/misc/interfaces/IUiPoolDataProviderV3.sol2.71 KB
- contracts/misc/interfaces/IWETH.sol337 B
- contracts/misc/interfaces/IWETHGateway.sol583 B
- contracts/mocks/flashloan/MockFlashLoanReceiver.sol2.57 KB
- contracts/mocks/oracle/LendingRateOracle.sol877 B
- contracts/mocks/oracle/PriceOracle.sol882 B
- contracts/mocks/swap/MockParaSwapAugustus.sol2.1 KB
- contracts/mocks/swap/MockParaSwapAugustusRegistry.sol482 B
- contracts/mocks/swap/MockParaSwapTokenTransferProxy.sol484 B
- contracts/mocks/swap/MockUniswapV2Router02.sol3.18 KB
- contracts/mocks/tokens/MintableDelegationERC20.sol793 B
- contracts/mocks/tokens/MintableERC20.sol659 B
- contracts/mocks/upgradeability/MockAToken.sol402 B
- contracts/mocks/upgradeability/MockStableDebtToken.sol284 B
- contracts/mocks/upgradeability/MockVariableDebtToken.sol292 B
- contracts/protocol/configuration/LendingPoolAddressesProvider.sol8.1 KB
- contracts/protocol/configuration/LendingPoolAddressesProviderRegistry.sol3.22 KB
- contracts/protocol/lendingpool/LendingPool.sol32.46 KB
- contracts/protocol/lendingpool/LendingPoolCollateralManager.sol12.33 KB
- contracts/protocol/lendingpool/LendingPoolConfigurator.sol16.69 KB
- contracts/protocol/lendingpool/LendingPoolStorage.sol1.22 KB
- contracts/protocol/libraries/aave-upgradeability/BaseImmutableAdminUpgradeabilityProxy.sol2.54 KB
- contracts/protocol/libraries/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol795 B
- contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol2.48 KB
- contracts/protocol/libraries/configuration/ReserveConfiguration.sol12.11 KB
- contracts/protocol/libraries/configuration/UserConfiguration.sol4.05 KB
- contracts/protocol/libraries/helpers/Errors.sol8.93 KB
- contracts/protocol/libraries/helpers/Helpers.sol1.06 KB
- contracts/protocol/libraries/logic/GenericLogic.sol9.51 KB
- contracts/protocol/libraries/logic/ReserveLogic.sol13.84 KB
- contracts/protocol/libraries/logic/ValidationLogic.sol17.43 KB
- contracts/protocol/libraries/math/MathUtils.sol3.07 KB
- contracts/protocol/libraries/math/PercentageMath.sol1.81 KB
- contracts/protocol/libraries/math/WadRayMath.sol3.38 KB
- contracts/protocol/libraries/types/DataTypes.sol1.53 KB
- contracts/protocol/tokenization/AToken.sol13.15 KB
- contracts/protocol/tokenization/DelegationAwareAToken.sol1.03 KB
- contracts/protocol/tokenization/IncentivizedERC20.sol8.48 KB
- contracts/protocol/tokenization/StableDebtToken.sol13.87 KB
- contracts/protocol/tokenization/VariableDebtToken.sol6.72 KB
- contracts/protocol/tokenization/base/DebtTokenBase.sol3.88 KB
contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
/**
* @title DefaultReserveInterestRateStrategy contract
* @notice Implements the calculation of the interest rates depending on the reserve state
* @dev The model of interest rate is based on 2 slopes, one before the `OPTIMAL_UTILIZATION_RATE`
* 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
**/
contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
using WadRayMath for uint256;
using SafeMath for uint256;
using PercentageMath for uint256;
/**
* @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates.
* Expressed in ray
**/
uint256 public immutable OPTIMAL_UTILIZATION_RATE;
/**
* @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.
* Expressed in ray
**/
uint256 public immutable EXCESS_UTILIZATION_RATE;
ILendingPoolAddressesProvider public immutable addressesProvider;
// Base variable borrow rate when Utilization rate = 0. Expressed in ray
uint256 internal immutable _baseVariableBorrowRate;
// Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _variableRateSlope1;
// Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _variableRateSlope2;
// Slope of the stable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _stableRateSlope1;
// Slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _stableRateSlope2;
constructor(
ILendingPoolAddressesProvider provider,
uint256 optimalUtilizationRate,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2,
uint256 stableRateSlope1,
uint256 stableRateSlope2
) public {
OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate;
EXCESS_UTILIZATION_RATE = WadRayMath.ray().sub(optimalUtilizationRate);
addressesProvider = provider;
_baseVariableBorrowRate = baseVariableBorrowRate;
_variableRateSlope1 = variableRateSlope1;
_variableRateSlope2 = variableRateSlope2;
_stableRateSlope1 = stableRateSlope1;
_stableRateSlope2 = stableRateSlope2;
}
function variableRateSlope1() external view returns (uint256) {
return _variableRateSlope1;
}
function variableRateSlope2() external view returns (uint256) {
return _variableRateSlope2;
}
function stableRateSlope1() external view returns (uint256) {
return _stableRateSlope1;
}
function stableRateSlope2() external view returns (uint256) {
return _stableRateSlope2;
}
function baseVariableBorrowRate() external view override returns (uint256) {
return _baseVariableBorrowRate;
}
function getMaxVariableBorrowRate() external view override returns (uint256) {
return _baseVariableBorrowRate.add(_variableRateSlope1).add(_variableRateSlope2);
}
/**
* @dev Calculates the interest rates depending on the reserve's state and configurations
* @param reserve The address of the reserve
* @param liquidityAdded The liquidity added during the operation
* @param liquidityTaken The liquidity taken during the operation
* @param totalStableDebt The total borrowed from the reserve a stable rate
* @param totalVariableDebt The total borrowed from the reserve at a variable rate
* @param averageStableBorrowRate The weighted average of all the stable rate loans
* @param reserveFactor The reserve portion of the interest that goes to the treasury of the market
* @return The liquidity rate, the stable borrow rate and the variable borrow rate
**/
function calculateInterestRates(
address reserve,
address aToken,
uint256 liquidityAdded,
uint256 liquidityTaken,
uint256 totalStableDebt,
uint256 totalVariableDebt,
uint256 averageStableBorrowRate,
uint256 reserveFactor
)
external
view
override
returns (
uint256,
uint256,
uint256
)
{
uint256 availableLiquidity = IERC20(reserve).balanceOf(aToken);
//avoid stack too deep
availableLiquidity = availableLiquidity.add(liquidityAdded).sub(liquidityTaken);
return
calculateInterestRates(
reserve,
availableLiquidity,
totalStableDebt,
totalVariableDebt,
averageStableBorrowRate,
reserveFactor
);
}
struct CalcInterestRatesLocalVars {
uint256 totalDebt;
uint256 currentVariableBorrowRate;
uint256 currentStableBorrowRate;
uint256 currentLiquidityRate;
uint256 utilizationRate;
}
/**
* @dev Calculates the interest rates depending on the reserve's state and configurations.
* NOTE This function is kept for compatibility with the previous DefaultInterestRateStrategy interface.
* New protocol implementation uses the new calculateInterestRates() interface
* @param reserve The address of the reserve
* @param availableLiquidity The liquidity available in the corresponding aToken
* @param totalStableDebt The total borrowed from the reserve a stable rate
* @param totalVariableDebt The total borrowed from the reserve at a variable rate
* @param averageStableBorrowRate The weighted average of all the stable rate loans
* @param reserveFactor The reserve portion of the interest that goes to the treasury of the market
* @return The liquidity rate, the stable borrow rate and the variable borrow rate
**/
function calculateInterestRates(
address reserve,
uint256 availableLiquidity,
uint256 totalStableDebt,
uint256 totalVariableDebt,
uint256 averageStableBorrowRate,
uint256 reserveFactor
)
public
view
override
returns (
uint256,
uint256,
uint256
)
{
CalcInterestRatesLocalVars memory vars;
vars.totalDebt = totalStableDebt.add(totalVariableDebt);
vars.currentVariableBorrowRate = 0;
vars.currentStableBorrowRate = 0;
vars.currentLiquidityRate = 0;
vars.utilizationRate = vars.totalDebt == 0
? 0
: vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt));
vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle())
.getMarketBorrowRate(reserve);
if (vars.utilizationRate > OPTIMAL_UTILIZATION_RATE) {
uint256 excessUtilizationRateRatio =
vars.utilizationRate.sub(OPTIMAL_UTILIZATION_RATE).rayDiv(EXCESS_UTILIZATION_RATE);
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(_stableRateSlope1).add(
_stableRateSlope2.rayMul(excessUtilizationRateRatio)
);
vars.currentVariableBorrowRate = _baseVariableBorrowRate.add(_variableRateSlope1).add(
_variableRateSlope2.rayMul(excessUtilizationRateRatio)
);
} else {
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(
_stableRateSlope1.rayMul(vars.utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))
);
vars.currentVariableBorrowRate = _baseVariableBorrowRate.add(
vars.utilizationRate.rayMul(_variableRateSlope1).rayDiv(OPTIMAL_UTILIZATION_RATE)
);
}
vars.currentLiquidityRate = _getOverallBorrowRate(
totalStableDebt,
totalVariableDebt,
vars
.currentVariableBorrowRate,
averageStableBorrowRate
)
.rayMul(vars.utilizationRate)
.percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor));
return (
vars.currentLiquidityRate,
vars.currentStableBorrowRate,
vars.currentVariableBorrowRate
);
}
/**
* @dev Calculates the overall borrow rate as the weighted average between the total variable debt and total stable debt
* @param totalStableDebt The total borrowed from the reserve a stable rate
* @param totalVariableDebt The total borrowed from the reserve at a variable rate
* @param currentVariableBorrowRate The current variable borrow rate of the reserve
* @param currentAverageStableBorrowRate The current weighted average of all the stable rate loans
* @return The weighted averaged borrow rate
**/
function _getOverallBorrowRate(
uint256 totalStableDebt,
uint256 totalVariableDebt,
uint256 currentVariableBorrowRate,
uint256 currentAverageStableBorrowRate
) internal pure returns (uint256) {
uint256 totalDebt = totalStableDebt.add(totalVariableDebt);
if (totalDebt == 0) return 0;
uint256 weightedVariableRate = totalVariableDebt.wadToRay().rayMul(currentVariableBorrowRate);
uint256 weightedStableRate = totalStableDebt.wadToRay().rayMul(currentAverageStableBorrowRate);
uint256 overallBorrowRate =
weightedVariableRate.add(weightedStableRate).rayDiv(totalDebt.wadToRay());
return overallBorrowRate;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.