-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPauser.sol
More file actions
213 lines (186 loc) · 7.46 KB
/
Pauser.sol
File metadata and controls
213 lines (186 loc) · 7.46 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/// @title Pauser
/// @notice Contract for managing pause states of various system functions
/// @author WalletConnect
contract Pauser is Initializable, AccessControlUpgradeable {
/// @notice Emitted when a flag has been updated
/// @param selector The selector of the flag that was updated
/// @param isPaused The new value of the flag
/// @param flagName The name of the flag that was updated
event FlagUpdated(bytes4 indexed selector, bool indexed isPaused, string flagName);
error InvalidInput();
/// @notice Role for pausing functions
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/// @notice Role for unpausing functions
bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE");
/// @notice Flag indicating if stakeWeight is paused
bool public isStakeWeightPaused;
/// @notice Flag indicating if submit oracle records is paused
bool public isSubmitOracleRecordsPaused;
/// @notice Flag indicating if locked token staker is paused
bool public isLockedTokenStakerPaused;
/// @notice Flag indicating if node reward manager is paused
bool public isNodeRewardManagerPaused;
/// @notice Flag indicating if wallet reward manager is paused
bool public isWalletRewardManagerPaused;
/// @notice Flag indicating if staking reward distributor is paused
bool public isStakingRewardDistributorPaused;
/// @notice Configuration for contract initialization
struct Init {
address admin;
address pauser;
}
/// @notice Initializes the contract
/// @dev MUST be called during the contract upgrade to set up the proxies state
/// @param init Initialization parameters
function initialize(Init memory init) external initializer {
__AccessControl_init();
_grantRole(DEFAULT_ADMIN_ROLE, init.admin);
if (init.pauser == address(0)) {
revert InvalidInput();
}
_grantRole(PAUSER_ROLE, init.pauser);
_grantRole(UNPAUSER_ROLE, init.admin);
}
/// @notice Pauses or unpauses staking
/// @param isPaused The new pause state
function setIsStakeWeightPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsStakeWeightPaused(isPaused);
}
/// @notice Pauses or unpauses locked token staker
/// @param isPaused The new pause state
function setIsLockedTokenStakerPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsLockedTokenStakerPaused(isPaused);
}
/// @notice Pauses or unpauses submit oracle records
/// @param isPaused The new pause state
function setIsSubmitOracleRecordsPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsSubmitOracleRecordsPaused(isPaused);
}
/// @notice Pauses or unpauses node reward manager
/// @param isPaused The new pause state
function setIsNodeRewardManagerPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsNodeRewardManagerPaused(isPaused);
}
/// @notice Pauses or unpauses wallet reward manager
/// @param isPaused The new pause state
function setIsWalletRewardManagerPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsWalletRewardManagerPaused(isPaused);
}
/// @notice Pauses or unpauses staking reward distributor
/// @param isPaused The new pause state
function setIsStakingRewardDistributorPaused(bool isPaused) external {
if (isPaused) {
_checkRole(PAUSER_ROLE);
} else {
_checkRole(UNPAUSER_ROLE);
}
_setIsStakingRewardDistributorPaused(isPaused);
}
/// @dev Sets the node reward manager pause state
/// @param isPaused The new pause state
function _setIsNodeRewardManagerPaused(bool isPaused) private {
isNodeRewardManagerPaused = isPaused;
emit FlagUpdated({
selector: this.isNodeRewardManagerPaused.selector,
isPaused: isPaused,
flagName: "isNodeRewardManagerPaused"
});
}
/// @dev Sets the wallet reward manager pause state
/// @param isPaused The new pause state
function _setIsWalletRewardManagerPaused(bool isPaused) private {
isWalletRewardManagerPaused = isPaused;
emit FlagUpdated({
selector: this.isWalletRewardManagerPaused.selector,
isPaused: isPaused,
flagName: "isWalletRewardManagerPaused"
});
}
/// @notice Pauses all actions
function pauseAll() external onlyRole(PAUSER_ROLE) {
_setIsStakeWeightPaused(true);
_setIsSubmitOracleRecordsPaused(true);
_setIsLockedTokenStakerPaused(true);
_setIsNodeRewardManagerPaused(true);
_setIsWalletRewardManagerPaused(true);
_setIsStakingRewardDistributorPaused(true);
}
/// @notice Unpauses all actions
function unpauseAll() external onlyRole(UNPAUSER_ROLE) {
_setIsStakeWeightPaused(false);
_setIsSubmitOracleRecordsPaused(false);
_setIsLockedTokenStakerPaused(false);
_setIsNodeRewardManagerPaused(false);
_setIsWalletRewardManagerPaused(false);
_setIsStakingRewardDistributorPaused(false);
}
/// @dev Sets the staking pause state
/// @param isPaused The new pause state
function _setIsStakeWeightPaused(bool isPaused) private {
isStakeWeightPaused = isPaused;
emit FlagUpdated({
selector: this.isStakeWeightPaused.selector,
isPaused: isPaused,
flagName: "isStakeWeightPaused"
});
}
/// @dev Sets the submit oracle records pause state
/// @param isPaused The new pause state
function _setIsSubmitOracleRecordsPaused(bool isPaused) private {
isSubmitOracleRecordsPaused = isPaused;
emit FlagUpdated({
selector: this.isSubmitOracleRecordsPaused.selector,
isPaused: isPaused,
flagName: "isSubmitOracleRecordsPaused"
});
}
/// @dev Sets the locked token staker pause state
/// @param isPaused The new pause state
function _setIsLockedTokenStakerPaused(bool isPaused) private {
isLockedTokenStakerPaused = isPaused;
emit FlagUpdated({
selector: this.isLockedTokenStakerPaused.selector,
isPaused: isPaused,
flagName: "isLockedTokenStakerPaused"
});
}
/// @dev Sets the staking reward distributor pause state
/// @param isPaused The new pause state
function _setIsStakingRewardDistributorPaused(bool isPaused) private {
isStakingRewardDistributorPaused = isPaused;
emit FlagUpdated({
selector: this.isStakingRewardDistributorPaused.selector,
isPaused: isPaused,
flagName: "isStakingRewardDistributorPaused"
});
}
}