feat: added risk admins

This commit is contained in:
Hadrien Charlanes 2021-05-12 01:08:02 +02:00
parent 992e026075
commit 0b0996b49c
3 changed files with 67 additions and 15 deletions

View File

@ -203,6 +203,18 @@ interface ILendingPoolConfigurator {
address indexed implementation address indexed implementation
); );
/**
* @dev Emitted when a new risk admin is registered
* @param admin the newly registered admin
**/
event RiskAdminRegistered(address indexed admin);
/**
* @dev Emitted when a risk admin is unregistered
* @param admin the unregistered admin
**/
event RiskAdminUnregistered(address indexed admin);
/** /**
* @dev Initializes reserves in batch * @dev Initializes reserves in batch
* @param input The array of reserves initialization parameters * @param input The array of reserves initialization parameters
@ -210,7 +222,7 @@ interface ILendingPoolConfigurator {
function batchInitReserve(InitReserveInput[] calldata input) external; function batchInitReserve(InitReserveInput[] calldata input) external;
/** /**
* @dev Updates the aToken implementation for the reserve * @dev pauseReservev Updates the aToken implementation for the reserve
* @param input The aToken update paramenters * @param input The aToken update paramenters
**/ **/
function updateAToken(UpdateATokenInput calldata input) external; function updateAToken(UpdateATokenInput calldata input) external;
@ -344,4 +356,23 @@ interface ILendingPoolConfigurator {
* @param supplyCap The new supply of the reserve * @param supplyCap The new supply of the reserve
**/ **/
function setSupplyCap(address asset, uint256 supplyCap) external; function setSupplyCap(address asset, uint256 supplyCap) external;
/**
* @dev Registers a new admin with rights on risk related configurations
* @param admin The address of the admin to register
**/
function registerRiskAdmin(address admin) external;
/**
* @dev Unegisters a risk admin
* @param admin The address of the admin to unregister
**/
function unregisterRiskAdmin(address admin) external;
/**
* @dev Returns wether an address in a risk admin or not
* @param admin The address of the potential admin
**/
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);
_; _;
@ -55,6 +57,14 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
_; _;
} }
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;
function getRevision() internal pure override returns (uint256) { function getRevision() internal pure override returns (uint256) {
@ -254,7 +264,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
address asset, address asset,
uint256 borrowCap, uint256 borrowCap,
bool stableBorrowRateEnabled bool stableBorrowRateEnabled
) external override onlyPoolAdmin { ) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setBorrowingEnabled(true); currentConfig.setBorrowingEnabled(true);
@ -268,7 +278,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
/// @inheritdoc ILendingPoolConfigurator /// @inheritdoc ILendingPoolConfigurator
function disableBorrowingOnReserve(address asset) external override onlyPoolAdmin { function disableBorrowingOnReserve(address asset) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setBorrowingEnabled(false); currentConfig.setBorrowingEnabled(false);
@ -283,7 +293,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus uint256 liquidationBonus
) external override onlyPoolAdmin { ) external override 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
@ -323,7 +333,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
/// @inheritdoc ILendingPoolConfigurator /// @inheritdoc ILendingPoolConfigurator
function enableReserveStableRate(address asset) external override onlyPoolAdmin { function enableReserveStableRate(address asset) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setStableRateBorrowingEnabled(true); currentConfig.setStableRateBorrowingEnabled(true);
@ -334,7 +344,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
/// @inheritdoc ILendingPoolConfigurator /// @inheritdoc ILendingPoolConfigurator
function disableReserveStableRate(address asset) external override onlyPoolAdmin { function disableReserveStableRate(address asset) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setStableRateBorrowingEnabled(false); currentConfig.setStableRateBorrowingEnabled(false);
@ -413,7 +423,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
/// @inheritdoc ILendingPoolConfigurator /// @inheritdoc ILendingPoolConfigurator
function setReserveFactor(address asset, uint256 reserveFactor) external override onlyPoolAdmin { function setReserveFactor(address asset, uint256 reserveFactor) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setReserveFactor(reserveFactor); currentConfig.setReserveFactor(reserveFactor);
@ -424,7 +434,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
///@inheritdoc ILendingPoolConfigurator ///@inheritdoc ILendingPoolConfigurator
function setBorrowCap(address asset, uint256 borrowCap) external override onlyPoolAdmin { function setBorrowCap(address asset, uint256 borrowCap) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setBorrowCap(borrowCap); currentConfig.setBorrowCap(borrowCap);
@ -435,7 +445,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
} }
///@inheritdoc ILendingPoolConfigurator ///@inheritdoc ILendingPoolConfigurator
function setSupplyCap(address asset, uint256 supplyCap) external override onlyPoolAdmin { function setSupplyCap(address asset, uint256 supplyCap) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setSupplyCap(supplyCap); currentConfig.setSupplyCap(supplyCap);
@ -445,15 +455,11 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
emit SupplyCapChanged(asset, supplyCap); emit SupplyCapChanged(asset, supplyCap);
} }
/** ///@inheritdoc ILendingPoolConfigurator
* @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
**/
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external external
override override
onlyPoolAdmin onlyRiskOrPoolAdmins
{ {
_pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); _pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress);
emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress); emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress);
@ -464,6 +470,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,