2020-05-29 16:45:37 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
2020-11-20 10:45:20 +00:00
|
|
|
pragma solidity 0.6.12;
|
2020-07-23 15:18:06 +00:00
|
|
|
pragma experimental ABIEncoderV2;
|
2020-05-29 16:45:37 +00:00
|
|
|
|
2020-11-23 10:28:57 +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-11-23 10:28:57 +00:00
|
|
|
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
|
|
|
import {ILendingPool} from '../../interfaces/ILendingPool.sol';
|
|
|
|
import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
|
2020-09-02 15:54:34 +00:00
|
|
|
import {Errors} from '../libraries/helpers/Errors.sol';
|
2020-09-28 17:33:39 +00:00
|
|
|
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
|
2020-11-24 13:53:34 +00:00
|
|
|
import {DataTypes} from '../libraries/types/DataTypes.sol';
|
2021-01-28 10:05:19 +00:00
|
|
|
import {IInitializableDebtToken} from '../../interfaces/IInitializableDebtToken.sol';
|
|
|
|
import {IInitializableAToken} from '../../interfaces/IInitializableAToken.sol';
|
|
|
|
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
|
|
|
|
import {ILendingPoolConfigurator} from '../../interfaces/ILendingPoolConfigurator.sol';
|
2020-05-29 16:45:37 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-20 23:40:03 +00:00
|
|
|
* @title LendingPoolConfigurator contract
|
|
|
|
* @author Aave
|
2020-11-25 14:31:27 +00:00
|
|
|
* @dev Implements the configuration methods for the Aave protocol
|
2020-06-20 23:40:03 +00:00
|
|
|
**/
|
2020-05-29 16:45:37 +00:00
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigurator {
|
2020-06-20 23:40:03 +00:00
|
|
|
using SafeMath for uint256;
|
2020-11-25 15:17:08 +00:00
|
|
|
using PercentageMath for uint256;
|
2020-11-24 15:17:27 +00:00
|
|
|
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2021-05-24 15:28:32 +00:00
|
|
|
ILendingPoolAddressesProvider internal _addressesProvider;
|
|
|
|
ILendingPool internal _pool;
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-05-11 23:08:02 +00:00
|
|
|
mapping(address => bool) private _riskAdmins;
|
|
|
|
|
2020-11-05 11:35:50 +00:00
|
|
|
modifier onlyPoolAdmin {
|
2021-05-24 15:28:32 +00:00
|
|
|
require(_addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
|
2020-11-05 11:35:50 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
modifier onlyEmergencyAdmin {
|
|
|
|
require(
|
2021-05-24 15:28:32 +00:00
|
|
|
_addressesProvider.getEmergencyAdmin() == msg.sender,
|
2020-11-05 11:35:50 +00:00
|
|
|
Errors.LPC_CALLER_NOT_EMERGENCY_ADMIN
|
|
|
|
);
|
2020-06-20 23:40:03 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2021-05-05 08:16:09 +00:00
|
|
|
modifier onlyEmergencyOrPoolAdmin {
|
|
|
|
require(
|
2021-05-31 08:34:10 +00:00
|
|
|
_addressesProvider.getEmergencyAdmin() == msg.sender ||
|
|
|
|
_addressesProvider.getPoolAdmin() == msg.sender,
|
2021-05-05 08:16:09 +00:00
|
|
|
Errors.LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN
|
|
|
|
);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2021-05-11 23:08:02 +00:00
|
|
|
modifier onlyRiskOrPoolAdmins {
|
|
|
|
require(
|
|
|
|
_riskAdmins[msg.sender] || addressesProvider.getPoolAdmin() == msg.sender,
|
|
|
|
Errors.LPC_CALLER_NOT_RISK_OR_POOL_ADMIN
|
|
|
|
);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:27:17 +00:00
|
|
|
uint256 internal constant CONFIGURATOR_REVISION = 0x1;
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getRevision() internal pure override returns (uint256) {
|
2020-06-20 23:40:03 +00:00
|
|
|
return CONFIGURATOR_REVISION;
|
|
|
|
}
|
|
|
|
|
2020-08-21 12:03:17 +00:00
|
|
|
function initialize(ILendingPoolAddressesProvider provider) public initializer {
|
2021-05-24 15:28:32 +00:00
|
|
|
_addressesProvider = provider;
|
|
|
|
_pool = ILendingPool(_addressesProvider.getLendingPool());
|
2020-06-20 23:40:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function batchInitReserve(InitReserveInput[] calldata input) external override onlyPoolAdmin {
|
2021-05-24 15:28:32 +00:00
|
|
|
ILendingPool cachedPool = _pool;
|
2021-02-26 17:17:10 +00:00
|
|
|
for (uint256 i = 0; i < input.length; i++) {
|
|
|
|
_initReserve(cachedPool, input[i]);
|
2021-01-28 10:05:19 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-19 16:29:32 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
function _initReserve(ILendingPool pool, InitReserveInput calldata input) internal {
|
2021-01-28 10:05:19 +00:00
|
|
|
address aTokenProxyAddress =
|
|
|
|
_initTokenWithProxy(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.aTokenImpl,
|
2021-01-28 10:05:19 +00:00
|
|
|
abi.encodeWithSelector(
|
|
|
|
IInitializableAToken.initialize.selector,
|
|
|
|
pool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.treasury,
|
|
|
|
input.underlyingAsset,
|
|
|
|
IAaveIncentivesController(input.incentivesController),
|
|
|
|
input.underlyingAssetDecimals,
|
|
|
|
input.aTokenName,
|
|
|
|
input.aTokenSymbol,
|
|
|
|
input.params
|
2021-01-28 10:05:19 +00:00
|
|
|
)
|
|
|
|
);
|
2020-06-30 12:09:28 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
address stableDebtTokenProxyAddress =
|
2021-01-28 10:05:19 +00:00
|
|
|
_initTokenWithProxy(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.stableDebtTokenImpl,
|
2021-01-28 10:05:19 +00:00
|
|
|
abi.encodeWithSelector(
|
|
|
|
IInitializableDebtToken.initialize.selector,
|
|
|
|
pool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.underlyingAsset,
|
|
|
|
IAaveIncentivesController(input.incentivesController),
|
|
|
|
input.underlyingAssetDecimals,
|
|
|
|
input.stableDebtTokenName,
|
|
|
|
input.stableDebtTokenSymbol,
|
|
|
|
input.params
|
2021-01-28 10:05:19 +00:00
|
|
|
)
|
|
|
|
);
|
2020-08-17 19:28:50 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
address variableDebtTokenProxyAddress =
|
2021-01-28 10:05:19 +00:00
|
|
|
_initTokenWithProxy(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.variableDebtTokenImpl,
|
2021-01-28 10:05:19 +00:00
|
|
|
abi.encodeWithSelector(
|
|
|
|
IInitializableDebtToken.initialize.selector,
|
|
|
|
pool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.underlyingAsset,
|
|
|
|
IAaveIncentivesController(input.incentivesController),
|
|
|
|
input.underlyingAssetDecimals,
|
|
|
|
input.variableDebtTokenName,
|
|
|
|
input.variableDebtTokenSymbol,
|
|
|
|
input.params
|
2021-01-28 10:05:19 +00:00
|
|
|
)
|
|
|
|
);
|
2020-08-07 16:23:52 +00:00
|
|
|
|
2020-07-23 15:18:06 +00:00
|
|
|
pool.initReserve(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.underlyingAsset,
|
2020-08-17 19:28:50 +00:00
|
|
|
aTokenProxyAddress,
|
|
|
|
stableDebtTokenProxyAddress,
|
|
|
|
variableDebtTokenProxyAddress,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.interestRateStrategyAddress
|
2020-05-29 16:45:37 +00:00
|
|
|
);
|
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig =
|
2021-02-26 17:17:10 +00:00
|
|
|
pool.getConfiguration(input.underlyingAsset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
currentConfig.setDecimals(input.underlyingAssetDecimals);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setActive(true);
|
2021-05-05 08:16:09 +00:00
|
|
|
currentConfig.setPaused(false);
|
2020-07-27 07:49:45 +00:00
|
|
|
currentConfig.setFrozen(false);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
pool.setConfiguration(input.underlyingAsset, currentConfig.data);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2020-08-17 19:28:50 +00:00
|
|
|
emit ReserveInitialized(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.underlyingAsset,
|
2020-08-17 19:28:50 +00:00
|
|
|
aTokenProxyAddress,
|
|
|
|
stableDebtTokenProxyAddress,
|
|
|
|
variableDebtTokenProxyAddress,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.interestRateStrategyAddress
|
2020-08-17 19:28:50 +00:00
|
|
|
);
|
2020-06-20 23:40:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function updateAToken(UpdateATokenInput calldata input) external override onlyPoolAdmin {
|
2021-05-24 15:28:32 +00:00
|
|
|
ILendingPool cachedPool = _pool;
|
2020-08-10 13:29:18 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
|
2020-08-10 13:29:18 +00:00
|
|
|
|
2021-04-30 14:14:59 +00:00
|
|
|
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-05-25 07:48:08 +00:00
|
|
|
bytes memory encodedCall =
|
|
|
|
abi.encodeWithSelector(
|
2021-01-28 10:05:19 +00:00
|
|
|
IInitializableAToken.initialize.selector,
|
|
|
|
cachedPool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.treasury,
|
|
|
|
input.asset,
|
|
|
|
input.incentivesController,
|
2021-01-28 10:05:19 +00:00
|
|
|
decimals,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.name,
|
|
|
|
input.symbol,
|
|
|
|
input.params
|
|
|
|
);
|
|
|
|
|
2021-05-25 07:48:08 +00:00
|
|
|
_upgradeTokenImplementation(reserveData.aTokenAddress, input.implementation, encodedCall);
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
emit ATokenUpgraded(input.asset, reserveData.aTokenAddress, input.implementation);
|
2020-08-18 00:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function updateStableDebtToken(UpdateDebtTokenInput calldata input)
|
|
|
|
external
|
|
|
|
override
|
|
|
|
onlyPoolAdmin
|
|
|
|
{
|
2021-05-24 15:28:32 +00:00
|
|
|
ILendingPool cachedPool = _pool;
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
|
2021-05-25 07:48:08 +00:00
|
|
|
|
2021-04-30 14:14:59 +00:00
|
|
|
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-05-25 07:48:08 +00:00
|
|
|
bytes memory encodedCall =
|
|
|
|
abi.encodeWithSelector(
|
2021-01-28 10:05:19 +00:00
|
|
|
IInitializableDebtToken.initialize.selector,
|
|
|
|
cachedPool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.asset,
|
|
|
|
input.incentivesController,
|
2021-01-28 10:05:19 +00:00
|
|
|
decimals,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.name,
|
|
|
|
input.symbol,
|
|
|
|
input.params
|
|
|
|
);
|
|
|
|
|
|
|
|
_upgradeTokenImplementation(
|
|
|
|
reserveData.stableDebtTokenAddress,
|
|
|
|
input.implementation,
|
|
|
|
encodedCall
|
2021-01-28 10:05:19 +00:00
|
|
|
);
|
2020-08-10 13:29:18 +00:00
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
emit StableDebtTokenUpgraded(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.asset,
|
2021-01-28 10:05:19 +00:00
|
|
|
reserveData.stableDebtTokenAddress,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.implementation
|
2021-01-28 10:05:19 +00:00
|
|
|
);
|
2020-08-18 00:16:46 +00:00
|
|
|
}
|
2020-08-25 08:53:58 +00:00
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function updateVariableDebtToken(UpdateDebtTokenInput calldata input)
|
|
|
|
external
|
|
|
|
override
|
|
|
|
onlyPoolAdmin
|
|
|
|
{
|
2021-05-24 15:28:32 +00:00
|
|
|
ILendingPool cachedPool = _pool;
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-02-26 17:17:10 +00:00
|
|
|
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
|
2020-08-18 00:16:46 +00:00
|
|
|
|
2021-04-30 14:14:59 +00:00
|
|
|
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
|
2021-01-28 10:05:19 +00:00
|
|
|
|
2021-05-25 07:48:08 +00:00
|
|
|
bytes memory encodedCall =
|
|
|
|
abi.encodeWithSelector(
|
2021-01-28 10:05:19 +00:00
|
|
|
IInitializableDebtToken.initialize.selector,
|
|
|
|
cachedPool,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.asset,
|
|
|
|
input.incentivesController,
|
2021-01-28 10:05:19 +00:00
|
|
|
decimals,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.name,
|
|
|
|
input.symbol,
|
|
|
|
input.params
|
|
|
|
);
|
|
|
|
|
|
|
|
_upgradeTokenImplementation(
|
|
|
|
reserveData.variableDebtTokenAddress,
|
|
|
|
input.implementation,
|
|
|
|
encodedCall
|
2021-01-28 10:05:19 +00:00
|
|
|
);
|
2020-08-18 00:16:46 +00:00
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
emit VariableDebtTokenUpgraded(
|
2021-02-26 17:17:10 +00:00
|
|
|
input.asset,
|
2021-01-28 10:05:19 +00:00
|
|
|
reserveData.variableDebtTokenAddress,
|
2021-02-26 17:17:10 +00:00
|
|
|
input.implementation
|
2021-01-28 10:05:19 +00:00
|
|
|
);
|
2020-08-10 13:29:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-25 07:48:08 +00:00
|
|
|
function enableBorrowingOnReserve(
|
|
|
|
address asset,
|
|
|
|
uint256 borrowCap,
|
|
|
|
bool stableBorrowRateEnabled
|
2021-05-11 23:08:02 +00:00
|
|
|
) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setBorrowingEnabled(true);
|
2021-04-27 17:08:49 +00:00
|
|
|
currentConfig.setBorrowCap(borrowCap);
|
2020-08-21 12:03:17 +00:00
|
|
|
currentConfig.setStableRateBorrowingEnabled(stableBorrowRateEnabled);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-05-24 15:28:32 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-05-25 07:48:08 +00:00
|
|
|
emit BorrowCapChanged(asset, borrowCap);
|
2020-08-21 12:03:17 +00:00
|
|
|
emit BorrowingEnabledOnReserve(asset, stableBorrowRateEnabled);
|
2020-06-20 23:40:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function disableBorrowingOnReserve(address asset) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setBorrowingEnabled(false);
|
|
|
|
|
2021-05-24 15:28:32 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2020-08-21 12:03:17 +00:00
|
|
|
emit BorrowingDisabledOnReserve(asset);
|
2020-06-20 23:40:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
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
|
2021-05-11 23:08:02 +00:00
|
|
|
) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap 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-11-25 14:27:17 +00:00
|
|
|
//collateral than needed to cover the debt
|
|
|
|
require(
|
|
|
|
liquidationBonus > PercentageMath.PERCENTAGE_FACTOR,
|
|
|
|
Errors.LPC_INVALID_CONFIGURATION
|
|
|
|
);
|
2020-11-10 17:16:27 +00:00
|
|
|
|
2020-11-25 14:27:17 +00:00
|
|
|
//if threshold * bonus is less than PERCENTAGE_FACTOR, it's guaranteed that at the moment
|
|
|
|
//a loan is taken there is enough collateral available to cover the liquidation bonus
|
2020-11-23 10:28:57 +00:00
|
|
|
require(
|
2020-11-25 14:27:17 +00:00
|
|
|
liquidationThreshold.percentMul(liquidationBonus) <= PercentageMath.PERCENTAGE_FACTOR,
|
2020-11-23 10:28:57 +00:00
|
|
|
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
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function enableReserveStableRate(address asset) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setStableRateBorrowingEnabled(true);
|
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function disableReserveStableRate(address asset) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setStableRateBorrowingEnabled(false);
|
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function activateReserve(address asset) external override onlyPoolAdmin {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setActive(true);
|
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function deactivateReserve(address asset) external override onlyPoolAdmin {
|
2020-10-30 14:12:11 +00:00
|
|
|
_checkNoLiquidity(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-07-23 15:18:06 +00:00
|
|
|
|
|
|
|
currentConfig.setActive(false);
|
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-26 06:48:39 +00:00
|
|
|
function freezeReserve(address asset) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap 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
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-26 06:48:39 +00:00
|
|
|
function unfreezeReserve(address asset) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap 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
|
|
|
|
2021-05-24 15:28:32 +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
|
|
|
}
|
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-31 08:34:10 +00:00
|
|
|
function pauseReserve(address asset) external override onlyEmergencyOrPoolAdmin {
|
2021-05-31 08:18:27 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2021-05-05 08:16:09 +00:00
|
|
|
|
|
|
|
currentConfig.setPaused(true);
|
|
|
|
|
2021-05-31 08:18:27 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2021-05-05 08:16:09 +00:00
|
|
|
|
|
|
|
emit ReservePaused(asset);
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:18:27 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-31 08:34:10 +00:00
|
|
|
function unpauseReserve(address asset) external override onlyEmergencyOrPoolAdmin {
|
2021-05-31 08:18:27 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2021-05-05 08:16:09 +00:00
|
|
|
|
|
|
|
currentConfig.setPaused(false);
|
|
|
|
|
2021-05-31 08:18:27 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2021-05-05 08:16:09 +00:00
|
|
|
|
|
|
|
emit ReserveUnpaused(asset);
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:18:27 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function setReserveFactor(address asset, uint256 reserveFactor) external override onlyRiskOrPoolAdmins {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2020-09-10 11:26:02 +00:00
|
|
|
|
|
|
|
currentConfig.setReserveFactor(reserveFactor);
|
|
|
|
|
2021-05-24 15:28:32 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2020-09-10 11:26:02 +00:00
|
|
|
|
|
|
|
emit ReserveFactorChanged(asset, reserveFactor);
|
|
|
|
}
|
|
|
|
|
2021-05-28 18:21:34 +00:00
|
|
|
///@inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function setBorrowCap(address asset, uint256 borrowCap) external override onlyRiskOrPoolAdmins {
|
2021-05-28 18:21:34 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2021-04-29 07:51:37 +00:00
|
|
|
|
|
|
|
currentConfig.setBorrowCap(borrowCap);
|
|
|
|
|
2021-05-28 18:21:34 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2021-04-29 07:51:37 +00:00
|
|
|
|
|
|
|
emit BorrowCapChanged(asset, borrowCap);
|
|
|
|
}
|
|
|
|
|
2021-05-28 18:21:34 +00:00
|
|
|
///@inheritdoc ILendingPoolConfigurator
|
2021-05-11 23:08:02 +00:00
|
|
|
function setSupplyCap(address asset, uint256 supplyCap) external override onlyRiskOrPoolAdmins {
|
2021-05-28 18:21:34 +00:00
|
|
|
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
|
2021-04-30 14:14:59 +00:00
|
|
|
|
|
|
|
currentConfig.setSupplyCap(supplyCap);
|
|
|
|
|
2021-05-28 18:21:34 +00:00
|
|
|
_pool.setConfiguration(asset, currentConfig.data);
|
2021-04-30 14:14:59 +00:00
|
|
|
|
|
|
|
emit SupplyCapChanged(asset, supplyCap);
|
|
|
|
}
|
|
|
|
|
2021-05-11 23:08:02 +00:00
|
|
|
///@inheritdoc ILendingPoolConfigurator
|
2020-08-21 12:03:17 +00:00
|
|
|
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
|
2020-06-20 23:40:03 +00:00
|
|
|
external
|
2021-05-24 15:31:12 +00:00
|
|
|
override
|
2021-05-11 23:08:02 +00:00
|
|
|
onlyRiskOrPoolAdmins
|
2020-06-20 23:40:03 +00:00
|
|
|
{
|
2021-05-24 15:28:32 +00:00
|
|
|
_pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress);
|
2020-08-21 12:03:17 +00:00
|
|
|
emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress);
|
2020-06-20 23:40:03 +00:00
|
|
|
}
|
2020-08-17 19:28:50 +00:00
|
|
|
|
2021-05-25 05:40:53 +00:00
|
|
|
/// @inheritdoc ILendingPoolConfigurator
|
2021-05-24 15:31:12 +00:00
|
|
|
function setPoolPause(bool val) external override onlyEmergencyAdmin {
|
2021-05-24 15:28:32 +00:00
|
|
|
_pool.setPause(val);
|
2020-11-25 14:27:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 23:08:02 +00:00
|
|
|
function registerRiskAdmin(address admin) external override onlyPoolAdmin {
|
|
|
|
_riskAdmins[admin] = true;
|
|
|
|
emit RiskAdminRegistered(admin);
|
|
|
|
}
|
|
|
|
|
|
|
|
function unregisterRiskAdmin(address admin) external override onlyPoolAdmin {
|
|
|
|
_riskAdmins[admin] = false;
|
|
|
|
emit RiskAdminUnregistered(admin);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRiskAdmin(address admin) external view override onlyPoolAdmin returns (bool) {
|
|
|
|
return _riskAdmins[admin];
|
|
|
|
}
|
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
function _initTokenWithProxy(address implementation, bytes memory initParams)
|
|
|
|
internal
|
|
|
|
returns (address)
|
|
|
|
{
|
2020-11-23 10:28:57 +00:00
|
|
|
InitializableImmutableAdminUpgradeabilityProxy proxy =
|
|
|
|
new InitializableImmutableAdminUpgradeabilityProxy(address(this));
|
2020-10-13 11:21:11 +00:00
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
proxy.initialize(implementation, initParams);
|
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 proxyAddress,
|
2021-01-28 10:05:19 +00:00
|
|
|
address implementation,
|
|
|
|
bytes memory initParams
|
2020-08-20 12:32:20 +00:00
|
|
|
) internal {
|
2020-11-23 10:28:57 +00:00
|
|
|
InitializableImmutableAdminUpgradeabilityProxy proxy =
|
|
|
|
InitializableImmutableAdminUpgradeabilityProxy(payable(proxyAddress));
|
2020-08-18 00:16:46 +00:00
|
|
|
|
2021-01-28 10:05:19 +00:00
|
|
|
proxy.upgradeToAndCall(implementation, initParams);
|
2020-08-18 00:16:46 +00:00
|
|
|
}
|
2020-09-14 11:03:39 +00:00
|
|
|
|
2020-09-28 17:33:39 +00:00
|
|
|
function _checkNoLiquidity(address asset) internal view {
|
2021-05-24 15:28:32 +00:00
|
|
|
DataTypes.ReserveData memory reserveData = _pool.getReserveData(asset);
|
2020-10-30 14:12:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|