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-10-15 13:25:27 +00:00
import { SafeMath } from ' ../dependencies/openzeppelin/contracts/SafeMath.sol ' ;
2020-10-15 13:16:05 +00:00
import { VersionedInitializable } from ' ../libraries/aave-upgradeability/VersionedInitializable.sol ' ;
2020-08-20 07:51:21 +00:00
import {
2020-10-14 11:55:38 +00:00
InitializableImmutableAdminUpgradeabilityProxy
} from ' ../libraries/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol ' ;
2020-08-20 07:51:21 +00:00
import { ReserveConfiguration } from ' ../libraries/configuration/ReserveConfiguration.sol ' ;
2020-08-21 12:03:17 +00:00
import { ILendingPoolAddressesProvider } from ' ../interfaces/ILendingPoolAddressesProvider.sol ' ;
2020-08-20 12:32:20 +00:00
import { ILendingPool } from ' ../interfaces/ILendingPool.sol ' ;
2020-10-19 16:29:32 +00:00
import { ITokenConfiguration } from ' ../tokenization/interfaces/ITokenConfiguration.sol ' ;
2020-10-15 13:25:27 +00:00
import { IERC20Detailed } from ' ../dependencies/openzeppelin/contracts/IERC20Detailed.sol ' ;
2020-09-02 15:54:34 +00:00
import { Errors } from ' ../libraries/helpers/Errors.sol ' ;
2020-10-09 15:59:10 +00:00
import { ReserveLogic } from ' ../libraries/logic/ReserveLogic.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 .
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param aToken the address of the overlying aToken contract
* @ param stableDebtToken the address of the associated stable rate debt token
* @ param variableDebtToken the address of the associated variable rate debt token
* @ param interestRateStrategyAddress the address of the interest rate strategy for the reserve
2020-06-20 23:40:03 +00:00
** /
event ReserveInitialized (
2020-08-21 12:03:17 +00:00
address indexed asset ,
address indexed aToken ,
address stableDebtToken ,
address variableDebtToken ,
address interestRateStrategyAddress
2020-06-20 23:40:03 +00:00
) ;
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
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param stableRateEnabled true if stable rate borrowing is enabled , false otherwise
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event BorrowingEnabledOnReserve ( address asset , bool stableRateEnabled ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when borrowing is disabled on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event BorrowingDisabledOnReserve ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is enabled as collateral .
2020-08-21 12:03:17 +00:00
* @ param asset 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
2020-06-20 23:40:03 +00:00
** /
event ReserveEnabledAsCollateral (
2020-08-21 12:03:17 +00:00
address indexed asset ,
uint256 ltv ,
uint256 liquidationThreshold ,
uint256 liquidationBonus
2020-06-20 23:40:03 +00:00
) ;
/**
* @ dev emitted when a reserve is disabled as collateral
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveDisabledAsCollateral ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when stable rate borrowing is enabled on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event StableRateEnabledOnReserve ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when stable rate borrowing is disabled on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event StableRateDisabledOnReserve ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is activated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveActivated ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is deactivated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveDeactivated ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is freezed
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveFreezed ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve is unfreezed
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveUnfreezed ( address indexed asset ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve loan to value is updated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param ltv the new value for the loan to value
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveBaseLtvChanged ( address asset , uint256 ltv ) ;
2020-06-20 23:40:03 +00:00
2020-09-10 11:26:02 +00:00
/**
* @ dev emitted when a reserve factor is updated
* @ param asset the address of the reserve
* @ param factor the new reserve factor
** /
event ReserveFactorChanged ( address asset , uint256 factor ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve liquidation threshold is updated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param threshold the new value for the liquidation threshold
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveLiquidationThresholdChanged ( address asset , uint256 threshold ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve liquidation bonus is updated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param bonus the new value for the liquidation bonus
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveLiquidationBonusChanged ( address asset , uint256 bonus ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when the reserve decimals are updated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param decimals the new decimals
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveDecimalsChanged ( address asset , uint256 decimals ) ;
2020-06-20 23:40:03 +00:00
/**
* @ dev emitted when a reserve interest strategy contract is updated
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param strategy the new address of the interest strategy contract
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
event ReserveInterestRateStrategyChanged ( address asset , address strategy ) ;
2020-06-20 23:40:03 +00:00
2020-08-18 00:16:46 +00:00
/**
* @ dev emitted when an aToken implementation is upgraded
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param proxy the aToken proxy address
* @ param implementation the new aToken implementation
2020-08-18 00:16:46 +00:00
** /
2020-08-21 12:03:17 +00:00
event ATokenUpgraded ( address asset , address proxy , address implementation ) ;
2020-08-18 00:16:46 +00:00
2020-08-18 16:48:23 +00:00
/**
2020-08-18 00:16:46 +00:00
* @ dev emitted when the implementation of a stable debt token is upgraded
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param proxy the stable debt token proxy address
* @ param implementation the new aToken implementation
2020-08-18 00:16:46 +00:00
** /
2020-08-21 12:03:17 +00:00
event StableDebtTokenUpgraded ( address asset , address proxy , address implementation ) ;
2020-08-18 00:16:46 +00:00
2020-08-18 16:48:23 +00:00
/**
2020-08-18 00:16:46 +00:00
* @ dev emitted when the implementation of a variable debt token is upgraded
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-08-25 08:53:58 +00:00
* @ param proxy the variable debt token proxy address
* @ param implementation the new aToken implementation
2020-08-18 00:16:46 +00:00
** /
2020-08-25 08:53:58 +00:00
event VariableDebtTokenUpgraded ( address asset , address proxy , address implementation ) ;
2020-08-18 00:16:46 +00:00
2020-08-21 12:03:17 +00:00
ILendingPoolAddressesProvider internal addressesProvider ;
ILendingPool internal pool ;
2020-07-23 15:18:06 +00:00
2020-06-20 23:40:03 +00:00
/**
* @ dev only the lending pool manager can call functions affected by this modifier
** /
2020-09-16 12:09:42 +00:00
modifier onlyAaveAdmin {
require ( addressesProvider . getAaveAdmin ( ) == msg . sender , Errors . CALLER_NOT_AAVE_ADMIN ) ;
2020-06-20 23:40:03 +00:00
_ ;
}
uint256 public constant CONFIGURATOR_REVISION = 0x3 ;
function getRevision ( ) internal override pure returns ( uint256 ) {
return CONFIGURATOR_REVISION ;
}
2020-08-21 12:03:17 +00:00
function initialize ( ILendingPoolAddressesProvider provider ) public initializer {
addressesProvider = provider ;
pool = ILendingPool ( addressesProvider . getLendingPool ( ) ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev initializes a reserve
2020-08-21 12:03:17 +00:00
* @ param aTokenImpl the address of the aToken contract implementation
* @ param stableDebtTokenImpl the address of the stable debt token contract
* @ param variableDebtTokenImpl the address of the variable debt token contract
* @ param underlyingAssetDecimals the decimals of the reserve underlying asset
* @ param interestRateStrategyAddress the address of the interest rate strategy contract for this reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-08 17:21:23 +00:00
function initReserve (
2020-08-21 12:03:17 +00:00
address aTokenImpl ,
address stableDebtTokenImpl ,
address variableDebtTokenImpl ,
uint8 underlyingAssetDecimals ,
address interestRateStrategyAddress
2020-09-16 12:09:42 +00:00
) public onlyAaveAdmin {
2020-10-19 16:29:32 +00:00
address asset = ITokenConfiguration ( aTokenImpl ) . UNDERLYING_ASSET_ADDRESS ( ) ;
require (
address ( pool ) == ITokenConfiguration ( aTokenImpl ) . POOL ( ) ,
Errors . INVALID_ATOKEN_POOL_ADDRESS
) ;
require (
address ( pool ) == ITokenConfiguration ( stableDebtTokenImpl ) . POOL ( ) ,
Errors . INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
) ;
require (
address ( pool ) == ITokenConfiguration ( variableDebtTokenImpl ) . POOL ( ) ,
Errors . INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
) ;
require (
asset == ITokenConfiguration ( stableDebtTokenImpl ) . UNDERLYING_ASSET_ADDRESS ( ) ,
Errors . INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
) ;
require (
asset == ITokenConfiguration ( variableDebtTokenImpl ) . UNDERLYING_ASSET_ADDRESS ( ) ,
Errors . INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
) ;
2020-08-25 08:53:58 +00:00
address aTokenProxyAddress = _initTokenWithProxy ( aTokenImpl , underlyingAssetDecimals ) ;
2020-06-30 12:09:28 +00:00
2020-08-18 16:48:23 +00:00
address stableDebtTokenProxyAddress = _initTokenWithProxy (
2020-08-21 12:03:17 +00:00
stableDebtTokenImpl ,
underlyingAssetDecimals
2020-08-17 19:28:50 +00:00
) ;
2020-08-18 16:48:23 +00:00
address variableDebtTokenProxyAddress = _initTokenWithProxy (
2020-08-21 12:03:17 +00:00
variableDebtTokenImpl ,
underlyingAssetDecimals
2020-08-17 19:28:50 +00:00
) ;
2020-08-07 16:23:52 +00:00
2020-07-23 15:18:06 +00:00
pool . initReserve (
2020-08-21 12:03:17 +00:00
asset ,
2020-08-17 19:28:50 +00:00
aTokenProxyAddress ,
stableDebtTokenProxyAddress ,
variableDebtTokenProxyAddress ,
2020-08-21 12:03:17 +00:00
interestRateStrategyAddress
2020-05-29 16:45:37 +00:00
) ;
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setDecimals ( underlyingAssetDecimals ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setActive ( true ) ;
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( false ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-17 19:28:50 +00:00
emit ReserveInitialized (
2020-08-21 12:03:17 +00:00
asset ,
2020-08-17 19:28:50 +00:00
aTokenProxyAddress ,
stableDebtTokenProxyAddress ,
variableDebtTokenProxyAddress ,
2020-08-21 12:03:17 +00:00
interestRateStrategyAddress
2020-08-17 19:28:50 +00:00
) ;
2020-06-20 23:40:03 +00:00
}
2020-08-10 18:20:08 +00:00
/**
2020-08-21 12:03:17 +00:00
* @ dev updates the aToken implementation for the asset
* @ param asset the address of the reserve to be updated
* @ param implementation the address of the new aToken implementation
2020-08-10 18:20:08 +00:00
** /
2020-09-16 12:09:42 +00:00
function updateAToken ( address asset , address implementation ) external onlyAaveAdmin {
2020-10-09 15:59:10 +00:00
ReserveLogic . ReserveData memory reserveData = pool . getReserveData ( asset ) ;
2020-08-10 13:29:18 +00:00
2020-10-09 15:59:10 +00:00
_upgradeTokenImplementation ( asset , reserveData . aTokenAddress , implementation ) ;
2020-08-10 13:29:18 +00:00
2020-10-09 15:59:10 +00:00
emit ATokenUpgraded ( asset , reserveData . aTokenAddress , implementation ) ;
2020-08-18 00:16:46 +00:00
}
/**
2020-08-21 12:03:17 +00:00
* @ dev updates the stable debt token implementation for the asset
* @ param asset the address of the reserve to be updated
* @ param implementation the address of the new aToken implementation
2020-08-18 00:16:46 +00:00
** /
2020-09-16 12:09:42 +00:00
function updateStableDebtToken ( address asset , address implementation ) external onlyAaveAdmin {
2020-10-09 15:59:10 +00:00
ReserveLogic . ReserveData memory reserveData = pool . getReserveData ( asset ) ;
2020-08-18 00:16:46 +00:00
2020-10-09 15:59:10 +00:00
_upgradeTokenImplementation ( asset , reserveData . stableDebtTokenAddress , implementation ) ;
2020-08-10 13:29:18 +00:00
2020-10-09 15:59:10 +00:00
emit StableDebtTokenUpgraded ( asset , reserveData . stableDebtTokenAddress , implementation ) ;
2020-08-18 00:16:46 +00:00
}
2020-08-25 08:53:58 +00:00
2020-08-18 00:16:46 +00:00
/**
2020-08-21 12:03:17 +00:00
* @ dev updates the variable debt token implementation for the asset
* @ param asset the address of the reserve to be updated
* @ param implementation the address of the new aToken implementation
2020-08-18 00:16:46 +00:00
** /
2020-09-16 12:09:42 +00:00
function updateVariableDebtToken ( address asset , address implementation ) external onlyAaveAdmin {
2020-10-09 15:59:10 +00:00
ReserveLogic . ReserveData memory reserveData = pool . getReserveData ( asset ) ;
2020-08-18 00:16:46 +00:00
2020-10-09 15:59:10 +00:00
_upgradeTokenImplementation ( asset , reserveData . variableDebtTokenAddress , implementation ) ;
2020-08-18 00:16:46 +00:00
2020-10-09 15:59:10 +00:00
emit VariableDebtTokenUpgraded ( asset , reserveData . variableDebtTokenAddress , implementation ) ;
2020-08-10 13:29:18 +00:00
}
2020-06-20 23:40:03 +00:00
/**
* @ dev enables borrowing on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param stableBorrowRateEnabled true if stable borrow rate needs to be enabled by default on this reserve
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
function enableBorrowingOnReserve ( address asset , bool stableBorrowRateEnabled )
2020-06-20 23:40:03 +00:00
external
2020-09-16 12:09:42 +00:00
onlyAaveAdmin
2020-06-20 23:40:03 +00:00
{
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setBorrowingEnabled ( true ) ;
2020-08-21 12:03:17 +00:00
currentConfig . setStableRateBorrowingEnabled ( stableBorrowRateEnabled ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
emit BorrowingEnabledOnReserve ( asset , stableBorrowRateEnabled ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev disables borrowing on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function disableBorrowingOnReserve ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setBorrowingEnabled ( false ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
emit BorrowingDisabledOnReserve ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev enables a reserve to be used as collateral
2020-08-21 12:03:17 +00:00
* @ param asset 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
2020-06-20 23:40:03 +00:00
** /
function enableReserveAsCollateral (
2020-08-21 12:03:17 +00:00
address asset ,
uint256 ltv ,
uint256 liquidationThreshold ,
uint256 liquidationBonus
2020-09-16 12:09:42 +00:00
) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setLtv ( ltv ) ;
currentConfig . setLiquidationThreshold ( liquidationThreshold ) ;
currentConfig . setLiquidationBonus ( liquidationBonus ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-25 08:53:58 +00:00
emit ReserveEnabledAsCollateral ( asset , ltv , liquidationThreshold , liquidationBonus ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev disables a reserve as collateral
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function disableReserveAsCollateral ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setLtv ( 0 ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveDisabledAsCollateral ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev enable stable rate borrowing on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function enableReserveStableRate ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setStableRateBorrowingEnabled ( true ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit StableRateEnabledOnReserve ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev disable stable rate borrowing on a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function disableReserveStableRate ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setStableRateBorrowingEnabled ( false ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit StableRateDisabledOnReserve ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev activates a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function activateReserve ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setActive ( true ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveActivated ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev deactivates a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function deactivateReserve ( address asset ) external onlyAaveAdmin {
2020-10-09 15:59:10 +00:00
ReserveLogic . ReserveData memory reserveData = pool . getReserveData ( asset ) ;
2020-10-14 12:24:01 +00:00
uint256 availableLiquidity = IERC20Detailed ( asset ) . balanceOf ( reserveData . aTokenAddress ) ;
2020-10-09 15:59:10 +00:00
2020-06-20 23:40:03 +00:00
require (
2020-10-14 12:24:01 +00:00
availableLiquidity == 0 && reserveData . currentLiquidityRate == 0 ,
2020-09-02 15:54:34 +00:00
Errors . RESERVE_LIQUIDITY_NOT_0
2020-06-20 23:40:03 +00:00
) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
currentConfig . setActive ( false ) ;
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveDeactivated ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ 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
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function freezeReserve ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( true ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveFreezed ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev unfreezes a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function unfreezeReserve ( address asset ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-07-27 07:49:45 +00:00
currentConfig . setFrozen ( false ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-06-20 23:40:03 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveUnfreezed ( asset ) ;
2020-06-20 23:40:03 +00:00
}
/**
2020-09-10 11:26:02 +00:00
* @ dev updates the ltv of a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param ltv the new value for the loan to value
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function setLtv ( address asset , uint256 ltv ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setLtv ( ltv ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveBaseLtvChanged ( asset , ltv ) ;
2020-06-20 23:40:03 +00:00
}
2020-10-13 11:21:11 +00:00
/**
2020-09-10 11:26:02 +00:00
* @ dev updates the reserve factor of a reserve
* @ param asset the address of the reserve
* @ param reserveFactor the new reserve factor of the reserve
** /
2020-09-17 14:37:51 +00:00
function setReserveFactor ( address asset , uint256 reserveFactor ) external onlyAaveAdmin {
2020-09-10 11:26:02 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
currentConfig . setReserveFactor ( reserveFactor ) ;
pool . setConfiguration ( asset , currentConfig . data ) ;
emit ReserveFactorChanged ( asset , reserveFactor ) ;
}
2020-06-20 23:40:03 +00:00
/**
* @ dev updates the liquidation threshold of a reserve .
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param threshold the new value for the liquidation threshold
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function setLiquidationThreshold ( address asset , uint256 threshold ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setLiquidationThreshold ( threshold ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveLiquidationThresholdChanged ( asset , threshold ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev updates the liquidation bonus of a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param bonus the new value for the liquidation bonus
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function setLiquidationBonus ( address asset , uint256 bonus ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setLiquidationBonus ( bonus ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveLiquidationBonusChanged ( asset , bonus ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev updates the reserve decimals
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param decimals the new number of decimals
2020-06-20 23:40:03 +00:00
** /
2020-09-16 12:09:42 +00:00
function setReserveDecimals ( address asset , uint256 decimals ) external onlyAaveAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration . Map memory currentConfig = pool . getConfiguration ( asset ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
currentConfig . setDecimals ( decimals ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
pool . setConfiguration ( asset , currentConfig . data ) ;
2020-07-23 15:18:06 +00:00
2020-08-21 12:03:17 +00:00
emit ReserveDecimalsChanged ( asset , decimals ) ;
2020-06-20 23:40:03 +00:00
}
/**
* @ dev sets the interest rate strategy of a reserve
2020-08-21 12:03:17 +00:00
* @ param asset the address of the reserve
* @ param rateStrategyAddress the new address of the interest strategy contract
2020-06-20 23:40:03 +00:00
** /
2020-08-21 12:03:17 +00:00
function setReserveInterestRateStrategyAddress ( address asset , address rateStrategyAddress )
2020-06-20 23:40:03 +00:00
external
2020-09-16 12:09:42 +00:00
onlyAaveAdmin
2020-06-20 23:40:03 +00:00
{
2020-08-21 12:03:17 +00:00
pool . setReserveInterestRateStrategyAddress ( asset , rateStrategyAddress ) ;
emit ReserveInterestRateStrategyChanged ( asset , rateStrategyAddress ) ;
2020-06-20 23:40:03 +00:00
}
2020-08-17 19:28:50 +00:00
/**
2020-08-18 16:48:23 +00:00
* @ dev initializes a token with a proxy and a specific implementation
2020-08-21 12:03:17 +00:00
* @ param implementation the address of the implementation
* @ param decimals the decimals of the token
2020-08-17 19:28:50 +00:00
** /
2020-08-25 08:53:58 +00:00
function _initTokenWithProxy ( address implementation , uint8 decimals ) internal returns ( address ) {
2020-10-13 11:21:11 +00:00
2020-10-14 11:55:38 +00:00
InitializableImmutableAdminUpgradeabilityProxy proxy
= new InitializableImmutableAdminUpgradeabilityProxy ( address ( this ) ) ;
2020-08-17 19:28:50 +00:00
bytes memory params = abi . encodeWithSignature (
' initialize(uint8,string,string) ' ,
2020-08-21 12:03:17 +00:00
decimals ,
IERC20Detailed ( implementation ) . name ( ) ,
IERC20Detailed ( implementation ) . symbol ( )
2020-08-17 19:28:50 +00:00
) ;
2020-10-13 08:38:22 +00:00
proxy . initialize ( implementation , params ) ;
2020-08-17 19:28:50 +00:00
return address ( proxy ) ;
}
2020-08-18 00:16:46 +00:00
2020-08-18 16:48:23 +00:00
function _upgradeTokenImplementation (
2020-08-21 12:03:17 +00:00
address asset ,
address proxyAddress ,
address implementation
2020-08-20 12:32:20 +00:00
) internal {
2020-10-13 11:21:11 +00:00
2020-10-14 11:55:38 +00:00
InitializableImmutableAdminUpgradeabilityProxy proxy
= InitializableImmutableAdminUpgradeabilityProxy ( payable ( proxyAddress ) ) ;
2020-08-18 00:16:46 +00:00
2020-10-09 15:59:10 +00:00
ReserveConfiguration . Map memory configuration = pool . getConfiguration ( asset ) ;
2020-08-18 16:48:23 +00:00
2020-10-12 12:25:03 +00:00
( , , , uint256 decimals , ) = configuration . getParamsMemory ( ) ;
2020-08-18 16:48:23 +00:00
2020-08-18 00:16:46 +00:00
bytes memory params = abi . encodeWithSignature (
' initialize(uint8,string,string) ' ,
2020-08-18 16:48:23 +00:00
uint8 ( decimals ) ,
2020-08-21 12:03:17 +00:00
IERC20Detailed ( implementation ) . name ( ) ,
IERC20Detailed ( implementation ) . symbol ( )
2020-08-18 00:16:46 +00:00
) ;
2020-08-21 12:03:17 +00:00
proxy . upgradeToAndCall ( implementation , params ) ;
2020-08-18 00:16:46 +00:00
}
2020-09-14 11:03:39 +00:00
/**
2020-09-15 09:03:04 +00:00
* @ dev pauses or unpauses LendingPool actions
2020-09-15 12:21:17 +00:00
* @ param val the boolean value to set the current pause state of LendingPool
2020-09-14 11:03:39 +00:00
** /
2020-09-16 12:09:42 +00:00
function setPoolPause ( bool val ) external onlyAaveAdmin {
2020-09-15 09:03:04 +00:00
pool . setPause ( val ) ;
2020-09-14 11:03:39 +00:00
}
2020-05-29 16:45:37 +00:00
}