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

563 lines
20 KiB
Solidity
Raw Normal View History

// 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;
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';
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingPool} from '../../interfaces/ILendingPool.sol';
import {ITokenConfiguration} from '../../interfaces/ITokenConfiguration.sol';
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 {DataTypes} from '../libraries/types/DataTypes.sol';
/**
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
**/
contract LendingPoolConfigurator is VersionedInitializable {
2020-06-20 23:40:03 +00:00
using SafeMath for uint256;
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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when a reserve is initialized.
* @param asset The address of the underlying asset of the reserve
* @param aToken The address of the associated 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-11-25 14:27:17 +00:00
* @dev Emitted when borrowing is enabled on a reserve
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when borrowing is disabled on a reserve
* @param asset The address of the underlying asset 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-11-25 14:27:17 +00:00
* @dev Emitted when the collateralization risk parameters for the specified asset are updated.
* @param asset The address of the underlying asset 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
);
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when stable rate borrowing is enabled on a reserve
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when stable rate borrowing is disabled on a reserve
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when a reserve is activated
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when a reserve is deactivated
* @param asset The address of the underlying asset 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-11-25 14:27:17 +00:00
* @dev Emitted when a reserve is frozen
* @param asset The address of the underlying asset 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-11-25 14:27:17 +00:00
* @dev Emitted when a reserve is unfrozen
* @param asset The address of the underlying asset 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-11-25 14:27:17 +00:00
* @dev Emitted when a reserve factor is updated
* @param asset The address of the underlying asset of the reserve
* @param factor The new reserve factor
**/
event ReserveFactorChanged(address indexed asset, uint256 factor);
2020-06-20 23:40:03 +00:00
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when the reserve decimals are updated
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when a reserve interest strategy contract is updated
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when an aToken implementation is upgraded
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when the implementation of a stable debt token is upgraded
* @param asset The address of the underlying asset 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
/**
2020-11-25 14:27:17 +00:00
* @dev Emitted when the implementation of a variable debt token is upgraded
* @param asset The address of the underlying asset 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-11-05 11:35:50 +00:00
modifier onlyPoolAdmin {
require(addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
_;
}
modifier onlyEmergencyAdmin {
require(
addressesProvider.getEmergencyAdmin() == msg.sender,
Errors.LPC_CALLER_NOT_EMERGENCY_ADMIN
);
2020-06-20 23:40:03 +00:00
_;
}
2020-11-25 14:27:17 +00:00
uint256 internal constant CONFIGURATOR_REVISION = 0x1;
2020-06-20 23:40:03 +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 {
addressesProvider = provider;
pool = ILendingPool(addressesProvider.getLendingPool());
2020-06-20 23:40:03 +00:00
}
/**
2020-11-25 14:27:17 +00:00
* @dev Initializes a reserve
* @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
address stableDebtTokenProxyAddress =
_initTokenWithProxy(stableDebtTokenImpl, underlyingAssetDecimals);
2020-08-17 19:28:50 +00:00
address variableDebtTokenProxyAddress =
_initTokenWithProxy(variableDebtTokenImpl, underlyingAssetDecimals);
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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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-11-25 14:27:17 +00:00
* @dev Updates the aToken implementation for the reserve
* @param asset The address of the underlying asset 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 {
DataTypes.ReserveData memory reserveData = pool.getReserveData(asset);
_upgradeTokenImplementation(asset, reserveData.aTokenAddress, implementation);
emit ATokenUpgraded(asset, reserveData.aTokenAddress, implementation);
}
/**
2020-11-25 14:27:17 +00:00
* @dev Updates the stable debt token implementation for the reserve
* @param asset The address of the underlying asset 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 {
DataTypes.ReserveData memory reserveData = pool.getReserveData(asset);
_upgradeTokenImplementation(asset, reserveData.stableDebtTokenAddress, implementation);
emit StableDebtTokenUpgraded(asset, reserveData.stableDebtTokenAddress, implementation);
}
/**
2020-11-25 14:27:17 +00:00
* @dev Updates the variable debt token implementation for the asset
* @param asset The address of the underlying asset 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 {
DataTypes.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
/**
2020-11-25 14:27:17 +00:00
* @dev Enables borrowing on a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Disables borrowing on a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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-11-25 14:27:17 +00:00
* @dev Configures the reserve collateralization parameters
* all the values are expressed in percentages with two decimals of precision. A valid value is 10000, which means 100.00%
2020-11-25 14:27:17 +00:00
* @param asset The address of the underlying asset 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. The values is always above 100%. A value of 105%
* means the liquidator will receive a 5% bonus
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-11-24 15:17:27 +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
require(
2020-11-25 14:27:17 +00:00
liquidationThreshold.percentMul(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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Enable stable rate borrowing on a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Disable stable rate borrowing on a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Activates a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Deactivates a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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-11-25 14:27:17 +00:00
* @dev Freezes a reserve. A frozen reserve doesn't allow any new deposit, borrow or rate swap
* but allows repayments, liquidations, rate rebalances and withdrawals
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
/**
2020-11-25 14:27:17 +00:00
* @dev Unfreezes a reserve
* @param asset The address of the underlying asset 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-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
}
2020-10-08 13:41:48 +00:00
/**
2020-11-25 14:27:17 +00:00
* @dev Updates the reserve factor of a reserve
* @param asset The address of the underlying asset 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 {
2020-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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
/**
2020-11-25 14:27:17 +00:00
* @dev Sets the interest rate strategy of a reserve
* @param asset The address of the underlying asset 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-11-25 14:27:17 +00:00
* @dev pauses or unpauses all the actions of the protocol, including aToken transfers
* @param val true if protocol needs to be paused, false otherwise
2020-08-17 19:28:50 +00:00
**/
2020-11-25 14:27:17 +00:00
function setPoolPause(bool val) external onlyEmergencyAdmin {
pool.setPause(val);
}
function _initTokenWithProxy(address implementation, uint8 decimals) internal returns (address) {
InitializableImmutableAdminUpgradeabilityProxy proxy =
new InitializableImmutableAdminUpgradeabilityProxy(address(this));
2020-10-13 11:21:11 +00:00
bytes memory params =
abi.encodeWithSignature(
'initialize(uint8,string,string)',
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 {
InitializableImmutableAdminUpgradeabilityProxy proxy =
InitializableImmutableAdminUpgradeabilityProxy(payable(proxyAddress));
2020-11-24 15:17:27 +00:00
DataTypes.ReserveConfigurationMap 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)',
uint8(decimals),
IERC20Detailed(implementation).name(),
IERC20Detailed(implementation).symbol()
);
2020-08-21 12:03:17 +00:00
proxy.upgradeToAndCall(implementation, params);
}
2020-09-28 17:33:39 +00:00
function _checkNoLiquidity(address asset) internal view {
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
);
}
}