@bloxchain/contracts 1.0.0-alpha

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.
Files changed (34) hide show
  1. package/README.md +49 -0
  2. package/abi/BareBlox.abi.json +1341 -0
  3. package/abi/BaseStateMachine.abi.json +1308 -0
  4. package/abi/ControlBlox.abi.json +6210 -0
  5. package/abi/EngineBlox.abi.json +872 -0
  6. package/abi/GuardController.abi.json +3045 -0
  7. package/abi/IDefinition.abi.json +94 -0
  8. package/abi/RoleBlox.abi.json +4569 -0
  9. package/abi/RuntimeRBAC.abi.json +1857 -0
  10. package/abi/RuntimeRBACDefinitions.abi.json +133 -0
  11. package/abi/SecureBlox.abi.json +4085 -0
  12. package/abi/SecureOwnable.abi.json +4085 -0
  13. package/abi/SecureOwnableDefinitions.abi.json +354 -0
  14. package/abi/SimpleRWA20.abi.json +5545 -0
  15. package/abi/SimpleRWA20Definitions.abi.json +172 -0
  16. package/abi/SimpleVault.abi.json +5208 -0
  17. package/abi/SimpleVaultDefinitions.abi.json +250 -0
  18. package/contracts/core/access/RuntimeRBAC.sol +344 -0
  19. package/contracts/core/access/interface/IRuntimeRBAC.sol +108 -0
  20. package/contracts/core/access/lib/definitions/RuntimeRBACDefinitions.sol +168 -0
  21. package/contracts/core/base/BaseStateMachine.sol +834 -0
  22. package/contracts/core/base/interface/IBaseStateMachine.sol +153 -0
  23. package/contracts/core/execution/GuardController.sol +507 -0
  24. package/contracts/core/execution/interface/IGuardController.sol +120 -0
  25. package/contracts/core/execution/lib/definitions/GuardControllerDefinitions.sol +401 -0
  26. package/contracts/core/lib/EngineBlox.sol +2283 -0
  27. package/contracts/core/security/SecureOwnable.sol +419 -0
  28. package/contracts/core/security/interface/ISecureOwnable.sol +118 -0
  29. package/contracts/core/security/lib/definitions/SecureOwnableDefinitions.sol +757 -0
  30. package/contracts/interfaces/IDefinition.sol +40 -0
  31. package/contracts/interfaces/IEventForwarder.sol +33 -0
  32. package/contracts/interfaces/IOnActionHook.sol +79 -0
  33. package/contracts/utils/SharedValidation.sol +486 -0
  34. package/package.json +47 -0
