aave-protocol-v2/contracts/lendingpool/LendingPoolConfigurator.sol

634 lines
21 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
2020-07-23 15:18:06 +00:00
pragma experimental ABIEncoderV2;
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';
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';
import {Errors} from '../libraries/helpers/Errors.sol';
2020-09-28 17:33:39 +00:00
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol';
/**
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
**/
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
**/
event BorrowingEnabledOnReserve(address indexed 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
/**
2020-09-28 17:33:39 +00:00
* @dev emitted when a a reserve collateralization risk parameters are updated.
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
**/
2020-09-28 17:33:39 +00:00
event CollateralConfigurationChanged(
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 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
/**
2020-10-31 12:47:16 +00:00
* @dev emitted when a reserve is frozen
2020-08-21 12:03:17 +00:00
* @param asset the address of the reserve
2020-06-20 23:40:03 +00:00
**/
2020-10-31 12:47:16 +00:00
event ReserveFrozen(address indexed asset);
2020-06-20 23:40:03 +00:00
/**
2020-10-31 12:47:16 +00:00
* @dev emitted when a reserve is unfrozen
2020-08-21 12:03:17 +00:00
* @param asset the address of the reserve
2020-06-20 23:40:03 +00:00
**/
2020-10-31 12:47:16 +00:00
event ReserveUnfrozen(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
**/
event ReserveBaseLtvChanged(address indexed asset, uint256 ltv);
2020-06-20 23:40:03 +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 indexed 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
**/
event ReserveLiquidationThresholdChanged(address indexed 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
**/
event ReserveLiquidationBonusChanged(address indexed 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
**/
event ReserveDecimalsChanged(address indexed 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
**/
event ReserveInterestRateStrategyChanged(address indexed asset, address strategy);
2020-06-20 23:40:03 +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
**/
event ATokenUpgraded(
address indexed asset,
address indexed proxy,
address indexed implementation
);
2020-08-18 16:48:23 +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
**/
event StableDebtTokenUpgraded(
address indexed asset,
address indexed proxy,
address indexed implementation
);
2020-08-18 16:48:23 +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
* @param proxy the variable debt token proxy address
* @param implementation the new aToken implementation
**/
event VariableDebtTokenUpgraded(
address indexed asset,
address indexed proxy,
address indexed implementation
);
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
/**
2020-11-05 11:35:50 +00:00
* @dev only the pool admin can call functions affected by this modifier
2020-06-20 23:40:03 +00:00
**/
2020-11-05 11:35:50 +00:00
modifier onlyPoolAdmin {
require(addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
_;
}
/**
* @dev only the emergency admin can call functions affected by this modifier
**/
modifier onlyEmergencyAdmin {
require(
addressesProvider.getEmergencyAdmin() == msg.sender,
Errors.LPC_CALLER_NOT_EMERGENCY_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
**/
function initReserve(
2020-08-21 12:03:17 +00:00
address aTokenImpl,
address stableDebtTokenImpl,
address variableDebtTokenImpl,
uint8 underlyingAssetDecimals,
address interestRateStrategyAddress
2020-11-05 11:35:50 +00:00
) public onlyPoolAdmin {
2020-10-19 16:29:32 +00:00
address asset = ITokenConfiguration(aTokenImpl).UNDERLYING_ASSET_ADDRESS();
require(
address(pool) == ITokenConfiguration(aTokenImpl).POOL(),
2020-10-30 12:40:06 +00:00
Errors.LPC_INVALID_ATOKEN_POOL_ADDRESS
2020-10-19 16:29:32 +00:00
);
require(
address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(),
2020-10-30 12:40:06 +00:00
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
2020-10-19 16:29:32 +00:00
);
require(
address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(),
2020-10-30 12:40:06 +00:00
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
2020-10-19 16:29:32 +00:00
);
require(
asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
2020-10-30 12:40:06 +00:00
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
2020-10-19 16:29:32 +00:00
);
require(
asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
2020-10-30 12:40:06 +00:00
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
2020-10-19 16:29:32 +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-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);
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-11-05 11:35:50 +00:00
function updateAToken(address asset, address implementation) external onlyPoolAdmin {
ReserveLogic.ReserveData memory reserveData = pool.getReserveData(asset);
_upgradeTokenImplementation(asset, reserveData.aTokenAddress, implementation);
emit ATokenUpgraded(asset, reserveData.aTokenAddress, implementation);
}
/**
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-11-05 11:35:50 +00:00
function updateStableDebtToken(address asset, address implementation) external onlyPoolAdmin {
ReserveLogic.ReserveData memory reserveData = pool.getReserveData(asset);
_upgradeTokenImplementation(asset, reserveData.stableDebtTokenAddress, implementation);
emit StableDebtTokenUpgraded(asset, reserveData.stableDebtTokenAddress, implementation);
}
/**
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-11-05 11:35:50 +00:00
function updateVariableDebtToken(address asset, address implementation) external onlyPoolAdmin {
ReserveLogic.ReserveData memory reserveData = pool.getReserveData(asset);
_upgradeTokenImplementation(asset, reserveData.variableDebtTokenAddress, implementation);
emit VariableDebtTokenUpgraded(asset, reserveData.variableDebtTokenAddress, implementation);
}
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-11-05 11:35:50 +00:00
onlyPoolAdmin
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-11-05 11:35:50 +00:00
function disableBorrowingOnReserve(address asset) external onlyPoolAdmin {
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
}
/**
2020-10-31 11:17:59 +00:00
* @dev configures the reserve collateralization parameters
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
**/
2020-09-28 17:33:39 +00:00
function configureReserveAsCollateral(
2020-08-21 12:03:17 +00:00
address asset,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus
2020-11-05 11:35:50 +00:00
) external onlyPoolAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
2020-07-23 15:18:06 +00:00
2020-10-31 11:17:59 +00:00
//validation of the parameters: the LTV can
//only be lower or equal than the liquidation threshold
2020-09-28 17:33:39 +00:00
//(otherwise a loan against the asset would cause instantaneous liquidation)
2020-10-31 12:10:26 +00:00
require(ltv <= liquidationThreshold, Errors.LPC_INVALID_CONFIGURATION);
2020-07-23 15:18:06 +00:00
2020-10-31 11:33:26 +00:00
if (liquidationThreshold != 0) {
2020-10-31 11:17:59 +00:00
//liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less
2020-10-31 11:33:26 +00:00
//collateral than needed to cover the debt
2020-10-31 12:10:26 +00:00
require(
liquidationBonus > PercentageMath.PERCENTAGE_FACTOR,
Errors.LPC_INVALID_CONFIGURATION
);
2020-10-31 11:17:59 +00:00
} else {
2020-10-31 12:10:26 +00:00
require(liquidationBonus == 0, Errors.LPC_INVALID_CONFIGURATION);
2020-10-31 11:33:26 +00:00
//if the liquidation threshold is being set to 0,
// the reserve is being disabled as collateral. To do so,
//we need to ensure no liquidity is deposited
2020-09-28 17:33:39 +00:00
_checkNoLiquidity(asset);
}
2020-06-20 23:40:03 +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-09-28 17:33:39 +00:00
emit CollateralConfigurationChanged(asset, ltv, liquidationThreshold, liquidationBonus);
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-11-05 11:35:50 +00:00
function enableReserveStableRate(address asset) external onlyPoolAdmin {
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-11-05 11:35:50 +00:00
function disableReserveStableRate(address asset) external onlyPoolAdmin {
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-11-05 11:35:50 +00:00
function activateReserve(address asset) external onlyPoolAdmin {
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-11-05 11:35:50 +00:00
function deactivateReserve(address asset) external onlyPoolAdmin {
2020-10-30 14:12:11 +00:00
_checkNoLiquidity(asset);
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
}
/**
2020-10-31 12:47:16 +00:00
* @dev freezes a reserve. A frozen 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-11-05 11:35:50 +00:00
function freezeReserve(address asset) external onlyPoolAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
2020-07-23 15:18:06 +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-10-31 12:47:16 +00:00
emit ReserveFrozen(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-11-05 11:35:50 +00:00
function unfreezeReserve(address asset) external onlyPoolAdmin {
2020-08-21 12:03:17 +00:00
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
2020-07-23 15:18:06 +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-10-31 12:47:16 +00:00
emit ReserveUnfrozen(asset);
2020-06-20 23:40:03 +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-11-05 11:35:50 +00:00
function setLtv(address asset, uint256 ltv) external onlyPoolAdmin {
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-08 13:41:48 +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-11-05 11:35:50 +00:00
function setReserveFactor(address asset, uint256 reserveFactor) external onlyPoolAdmin {
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-11-05 11:35:50 +00:00
function setLiquidationThreshold(address asset, uint256 threshold) external onlyPoolAdmin {
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-11-05 11:35:50 +00:00
function setLiquidationBonus(address asset, uint256 bonus) external onlyPoolAdmin {
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 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-11-05 11:35:50 +00:00
onlyPoolAdmin
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
**/
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
);
proxy.initialize(implementation, params);
2020-08-17 19:28:50 +00:00
return address(proxy);
}
2020-08-18 16:48:23 +00:00
function _upgradeTokenImplementation(
2020-08-21 12:03:17 +00:00
address asset,
address proxyAddress,
address implementation
) internal {
2020-10-14 11:55:38 +00:00
InitializableImmutableAdminUpgradeabilityProxy proxy
= InitializableImmutableAdminUpgradeabilityProxy(payable(proxyAddress));
ReserveConfiguration.Map memory configuration = pool.getConfiguration(asset);
2020-08-18 16:48:23 +00:00
(, , , uint256 decimals, ) = configuration.getParamsMemory();
2020-08-18 16:48:23 +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-21 12:03:17 +00:00
proxy.upgradeToAndCall(implementation, params);
}
/**
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-11-05 11:35:50 +00:00
function setPoolPause(bool val) external onlyEmergencyAdmin {
2020-09-15 09:03:04 +00:00
pool.setPause(val);
}
2020-09-28 17:33:39 +00:00
function _checkNoLiquidity(address asset) internal view {
2020-10-30 14:12:11 +00:00
ReserveLogic.ReserveData memory reserveData = pool.getReserveData(asset);
uint256 availableLiquidity = IERC20Detailed(asset).balanceOf(reserveData.aTokenAddress);
2020-09-28 17:33:39 +00:00
require(
2020-10-30 14:12:11 +00:00
availableLiquidity == 0 && reserveData.currentLiquidityRate == 0,
2020-10-31 12:10:26 +00:00
Errors.LPC_RESERVE_LIQUIDITY_NOT_0
2020-09-28 17:33:39 +00:00
);
}
}