mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added PausablePool contract to support errors by number.
This commit is contained in:
parent
202ddbdec4
commit
6e0091a668
|
@ -4,7 +4,6 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
|
||||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
|
||||
import {Pausable} from '@openzeppelin/contracts/utils/Pausable.sol';
|
||||
import {
|
||||
VersionedInitializable
|
||||
} from '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
|
||||
|
@ -25,6 +24,7 @@ import {LendingPoolLiquidationManager} from './LendingPoolLiquidationManager.sol
|
|||
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
|
||||
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
|
||||
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||
import {PausablePool} from '../misc/PausablePool.sol';
|
||||
|
||||
/**
|
||||
* @title LendingPool contract
|
||||
|
@ -32,7 +32,7 @@ import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
|||
* @author Aave
|
||||
**/
|
||||
|
||||
contract LendingPool is VersionedInitializable, Pausable, ILendingPool {
|
||||
contract LendingPool is VersionedInitializable, PausablePool, ILendingPool {
|
||||
using SafeMath for uint256;
|
||||
using WadRayMath for uint256;
|
||||
using ReserveLogic for ReserveLogic.ReserveData;
|
||||
|
@ -929,9 +929,9 @@ contract LendingPool is VersionedInitializable, Pausable, ILendingPool {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the contract is paused, and false otherwise.
|
||||
* @dev retrieve pause status
|
||||
*/
|
||||
function isPaused() public override view returns (bool) {
|
||||
return Pausable.paused();
|
||||
return PausablePool.paused();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ library Errors {
|
|||
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
||||
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
||||
string public constant INVALID_ATOKEN_BALANCE = '52'; // balance on burning is invalid
|
||||
|
||||
// require error messages - ReserveLogic
|
||||
|
||||
// require error messages - ReserveLogic
|
||||
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
|
||||
string public constant LIQUIDITY_INDEX_OVERFLOW = '47'; // Liquidity index overflows uint128
|
||||
string public constant VARIABLE_BORROW_INDEX_OVERFLOW = '48'; // Variable borrow index overflows uint128
|
||||
|
@ -73,4 +73,8 @@ library Errors {
|
|||
string public constant MULTIPLICATION_OVERFLOW = '44';
|
||||
string public constant ADDITION_OVERFLOW = '45';
|
||||
string public constant DIVISION_BY_ZERO = '46';
|
||||
|
||||
// pausable error message
|
||||
string public constant IS_PAUSED = '54'; // 'Pool is paused'
|
||||
string public constant IS_ACTIVE = '55'; // 'Pool is active'
|
||||
}
|
||||
|
|
88
contracts/misc/PausablePool.sol
Normal file
88
contracts/misc/PausablePool.sol
Normal file
|
@ -0,0 +1,88 @@
|
|||
pragma solidity ^0.6.0;
|
||||
|
||||
import {Context} from './Context.sol';
|
||||
|
||||
/**
|
||||
* @dev Contract module which allows children to implement an emergency stop
|
||||
* mechanism that can be triggered by an authorized account.
|
||||
*
|
||||
* This module is used through inheritance. It will make available the
|
||||
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
|
||||
* the functions of your contract. Note that they will not be pausable by
|
||||
* simply including this module, only once the modifiers are put in place.
|
||||
*/
|
||||
contract PausablePool is Context {
|
||||
/**
|
||||
* @dev Emitted when the pause is triggered by `account`.
|
||||
*/
|
||||
event Paused(address account);
|
||||
|
||||
/**
|
||||
* @dev Emitted when the pause is lifted by `account`.
|
||||
*/
|
||||
event Unpaused(address account);
|
||||
|
||||
bool private _paused;
|
||||
|
||||
/**
|
||||
* @dev Initializes the contract in unpaused state.
|
||||
*/
|
||||
constructor() internal {
|
||||
_paused = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the contract is paused, and false otherwise.
|
||||
*/
|
||||
function paused() public virtual view returns (bool) {
|
||||
return _paused;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Modifier to make a function callable only when the contract is not paused.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The contract must not be paused.
|
||||
*/
|
||||
modifier whenNotPaused() {
|
||||
require(!_paused, '54');
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Modifier to make a function callable only when the contract is paused.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The contract must be paused.
|
||||
*/
|
||||
modifier whenPaused() {
|
||||
require(_paused, '55');
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Triggers stopped state.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The contract must not be paused.
|
||||
*/
|
||||
function _pause() internal virtual whenNotPaused {
|
||||
_paused = true;
|
||||
emit Paused(_msgSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns to normal state.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The contract must be paused.
|
||||
*/
|
||||
function _unpause() internal virtual whenPaused {
|
||||
_paused = false;
|
||||
emit Unpaused(_msgSender());
|
||||
}
|
||||
}
|
|
@ -99,7 +99,8 @@ export enum ProtocolErrors {
|
|||
NO_ERRORS = '42', // 'No errors'
|
||||
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
|
||||
|
||||
IS_PAUSED = 'Pausable: paused',
|
||||
IS_PAUSED = '54', // Pool is paused
|
||||
IS_ACTIVE = '55', // Pool is active
|
||||
|
||||
// old
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user