@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.
@@ -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
- isProtected: true,
66
- handlerForSelectors: handlerForSelectors
67
- });
68
-
69
- // Execution function schema (required for dual-permission model)
70
- // This is checked in EngineBlox._validateExecutionAndHandlerPermissions
71
- // Must support both SIGN (for owner) and EXECUTE (for broadcaster) actions
72
- EngineBlox.TxAction[] memory executionActions = new EngineBlox.TxAction[](2);
73
- executionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
74
- executionActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
75
-
76
- // Execution selectors must have at least one element pointing to themselves (self-reference)
77
- bytes4[] memory executionHandlerForSelectors = new bytes4[](1);
78
- executionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
79
-
80
- schemas[1] = EngineBlox.FunctionSchema({
81
- functionSignature: "executeRoleConfigBatch((uint8,bytes)[])",
82
- functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
83
- operationType: ROLE_CONFIG_BATCH,
84
- operationName: "ROLE_CONFIG_BATCH",
85
- supportedActionsBitmap: EngineBlox.createBitmapFromActions(executionActions),
86
- isProtected: true,
87
- handlerForSelectors: executionHandlerForSelectors
88
- });
89
-
90
- return schemas;
91
- }
92
-
93
- /**
94
- * @dev Returns predefined role hashes and their corresponding function permissions
95
- * @return RolePermission struct containing roleHashes and functionPermissions arrays
96
- *
97
- * OWNER: allowed to SIGN_META_REQUEST_AND_APPROVE for the batch handler
98
- * BROADCASTER: allowed to EXECUTE_META_REQUEST_AND_APPROVE for both:
99
- * - Handler selector (ROLE_CONFIG_BATCH_META_SELECTOR) - checked via msg.sig
100
- * - Execution selector (ROLE_CONFIG_BATCH_EXECUTE_SELECTOR) - checked in EngineBlox
101
- */
102
- function getRolePermissions() public pure returns (IDefinition.RolePermission memory) {
103
- bytes32[] memory roleHashes = new bytes32[](4);
104
- EngineBlox.FunctionPermission[] memory functionPermissions =
105
- new EngineBlox.FunctionPermission[](4);
106
-
107
- // Owner: sign meta batch (handler function permission)
108
- EngineBlox.TxAction[] memory ownerHandlerActions = new EngineBlox.TxAction[](1);
109
- ownerHandlerActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
110
-
111
- bytes4[] memory ownerHandlerHandlerForSelectors = new bytes4[](1);
112
- ownerHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
113
-
114
- roleHashes[0] = EngineBlox.OWNER_ROLE;
115
- functionPermissions[0] = EngineBlox.FunctionPermission({
116
- functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
117
- grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerHandlerActions),
118
- handlerForSelectors: ownerHandlerHandlerForSelectors
119
- });
120
-
121
- // Owner: sign meta batch (execution function permission)
122
- // Required because verifySignature checks both handler and execution selectors for the signer
123
- EngineBlox.TxAction[] memory ownerExecutionActions = new EngineBlox.TxAction[](1);
124
- ownerExecutionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
125
-
126
- bytes4[] memory ownerExecutionHandlerForSelectors = new bytes4[](1);
127
- ownerExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
128
-
129
- roleHashes[1] = EngineBlox.OWNER_ROLE;
130
- functionPermissions[1] = EngineBlox.FunctionPermission({
131
- functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
132
- grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerExecutionActions),
133
- handlerForSelectors: ownerExecutionHandlerForSelectors
134
- });
135
-
136
- // Broadcaster: execute meta batch (handler function permission)
137
- EngineBlox.TxAction[] memory broadcasterHandlerActions = new EngineBlox.TxAction[](1);
138
- broadcasterHandlerActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
139
-
140
- bytes4[] memory broadcasterHandlerHandlerForSelectors = new bytes4[](1);
141
- broadcasterHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
142
-
143
- roleHashes[2] = EngineBlox.BROADCASTER_ROLE;
144
- functionPermissions[2] = EngineBlox.FunctionPermission({
145
- functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
146
- grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterHandlerActions),
147
- handlerForSelectors: broadcasterHandlerHandlerForSelectors
148
- });
149
-
150
- // Broadcaster: execute meta batch (execution function permission)
151
- // Required because _validateExecutionAndHandlerPermissions checks both handler and execution selectors
152
- EngineBlox.TxAction[] memory broadcasterExecutionActions = new EngineBlox.TxAction[](1);
153
- broadcasterExecutionActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
154
-
155
- bytes4[] memory broadcasterExecutionHandlerForSelectors = new bytes4[](1);
156
- broadcasterExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
157
-
158
- roleHashes[3] = EngineBlox.BROADCASTER_ROLE;
159
- functionPermissions[3] = EngineBlox.FunctionPermission({
160
- functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
161
- grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterExecutionActions),
162
- handlerForSelectors: broadcasterExecutionHandlerForSelectors
163
- });
164
-
165
- return IDefinition.RolePermission({
166
- roleHashes: roleHashes,
167
- functionPermissions: functionPermissions
168
- });
169
- }
170
-
171
- /**
172
- * @dev Returns all available RoleConfig action types and their decode formats for discovery.
173
- * @return actionNames Human-readable action names (same order as RoleConfigActionType enum)
174
- * @return formats ABI decode format for each action's data, e.g. "(string roleName, uint256 maxWallets)"
175
- * @notice Use with RoleConfigActionType enum: actionNames[i] and formats[i] describe enum value i
176
- */
177
- function getRoleConfigActionSpecs() public pure returns (string[] memory actionNames, string[] memory formats) {
178
- actionNames = new string[](6);
179
- formats = new string[](6);
180
-
181
- actionNames[0] = "CREATE_ROLE";
182
- formats[0] = "(string roleName, uint256 maxWallets)";
183
-
184
- actionNames[1] = "REMOVE_ROLE";
185
- formats[1] = "(bytes32 roleHash)";
186
-
187
- actionNames[2] = "ADD_WALLET";
188
- formats[2] = "(bytes32 roleHash, address wallet)";
189
-
190
- actionNames[3] = "REVOKE_WALLET";
191
- formats[3] = "(bytes32 roleHash, address wallet)";
192
-
193
- actionNames[4] = "ADD_FUNCTION_TO_ROLE";
194
- formats[4] = "(bytes32 roleHash, FunctionPermission functionPermission)";
195
-
196
- actionNames[5] = "REMOVE_FUNCTION_FROM_ROLE";
197
- formats[5] = "(bytes32 roleHash, bytes4 functionSelector)";
198
- }
199
-
200
- // ============ ROLE CONFIG ACTION DATA ENCODERS ============
201
- // Use these helpers to build action.data for each RoleConfigActionType without reading the contract.
202
- // Each encoder returns bytes suitable for RoleConfigAction(actionType, data).
203
-
204
- /**
205
- * @dev Encodes data for CREATE_ROLE. Use with RoleConfigActionType.CREATE_ROLE.
206
- * @param roleName Name of the role to create
207
- * @param maxWallets Maximum number of wallets that can be assigned to this role
208
- */
209
- function encodeCreateRole(string memory roleName, uint256 maxWallets) public pure returns (bytes memory) {
210
- return abi.encode(roleName, maxWallets);
211
- }
212
-
213
- /**
214
- * @dev Encodes data for REMOVE_ROLE. Use with RoleConfigActionType.REMOVE_ROLE.
215
- * @param roleHash keccak256 hash of the role name
216
- */
217
- function encodeRemoveRole(bytes32 roleHash) public pure returns (bytes memory) {
218
- return abi.encode(roleHash);
219
- }
220
-
221
- /**
222
- * @dev Encodes data for ADD_WALLET. Use with RoleConfigActionType.ADD_WALLET.
223
- * @param roleHash Role to add the wallet to
224
- * @param wallet Address to assign to the role
225
- */
226
- function encodeAddWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
227
- return abi.encode(roleHash, wallet);
228
- }
229
-
230
- /**
231
- * @dev Encodes data for REVOKE_WALLET. Use with RoleConfigActionType.REVOKE_WALLET.
232
- * @param roleHash Role to revoke the wallet from
233
- * @param wallet Address to revoke
234
- */
235
- function encodeRevokeWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
236
- return abi.encode(roleHash, wallet);
237
- }
238
-
239
- /**
240
- * @dev Encodes data for ADD_FUNCTION_TO_ROLE. Use with RoleConfigActionType.ADD_FUNCTION_TO_ROLE.
241
- * @param roleHash Role to grant the function permission to
242
- * @param functionPermission FunctionPermission (functionSelector, grantedActionsBitmap, handlerForSelectors)
243
- */
244
- function encodeAddFunctionToRole(
245
- bytes32 roleHash,
246
- EngineBlox.FunctionPermission memory functionPermission
247
- ) public pure returns (bytes memory) {
248
- return abi.encode(roleHash, functionPermission);
249
- }
250
-
251
- /**
252
- * @dev Encodes data for REMOVE_FUNCTION_FROM_ROLE. Use with RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE.
253
- * @param roleHash Role to remove the function from
254
- * @param functionSelector Selector of the function to remove
255
- */
256
- function encodeRemoveFunctionFromRole(bytes32 roleHash, bytes4 functionSelector) public pure returns (bytes memory) {
257
- return abi.encode(roleHash, functionSelector);
258
- }
259
-
260
- /**
261
- * @dev Creates execution params for a RBAC configuration batch (pure helper for EngineBlox).
262
- * @param actions Encoded role configuration actions (IRuntimeRBAC.RoleConfigAction[] layout)
263
- * @return The execution params for EngineBlox
264
- */
265
- function roleConfigBatchExecutionParams(
266
- IRuntimeRBAC.RoleConfigAction[] memory actions
267
- ) public pure returns (bytes memory) {
268
- return abi.encode(actions);
269
- }
270
-
271
- /**
272
- * @dev Creates execution params from pre-encoded actions (e.g. abi.encode(RuntimeRBAC.RoleConfigAction[])).
273
- * Use when callers have RuntimeRBAC.RoleConfigAction[] and same encoding applies.
274
- * @param preEncoded ABI-encoded role config actions array
275
- * @return The execution params for EngineBlox
276
- */
277
- function roleConfigBatchExecutionParams(bytes memory preEncoded) public pure returns (bytes memory) {
278
- return preEncoded;
279
- }
280
-
281
- /**
282
- * @dev ERC165: report support for IDefinition and IERC165 when this library is used at an address.
283
- * IDefinition extends IERC165; both interface IDs must be reported for ERC165 compliance.
284
- */
285
- function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
286
- return interfaceId == type(IERC165).interfaceId || interfaceId == type(IDefinition).interfaceId;
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
+ }