feat: implemented pause validation for reserve assets

This commit is contained in:
Hadrien Charlanes 2021-05-10 10:01:50 +02:00
parent f60b8fffcf
commit 2019b5f500
3 changed files with 37 additions and 19 deletions

View File

@ -465,7 +465,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
) external override whenNotPaused { ) external override whenNotPaused {
FlashLoanLocalVars memory vars; FlashLoanLocalVars memory vars;
ValidationLogic.validateFlashloan(assets, amounts); ValidationLogic.validateFlashloan(assets, amounts, _reserves);
address[] memory aTokenAddresses = new address[](assets.length); address[] memory aTokenAddresses = new address[](assets.length);
uint256[] memory premiums = new uint256[](assets.length); uint256[] memory premiums = new uint256[](assets.length);
@ -728,6 +728,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (fromConfig.isUsingAsCollateral(reserveId)) { if (fromConfig.isUsingAsCollateral(reserveId)) {
if (fromConfig.isBorrowingAny()) { if (fromConfig.isBorrowingAny()) {
ValidationLogic.validateHealthFactor( ValidationLogic.validateHealthFactor(
asset,
from, from,
_reserves, _reserves,
_usersConfig[from], _usersConfig[from],

View File

@ -119,6 +119,7 @@ library Errors {
NO_ACTIVE_RESERVE, NO_ACTIVE_RESERVE,
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
INVALID_EQUAL_ASSETS_TO_SWAP, INVALID_EQUAL_ASSETS_TO_SWAP,
FROZEN_RESERVE FROZEN_RESERVE,
PAUSED_RESERVE
} }
} }

View File

@ -40,19 +40,15 @@ library ValidationLogic {
* @param reserve The reserve object on which the user is depositing * @param reserve The reserve object on which the user is depositing
* @param amount The amount to be deposited * @param amount The amount to be deposited
*/ */
<<<<<<< HEAD
function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) internal view { function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) internal view {
DataTypes.ReserveConfigurationMap memory reserveConfiguration = reserve.configuration; DataTypes.ReserveConfigurationMap memory reserveConfiguration = reserve.configuration;
(bool isActive, bool isFrozen, , ) = reserveConfiguration.getFlagsMemory(); (bool isActive, bool isFrozen, , bool isPaused) = reserveConfiguration.getFlagsMemory();
(, , , uint256 reserveDecimals, ) = reserveConfiguration.getParamsMemory(); (, , , uint256 reserveDecimals, ) = reserveConfiguration.getParamsMemory();
uint256 supplyCap = reserveConfiguration.getSupplyCapMemory(); uint256 supplyCap = reserveConfiguration.getSupplyCapMemory();
=======
function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) external view {
(bool isActive, bool isFrozen, , , ) = reserve.configuration.getFlags();
>>>>>>> 2e1af3c (feat: added bool isPaused in data reserve config)
require(amount != 0, Errors.VL_INVALID_AMOUNT); require(amount != 0, Errors.VL_INVALID_AMOUNT);
require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!isPaused, Errors.VL_RESERVE_PAUSED);
require(!isFrozen, Errors.VL_RESERVE_FROZEN); require(!isFrozen, Errors.VL_RESERVE_FROZEN);
require( require(
supplyCap == 0 || supplyCap == 0 ||
@ -76,8 +72,9 @@ library ValidationLogic {
require(amount != 0, Errors.VL_INVALID_AMOUNT); require(amount != 0, Errors.VL_INVALID_AMOUNT);
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE); require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
(bool isActive, , , , ) = reservesData[reserveAddress].configuration.getFlags(); (bool isActive, , , , bool isPaused) = reservesData[reserveAddress].configuration.getFlags();
require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!isPaused, Errors.VL_RESERVE_PAUSED);
} }
struct ValidateBorrowLocalVars { struct ValidateBorrowLocalVars {
@ -130,7 +127,6 @@ library ValidationLogic {
) internal view { ) internal view {
ValidateBorrowLocalVars memory vars; ValidateBorrowLocalVars memory vars;
<<<<<<< HEAD
DataTypes.ReserveConfigurationMap memory reserveConfiguration = reserve.configuration; DataTypes.ReserveConfigurationMap memory reserveConfiguration = reserve.configuration;
(, , , vars.reserveDecimals, ) = reserveConfiguration.getParamsMemory(); (, , , vars.reserveDecimals, ) = reserveConfiguration.getParamsMemory();
@ -138,13 +134,9 @@ library ValidationLogic {
vars.isActive, vars.isActive,
vars.isFrozen, vars.isFrozen,
vars.borrowingEnabled, vars.borrowingEnabled,
vars.stableRateBorrowingEnabled vars.stableRateBorrowingEnabled,
vars.isPaused
) = reserveConfiguration.getFlagsMemory(); ) = reserveConfiguration.getFlagsMemory();
=======
(vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled, vars.isPaused) = reserve
.configuration
.getFlags();
>>>>>>> 2e1af3c (feat: added bool isPaused in data reserve config)
require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE); require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!vars.isPaused, Errors.VL_RESERVE_PAUSED); require(!vars.isPaused, Errors.VL_RESERVE_PAUSED);
@ -251,9 +243,9 @@ library ValidationLogic {
uint256 stableDebt, uint256 stableDebt,
uint256 variableDebt uint256 variableDebt
) external view { ) external view {
bool isActive = reserve.configuration.getActive(); (bool isActive, , , , bool isPaused) = reserve.configuration.getFlags();
require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!isPaused, Errors.VL_RESERVE_PAUSED);
require(amountSent > 0, Errors.VL_INVALID_AMOUNT); require(amountSent > 0, Errors.VL_INVALID_AMOUNT);
@ -363,6 +355,9 @@ library ValidationLogic {
*/ */
function validateSetUseReserveAsCollateral(DataTypes.ReserveData storage reserve) external view { function validateSetUseReserveAsCollateral(DataTypes.ReserveData storage reserve) external view {
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender); uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
bool isPaused = reserve.configuration.getPaused();
require(!isPaused, Errors.VL_RESERVE_PAUSED);
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0); require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
} }
@ -372,7 +367,17 @@ library ValidationLogic {
* @param assets The assets being flashborrowed * @param assets The assets being flashborrowed
* @param amounts The amounts for each asset being borrowed * @param amounts The amounts for each asset being borrowed
**/ **/
function validateFlashloan(address[] memory assets, uint256[] memory amounts) external pure { function validateFlashloan(
address[] memory assets,
uint256[] memory amounts,
mapping(address => DataTypes.ReserveData) storage reservesData
) external view {
for (uint i = 0; i < assets.length; i++) {
require(
!reservesData[assets[i]].configuration.getPaused(),
Errors.VL_RESERVE_PAUSED
);
}
require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS); require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS);
} }
@ -401,6 +406,14 @@ library ValidationLogic {
Errors.VL_NO_ACTIVE_RESERVE Errors.VL_NO_ACTIVE_RESERVE
); );
} }
if (
collateralReserve.configuration.getPaused() || principalReserve.configuration.getPaused()
) {
return (
uint256(Errors.CollateralManagerErrors.PAUSED_RESERVE),
Errors.VL_RESERVE_PAUSED
);
}
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) { if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
return ( return (
@ -441,6 +454,7 @@ library ValidationLogic {
* @param oracle The price oracle * @param oracle The price oracle
*/ */
function validateHealthFactor( function validateHealthFactor(
address reserveAddress,
address from, address from,
mapping(address => DataTypes.ReserveData) storage reservesData, mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig, DataTypes.UserConfigurationMap storage userConfig,
@ -448,6 +462,8 @@ library ValidationLogic {
uint256 reservesCount, uint256 reservesCount,
address oracle address oracle
) internal view { ) internal view {
bool isPaused = reservesData[reserveAddress].configuration.getPaused();
require(!isPaused, Errors.VL_RESERVE_PAUSED);
(, , , , uint256 healthFactor) = (, , , , uint256 healthFactor) =
GenericLogic.calculateUserAccountData( GenericLogic.calculateUserAccountData(
from, from,