@bloxchain/contracts 1.0.0-alpha.15 → 1.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abi/BaseStateMachine.abi.json +5 -0
- package/abi/GuardController.abi.json +5 -0
- package/abi/GuardControllerDefinitions.abi.json +5 -0
- package/abi/IDefinition.abi.json +5 -0
- package/abi/RuntimeRBAC.abi.json +5 -0
- package/abi/RuntimeRBACDefinitions.abi.json +5 -0
- package/abi/SecureOwnable.abi.json +5 -0
- package/abi/SecureOwnableDefinitions.abi.json +5 -0
- package/core/access/lib/definitions/RuntimeRBACDefinitions.sol +290 -288
- package/core/base/BaseStateMachine.sol +947 -943
- package/core/execution/GuardController.sol +1 -0
- package/core/execution/lib/definitions/GuardControllerDefinitions.sol +514 -506
- package/core/lib/EngineBlox.sol +32 -7
- package/core/security/lib/definitions/SecureOwnableDefinitions.sol +802 -786
- package/package.json +1 -1
|
@@ -1,288 +1,290 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
pragma solidity 0.8.34;
|
|
3
|
-
|
|
4
|
-
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
-
import "../../../lib/EngineBlox.sol";
|
|
6
|
-
import "../../../lib/interfaces/IDefinition.sol";
|
|
7
|
-
import "../../../access/interface/IRuntimeRBAC.sol";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @title RuntimeRBACDefinitions
|
|
11
|
-
* @dev Library containing predefined definitions for RuntimeRBAC initialization
|
|
12
|
-
* This library holds static data that can be used to initialize RuntimeRBAC contracts
|
|
13
|
-
* without increasing the main contract size
|
|
14
|
-
*
|
|
15
|
-
* This library implements the IDefinition interface from EngineBlox
|
|
16
|
-
* and provides a direct initialization function for RuntimeRBAC contracts
|
|
17
|
-
*/
|
|
18
|
-
library RuntimeRBACDefinitions {
|
|
19
|
-
|
|
20
|
-
// Operation Type Constants
|
|
21
|
-
bytes32 public constant ROLE_CONFIG_BATCH = keccak256("ROLE_CONFIG_BATCH");
|
|
22
|
-
|
|
23
|
-
// Function Selector Constants
|
|
24
|
-
// Internal execution entrypoint for RBAC configuration batches
|
|
25
|
-
bytes4 public constant ROLE_CONFIG_BATCH_EXECUTE_SELECTOR =
|
|
26
|
-
bytes4(keccak256("executeRoleConfigBatch((uint8,bytes)[])"));
|
|
27
|
-
|
|
28
|
-
// Meta-transaction Function Selectors
|
|
29
|
-
// roleConfigBatchRequestAndApprove(EngineBlox.MetaTransaction memory metaTx)
|
|
30
|
-
bytes4 public constant ROLE_CONFIG_BATCH_META_SELECTOR =
|
|
31
|
-
bytes4(
|
|
32
|
-
keccak256(
|
|
33
|
-
"roleConfigBatchRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))"
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @dev Returns predefined function schemas
|
|
39
|
-
* @return Array of function schema definitions
|
|
40
|
-
*
|
|
41
|
-
* Registers the meta-transaction handler for RBAC configuration batches.
|
|
42
|
-
* All runtime RBAC changes must go through this single time-locked workflow.
|
|
43
|
-
*
|
|
44
|
-
* Function schemas include:
|
|
45
|
-
* - Handler function (roleConfigBatchRequestAndApprove): checked via msg.sig
|
|
46
|
-
* - Execution function (executeRoleConfigBatch): checked in EngineBlox for dual-permission model
|
|
47
|
-
*/
|
|
48
|
-
function getFunctionSchemas() public pure returns (EngineBlox.FunctionSchema[] memory) {
|
|
49
|
-
EngineBlox.FunctionSchema[] memory schemas = new EngineBlox.FunctionSchema[](2);
|
|
50
|
-
|
|
51
|
-
// Meta-transaction handler function schema
|
|
52
|
-
EngineBlox.TxAction[] memory metaRequestApproveActions = new EngineBlox.TxAction[](2);
|
|
53
|
-
metaRequestApproveActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
|
|
54
|
-
metaRequestApproveActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
|
|
55
|
-
|
|
56
|
-
bytes4[] memory handlerForSelectors = new bytes4[](1);
|
|
57
|
-
handlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
|
|
58
|
-
|
|
59
|
-
schemas[0] = EngineBlox.FunctionSchema({
|
|
60
|
-
functionSignature: "roleConfigBatchRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
61
|
-
functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
|
|
62
|
-
operationType: ROLE_CONFIG_BATCH,
|
|
63
|
-
operationName: "ROLE_CONFIG_BATCH",
|
|
64
|
-
supportedActionsBitmap: EngineBlox.createBitmapFromActions(metaRequestApproveActions),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
executionActions[
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
* @
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* @
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
* @
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
* @
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
* @
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
* @
|
|
275
|
-
*
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
pragma solidity 0.8.34;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
+
import "../../../lib/EngineBlox.sol";
|
|
6
|
+
import "../../../lib/interfaces/IDefinition.sol";
|
|
7
|
+
import "../../../access/interface/IRuntimeRBAC.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title RuntimeRBACDefinitions
|
|
11
|
+
* @dev Library containing predefined definitions for RuntimeRBAC initialization
|
|
12
|
+
* This library holds static data that can be used to initialize RuntimeRBAC contracts
|
|
13
|
+
* without increasing the main contract size
|
|
14
|
+
*
|
|
15
|
+
* This library implements the IDefinition interface from EngineBlox
|
|
16
|
+
* and provides a direct initialization function for RuntimeRBAC contracts
|
|
17
|
+
*/
|
|
18
|
+
library RuntimeRBACDefinitions {
|
|
19
|
+
|
|
20
|
+
// Operation Type Constants
|
|
21
|
+
bytes32 public constant ROLE_CONFIG_BATCH = keccak256("ROLE_CONFIG_BATCH");
|
|
22
|
+
|
|
23
|
+
// Function Selector Constants
|
|
24
|
+
// Internal execution entrypoint for RBAC configuration batches
|
|
25
|
+
bytes4 public constant ROLE_CONFIG_BATCH_EXECUTE_SELECTOR =
|
|
26
|
+
bytes4(keccak256("executeRoleConfigBatch((uint8,bytes)[])"));
|
|
27
|
+
|
|
28
|
+
// Meta-transaction Function Selectors
|
|
29
|
+
// roleConfigBatchRequestAndApprove(EngineBlox.MetaTransaction memory metaTx)
|
|
30
|
+
bytes4 public constant ROLE_CONFIG_BATCH_META_SELECTOR =
|
|
31
|
+
bytes4(
|
|
32
|
+
keccak256(
|
|
33
|
+
"roleConfigBatchRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))"
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @dev Returns predefined function schemas
|
|
39
|
+
* @return Array of function schema definitions
|
|
40
|
+
*
|
|
41
|
+
* Registers the meta-transaction handler for RBAC configuration batches.
|
|
42
|
+
* All runtime RBAC changes must go through this single time-locked workflow.
|
|
43
|
+
*
|
|
44
|
+
* Function schemas include:
|
|
45
|
+
* - Handler function (roleConfigBatchRequestAndApprove): checked via msg.sig
|
|
46
|
+
* - Execution function (executeRoleConfigBatch): checked in EngineBlox for dual-permission model
|
|
47
|
+
*/
|
|
48
|
+
function getFunctionSchemas() public pure returns (EngineBlox.FunctionSchema[] memory) {
|
|
49
|
+
EngineBlox.FunctionSchema[] memory schemas = new EngineBlox.FunctionSchema[](2);
|
|
50
|
+
|
|
51
|
+
// Meta-transaction handler function schema
|
|
52
|
+
EngineBlox.TxAction[] memory metaRequestApproveActions = new EngineBlox.TxAction[](2);
|
|
53
|
+
metaRequestApproveActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
|
|
54
|
+
metaRequestApproveActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
|
|
55
|
+
|
|
56
|
+
bytes4[] memory handlerForSelectors = new bytes4[](1);
|
|
57
|
+
handlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
|
|
58
|
+
|
|
59
|
+
schemas[0] = EngineBlox.FunctionSchema({
|
|
60
|
+
functionSignature: "roleConfigBatchRequestAndApprove(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
61
|
+
functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
|
|
62
|
+
operationType: ROLE_CONFIG_BATCH,
|
|
63
|
+
operationName: "ROLE_CONFIG_BATCH",
|
|
64
|
+
supportedActionsBitmap: EngineBlox.createBitmapFromActions(metaRequestApproveActions),
|
|
65
|
+
enforceHandlerRelations: true,
|
|
66
|
+
isProtected: true,
|
|
67
|
+
handlerForSelectors: handlerForSelectors
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Execution function schema (required for dual-permission model)
|
|
71
|
+
// This is checked in EngineBlox._validateExecutionAndHandlerPermissions
|
|
72
|
+
// Must support both SIGN (for owner) and EXECUTE (for broadcaster) actions
|
|
73
|
+
EngineBlox.TxAction[] memory executionActions = new EngineBlox.TxAction[](2);
|
|
74
|
+
executionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
|
|
75
|
+
executionActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
|
|
76
|
+
|
|
77
|
+
// Execution selectors must have at least one element pointing to themselves (self-reference)
|
|
78
|
+
bytes4[] memory executionHandlerForSelectors = new bytes4[](1);
|
|
79
|
+
executionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
|
|
80
|
+
|
|
81
|
+
schemas[1] = EngineBlox.FunctionSchema({
|
|
82
|
+
functionSignature: "executeRoleConfigBatch((uint8,bytes)[])",
|
|
83
|
+
functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
|
|
84
|
+
operationType: ROLE_CONFIG_BATCH,
|
|
85
|
+
operationName: "ROLE_CONFIG_BATCH",
|
|
86
|
+
supportedActionsBitmap: EngineBlox.createBitmapFromActions(executionActions),
|
|
87
|
+
enforceHandlerRelations: false,
|
|
88
|
+
isProtected: true,
|
|
89
|
+
handlerForSelectors: executionHandlerForSelectors
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return schemas;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @dev Returns predefined role hashes and their corresponding function permissions
|
|
97
|
+
* @return RolePermission struct containing roleHashes and functionPermissions arrays
|
|
98
|
+
*
|
|
99
|
+
* OWNER: allowed to SIGN_META_REQUEST_AND_APPROVE for the batch handler
|
|
100
|
+
* BROADCASTER: allowed to EXECUTE_META_REQUEST_AND_APPROVE for both:
|
|
101
|
+
* - Handler selector (ROLE_CONFIG_BATCH_META_SELECTOR) - checked via msg.sig
|
|
102
|
+
* - Execution selector (ROLE_CONFIG_BATCH_EXECUTE_SELECTOR) - checked in EngineBlox
|
|
103
|
+
*/
|
|
104
|
+
function getRolePermissions() public pure returns (IDefinition.RolePermission memory) {
|
|
105
|
+
bytes32[] memory roleHashes = new bytes32[](4);
|
|
106
|
+
EngineBlox.FunctionPermission[] memory functionPermissions =
|
|
107
|
+
new EngineBlox.FunctionPermission[](4);
|
|
108
|
+
|
|
109
|
+
// Owner: sign meta batch (handler function permission)
|
|
110
|
+
EngineBlox.TxAction[] memory ownerHandlerActions = new EngineBlox.TxAction[](1);
|
|
111
|
+
ownerHandlerActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
|
|
112
|
+
|
|
113
|
+
bytes4[] memory ownerHandlerHandlerForSelectors = new bytes4[](1);
|
|
114
|
+
ownerHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
|
|
115
|
+
|
|
116
|
+
roleHashes[0] = EngineBlox.OWNER_ROLE;
|
|
117
|
+
functionPermissions[0] = EngineBlox.FunctionPermission({
|
|
118
|
+
functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
|
|
119
|
+
grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerHandlerActions),
|
|
120
|
+
handlerForSelectors: ownerHandlerHandlerForSelectors
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Owner: sign meta batch (execution function permission)
|
|
124
|
+
// Required because verifySignature checks both handler and execution selectors for the signer
|
|
125
|
+
EngineBlox.TxAction[] memory ownerExecutionActions = new EngineBlox.TxAction[](1);
|
|
126
|
+
ownerExecutionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
|
|
127
|
+
|
|
128
|
+
bytes4[] memory ownerExecutionHandlerForSelectors = new bytes4[](1);
|
|
129
|
+
ownerExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
|
|
130
|
+
|
|
131
|
+
roleHashes[1] = EngineBlox.OWNER_ROLE;
|
|
132
|
+
functionPermissions[1] = EngineBlox.FunctionPermission({
|
|
133
|
+
functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
|
|
134
|
+
grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerExecutionActions),
|
|
135
|
+
handlerForSelectors: ownerExecutionHandlerForSelectors
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Broadcaster: execute meta batch (handler function permission)
|
|
139
|
+
EngineBlox.TxAction[] memory broadcasterHandlerActions = new EngineBlox.TxAction[](1);
|
|
140
|
+
broadcasterHandlerActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
|
|
141
|
+
|
|
142
|
+
bytes4[] memory broadcasterHandlerHandlerForSelectors = new bytes4[](1);
|
|
143
|
+
broadcasterHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
|
|
144
|
+
|
|
145
|
+
roleHashes[2] = EngineBlox.BROADCASTER_ROLE;
|
|
146
|
+
functionPermissions[2] = EngineBlox.FunctionPermission({
|
|
147
|
+
functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
|
|
148
|
+
grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterHandlerActions),
|
|
149
|
+
handlerForSelectors: broadcasterHandlerHandlerForSelectors
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Broadcaster: execute meta batch (execution function permission)
|
|
153
|
+
// Required because _validateExecutionAndHandlerPermissions checks both handler and execution selectors
|
|
154
|
+
EngineBlox.TxAction[] memory broadcasterExecutionActions = new EngineBlox.TxAction[](1);
|
|
155
|
+
broadcasterExecutionActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
|
|
156
|
+
|
|
157
|
+
bytes4[] memory broadcasterExecutionHandlerForSelectors = new bytes4[](1);
|
|
158
|
+
broadcasterExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
|
|
159
|
+
|
|
160
|
+
roleHashes[3] = EngineBlox.BROADCASTER_ROLE;
|
|
161
|
+
functionPermissions[3] = EngineBlox.FunctionPermission({
|
|
162
|
+
functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
|
|
163
|
+
grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterExecutionActions),
|
|
164
|
+
handlerForSelectors: broadcasterExecutionHandlerForSelectors
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return IDefinition.RolePermission({
|
|
168
|
+
roleHashes: roleHashes,
|
|
169
|
+
functionPermissions: functionPermissions
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @dev Returns all available RoleConfig action types and their decode formats for discovery.
|
|
175
|
+
* @return actionNames Human-readable action names (same order as RoleConfigActionType enum)
|
|
176
|
+
* @return formats ABI decode format for each action's data, e.g. "(string roleName, uint256 maxWallets)"
|
|
177
|
+
* @notice Use with RoleConfigActionType enum: actionNames[i] and formats[i] describe enum value i
|
|
178
|
+
*/
|
|
179
|
+
function getRoleConfigActionSpecs() public pure returns (string[] memory actionNames, string[] memory formats) {
|
|
180
|
+
actionNames = new string[](6);
|
|
181
|
+
formats = new string[](6);
|
|
182
|
+
|
|
183
|
+
actionNames[0] = "CREATE_ROLE";
|
|
184
|
+
formats[0] = "(string roleName, uint256 maxWallets)";
|
|
185
|
+
|
|
186
|
+
actionNames[1] = "REMOVE_ROLE";
|
|
187
|
+
formats[1] = "(bytes32 roleHash)";
|
|
188
|
+
|
|
189
|
+
actionNames[2] = "ADD_WALLET";
|
|
190
|
+
formats[2] = "(bytes32 roleHash, address wallet)";
|
|
191
|
+
|
|
192
|
+
actionNames[3] = "REVOKE_WALLET";
|
|
193
|
+
formats[3] = "(bytes32 roleHash, address wallet)";
|
|
194
|
+
|
|
195
|
+
actionNames[4] = "ADD_FUNCTION_TO_ROLE";
|
|
196
|
+
formats[4] = "(bytes32 roleHash, FunctionPermission functionPermission)";
|
|
197
|
+
|
|
198
|
+
actionNames[5] = "REMOVE_FUNCTION_FROM_ROLE";
|
|
199
|
+
formats[5] = "(bytes32 roleHash, bytes4 functionSelector)";
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ============ ROLE CONFIG ACTION DATA ENCODERS ============
|
|
203
|
+
// Use these helpers to build action.data for each RoleConfigActionType without reading the contract.
|
|
204
|
+
// Each encoder returns bytes suitable for RoleConfigAction(actionType, data).
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @dev Encodes data for CREATE_ROLE. Use with RoleConfigActionType.CREATE_ROLE.
|
|
208
|
+
* @param roleName Name of the role to create
|
|
209
|
+
* @param maxWallets Maximum number of wallets that can be assigned to this role
|
|
210
|
+
*/
|
|
211
|
+
function encodeCreateRole(string memory roleName, uint256 maxWallets) public pure returns (bytes memory) {
|
|
212
|
+
return abi.encode(roleName, maxWallets);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @dev Encodes data for REMOVE_ROLE. Use with RoleConfigActionType.REMOVE_ROLE.
|
|
217
|
+
* @param roleHash keccak256 hash of the role name
|
|
218
|
+
*/
|
|
219
|
+
function encodeRemoveRole(bytes32 roleHash) public pure returns (bytes memory) {
|
|
220
|
+
return abi.encode(roleHash);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @dev Encodes data for ADD_WALLET. Use with RoleConfigActionType.ADD_WALLET.
|
|
225
|
+
* @param roleHash Role to add the wallet to
|
|
226
|
+
* @param wallet Address to assign to the role
|
|
227
|
+
*/
|
|
228
|
+
function encodeAddWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
|
|
229
|
+
return abi.encode(roleHash, wallet);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @dev Encodes data for REVOKE_WALLET. Use with RoleConfigActionType.REVOKE_WALLET.
|
|
234
|
+
* @param roleHash Role to revoke the wallet from
|
|
235
|
+
* @param wallet Address to revoke
|
|
236
|
+
*/
|
|
237
|
+
function encodeRevokeWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
|
|
238
|
+
return abi.encode(roleHash, wallet);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @dev Encodes data for ADD_FUNCTION_TO_ROLE. Use with RoleConfigActionType.ADD_FUNCTION_TO_ROLE.
|
|
243
|
+
* @param roleHash Role to grant the function permission to
|
|
244
|
+
* @param functionPermission FunctionPermission (functionSelector, grantedActionsBitmap, handlerForSelectors)
|
|
245
|
+
*/
|
|
246
|
+
function encodeAddFunctionToRole(
|
|
247
|
+
bytes32 roleHash,
|
|
248
|
+
EngineBlox.FunctionPermission memory functionPermission
|
|
249
|
+
) public pure returns (bytes memory) {
|
|
250
|
+
return abi.encode(roleHash, functionPermission);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @dev Encodes data for REMOVE_FUNCTION_FROM_ROLE. Use with RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE.
|
|
255
|
+
* @param roleHash Role to remove the function from
|
|
256
|
+
* @param functionSelector Selector of the function to remove
|
|
257
|
+
*/
|
|
258
|
+
function encodeRemoveFunctionFromRole(bytes32 roleHash, bytes4 functionSelector) public pure returns (bytes memory) {
|
|
259
|
+
return abi.encode(roleHash, functionSelector);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @dev Creates execution params for a RBAC configuration batch (pure helper for EngineBlox).
|
|
264
|
+
* @param actions Encoded role configuration actions (IRuntimeRBAC.RoleConfigAction[] layout)
|
|
265
|
+
* @return The execution params for EngineBlox
|
|
266
|
+
*/
|
|
267
|
+
function roleConfigBatchExecutionParams(
|
|
268
|
+
IRuntimeRBAC.RoleConfigAction[] memory actions
|
|
269
|
+
) public pure returns (bytes memory) {
|
|
270
|
+
return abi.encode(actions);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @dev Creates execution params from pre-encoded actions (e.g. abi.encode(RuntimeRBAC.RoleConfigAction[])).
|
|
275
|
+
* Use when callers have RuntimeRBAC.RoleConfigAction[] and same encoding applies.
|
|
276
|
+
* @param preEncoded ABI-encoded role config actions array
|
|
277
|
+
* @return The execution params for EngineBlox
|
|
278
|
+
*/
|
|
279
|
+
function roleConfigBatchExecutionParams(bytes memory preEncoded) public pure returns (bytes memory) {
|
|
280
|
+
return preEncoded;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @dev ERC165: report support for IDefinition and IERC165 when this library is used at an address.
|
|
285
|
+
* IDefinition extends IERC165; both interface IDs must be reported for ERC165 compliance.
|
|
286
|
+
*/
|
|
287
|
+
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
|
|
288
|
+
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IDefinition).interfaceId;
|
|
289
|
+
}
|
|
290
|
+
}
|