2020-05-29 16:45:37 +00:00
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^ 0 . 6 . 8 ;
2020-07-23 15:18:06 +00:00
pragma experimental ABIEncoderV2 ;
2020-05-29 16:45:37 +00:00
2020-06-20 23:40:03 +00:00
import ' @openzeppelin/contracts/math/SafeMath.sol ' ;
2020-05-29 16:45:37 +00:00
2020-06-20 23:40:03 +00:00
import ' ../libraries/openzeppelin-upgradeability/VersionedInitializable.sol ' ;
2020-07-23 15:18:06 +00:00
import ' ../libraries/ReserveConfiguration.sol ' ;
2020-06-20 23:40:03 +00:00
import ' ../configuration/LendingPoolAddressesProvider.sol ' ;
2020-08-07 16:23:52 +00:00
import ' ../libraries/openzeppelin-upgradeability/InitializableAdminUpgradeabilityProxy.sol ' ;
import { LendingPool } from ' ./LendingPool.sol ' ;
import { IERC20Detailed } from ' ../interfaces/IERC20Detailed.sol ' ;
2020-05-29 16:45:37 +00:00
/**
2020-06-20 23:40:03 +00:00
* @ title LendingPoolConfigurator contract
* @ author Aave
2020-07-27 08:03:53 +00:00
* @ notice Executes configuration methods on the LendingPoolCore contract . Allows to enable / disable reserves
* and set different protocol parameters .
2020-06-20 23:40:03 +00:00
** /
2020-05-29 16:45:37 +00:00
contract LendingPoolConfigurator is VersionedInitializable {
2020-06-20 23:40:03 +00:00
using SafeMath for uint256 ;
2020-07-23 15:18:06 +00:00
using ReserveConfiguration for ReserveConfiguration . Map ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is initialized .
* @ param _reserve the address of the reserve
* @ param _aToken the address of the overlying aToken contract
* @ param _interestRateStrategyAddress the address of the interest rate strategy for the reserve
** /
event ReserveInitialized (
address indexed _reserve ,
address indexed _aToken ,
address _interestRateStrategyAddress
) ;
2020-07-13 08:54:08 +00:00
/**
2020-06-20 23:40:03 +00:00
* @ dev emitted when borrowing is enabled on a reserve
* @ param _reserve the address of the reserve
* @ param _stableRateEnabled true if stable rate borrowing is enabled , false otherwise
** /
event BorrowingEnabledOnReserve ( address _reserve , bool _stableRateEnabled ) ;
/**
* @ dev emitted when borrowing is disabled on a reserve
* @ param _reserve the address of the reserve
** /
event BorrowingDisabledOnReserve ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve is enabled as collateral .
* @ param _reserve the address of the reserve
* @ param _ltv the loan to value of the asset when used as collateral
* @ param _liquidationThreshold the threshold at which loans using this asset as collateral will be considered undercollateralized
* @ param _liquidationBonus the bonus liquidators receive to liquidate this asset
** /
event ReserveEnabledAsCollateral (
address indexed _reserve ,
uint256 _ltv ,
uint256 _liquidationThreshold ,
uint256 _liquidationBonus
) ;
/**
* @ dev emitted when a reserve is disabled as collateral
* @ param _reserve the address of the reserve
** /
event ReserveDisabledAsCollateral ( address indexed _reserve ) ;
/**
* @ dev emitted when stable rate borrowing is enabled on a reserve
* @ param _reserve the address of the reserve
** /
event StableRateEnabledOnReserve ( address indexed _reserve ) ;
/**
* @ dev emitted when stable rate borrowing is disabled on a reserve
* @ param _reserve the address of the reserve
** /
event StableRateDisabledOnReserve ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve is activated
* @ param _reserve the address of the reserve
** /
event ReserveActivated ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve is deactivated
* @ param _reserve the address of the reserve
** /
event ReserveDeactivated ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve is freezed
* @ param _reserve the address of the reserve
** /
event ReserveFreezed ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve is unfreezed
* @ param _reserve the address of the reserve
** /
event ReserveUnfreezed ( address indexed _reserve ) ;
/**
* @ dev emitted when a reserve loan to value is updated
* @ param _reserve the address of the reserve
* @ param _ltv the new value for the loan to value
** /
event ReserveBaseLtvChanged ( address _reserve , uint256 _ltv ) ;
/**
* @ dev emitted when a reserve liquidation threshold is updated
* @ param _reserve the address of the reserve
* @ param _threshold the new value for the liquidation threshold
** /
event ReserveLiquidationThresholdChanged ( address _reserve , uint256 _threshold ) ;
/**
* @ dev emitted when a reserve liquidation bonus is updated
* @ param _reserve the address of the reserve
* @ param _bonus the new value for the liquidation bonus
** /
event ReserveLiquidationBonusChanged ( address _reserve , uint256 _bonus ) ;
/**
* @ dev emitted when the reserve decimals are updated
* @ param _reserve the address of the reserve
* @ param _decimals the new decimals
** /
event ReserveDecimalsChanged ( address _reserve , uint256 _decimals ) ;
/**
* @ dev emitted when a reserve interest strategy contract is updated
* @ param _reserve the address of the reserve
* @ param _strategy the new address of the interest strategy contract
** /
event ReserveInterestRateStrategyChanged ( address _reserve , address _strategy ) ;
LendingPoolAddressesProvider public poolAddressesProvider ;
2020-07-23 15:18:06 +00:00
LendingPool public pool ;
2020-06-20 23:40:03 +00:00
/**
* @ dev only the lending pool manager can call functions affected by this modifier
** /
modifier onlyLendingPoolManager {
require (
poolAddressesProvider . getLendingPoolManager ( ) == msg . sender ,
' The caller must be a lending pool manager '
2020-05-29 16:45:37 +00:00
) ;
2020-06-20 23:40:03 +00:00
_ ;
}
uint256 public constant CONFIGURATOR_REVISION = 0x3 ;
function getRevision ( ) internal override pure returns ( uint256 ) {
return CONFIGURATOR_REVISION ;
}
function initialize ( LendingPoolAddressesProvider _poolAddressesProvider ) public initializer {
poolAddressesProvider = _poolAddressesProvider ;
2020-07-23 15:18:06 +00:00
pool = LendingPool ( payable ( poolAddressesProvider . getLendingPool ( ) ) ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev initializes a reserve
* @ param _reserve the address of the reserve to be initialized
* @ param _underlyingAssetDecimals the decimals of the reserve underlying asset
* @ param _interestRateStrategyAddress the address of the interest rate strategy contract for this reserve
** /
function initReserve (
address _reserve ,
uint8 _underlyingAssetDecimals ,
2020-08-07 16:23:52 +00:00
address _aTokenInstance ,
2020-06-30 12:09:28 +00:00
address _interestRateStrategyAddress ,
address _stableDebtTokenAddress ,
address _variableDebtTokenAddress
2020-06-20 23:40:03 +00:00
) external onlyLendingPoolManager {
initReserveWithData (
_reserve ,
2020-08-07 16:23:52 +00:00
_aTokenInstance ,
2020-06-30 12:09:28 +00:00
_stableDebtTokenAddress ,
_variableDebtTokenAddress ,
2020-06-20 23:40:03 +00:00
_underlyingAssetDecimals ,
_interestRateStrategyAddress
2020-05-29 16:45:37 +00:00
) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev initializes a reserve using aTokenData provided externally ( useful if the underlying ERC20 contract doesn ' t expose name or decimals)
* @ param _reserve the address of the reserve to be initialized
2020-08-07 16:23:52 +00:00
* @ param _aTokenInstance the name of the aToken contract
2020-06-20 23:40:03 +00:00
* @ param _underlyingAssetDecimals the decimals of the reserve underlying asset
* @ param _interestRateStrategyAddress the address of the interest rate strategy contract for this reserve
** /
function initReserveWithData (
address _reserve ,
2020-08-07 16:23:52 +00:00
address _aTokenInstance ,
2020-06-30 12:09:28 +00:00
address _stableDebtTokenAddress ,
address _variableDebtTokenAddress ,
2020-06-20 23:40:03 +00:00
uint8 _underlyingAssetDecimals ,
address _interestRateStrategyAddress
) public onlyLendingPoolManager {
2020-08-07 16:23:52 +00:00
InitializableAdminUpgradeabilityProxy aTokenProxy = new InitializableAdminUpgradeabilityProxy ( ) ;
bytes memory params = abi . encodeWithSignature (
' initialize(address,address,uint8,string,string) ' ,
address ( poolAddressesProvider ) ,
2020-06-20 23:40:03 +00:00
_reserve ,
_underlyingAssetDecimals ,
2020-08-07 16:23:52 +00:00
IERC20Detailed ( _aTokenInstance ) . name ( ) ,
IERC20Detailed ( _aTokenInstance ) . symbol ( )
2020-06-20 23:40:03 +00:00
) ;
2020-06-30 12:09:28 +00:00
2020-08-07 16:23:52 +00:00
aTokenProxy . initialize ( _aTokenInstance , address ( this ) , params ) ;
2020-07-23 15:18:06 +00:00
pool . initReserve (
2020-06-20 23:40:03 +00:00
_reserve ,
2020-08-07 16:23:52 +00:00
address ( aTokenProxy ) ,
2020-06-30 12:09:28 +00:00
_stableDebtTokenAddress ,
_variableDebtTokenAddress ,
2020-06-20 23:40:03 +00:00
_interestRateStrategyAddress
2020-05-29 16:45:37 +00:00
) ;
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setDecimals ( _underlyingAssetDecimals ) ;
currentConfig . setActive ( true ) ;
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( false ) ;
2020-07-23 15:18:06 +00:00
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-08-07 16:23:52 +00:00
emit ReserveInitialized ( _reserve , address ( aTokenProxy ) , _interestRateStrategyAddress ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev enables borrowing on a reserve
* @ param _reserve the address of the reserve
* @ param _stableBorrowRateEnabled true if stable borrow rate needs to be enabled by default on this reserve
** /
function enableBorrowingOnReserve ( address _reserve , bool _stableBorrowRateEnabled )
external
onlyLendingPoolManager
{
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setBorrowingEnabled ( true ) ;
currentConfig . setStableRateBorrowingEnabled ( _stableBorrowRateEnabled ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit BorrowingEnabledOnReserve ( _reserve , _stableBorrowRateEnabled ) ;
}
/**
* @ dev disables borrowing on a reserve
* @ param _reserve the address of the reserve
** /
function disableBorrowingOnReserve ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setBorrowingEnabled ( false ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit BorrowingDisabledOnReserve ( _reserve ) ;
}
/**
* @ dev enables a reserve to be used as collateral
* @ param _reserve the address of the reserve
* @ param _baseLTVasCollateral the loan to value of the asset when used as collateral
* @ param _liquidationThreshold the threshold at which loans using this asset as collateral will be considered undercollateralized
* @ param _liquidationBonus the bonus liquidators receive to liquidate this asset
** /
function enableReserveAsCollateral (
address _reserve ,
uint256 _baseLTVasCollateral ,
uint256 _liquidationThreshold ,
uint256 _liquidationBonus
) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setLtv ( _baseLTVasCollateral ) ;
currentConfig . setLiquidationThreshold ( _liquidationThreshold ) ;
currentConfig . setLiquidationBonus ( _liquidationBonus ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveEnabledAsCollateral (
_reserve ,
_baseLTVasCollateral ,
_liquidationThreshold ,
_liquidationBonus
) ;
}
/**
* @ dev disables a reserve as collateral
* @ param _reserve the address of the reserve
** /
function disableReserveAsCollateral ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setLtv ( 0 ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveDisabledAsCollateral ( _reserve ) ;
}
/**
* @ dev enable stable rate borrowing on a reserve
* @ param _reserve the address of the reserve
** /
function enableReserveStableRate ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setStableRateBorrowingEnabled ( true ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit StableRateEnabledOnReserve ( _reserve ) ;
}
/**
* @ dev disable stable rate borrowing on a reserve
* @ param _reserve the address of the reserve
** /
2020-06-27 02:13:32 +00:00
function disableReserveStableRate ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setStableRateBorrowingEnabled ( false ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit StableRateDisabledOnReserve ( _reserve ) ;
}
/**
* @ dev activates a reserve
* @ param _reserve the address of the reserve
** /
function activateReserve ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setActive ( true ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveActivated ( _reserve ) ;
}
/**
* @ dev deactivates a reserve
* @ param _reserve the address of the reserve
** /
function deactivateReserve ( address _reserve ) external onlyLendingPoolManager {
(
uint256 availableLiquidity ,
uint256 totalBorrowsStable ,
uint256 totalBorrowsVariable ,
,
,
,
,
,
,
) = pool . getReserveData ( _reserve ) ;
require (
availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0 ,
' The liquidity of the reserve needs to be 0 '
) ;
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setActive ( false ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveDeactivated ( _reserve ) ;
}
/**
* @ dev freezes a reserve . A freezed reserve doesn ' t accept any new deposit, borrow or rate swap, but can accept repayments, liquidations, rate rebalances and redeems
* @ param _reserve the address of the reserve
** /
function freezeReserve ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( true ) ;
2020-07-23 15:18:06 +00:00
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveFreezed ( _reserve ) ;
}
/**
* @ dev unfreezes a reserve
* @ param _reserve the address of the reserve
** /
function unfreezeReserve ( address _reserve ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( false ) ;
2020-07-23 15:18:06 +00:00
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveUnfreezed ( _reserve ) ;
}
/**
* @ dev emitted when a reserve loan to value is updated
* @ param _reserve the address of the reserve
* @ param _ltv the new value for the loan to value
** /
2020-07-23 15:18:06 +00:00
function setLtv ( address _reserve , uint256 _ltv ) external onlyLendingPoolManager {
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setLtv ( _ltv ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveBaseLtvChanged ( _reserve , _ltv ) ;
}
/**
* @ dev updates the liquidation threshold of a reserve .
* @ param _reserve the address of the reserve
* @ param _threshold the new value for the liquidation threshold
** /
2020-07-23 15:18:06 +00:00
function setLiquidationThreshold ( address _reserve , uint256 _threshold )
2020-06-20 23:40:03 +00:00
external
onlyLendingPoolManager
{
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setLiquidationThreshold ( _threshold ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveLiquidationThresholdChanged ( _reserve , _threshold ) ;
}
/**
* @ dev updates the liquidation bonus of a reserve
* @ param _reserve the address of the reserve
* @ param _bonus the new value for the liquidation bonus
** /
2020-07-23 15:18:06 +00:00
function setLiquidationBonus ( address _reserve , uint256 _bonus ) external onlyLendingPoolManager {
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setLiquidationBonus ( _bonus ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveLiquidationBonusChanged ( _reserve , _bonus ) ;
}
/**
* @ dev updates the reserve decimals
* @ param _reserve the address of the reserve
* @ param _decimals the new number of decimals
** /
function setReserveDecimals ( address _reserve , uint256 _decimals ) external onlyLendingPoolManager {
2020-07-23 15:18:06 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( _reserve ) ;
currentConfig . setDecimals ( _decimals ) ;
pool . setConfiguration ( _reserve , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
emit ReserveDecimalsChanged ( _reserve , _decimals ) ;
}
/**
* @ dev sets the interest rate strategy of a reserve
* @ param _reserve the address of the reserve
* @ param _rateStrategyAddress the new address of the interest strategy contract
** /
function setReserveInterestRateStrategyAddress ( address _reserve , address _rateStrategyAddress )
external
onlyLendingPoolManager
{
pool . setReserveInterestRateStrategyAddress ( _reserve , _rateStrategyAddress ) ;
emit ReserveInterestRateStrategyChanged ( _reserve , _rateStrategyAddress ) ;
}
2020-05-29 16:45:37 +00:00
}