-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pausable.sol
84 lines (73 loc) · 2.25 KB
/
Pausable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.9;
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "../access/WithMidasAccessControl.sol";
/**
* @title Pausable
* @notice Base contract that implements basic functions and modifiers
* with pause functionality
* @author RedDuck Software
*/
abstract contract Pausable is WithMidasAccessControl, PausableUpgradeable {
mapping(bytes4 => bool) public fnPaused;
/**
* @param caller caller address (msg.sender)
* @param fn function id
*/
event PauseFn(address indexed caller, bytes4 fn);
/**
* @param caller caller address (msg.sender)
* @param fn function id
*/
event UnpauseFn(address indexed caller, bytes4 fn);
modifier whenFnNotPaused(bytes4 fn) {
_requireNotPaused();
require(!fnPaused[fn], "Pausable: fn paused");
_;
}
/**
* @dev checks that a given `account`
* has a determinedPauseAdminRole
*/
modifier onlyPauseAdmin() {
_onlyRole(pauseAdminRole(), msg.sender);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _accessControl MidasAccessControl contract address
*/
// solhint-disable-next-line func-name-mixedcase
function __Pausable_init(address _accessControl) internal onlyInitializing {
super.__Pausable_init();
__WithMidasAccessControl_init(_accessControl);
}
function pause() external onlyPauseAdmin {
_pause();
}
function unpause() external onlyPauseAdmin {
_unpause();
}
/**
* @dev pause specific function
* @param fn function id
*/
function pauseFn(bytes4 fn) external onlyPauseAdmin {
require(!fnPaused[fn], "Pausable: fn paused");
fnPaused[fn] = true;
emit PauseFn(msg.sender, fn);
}
/**
* @dev unpause specific function
* @param fn function id
*/
function unpauseFn(bytes4 fn) external onlyPauseAdmin {
require(fnPaused[fn], "Pausable: fn unpaused");
fnPaused[fn] = false;
emit UnpauseFn(msg.sender, fn);
}
/**
* @dev virtual function to determine pauseAdmin role
*/
function pauseAdminRole() public view virtual returns (bytes32);
}