refactor: refactored the pause pool funciton. From global pause to reserve local pauses

This commit is contained in:
Hadrien Charlanes 2021-07-01 14:15:40 +02:00
parent 8bf4b0acf4
commit 66165c4fdd
5 changed files with 41 additions and 58 deletions

View File

@ -350,16 +350,11 @@ interface ILendingPoolConfigurator {
function unfreezeReserve(address asset) external;
/**
* @dev Pauses a reserve. A paused reserve allow now user moves such as deposit, borrow, repay, swap interestrate, liquidate
* @dev Pauses/Unpauses a reserve. A paused reserve allow now user moves such as deposit, borrow, repay, swap interestrate, liquidate
* @param asset The address of the underlying asset of the reserve
* @param val true = pausing, false = unpausing
**/
function pauseReserve(address asset) external;
/**
* @dev Unpauses a reserve
* @param asset The address of the underlying asset of the reserve
**/
function unpauseReserve(address asset) external;
function setReservePause(address asset, bool val) external;
/**
* @dev Updates the reserve factor of a reserve
@ -378,6 +373,7 @@ interface ILendingPoolConfigurator {
/**
* @dev pauses or unpauses all the actions of the protocol, including aToken transfers
* Effectively it pauses every reserve
* @param val true if protocol needs to be paused, false otherwise
**/
function setPoolPause(bool val) external;

View File

@ -53,20 +53,11 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 public constant LENDINGPOOL_REVISION = 0x2;
modifier whenNotPaused() {
_whenNotPaused();
_;
}
modifier onlyLendingPoolConfigurator() {
_onlyLendingPoolConfigurator();
_;
}
function _whenNotPaused() internal view {
require(!_paused, Errors.LP_IS_PAUSED);
}
function _onlyLendingPoolConfigurator() internal view {
require(
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
@ -99,7 +90,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external override whenNotPaused {
) external override {
_executeDeposit(asset, amount, onBehalfOf, referralCode);
}
@ -131,7 +122,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address asset,
uint256 amount,
address to
) external override whenNotPaused returns (uint256) {
) external override returns (uint256) {
return _executeWithdraw(asset, amount, to);
}
@ -142,7 +133,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external override whenNotPaused {
) external override {
_executeBorrow(
ExecuteBorrowParams(
asset,
@ -162,7 +153,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount,
uint256 rateMode,
address onBehalfOf
) external override whenNotPaused returns (uint256) {
) external override returns (uint256) {
return _executeRepay(asset, amount, rateMode, onBehalfOf);
}
@ -190,7 +181,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
///@inheritdoc ILendingPool
function swapBorrowRateMode(address asset, uint256 rateMode) external override whenNotPaused {
function swapBorrowRateMode(address asset, uint256 rateMode) external override {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
@ -239,7 +230,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
///@inheritdoc ILendingPool
function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused {
function rebalanceStableBorrowRate(address asset, address user) external override {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
@ -274,11 +265,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
///@inheritdoc ILendingPool
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
external
override
whenNotPaused
{
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
@ -310,7 +297,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address user,
uint256 debtToCover,
bool receiveAToken
) external override whenNotPaused {
) external override {
address collateralManager = _addressesProvider.getLendingPoolCollateralManager();
//solium-disable-next-line
@ -359,7 +346,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) external override whenNotPaused {
) external override {
FlashLoanLocalVars memory vars;
vars.aTokenAddresses = new address[](assets.length);
@ -498,6 +485,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
ltv,
currentLiquidationThreshold,
healthFactor,
) = GenericLogic.getUserAccountData(
user,
_reserves,
@ -617,7 +605,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 amount,
uint256 balanceFromBefore,
uint256 balanceToBefore
) external override whenNotPaused {
) external override {
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
ValidationLogic.validateTransfer(_reserves[asset]);

View File

@ -407,25 +407,18 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
}
/// @inheritdoc ILendingPoolConfigurator
function pauseReserve(address asset) external override onlyEmergencyOrPoolAdmin {
function setReservePause(address asset, bool val) public override onlyEmergencyOrPoolAdmin {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setPaused(true);
currentConfig.setPaused(val);
_pool.setConfiguration(asset, currentConfig.data);
emit ReservePaused(asset);
}
/// @inheritdoc ILendingPoolConfigurator
function unpauseReserve(address asset) external override onlyEmergencyOrPoolAdmin {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setPaused(false);
_pool.setConfiguration(asset, currentConfig.data);
emit ReserveUnpaused(asset);
if (val) {
emit ReservePaused(asset);
} else {
emit ReserveUnpaused(asset);
}
}
/// @inheritdoc ILendingPoolConfigurator
@ -492,7 +485,11 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
/// @inheritdoc ILendingPoolConfigurator
function setPoolPause(bool val) external override onlyEmergencyAdmin {
_pool.setPause(val);
address[] memory reserves = _pool.getReservesList();
for (uint256 i = 0; i < reserves.length; i++) {
setReservePause(reserves[i], val);
}
}
/// @inheritdoc ILendingPoolConfigurator

View File

@ -22,6 +22,8 @@ contract LendingPoolStorage {
uint256 internal _reservesCount;
// Deprecated: global LendingPool pause state, no longer used
// Replaced by pause states for each reserve
bool internal _paused;
uint256 internal _maxStableRateBorrowSizePercent;

View File

@ -75,7 +75,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(await configurator.signer.getAddress()).to.be.equal(
await addressesProvider.getPoolAdmin()
);
await configurator.pauseReserve(weth.address);
await configurator.setReservePause(weth.address, true);
const {
decimals,
ltv,
@ -106,7 +106,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Unpauses the ETH reserve by pool admin ', async () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.unpauseReserve(weth.address);
await configurator.setReservePause(weth.address, false);
const {
decimals,
@ -138,7 +138,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Pauses the ETH reserve by emergency admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
testEnv;
await configurator.connect(emergencyAdmin.signer).pauseReserve(weth.address);
await configurator.connect(emergencyAdmin.signer).setReservePause(weth.address, true);
const {
decimals,
ltv,
@ -169,7 +169,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Unpauses the ETH reserve by emergency admin ', async () => {
const { configurator, helpersContract, weth, users, emergencyAdmin } = testEnv;
await configurator.connect(emergencyAdmin.signer).unpauseReserve(weth.address);
await configurator.connect(emergencyAdmin.signer).setReservePause(weth.address, false);
const {
decimals,
@ -202,7 +202,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Check the only admin or emergency admin can pauseReserve ', async () => {
const { configurator, users, weth, riskAdmin } = testEnv;
await expect(
configurator.connect(riskAdmin.signer).pauseReserve(weth.address),
configurator.connect(riskAdmin.signer).setReservePause(weth.address, true),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN);
});
@ -210,14 +210,14 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Check the only admin or emergency admin can unpauseReserve ', async () => {
const { configurator, users, weth, riskAdmin } = testEnv;
await expect(
configurator.connect(riskAdmin.signer).unpauseReserve(weth.address),
configurator.connect(riskAdmin.signer).setReservePause(weth.address, false),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN);
});
it('Pauses the ETH reserve by the pool admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
testEnv;
await configurator.pauseReserve(weth.address);
await configurator.setReservePause(weth.address, true);
const {
decimals,
ltv,
@ -251,7 +251,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Unpauses the ETH reserve by pool admin ', async () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.unpauseReserve(weth.address);
await configurator.setReservePause(weth.address, false);
const {
decimals,
@ -286,7 +286,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Pauses the ETH reserve by emergency admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
testEnv;
await configurator.connect(emergencyAdmin.signer).pauseReserve(weth.address);
await configurator.connect(emergencyAdmin.signer).setReservePause(weth.address, true);
const {
decimals,
ltv,
@ -320,7 +320,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Unpauses the ETH reserve by emergency admin ', async () => {
const { configurator, helpersContract, weth, users, emergencyAdmin } = testEnv;
await configurator.connect(emergencyAdmin.signer).unpauseReserve(weth.address);
await configurator.connect(emergencyAdmin.signer).setReservePause(weth.address, false);
const {
decimals,
@ -356,7 +356,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Check the only admin or emergency admin can pauseReserve ', async () => {
const { configurator, users, weth, riskAdmin } = testEnv;
await expect(
configurator.connect(riskAdmin.signer).pauseReserve(weth.address),
configurator.connect(riskAdmin.signer).setReservePause(weth.address, true),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN);
});
@ -364,7 +364,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Check the only admin or emergency admin can unpauseReserve ', async () => {
const { configurator, users, weth, riskAdmin } = testEnv;
await expect(
configurator.connect(riskAdmin.signer).unpauseReserve(weth.address),
configurator.connect(riskAdmin.signer).setReservePause(weth.address, false),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN);
});