diff --git a/contracts/protocol/libraries/helpers/ErrorsV2.sol b/contracts/protocol/libraries/helpers/ErrorsV2.sol new file mode 100644 index 000000000..702f4fb55 --- /dev/null +++ b/contracts/protocol/libraries/helpers/ErrorsV2.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: BSD-3-Clause +pragma solidity 0.6.12; + +contract ErrorsV2 { + // Interest Rate Mode + error VL_INVALID_INTEREST_RATE_MODE_SELECTED(); +} diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 080b792d3..dbb4608c8 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -15,6 +15,7 @@ import {Errors} from '../helpers/Errors.sol'; import {Helpers} from '../helpers/Helpers.sol'; import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol'; import {DataTypes} from '../types/DataTypes.sol'; +import {ErrorsV2} from '../helpers/ErrorsV2.sol'; /** * @title ReserveLogic library @@ -144,11 +145,12 @@ library ValidationLogic { require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED); //validate interest rate mode - require( - uint256(DataTypes.InterestRateMode.VARIABLE) == interestRateMode || - uint256(DataTypes.InterestRateMode.STABLE) == interestRateMode, - Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED - ); + if ( + uint256(DataTypes.InterestRateMode.VARIABLE) != interestRateMode && + uint256(DataTypes.InterestRateMode.STABLE) != interestRateMode + ) { + revert VL_INVALID_INTEREST_RATE_MODE_SELECTED(); + } ( vars.userCollateralBalanceETH, @@ -288,7 +290,7 @@ library ValidationLogic { Errors.VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY ); } else { - revert(Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED); + revert VL_INVALID_INTEREST_RATE_MODE_SELECTED(); } } @@ -312,8 +314,10 @@ library ValidationLogic { require(isActive, Errors.VL_NO_ACTIVE_RESERVE); //if the usage ratio is below 95%, no rebalances are needed - uint256 totalDebt = - stableDebtToken.totalSupply().add(variableDebtToken.totalSupply()).wadToRay(); + uint256 totalDebt = stableDebtToken + .totalSupply() + .add(variableDebtToken.totalSupply()) + .wadToRay(); uint256 availableLiquidity = IERC20(reserveAddress).balanceOf(aTokenAddress).wadToRay(); uint256 usageRatio = totalDebt == 0 ? 0 : totalDebt.rayDiv(availableLiquidity.add(totalDebt)); @@ -321,8 +325,9 @@ library ValidationLogic { //then we allow rebalancing of the stable rate positions. uint256 currentLiquidityRate = reserve.currentLiquidityRate; - uint256 maxVariableBorrowRate = - IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).getMaxVariableBorrowRate(); + uint256 maxVariableBorrowRate = IReserveInterestRateStrategy( + reserve.interestRateStrategyAddress + ).getMaxVariableBorrowRate(); require( usageRatio >= REBALANCE_UP_USAGE_RATIO_THRESHOLD && @@ -413,9 +418,8 @@ library ValidationLogic { ); } - bool isCollateralEnabled = - collateralReserve.configuration.getLiquidationThreshold() > 0 && - userConfig.isUsingAsCollateral(collateralReserve.id); + bool isCollateralEnabled = collateralReserve.configuration.getLiquidationThreshold() > 0 && + userConfig.isUsingAsCollateral(collateralReserve.id); //if collateral isn't enabled as collateral by user, it cannot be liquidated if (!isCollateralEnabled) { @@ -451,15 +455,14 @@ library ValidationLogic { uint256 reservesCount, address oracle ) internal view { - (, , , , uint256 healthFactor) = - GenericLogic.calculateUserAccountData( - from, - reservesData, - userConfig, - reserves, - reservesCount, - oracle - ); + (, , , , uint256 healthFactor) = GenericLogic.calculateUserAccountData( + from, + reservesData, + userConfig, + reserves, + reservesCount, + oracle + ); require( healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,