PausableUpgradeable.sol 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)
  3. pragma solidity ^0.8.0;
  4. import "../utils/ContextUpgradeable.sol";
  5. import "../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Contract module which allows children to implement an emergency stop
  8. * mechanism that can be triggered by an authorized account.
  9. *
  10. * This module is used through inheritance. It will make available the
  11. * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
  12. * the functions of your contract. Note that they will not be pausable by
  13. * simply including this module, only once the modifiers are put in place.
  14. */
  15. abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
  16. /**
  17. * @dev Emitted when the pause is triggered by `account`.
  18. */
  19. event Paused(address account);
  20. /**
  21. * @dev Emitted when the pause is lifted by `account`.
  22. */
  23. event Unpaused(address account);
  24. bool private _paused;
  25. /**
  26. * @dev Initializes the contract in unpaused state.
  27. */
  28. function __Pausable_init() internal onlyInitializing {
  29. __Pausable_init_unchained();
  30. }
  31. function __Pausable_init_unchained() internal onlyInitializing {
  32. _paused = false;
  33. }
  34. /**
  35. * @dev Returns true if the contract is paused, and false otherwise.
  36. */
  37. function paused() public view virtual returns (bool) {
  38. return _paused;
  39. }
  40. /**
  41. * @dev Modifier to make a function callable only when the contract is not paused.
  42. *
  43. * Requirements:
  44. *
  45. * - The contract must not be paused.
  46. */
  47. modifier whenNotPaused() {
  48. require(!paused(), "Pausable: paused");
  49. _;
  50. }
  51. /**
  52. * @dev Modifier to make a function callable only when the contract is paused.
  53. *
  54. * Requirements:
  55. *
  56. * - The contract must be paused.
  57. */
  58. modifier whenPaused() {
  59. require(paused(), "Pausable: not paused");
  60. _;
  61. }
  62. /**
  63. * @dev Triggers stopped state.
  64. *
  65. * Requirements:
  66. *
  67. * - The contract must not be paused.
  68. */
  69. function _pause() internal virtual whenNotPaused {
  70. _paused = true;
  71. emit Paused(_msgSender());
  72. }
  73. /**
  74. * @dev Returns to normal state.
  75. *
  76. * Requirements:
  77. *
  78. * - The contract must be paused.
  79. */
  80. function _unpause() internal virtual whenPaused {
  81. _paused = false;
  82. emit Unpaused(_msgSender());
  83. }
  84. /**
  85. * This empty reserved space is put in place to allow future versions to add new
  86. * variables without shifting down storage in the inheritance chain.
  87. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  88. */
  89. uint256[49] private __gap;
  90. }