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
3dd51dcc0a
commit
b6f8dedfca
|
@ -720,6 +720,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
) external override whenNotPaused {
|
) external override whenNotPaused {
|
||||||
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
||||||
|
|
||||||
|
ValidationLogic.validateTransfer(_reserves[asset]);
|
||||||
|
|
||||||
uint256 reserveId = _reserves[asset].id;
|
uint256 reserveId = _reserves[asset].id;
|
||||||
|
|
||||||
if (from != to) {
|
if (from != to) {
|
||||||
|
@ -728,7 +730,6 @@ 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],
|
||||||
|
|
|
@ -72,7 +72,7 @@ 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, , , , bool isPaused) = reservesData[reserveAddress].configuration.getFlags();
|
(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(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,8 @@ library ValidationLogic {
|
||||||
uint256 variableDebt,
|
uint256 variableDebt,
|
||||||
DataTypes.InterestRateMode currentRateMode
|
DataTypes.InterestRateMode currentRateMode
|
||||||
) external view {
|
) 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(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
require(!isPaused, Errors.VL_RESERVE_PAUSED);
|
||||||
|
@ -368,16 +369,13 @@ library ValidationLogic {
|
||||||
* @param amounts The amounts for each asset being borrowed
|
* @param amounts The amounts for each asset being borrowed
|
||||||
**/
|
**/
|
||||||
function validateFlashloan(
|
function validateFlashloan(
|
||||||
address[] memory assets,
|
address[] memory assets,
|
||||||
uint256[] memory amounts,
|
uint256[] memory amounts,
|
||||||
mapping(address => DataTypes.ReserveData) storage reservesData
|
mapping(address => DataTypes.ReserveData) storage reservesData
|
||||||
) external view {
|
) internal view {
|
||||||
for (uint i = 0; i < assets.length; i++) {
|
for (uint256 i = 0; i < assets.length; i++) {
|
||||||
require(
|
require(!reservesData[assets[i]].configuration.getPaused(), Errors.VL_RESERVE_PAUSED);
|
||||||
!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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,13 +404,8 @@ library ValidationLogic {
|
||||||
Errors.VL_NO_ACTIVE_RESERVE
|
Errors.VL_NO_ACTIVE_RESERVE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (collateralReserve.configuration.getPaused() || principalReserve.configuration.getPaused()) {
|
||||||
collateralReserve.configuration.getPaused() || principalReserve.configuration.getPaused()
|
return (uint256(Errors.CollateralManagerErrors.PAUSED_RESERVE), Errors.VL_RESERVE_PAUSED);
|
||||||
) {
|
|
||||||
return (
|
|
||||||
uint256(Errors.CollateralManagerErrors.PAUSED_RESERVE),
|
|
||||||
Errors.VL_RESERVE_PAUSED
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
|
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
|
||||||
|
@ -454,7 +447,6 @@ 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,
|
||||||
|
@ -462,8 +454,6 @@ 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,
|
||||||
|
@ -479,4 +469,12 @@ library ValidationLogic {
|
||||||
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
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