@bloxchain/contracts 1.0.0-alpha.11 → 1.0.0-alpha.13

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 (43) hide show
  1. package/README.md +2 -2
  2. package/abi/AccountBlox.abi.json +11 -0
  3. package/abi/EngineBlox.abi.json +0 -35
  4. package/abi/GuardController.abi.json +4 -4
  5. package/abi/GuardControllerDefinitions.abi.json +13 -0
  6. package/abi/RoleBlox.abi.json +11 -0
  7. package/abi/RuntimeRBAC.abi.json +11 -0
  8. package/abi/SecureBlox.abi.json +4 -4
  9. package/abi/SecureOwnable.abi.json +4 -4
  10. package/abi/SimpleRWA20.abi.json +4 -4
  11. package/abi/SimpleVault.abi.json +4 -4
  12. package/core/access/RuntimeRBAC.sol +82 -57
  13. package/core/access/interface/IRuntimeRBAC.sol +1 -1
  14. package/core/access/lib/definitions/RuntimeRBACDefinitions.sol +288 -288
  15. package/core/base/BaseStateMachine.sol +16 -16
  16. package/core/base/interface/IBaseStateMachine.sol +160 -160
  17. package/core/execution/GuardController.sol +60 -43
  18. package/core/execution/interface/IGuardController.sol +160 -160
  19. package/core/execution/lib/definitions/GuardControllerDefinitions.sol +493 -490
  20. package/core/lib/EngineBlox.sol +3 -75
  21. package/core/lib/interfaces/IDefinition.sol +49 -49
  22. package/core/lib/interfaces/IEventForwarder.sol +33 -33
  23. package/core/lib/utils/SharedValidation.sol +1 -1
  24. package/core/pattern/Account.sol +75 -75
  25. package/core/security/SecureOwnable.sol +19 -15
  26. package/core/security/interface/ISecureOwnable.sol +105 -105
  27. package/core/security/lib/definitions/SecureOwnableDefinitions.sol +1 -1
  28. package/package.json +49 -49
  29. package/standards/behavior/ICopyable.sol +3 -5
  30. package/standards/hooks/IOnActionHook.sol +1 -1
  31. package/core/research/BloxchainWallet.sol +0 -133
  32. package/core/research/FactoryBlox/FactoryBlox.sol +0 -344
  33. package/core/research/FactoryBlox/FactoryBloxDefinitions.sol +0 -144
  34. package/core/research/erc1155-blox/ERC1155Blox.sol +0 -170
  35. package/core/research/erc1155-blox/lib/definitions/ERC1155BloxDefinitions.sol +0 -203
  36. package/core/research/erc20-blox/ERC20Blox.sol +0 -135
  37. package/core/research/erc20-blox/lib/definitions/ERC20BloxDefinitions.sol +0 -185
  38. package/core/research/erc721-blox/ERC721Blox.sol +0 -131
  39. package/core/research/erc721-blox/lib/definitions/ERC721BloxDefinitions.sol +0 -172
  40. package/core/research/lending-blox/.gitkeep +0 -1
  41. package/core/research/p2p-blox/P2PBlox.sol +0 -266
  42. package/core/research/p2p-blox/README.md +0 -85
  43. package/core/research/p2p-blox/lib/definitions/P2PBloxDefinitions.sol +0 -19
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@bloxchain/contracts.svg)](https://www.npmjs.com/package/@bloxchain/contracts)
4
4
  [![License: MPL-2.0](https://img.shields.io/badge/License-MPL--2.0-blue.svg)](https://opensource.org/licenses/MPL-2.0)
5
- [![Solidity](https://img.shields.io/badge/Solidity-0.8.33-blue.svg)](https://soliditylang.org/)
5
+ [![Solidity](https://img.shields.io/badge/Solidity-0.8.34-blue.svg)](https://soliditylang.org/)
6
6
 
7
7
  Bloxchain Protocol smart contracts – state abstraction and core components for building on the Bloxchain Protocol.
8
8
 
@@ -12,7 +12,7 @@ Bloxchain Protocol smart contracts – state abstraction and core components for
12
12
  ## Requirements
13
13
 
14
14
  - **Node.js**: >= 18.0.0 (for tooling; Solidity has no runtime dependency)
15
- - **Solidity**: 0.8.x (0.8.33 recommended)
15
+ - **Solidity**: 0.8.x (0.8.34 recommended)
16
16
  - **Compilers**: Foundry, Hardhat, or Truffle
17
17
 
18
18
  ## Installation
@@ -42,6 +42,17 @@
42
42
  "name": "CannotModifyProtected",
43
43
  "type": "error"
44
44
  },
45
+ {
46
+ "inputs": [
47
+ {
48
+ "internalType": "bytes4",
49
+ "name": "functionSelector",
50
+ "type": "bytes4"
51
+ }
52
+ ],
53
+ "name": "ContractFunctionMustBeProtected",
54
+ "type": "error"
55
+ },
45
56
  {
46
57
  "inputs": [
47
58
  {
@@ -58,17 +58,6 @@
58
58
  "name": "ConflictingMetaTxPermissions",
59
59
  "type": "error"
60
60
  },
61
- {
62
- "inputs": [
63
- {
64
- "internalType": "bytes4",
65
- "name": "functionSelector",
66
- "type": "bytes4"
67
- }
68
- ],
69
- "name": "ContractFunctionMustBeProtected",
70
- "type": "error"
71
- },
72
61
  {
73
62
  "inputs": [
74
63
  {
@@ -824,29 +813,5 @@
824
813
  ],
825
814
  "stateMutability": "view",
826
815
  "type": "function"
827
- },
828
- {
829
- "inputs": [
830
- {
831
- "internalType": "address",
832
- "name": "contractAddress",
833
- "type": "address"
834
- },
835
- {
836
- "internalType": "bytes4",
837
- "name": "selector",
838
- "type": "bytes4"
839
- }
840
- ],
841
- "name": "selectorExistsInContract",
842
- "outputs": [
843
- {
844
- "internalType": "bool",
845
- "name": "",
846
- "type": "bool"
847
- }
848
- ],
849
- "stateMutability": "view",
850
- "type": "function"
851
816
  }
852
817
  ]
@@ -34,12 +34,12 @@
34
34
  {
35
35
  "inputs": [
36
36
  {
37
- "internalType": "bytes32",
38
- "name": "resourceId",
39
- "type": "bytes32"
37
+ "internalType": "bytes4",
38
+ "name": "functionSelector",
39
+ "type": "bytes4"
40
40
  }
41
41
  ],
42
- "name": "CannotModifyProtected",
42
+ "name": "ContractFunctionMustBeProtected",
43
43
  "type": "error"
44
44
  },
45
45
  {
@@ -64,6 +64,19 @@
64
64
  "stateMutability": "view",
65
65
  "type": "function"
66
66
  },
67
+ {
68
+ "inputs": [],
69
+ "name": "EXECUTE_WITH_PAYMENT_SELECTOR",
70
+ "outputs": [
71
+ {
72
+ "internalType": "bytes4",
73
+ "name": "",
74
+ "type": "bytes4"
75
+ }
76
+ ],
77
+ "stateMutability": "view",
78
+ "type": "function"
79
+ },
67
80
  {
68
81
  "inputs": [],
69
82
  "name": "EXECUTE_WITH_TIMELOCK_SELECTOR",
@@ -42,6 +42,17 @@
42
42
  "name": "CannotModifyProtected",
43
43
  "type": "error"
44
44
  },
45
+ {
46
+ "inputs": [
47
+ {
48
+ "internalType": "bytes4",
49
+ "name": "functionSelector",
50
+ "type": "bytes4"
51
+ }
52
+ ],
53
+ "name": "ContractFunctionMustBeProtected",
54
+ "type": "error"
55
+ },
45
56
  {
46
57
  "inputs": [],
47
58
  "name": "InvalidInitialization",
@@ -42,6 +42,17 @@
42
42
  "name": "CannotModifyProtected",
43
43
  "type": "error"
44
44
  },
45
+ {
46
+ "inputs": [
47
+ {
48
+ "internalType": "bytes4",
49
+ "name": "functionSelector",
50
+ "type": "bytes4"
51
+ }
52
+ ],
53
+ "name": "ContractFunctionMustBeProtected",
54
+ "type": "error"
55
+ },
45
56
  {
46
57
  "inputs": [],
47
58
  "name": "InvalidInitialization",
@@ -18,12 +18,12 @@
18
18
  {
19
19
  "inputs": [
20
20
  {
21
- "internalType": "bytes32",
22
- "name": "resourceId",
23
- "type": "bytes32"
21
+ "internalType": "bytes4",
22
+ "name": "functionSelector",
23
+ "type": "bytes4"
24
24
  }
25
25
  ],
26
- "name": "CannotModifyProtected",
26
+ "name": "ContractFunctionMustBeProtected",
27
27
  "type": "error"
28
28
  },
29
29
  {
@@ -18,12 +18,12 @@
18
18
  {
19
19
  "inputs": [
20
20
  {
21
- "internalType": "bytes32",
22
- "name": "resourceId",
23
- "type": "bytes32"
21
+ "internalType": "bytes4",
22
+ "name": "functionSelector",
23
+ "type": "bytes4"
24
24
  }
25
25
  ],
26
- "name": "CannotModifyProtected",
26
+ "name": "ContractFunctionMustBeProtected",
27
27
  "type": "error"
28
28
  },
29
29
  {
@@ -18,12 +18,12 @@
18
18
  {
19
19
  "inputs": [
20
20
  {
21
- "internalType": "bytes32",
22
- "name": "resourceId",
23
- "type": "bytes32"
21
+ "internalType": "bytes4",
22
+ "name": "functionSelector",
23
+ "type": "bytes4"
24
24
  }
25
25
  ],
26
- "name": "CannotModifyProtected",
26
+ "name": "ContractFunctionMustBeProtected",
27
27
  "type": "error"
28
28
  },
29
29
  {
@@ -18,12 +18,12 @@
18
18
  {
19
19
  "inputs": [
20
20
  {
21
- "internalType": "bytes32",
22
- "name": "resourceId",
23
- "type": "bytes32"
21
+ "internalType": "bytes4",
22
+ "name": "functionSelector",
23
+ "type": "bytes4"
24
24
  }
25
25
  ],
26
- "name": "CannotModifyProtected",
26
+ "name": "ContractFunctionMustBeProtected",
27
27
  "type": "error"
28
28
  },
29
29
  {
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MPL-2.0
2
- pragma solidity 0.8.33;
2
+ pragma solidity 0.8.34;
3
3
 
4
4
  // Contract imports
5
5
  import "../base/BaseStateMachine.sol";
@@ -44,18 +44,15 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
44
44
  uint256 timeLockPeriodSec,
45
45
  address eventForwarder
46
46
  ) public virtual onlyInitializing {
47
- // Initialize base state machine (only if not already initialized)
48
- if (!_secureState.initialized) {
49
- _initializeBaseStateMachine(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
50
- }
51
-
47
+ _initializeBaseStateMachine(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
48
+
52
49
  // Load RuntimeRBAC-specific definitions
53
50
  IDefinition.RolePermission memory permissions = RuntimeRBACDefinitions.getRolePermissions();
54
51
  _loadDefinitions(
55
52
  RuntimeRBACDefinitions.getFunctionSchemas(),
56
53
  permissions.roleHashes,
57
54
  permissions.functionPermissions,
58
- true // Allow protected schemas for factory settings
55
+ true // Enforce all function schemas are protected
59
56
  );
60
57
  }
61
58
 
@@ -117,58 +114,17 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
117
114
  IRuntimeRBAC.RoleConfigAction calldata action = actions[i];
118
115
 
119
116
  if (action.actionType == IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE) {
120
- // Decode CREATE_ROLE action data
121
- // Format: (string roleName, uint256 maxWallets)
122
- (
123
- string memory roleName,
124
- uint256 maxWallets
125
- ) = abi.decode(action.data, (string, uint256));
126
-
127
- // Create the role in the secure state with isProtected = false
128
- bytes32 roleHash = _createRole(roleName, maxWallets, false);
129
-
130
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE, roleHash, bytes4(0)));
117
+ _executeCreateRole(action.data);
131
118
  } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE) {
132
- // Decode REMOVE_ROLE action data
133
- // Format: (bytes32 roleHash)
134
- (bytes32 roleHash) = abi.decode(action.data, (bytes32));
135
- _removeRole(roleHash);
136
-
137
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE, roleHash, bytes4(0)));
119
+ _executeRemoveRole(action.data);
138
120
  } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.ADD_WALLET) {
139
- // Decode ADD_WALLET action data
140
- // Format: (bytes32 roleHash, address wallet)
141
- (bytes32 roleHash, address wallet) = abi.decode(action.data, (bytes32, address));
142
- _requireRoleNotProtected(roleHash);
143
- _assignWallet(roleHash, wallet);
144
-
145
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.ADD_WALLET, roleHash, bytes4(0)));
121
+ _executeAddWallet(action.data);
146
122
  } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET) {
147
- // Decode REVOKE_WALLET action data
148
- // Format: (bytes32 roleHash, address wallet)
149
- (bytes32 roleHash, address wallet) = abi.decode(action.data, (bytes32, address));
150
- _requireRoleNotProtected(roleHash);
151
- _revokeWallet(roleHash, wallet);
152
-
153
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET, roleHash, bytes4(0)));
123
+ _executeRevokeWallet(action.data);
154
124
  } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE) {
155
- // Decode ADD_FUNCTION_TO_ROLE action data
156
- // Format: (bytes32 roleHash, FunctionPermission functionPermission)
157
- (
158
- bytes32 roleHash,
159
- EngineBlox.FunctionPermission memory functionPermission
160
- ) = abi.decode(action.data, (bytes32, EngineBlox.FunctionPermission));
161
-
162
- _addFunctionToRole(roleHash, functionPermission);
163
-
164
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE, roleHash, functionPermission.functionSelector));
125
+ _executeAddFunctionToRole(action.data);
165
126
  } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE) {
166
- // Decode REMOVE_FUNCTION_FROM_ROLE action data
167
- // Format: (bytes32 roleHash, bytes4 functionSelector)
168
- (bytes32 roleHash, bytes4 functionSelector) = abi.decode(action.data, (bytes32, bytes4));
169
- _removeFunctionFromRole(roleHash, functionSelector);
170
-
171
- _logComponentEvent(_encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE, roleHash, functionSelector));
127
+ _executeRemoveFunctionFromRole(action.data);
172
128
  } else {
173
129
  revert SharedValidation.NotSupported();
174
130
  }
