Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contracts/protocol/libraries/helpers/ErrorsV2.sol
Original file line number Diff line number Diff line change
@@ -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();
}
47 changes: 25 additions & 22 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -312,17 +314,20 @@ 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));

//if the liquidity rate is below REBALANCE_UP_THRESHOLD of the max variable APR at 95% usage,
//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 &&
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down