@@ -0,0 +1,168 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ pragma solidity 0.8.33;
3
+
4
+ import "../../../lib/EngineBlox.sol";
5
+ import "../../../../interfaces/IDefinition.sol";
6
+
7
+ /**
8
+ * @title RuntimeRBACDefinitions
9
+ * @dev Library containing predefined definitions for RuntimeRBAC initialization
10
+ * This library holds static data that can be used to initialize RuntimeRBAC contracts
11
+ * without increasing the main contract size
12
+ *
13
+ * This library implements the IDefinition interface from EngineBlox
14
+ * and provides a direct initialization function for RuntimeRBAC contracts
15
+ */
16
+ library RuntimeRBACDefinitions {
17
+
18
+ // Operation Type Constants
19
+ bytes32 public constant ROLE_CONFIG_BATCH = keccak256("ROLE_CONFIG_BATCH");
20
+
21
+ // Function Selector Constants
22
+ // Internal execution entrypoint for RBAC configuration batches
23
+ bytes4 public constant ROLE_CONFIG_BATCH_EXECUTE_SELECTOR =
24
+ bytes4(keccak256("executeRoleConfigBatch((uint8,bytes)[])"));
25
+
26
+ // Meta-transaction Function Selectors
27
+ // roleConfigBatchRequestAndApprove(EngineBlox.MetaTransaction memory metaTx)
28
+ bytes4 public constant ROLE_CONFIG_BATCH_META_SELECTOR =
29
+ bytes4(
30
+ keccak256(
31
+ "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))"
32
+ )
33
+ );
34
+
35
+ /**
36
+ * @dev Returns predefined function schemas
37
+ * @return Array of function schema definitions
38
+ *
39
+ * Registers the meta-transaction handler for RBAC configuration batches.
40
+ * All runtime RBAC changes must go through this single time-locked workflow.
41
+ *
42
+ * Function schemas include:
43
+ * - Handler function (roleConfigBatchRequestAndApprove): checked via msg.sig
44
+ * - Execution function (executeRoleConfigBatch): checked in EngineBlox for dual-permission model
45
+ */
46
+ function getFunctionSchemas() public pure returns (EngineBlox.FunctionSchema[] memory) {
47
+ EngineBlox.FunctionSchema[] memory schemas = new EngineBlox.FunctionSchema[](2);
48
+
49
+ // Meta-transaction handler function schema
50
+ EngineBlox.TxAction[] memory metaRequestApproveActions = new EngineBlox.TxAction[](2);
51
+ metaRequestApproveActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
52
+ metaRequestApproveActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
53
+
54
+ bytes4[] memory handlerForSelectors = new bytes4[](1);
55
+ handlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
56
+
57
+ schemas[0] = EngineBlox.FunctionSchema({
58
+ 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))",
59
+ functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
60
+ operationType: ROLE_CONFIG_BATCH,
61
+ operationName: "ROLE_CONFIG_BATCH",
62
+ supportedActionsBitmap: EngineBlox.createBitmapFromActions(metaRequestApproveActions),
63
+ isProtected: true,
64
+ handlerForSelectors: handlerForSelectors
65
+ });
66
+
67
+ // Execution function schema (required for dual-permission model)
68
+ // This is checked in EngineBlox._validateExecutionAndHandlerPermissions
69
+ // Must support both SIGN (for owner) and EXECUTE (for broadcaster) actions
70
+ EngineBlox.TxAction[] memory executionActions = new EngineBlox.TxAction[](2);
71
+ executionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
72
+ executionActions[1] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
73
+
74
+ // Execution selectors must have at least one element pointing to themselves (self-reference)
75
+ bytes4[] memory executionHandlerForSelectors = new bytes4[](1);
76
+ executionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
77
+
78
+ schemas[1] = EngineBlox.FunctionSchema({
79
+ functionSignature: "executeRoleConfigBatch((uint8,bytes)[])",
80
+ functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
81
+ operationType: ROLE_CONFIG_BATCH,
82
+ operationName: "ROLE_CONFIG_BATCH",
83
+ supportedActionsBitmap: EngineBlox.createBitmapFromActions(executionActions),
84
+ isProtected: true,
85
+ handlerForSelectors: executionHandlerForSelectors
86
+ });
87
+
88
+ return schemas;
89
+ }
90
+
91
+ /**
92
+ * @dev Returns predefined role hashes and their corresponding function permissions
93
+ * @return RolePermission struct containing roleHashes and functionPermissions arrays
94
+ *
95
+ * OWNER: allowed to SIGN_META_REQUEST_AND_APPROVE for the batch handler
96
+ * BROADCASTER: allowed to EXECUTE_META_REQUEST_AND_APPROVE for both:
97
+ * - Handler selector (ROLE_CONFIG_BATCH_META_SELECTOR) - checked via msg.sig
98
+ * - Execution selector (ROLE_CONFIG_BATCH_EXECUTE_SELECTOR) - checked in EngineBlox
99
+ */
100
+ function getRolePermissions() public pure returns (IDefinition.RolePermission memory) {
101
+ bytes32[] memory roleHashes = new bytes32[](4);
102
+ EngineBlox.FunctionPermission[] memory functionPermissions =
103
+ new EngineBlox.FunctionPermission[](4);
104
+
105
+ // Owner: sign meta batch (handler function permission)
106
+ EngineBlox.TxAction[] memory ownerHandlerActions = new EngineBlox.TxAction[](1);
107
+ ownerHandlerActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
108
+
109
+ bytes4[] memory ownerHandlerHandlerForSelectors = new bytes4[](1);
110
+ ownerHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
111
+
112
+ roleHashes[0] = EngineBlox.OWNER_ROLE;
113
+ functionPermissions[0] = EngineBlox.FunctionPermission({
114
+ functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
115
+ grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerHandlerActions),
116
+ handlerForSelectors: ownerHandlerHandlerForSelectors
117
+ });
118
+
119
+ // Owner: sign meta batch (execution function permission)
120
+ // Required because verifySignature checks both handler and execution selectors for the signer
121
+ EngineBlox.TxAction[] memory ownerExecutionActions = new EngineBlox.TxAction[](1);
122
+ ownerExecutionActions[0] = EngineBlox.TxAction.SIGN_META_REQUEST_AND_APPROVE;
123
+
124
+ bytes4[] memory ownerExecutionHandlerForSelectors = new bytes4[](1);
125
+ ownerExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
126
+
127
+ roleHashes[1] = EngineBlox.OWNER_ROLE;
128
+ functionPermissions[1] = EngineBlox.FunctionPermission({
129
+ functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
130
+ grantedActionsBitmap: EngineBlox.createBitmapFromActions(ownerExecutionActions),
131
+ handlerForSelectors: ownerExecutionHandlerForSelectors
132
+ });
133
+
134
+ // Broadcaster: execute meta batch (handler function permission)
135
+ EngineBlox.TxAction[] memory broadcasterHandlerActions = new EngineBlox.TxAction[](1);
136
+ broadcasterHandlerActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
137
+
138
+ bytes4[] memory broadcasterHandlerHandlerForSelectors = new bytes4[](1);
139
+ broadcasterHandlerHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR;
140
+
141
+ roleHashes[2] = EngineBlox.BROADCASTER_ROLE;
142
+ functionPermissions[2] = EngineBlox.FunctionPermission({
143
+ functionSelector: ROLE_CONFIG_BATCH_META_SELECTOR,
144
+ grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterHandlerActions),
145
+ handlerForSelectors: broadcasterHandlerHandlerForSelectors
146
+ });
147
+
148
+ // Broadcaster: execute meta batch (execution function permission)
149
+ // Required because _validateExecutionAndHandlerPermissions checks both handler and execution selectors
150
+ EngineBlox.TxAction[] memory broadcasterExecutionActions = new EngineBlox.TxAction[](1);
151
+ broadcasterExecutionActions[0] = EngineBlox.TxAction.EXECUTE_META_REQUEST_AND_APPROVE;
152
+
153
+ bytes4[] memory broadcasterExecutionHandlerForSelectors = new bytes4[](1);
154
+ broadcasterExecutionHandlerForSelectors[0] = ROLE_CONFIG_BATCH_EXECUTE_SELECTOR; // Self-reference indicates execution selector
155
+
156
+ roleHashes[3] = EngineBlox.BROADCASTER_ROLE;
157
+ functionPermissions[3] = EngineBlox.FunctionPermission({
158
+ functionSelector: ROLE_CONFIG_BATCH_EXECUTE_SELECTOR,
159
+ grantedActionsBitmap: EngineBlox.createBitmapFromActions(broadcasterExecutionActions),
160
+ handlerForSelectors: broadcasterExecutionHandlerForSelectors
161
+ });
162
+
163
+ return IDefinition.RolePermission({
164
+ roleHashes: roleHashes,
165
+ functionPermissions: functionPermissions
166
+ });
167
+ }
168
+ }