feat: added risk admins

This commit is contained in:
Hadrien Charlanes 2021-05-12 01:08:02 +02:00
parent f3418670f8
commit 32944733bd
3 changed files with 58 additions and 27 deletions

View File

@ -202,4 +202,14 @@ interface ILendingPoolConfigurator {
address indexed proxy, address indexed proxy,
address indexed implementation address indexed implementation
); );
event RiskAdminRegistered(address indexed admin);
event RiskAdminUnregistered(address indexed admin);
function registerRiskAdmin(address admin) external;
function unregisterRiskAdmin(address admin) external;
function isRiskAdmin(address admin) external view returns (bool);
} }

View File

@ -33,6 +33,8 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
ILendingPoolAddressesProvider internal addressesProvider; ILendingPoolAddressesProvider internal addressesProvider;
ILendingPool internal pool; ILendingPool internal pool;
mapping(address => bool) private _riskAdmins;
modifier onlyPoolAdmin { modifier onlyPoolAdmin {
require(addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN); require(addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
_; _;
@ -48,13 +50,20 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
modifier onlyEmergencyOrPoolAdmin { modifier onlyEmergencyOrPoolAdmin {
require( require(
addressesProvider.getEmergencyAdmin() == msg.sender addressesProvider.getEmergencyAdmin() == msg.sender ||
|| addressesProvider.getPoolAdmin() == msg.sender, addressesProvider.getPoolAdmin() == msg.sender,
Errors.LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN Errors.LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN
); );
_; _;
} }
modifier onlyRiskOrPoolAdmins {
require(
_riskAdmins[msg.sender] || addressesProvider.getPoolAdmin() == msg.sender,
Errors.LPC_CALLER_NOT_RISK_OR_POOL_ADMIN
);
_;
}
uint256 internal constant CONFIGURATOR_REVISION = 0x1; uint256 internal constant CONFIGURATOR_REVISION = 0x1;
@ -162,7 +171,8 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector( bytes memory encodedCall =
abi.encodeWithSelector(
IInitializableAToken.initialize.selector, IInitializableAToken.initialize.selector,
cachedPool, cachedPool,
input.treasury, input.treasury,
@ -174,11 +184,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
input.params input.params
); );
_upgradeTokenImplementation( _upgradeTokenImplementation(reserveData.aTokenAddress, input.implementation, encodedCall);
reserveData.aTokenAddress,
input.implementation,
encodedCall
);
emit ATokenUpgraded(input.asset, reserveData.aTokenAddress, input.implementation); emit ATokenUpgraded(input.asset, reserveData.aTokenAddress, input.implementation);
} }
@ -190,10 +196,11 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
ILendingPool cachedPool = pool; ILendingPool cachedPool = pool;
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset); DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector( bytes memory encodedCall =
abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector, IInitializableDebtToken.initialize.selector,
cachedPool, cachedPool,
input.asset, input.asset,
@ -220,17 +227,15 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
/** /**
* @dev Updates the variable debt token implementation for the asset * @dev Updates the variable debt token implementation for the asset
**/ **/
function updateVariableDebtToken(UpdateDebtTokenInput calldata input) function updateVariableDebtToken(UpdateDebtTokenInput calldata input) external onlyPoolAdmin {
external
onlyPoolAdmin
{
ILendingPool cachedPool = pool; ILendingPool cachedPool = pool;
DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset); DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset);
(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory();
bytes memory encodedCall = abi.encodeWithSelector( bytes memory encodedCall =
abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector, IInitializableDebtToken.initialize.selector,
cachedPool, cachedPool,
input.asset, input.asset,
@ -259,10 +264,11 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @param asset The address of the underlying asset of the 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 * @param stableBorrowRateEnabled True if stable borrow rate needs to be enabled by default on this reserve
**/ **/
function enableBorrowingOnReserve(address asset, uint256 borrowCap, bool stableBorrowRateEnabled) function enableBorrowingOnReserve(
external address asset,
onlyPoolAdmin uint256 borrowCap,
{ bool stableBorrowRateEnabled
) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setBorrowingEnabled(true); currentConfig.setBorrowingEnabled(true);
@ -278,7 +284,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @dev Disables borrowing on a reserve * @dev Disables borrowing on a reserve
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
**/ **/
function disableBorrowingOnReserve(address asset) external onlyPoolAdmin { function disableBorrowingOnReserve(address asset) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setBorrowingEnabled(false); currentConfig.setBorrowingEnabled(false);
@ -301,7 +307,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus uint256 liquidationBonus
) external onlyPoolAdmin { ) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
//validation of the parameters: the LTV can //validation of the parameters: the LTV can
@ -344,7 +350,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @dev Enable stable rate borrowing on a reserve * @dev Enable stable rate borrowing on a reserve
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
**/ **/
function enableReserveStableRate(address asset) external onlyPoolAdmin { function enableReserveStableRate(address asset) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setStableRateBorrowingEnabled(true); currentConfig.setStableRateBorrowingEnabled(true);
@ -358,7 +364,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @dev Disable stable rate borrowing on a reserve * @dev Disable stable rate borrowing on a reserve
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
**/ **/
function disableReserveStableRate(address asset) external onlyPoolAdmin { function disableReserveStableRate(address asset) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setStableRateBorrowingEnabled(false); currentConfig.setStableRateBorrowingEnabled(false);
@ -460,7 +466,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
* @param reserveFactor The new reserve factor of the reserve * @param reserveFactor The new reserve factor of the reserve
**/ **/
function setReserveFactor(address asset, uint256 reserveFactor) external onlyPoolAdmin { function setReserveFactor(address asset, uint256 reserveFactor) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setReserveFactor(reserveFactor); currentConfig.setReserveFactor(reserveFactor);
@ -475,7 +481,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
* @param borrowCap The new borrow of the reserve * @param borrowCap The new borrow of the reserve
**/ **/
function setBorrowCap(address asset, uint256 borrowCap) external onlyPoolAdmin { function setBorrowCap(address asset, uint256 borrowCap) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setBorrowCap(borrowCap); currentConfig.setBorrowCap(borrowCap);
@ -490,7 +496,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
* @param supplyCap The new supply of the reserve * @param supplyCap The new supply of the reserve
**/ **/
function setSupplyCap(address asset, uint256 supplyCap) external onlyPoolAdmin { function setSupplyCap(address asset, uint256 supplyCap) external onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset);
currentConfig.setSupplyCap(supplyCap); currentConfig.setSupplyCap(supplyCap);
@ -507,7 +513,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
**/ **/
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external external
onlyPoolAdmin onlyRiskOrPoolAdmins
{ {
pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress);
emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress); emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress);
@ -521,6 +527,20 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
pool.setPause(val); pool.setPause(val);
} }
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];
}
function _initTokenWithProxy(address implementation, bytes memory initParams) function _initTokenWithProxy(address implementation, bytes memory initParams)
internal internal
returns (address) returns (address)

View File

@ -108,6 +108,7 @@ library Errors {
string public constant RC_INVALID_SUPPLY_CAP = '84'; string public constant RC_INVALID_SUPPLY_CAP = '84';
string public constant LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85'; string public constant LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85';
string public constant VL_RESERVE_PAUSED = '86'; string public constant VL_RESERVE_PAUSED = '86';
string public constant LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87';
enum CollateralManagerErrors { enum CollateralManagerErrors {
NO_ERROR, NO_ERROR,