mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: implemented pause validation for reserve assets
This commit is contained in:
parent
788ab15665
commit
05f66f0513
|
@ -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],
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,11 @@ library ValidationLogic {
|
||||||
* @param amount The amount to be deposited
|
* @param amount The amount to be deposited
|
||||||
*/
|
*/
|
||||||
function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) external view {
|
function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) external view {
|
||||||
(bool isActive, bool isFrozen, , , ) = reserve.configuration.getFlags();
|
(bool isActive, bool isFrozen, , , bool isPaused) = reserve.configuration.getFlags();
|
||||||
|
|
||||||
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(
|
||||||
IERC20(reserve.aTokenAddress)
|
IERC20(reserve.aTokenAddress)
|
||||||
|
@ -70,8 +71,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 {
|
||||||
|
@ -233,10 +235,10 @@ library ValidationLogic {
|
||||||
address onBehalfOf,
|
address onBehalfOf,
|
||||||
uint256 stableDebt,
|
uint256 stableDebt,
|
||||||
uint256 variableDebt
|
uint256 variableDebt
|
||||||
) internal 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);
|
||||||
|
|
||||||
|
@ -348,6 +350,9 @@ library ValidationLogic {
|
||||||
DataTypes.ReserveData storage reserve
|
DataTypes.ReserveData storage reserve
|
||||||
) external view {
|
) 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);
|
||||||
}
|
}
|
||||||
|
@ -357,7 +362,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) internal pure {
|
function validateFlashloan(
|
||||||
|
address[] memory assets,
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS);
|
require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,6 +401,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 (
|
||||||
|
@ -426,6 +449,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,
|
||||||
|
@ -433,6 +457,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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user