Merge branch 'fix/130' into 'master'

Resolve "Add a modifier for _whenNotPaused()"

Closes #130

See merge request aave-tech/protocol-v2!152
This commit is contained in:
The-3D 2020-11-10 16:48:30 +00:00
commit 3fc812e7fb

View File

@ -43,6 +43,22 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 public constant MAX_NUMBER_RESERVES = 128; uint256 public constant MAX_NUMBER_RESERVES = 128;
uint256 public constant LENDINGPOOL_REVISION = 0x2; uint256 public constant LENDINGPOOL_REVISION = 0x2;
/**
* @dev functions marked by this modifier can only be called when the protocol is not paused
**/
modifier whenNotPaused() {
_whenNotPaused();
_;
}
/**
* @dev functions marked by this modifier can only be called by the LendingPoolConfigurator
**/
modifier onlyLendingPoolConfigurator() {
_onlyLendingPoolConfigurator();
_;
}
/** /**
* @dev only lending pools configurator can use functions affected by this modifier * @dev only lending pools configurator can use functions affected by this modifier
**/ **/
@ -89,8 +105,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount, uint256 amount,
address onBehalfOf, address onBehalfOf,
uint16 referralCode uint16 referralCode
) external override { ) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
ValidationLogic.validateDeposit(reserve, amount); ValidationLogic.validateDeposit(reserve, amount);
@ -123,8 +138,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address asset, address asset,
uint256 amount, uint256 amount,
address to address to
) external override { ) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
address aToken = reserve.aTokenAddress; address aToken = reserve.aTokenAddress;
@ -178,8 +193,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 interestRateMode, uint256 interestRateMode,
uint16 referralCode, uint16 referralCode,
address onBehalfOf address onBehalfOf
) external override { ) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
_executeBorrow( _executeBorrow(
@ -209,8 +223,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount, uint256 amount,
uint256 rateMode, uint256 rateMode,
address onBehalfOf address onBehalfOf
) external override { ) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
@ -266,8 +279,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @param asset the address of the reserve on which the user borrowed * @param asset the address of the reserve on which the user borrowed
* @param rateMode the rate mode that the user wants to swap * @param rateMode the rate mode that the user wants to swap
**/ **/
function swapBorrowRateMode(address asset, uint256 rateMode) external override { function swapBorrowRateMode(address asset, uint256 rateMode) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(msg.sender, reserve); (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(msg.sender, reserve);
@ -321,8 +334,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @param asset the address of the reserve * @param asset the address of the reserve
* @param user the address of the user to be rebalanced * @param user the address of the user to be rebalanced
**/ **/
function rebalanceStableBorrowRate(address asset, address user) external override { function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
@ -360,8 +372,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @param asset the address of the reserve * @param asset the address of the reserve
* @param useAsCollateral true if the user wants to use the deposit as collateral, false otherwise. * @param useAsCollateral true if the user wants to use the deposit as collateral, false otherwise.
**/ **/
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override { function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override whenNotPaused {
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
ValidationLogic.validateSetUseReserveAsCollateral( ValidationLogic.validateSetUseReserveAsCollateral(
@ -399,8 +411,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address user, address user,
uint256 purchaseAmount, uint256 purchaseAmount,
bool receiveAToken bool receiveAToken
) external override { ) external override whenNotPaused {
_whenNotPaused();
address collateralManager = _addressesProvider.getLendingPoolCollateralManager(); address collateralManager = _addressesProvider.getLendingPoolCollateralManager();
//solium-disable-next-line //solium-disable-next-line
@ -456,8 +467,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address onBehalfOf, address onBehalfOf,
bytes calldata params, bytes calldata params,
uint16 referralCode uint16 referralCode
) external override { ) external override whenNotPaused {
_whenNotPaused();
FlashLoanLocalVars memory vars; FlashLoanLocalVars memory vars;
@ -693,8 +703,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount, uint256 amount,
uint256 balanceFromBefore, uint256 balanceFromBefore,
uint256 balanceToBefore uint256 balanceToBefore
) external override { ) external override whenNotPaused {
_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);
@ -743,8 +752,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address stableDebtAddress, address stableDebtAddress,
address variableDebtAddress, address variableDebtAddress,
address interestRateStrategyAddress address interestRateStrategyAddress
) external override { ) external override onlyLendingPoolConfigurator {
_onlyLendingPoolConfigurator();
_reserves[asset].init( _reserves[asset].init(
aTokenAddress, aTokenAddress,
stableDebtAddress, stableDebtAddress,
@ -762,8 +771,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external external
override override
onlyLendingPoolConfigurator
{ {
_onlyLendingPoolConfigurator();
_reserves[asset].interestRateStrategyAddress = rateStrategyAddress; _reserves[asset].interestRateStrategyAddress = rateStrategyAddress;
} }
@ -772,8 +781,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @param asset the address of the reserve * @param asset the address of the reserve
* @param configuration the configuration map * @param configuration the configuration map
**/ **/
function setConfiguration(address asset, uint256 configuration) external override { function setConfiguration(address asset, uint256 configuration) external override onlyLendingPoolConfigurator {
_onlyLendingPoolConfigurator();
_reserves[asset].configuration.data = configuration; _reserves[asset].configuration.data = configuration;
} }
@ -781,8 +789,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @dev Set the _pause state * @dev Set the _pause state
* @param val the boolean value to set the current pause state of LendingPool * @param val the boolean value to set the current pause state of LendingPool
*/ */
function setPause(bool val) external override { function setPause(bool val) external override onlyLendingPoolConfigurator {
_onlyLendingPoolConfigurator();
_paused = val; _paused = val;
if (_paused) { if (_paused) {