mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
refactor: refactor validation logic after merging validateHealthFactor
This commit is contained in:
parent
2f388c1b49
commit
e18bd375cc
|
@ -720,6 +720,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
|||
) external override whenNotPaused {
|
||||
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
||||
|
||||
ValidationLogic.validateTransfer(_reserves[asset]);
|
||||
|
||||
uint256 reserveId = _reserves[asset].id;
|
||||
|
||||
if (from != to) {
|
||||
|
@ -728,7 +730,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
|||
if (fromConfig.isUsingAsCollateral(reserveId)) {
|
||||
if (fromConfig.isBorrowingAny()) {
|
||||
ValidationLogic.validateHealthFactor(
|
||||
asset,
|
||||
from,
|
||||
_reserves,
|
||||
_usersConfig[from],
|
||||
|
|
|
@ -48,15 +48,13 @@ library ValidationLogic {
|
|||
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||
require(!isFrozen, Errors.VL_RESERVE_FROZEN);
|
||||
require(
|
||||
IERC20(reserve.aTokenAddress)
|
||||
.totalSupply()
|
||||
.add(amount)
|
||||
.div(10 ** reserve.configuration.getDecimals()) < reserve.configuration.getSupplyCap(),
|
||||
IERC20(reserve.aTokenAddress).totalSupply().add(amount).div(
|
||||
10**reserve.configuration.getDecimals()
|
||||
) < reserve.configuration.getSupplyCap(),
|
||||
Errors.VL_SUPPLY_CAP_EXCEEDED
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev Validates a withdraw action
|
||||
* @param reserve The reserve object
|
||||
|
@ -71,7 +69,7 @@ library ValidationLogic {
|
|||
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
||||
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
||||
|
||||
(bool isActive, , , , bool isPaused) = reservesData[reserveAddress].configuration.getFlags();
|
||||
(bool isActive, , , , bool isPaused) = reserve.configuration.getFlags();
|
||||
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||
}
|
||||
|
@ -124,9 +122,13 @@ library ValidationLogic {
|
|||
) internal view {
|
||||
ValidateBorrowLocalVars memory vars;
|
||||
|
||||
(vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled, vars.isPaused) = reserve
|
||||
.configuration
|
||||
.getFlags();
|
||||
(
|
||||
vars.isActive,
|
||||
vars.isFrozen,
|
||||
vars.borrowingEnabled,
|
||||
vars.stableRateBorrowingEnabled,
|
||||
vars.isPaused
|
||||
) = reserve.configuration.getFlags();
|
||||
|
||||
require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
require(!vars.isPaused, Errors.VL_RESERVE_PAUSED);
|
||||
|
@ -146,17 +148,15 @@ library ValidationLogic {
|
|||
.getTotalSupplyAndAvgRate();
|
||||
|
||||
vars.totalSupplyVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress)
|
||||
.scaledTotalSupply()
|
||||
.rayMul(reserve.variableBorrowIndex);
|
||||
|
||||
.scaledTotalSupply()
|
||||
.rayMul(reserve.variableBorrowIndex);
|
||||
|
||||
require(
|
||||
vars.totalSupplyStableDebt
|
||||
.add(vars.totalSupplyVariableDebt)
|
||||
.add(amount)
|
||||
.div(10 ** reserve.configuration.getDecimals())
|
||||
< reserve.configuration.getBorrowCap(),
|
||||
Errors.VL_BORROW_CAP_EXCEEDED);
|
||||
vars.totalSupplyStableDebt.add(vars.totalSupplyVariableDebt).add(amount).div(
|
||||
10**reserve.configuration.getDecimals()
|
||||
) < reserve.configuration.getBorrowCap(),
|
||||
Errors.VL_BORROW_CAP_EXCEEDED
|
||||
);
|
||||
|
||||
(
|
||||
vars.userCollateralBalanceETH,
|
||||
|
@ -271,7 +271,8 @@ library ValidationLogic {
|
|||
uint256 variableDebt,
|
||||
DataTypes.InterestRateMode currentRateMode
|
||||
) external view {
|
||||
(bool isActive, bool isFrozen, , bool stableRateEnabled, bool isPaused) = reserve.configuration.getFlags();
|
||||
(bool isActive, bool isFrozen, , bool stableRateEnabled, bool isPaused) =
|
||||
reserve.configuration.getFlags();
|
||||
|
||||
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||
|
@ -346,9 +347,7 @@ library ValidationLogic {
|
|||
* @dev Validates the action of setting an asset as collateral
|
||||
* @param reserve The state of the reserve that the user is enabling or disabling as collateral
|
||||
*/
|
||||
function validateSetUseReserveAsCollateral(
|
||||
DataTypes.ReserveData storage reserve
|
||||
) external view {
|
||||
function validateSetUseReserveAsCollateral(DataTypes.ReserveData storage reserve) external view {
|
||||
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
|
||||
bool isPaused = reserve.configuration.getPaused();
|
||||
|
||||
|
@ -367,11 +366,8 @@ library ValidationLogic {
|
|||
uint256[] memory amounts,
|
||||
mapping(address => DataTypes.ReserveData) storage reservesData
|
||||
) internal view {
|
||||
for (uint i = 0; i < assets.length; i++) {
|
||||
require(
|
||||
!reservesData[assets[i]].configuration.getPaused(),
|
||||
Errors.VL_RESERVE_PAUSED
|
||||
);
|
||||
for (uint256 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);
|
||||
}
|
||||
|
@ -401,13 +397,8 @@ library ValidationLogic {
|
|||
Errors.VL_NO_ACTIVE_RESERVE
|
||||
);
|
||||
}
|
||||
if (
|
||||
collateralReserve.configuration.getPaused() || principalReserve.configuration.getPaused()
|
||||
) {
|
||||
return (
|
||||
uint256(Errors.CollateralManagerErrors.PAUSED_RESERVE),
|
||||
Errors.VL_RESERVE_PAUSED
|
||||
);
|
||||
if (collateralReserve.configuration.getPaused() || principalReserve.configuration.getPaused()) {
|
||||
return (uint256(Errors.CollateralManagerErrors.PAUSED_RESERVE), Errors.VL_RESERVE_PAUSED);
|
||||
}
|
||||
|
||||
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
|
||||
|
@ -449,7 +440,6 @@ library ValidationLogic {
|
|||
* @param oracle The price oracle
|
||||
*/
|
||||
function validateHealthFactor(
|
||||
address reserveAddress,
|
||||
address from,
|
||||
mapping(address => DataTypes.ReserveData) storage reservesData,
|
||||
DataTypes.UserConfigurationMap storage userConfig,
|
||||
|
@ -457,8 +447,6 @@ library ValidationLogic {
|
|||
uint256 reservesCount,
|
||||
address oracle
|
||||
) internal view {
|
||||
bool isPaused = reservesData[reserveAddress].configuration.getPaused();
|
||||
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||
(, , , , uint256 healthFactor) =
|
||||
GenericLogic.calculateUserAccountData(
|
||||
from,
|
||||
|
@ -474,4 +462,12 @@ library ValidationLogic {
|
|||
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validates a transfer action
|
||||
* @param reserve The reserve object
|
||||
*/
|
||||
function validateTransfer(DataTypes.ReserveData storage reserve) internal view {
|
||||
require(!reserve.configuration.getPaused(), Errors.VL_RESERVE_PAUSED);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user