@@ -176,9 +132,78 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
176
132
  }
177
133
 
178
134
  /**
179
- * @dev Encodes RBAC config event payload for ComponentEvent. Decode as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector).
135
+ * @dev Executes CREATE_ROLE: creates a new non-protected role
136
+ * @param data ABI-encoded (string roleName, uint256 maxWallets)
137
+ */
138
+ function _executeCreateRole(bytes calldata data) internal {
139
+ (string memory roleName, uint256 maxWallets) = abi.decode(data, (string, uint256));
140
+ bytes32 roleHash = _createRole(roleName, maxWallets, false);
141
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE, roleHash, bytes4(0), address(0));
142
+ }
143
+
144
+ /**
145
+ * @dev Executes REMOVE_ROLE: removes a role by hash
146
+ * @param data ABI-encoded (bytes32 roleHash)
147
+ */
148
+ function _executeRemoveRole(bytes calldata data) internal {
149
+ (bytes32 roleHash) = abi.decode(data, (bytes32));
150
+ _removeRole(roleHash);
151
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE, roleHash, bytes4(0), address(0));
152
+ }
153
+
154
+ /**
155
+ * @dev Executes ADD_WALLET: assigns a wallet to a role (role must not be protected)
156
+ * @param data ABI-encoded (bytes32 roleHash, address wallet)
157
+ */
158
+ function _executeAddWallet(bytes calldata data) internal {
159
+ (bytes32 roleHash, address wallet) = abi.decode(data, (bytes32, address));
160
+ _requireRoleNotProtected(roleHash);
161
+ _assignWallet(roleHash, wallet);
162
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.ADD_WALLET, roleHash, bytes4(0), wallet);
163
+ }
164
+
165
+ /**
166
+ * @dev Executes REVOKE_WALLET: revokes a wallet from a role (role must not be protected)
167
+ * @param data ABI-encoded (bytes32 roleHash, address wallet)
168
+ */
169
+ function _executeRevokeWallet(bytes calldata data) internal {
170
+ (bytes32 roleHash, address wallet) = abi.decode(data, (bytes32, address));
171
+ _requireRoleNotProtected(roleHash);
172
+ _revokeWallet(roleHash, wallet);
173
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET, roleHash, bytes4(0), wallet);
174
+ }
175
+
176
+ /**
177
+ * @dev Executes ADD_FUNCTION_TO_ROLE: adds a function permission to a role
178
+ * @param data ABI-encoded (bytes32 roleHash, FunctionPermission functionPermission)
179
+ */
180
+ function _executeAddFunctionToRole(bytes calldata data) internal {
181
+ (
182
+ bytes32 roleHash,
183
+ EngineBlox.FunctionPermission memory functionPermission
184
+ ) = abi.decode(data, (bytes32, EngineBlox.FunctionPermission));
185
+ _addFunctionToRole(roleHash, functionPermission);
186
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE, roleHash, functionPermission.functionSelector, address(0));
187
+ }
188
+
189
+ /**
190
+ * @dev Executes REMOVE_FUNCTION_FROM_ROLE: removes a function permission from a role
191
+ * @param data ABI-encoded (bytes32 roleHash, bytes4 functionSelector)
192
+ */
193
+ function _executeRemoveFunctionFromRole(bytes calldata data) internal {
194
+ (bytes32 roleHash, bytes4 functionSelector) = abi.decode(data, (bytes32, bytes4));
195
+ _removeFunctionFromRole(roleHash, functionSelector);
196
+ _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE, roleHash, functionSelector, address(0));
197
+ }
198
+
199
+ /**
200
+ * @dev Encodes and logs a role config event via ComponentEvent. Payload decodes as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector, address wallet).
201
+ * @param action The role config action type
202
+ * @param roleHash The role hash
203
+ * @param selector The function selector (or zero for N/A)
204
+ * @param wallet The wallet address (or zero for actions that do not apply to a wallet)
180
205
  */
181
- function _encodeRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType action, bytes32 roleHash, bytes4 selector) internal pure returns (bytes memory) {
182
- return abi.encode(action, roleHash, selector);
206
+ function _logRoleConfigEvent(IRuntimeRBAC.RoleConfigActionType action, bytes32 roleHash, bytes4 selector, address wallet) internal {
207
+ _logComponentEvent(abi.encode(action, roleHash, selector, wallet));
183
208
  }
184
209
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MPL-2.0
2
- pragma solidity 0.8.33;
2
+ pragma solidity 0.8.34;
3
3
 
4
4
  import "../../lib/EngineBlox.sol";
5
5