Initial commit

This commit is contained in:
The3D 2020-09-28 19:33:39 +02:00
parent 479f6f6b72
commit 948bd960be
3 changed files with 47 additions and 43 deletions

View File

@ -14,7 +14,7 @@ import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddresses
import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol'; import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
import {Errors} from '../libraries/helpers/Errors.sol'; import {Errors} from '../libraries/helpers/Errors.sol';
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
/** /**
* @title LendingPoolConfigurator contract * @title LendingPoolConfigurator contract
* @author Aave * @author Aave
@ -56,25 +56,19 @@ contract LendingPoolConfigurator is VersionedInitializable {
event BorrowingDisabledOnReserve(address indexed asset); event BorrowingDisabledOnReserve(address indexed asset);
/** /**
* @dev emitted when a reserve is enabled as collateral. * @dev emitted when a a reserve collateralization risk parameters are updated.
* @param asset the address of the reserve * @param asset the address of the reserve
* @param ltv the loan to value of the asset when used as collateral * @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 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 * @param liquidationBonus the bonus liquidators receive to liquidate this asset
**/ **/
event ReserveEnabledAsCollateral( event CollateralConfigurationChanged(
address indexed asset, address indexed asset,
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus uint256 liquidationBonus
); );
/**
* @dev emitted when a reserve is disabled as collateral
* @param asset the address of the reserve
**/
event ReserveDisabledAsCollateral(address indexed asset);
/** /**
* @dev emitted when stable rate borrowing is enabled on a reserve * @dev emitted when stable rate borrowing is enabled on a reserve
* @param asset the address of the reserve * @param asset the address of the reserve
@ -326,41 +320,45 @@ contract LendingPoolConfigurator is VersionedInitializable {
} }
/** /**
* @dev enables a reserve to be used as collateral * @dev configures the reserve collateralization parameters
* @param asset the address of the reserve * @param asset the address of the reserve
* @param ltv the loan to value of the asset when used as collateral * @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 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 * @param liquidationBonus the bonus liquidators receive to liquidate this asset
**/ **/
function enableReserveAsCollateral( function configureReserveAsCollateral(
address asset, address asset,
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus uint256 liquidationBonus
) external onlyAaveAdmin { ) external onlyAaveAdmin {
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
//validation of the parameters: the LTV can
//only be lower or equal than the liquidation threshold
//(otherwise a loan against the asset would cause instantaneous liquidation)
require(ltv <= liquidationThreshold, Errors.INVALID_CONFIGURATION);
//liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less
//collateral than needed to repay the debt
require(liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_CONFIGURATION);
//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
if(liquidationThreshold == 0) {
_checkNoLiquidity(asset);
}
currentConfig.setLtv(ltv); currentConfig.setLtv(ltv);
currentConfig.setLiquidationThreshold(liquidationThreshold); currentConfig.setLiquidationThreshold(liquidationThreshold);
currentConfig.setLiquidationBonus(liquidationBonus); currentConfig.setLiquidationBonus(liquidationBonus);
pool.setConfiguration(asset, currentConfig.data); pool.setConfiguration(asset, currentConfig.data);
emit ReserveEnabledAsCollateral(asset, ltv, liquidationThreshold, liquidationBonus); emit CollateralConfigurationChanged(asset, ltv, liquidationThreshold, liquidationBonus);
}
/**
* @dev disables a reserve as collateral
* @param asset the address of the reserve
**/
function disableReserveAsCollateral(address asset) external onlyAaveAdmin {
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
currentConfig.setLtv(0);
pool.setConfiguration(asset, currentConfig.data);
emit ReserveDisabledAsCollateral(asset);
} }
/** /**
@ -410,22 +408,8 @@ contract LendingPoolConfigurator is VersionedInitializable {
* @param asset the address of the reserve * @param asset the address of the reserve
**/ **/
function deactivateReserve(address asset) external onlyAaveAdmin { function deactivateReserve(address asset) external onlyAaveAdmin {
(
uint256 availableLiquidity, _checkNoLiquidity(asset);
uint256 totalStableDebt,
uint256 totalVariableDebt,
,
,
,
,
,
,
) = pool.getReserveData(asset);
require(
availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0,
Errors.RESERVE_LIQUIDITY_NOT_0
);
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
@ -601,4 +585,23 @@ contract LendingPoolConfigurator is VersionedInitializable {
function setPoolPause(bool val) external onlyAaveAdmin { function setPoolPause(bool val) external onlyAaveAdmin {
pool.setPause(val); pool.setPause(val);
} }
function _checkNoLiquidity(address asset) internal view {
(
uint256 availableLiquidity,
uint256 totalStableDebt,
uint256 totalVariableDebt,
,
,
,
,
,
,
) = pool.getReserveData(asset);
require(
availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0,
Errors.RESERVE_LIQUIDITY_NOT_0
);
}
} }

View File

@ -61,6 +61,7 @@ library Errors {
//require error messages - LendingPoolConfiguration //require error messages - LendingPoolConfiguration
string public constant CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin' string public constant CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin'
string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0' string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
string public constant INVALID_CONFIGURATION = '52'; // 'Invalid risk parameters for the reserve'
//require error messages - LendingPoolAddressesProviderRegistry //require error messages - LendingPoolAddressesProviderRegistry
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered' string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'

View File

@ -104,7 +104,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Deactivates the ETH reserve as collateral', async () => { it('Deactivates the ETH reserve as collateral', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, pool, weth} = testEnv;
await configurator.disableReserveAsCollateral(weth.address); await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0);
const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address);
expect(usageAsCollateralEnabled).to.be.equal(false); expect(usageAsCollateralEnabled).to.be.equal(false);
}); });