@rootzero/contracts 0.9.9 → 1.0.1
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/Endpoints.sol +2 -0
- package/Events.sol +1 -0
- package/README.md +19 -18
- package/blocks/Cursors.sol +104 -52
- package/blocks/Keys.sol +6 -0
- package/blocks/Schema.sol +4 -2
- package/blocks/Writers.sol +4 -4
- package/commands/Burn.sol +4 -1
- package/commands/Credit.sol +4 -1
- package/commands/Debit.sol +4 -1
- package/commands/Deposit.sol +8 -2
- package/commands/Payout.sol +7 -3
- package/commands/Provision.sol +8 -2
- package/commands/Relay.sol +57 -0
- package/commands/Withdraw.sol +4 -1
- package/commands/admin/AllowAssets.sol +6 -1
- package/commands/admin/Allowance.sol +4 -1
- package/commands/admin/Appoint.sol +4 -1
- package/commands/admin/Authorize.sol +4 -1
- package/commands/admin/DenyAssets.sol +6 -1
- package/commands/admin/Destroy.sol +4 -2
- package/commands/admin/Dismiss.sol +4 -1
- package/commands/admin/Execute.sol +5 -2
- package/commands/admin/Init.sol +4 -2
- package/commands/admin/Unauthorize.sol +4 -1
- package/core/Host.sol +10 -1
- package/core/Pipeline.sol +2 -1
- package/core/Runtime.sol +3 -3
- package/events/Admin.sol +5 -5
- package/events/Chain.sol +20 -0
- package/events/Command.sol +5 -5
- package/guards/Revoke.sol +1 -1
- package/package.json +1 -1
- package/peer/AllowAssets.sol +3 -1
- package/peer/Allowance.sol +3 -1
- package/peer/BalancePull.sol +3 -1
- package/peer/DenyAssets.sol +3 -1
- package/peer/Dispatch.sol +50 -0
- package/peer/Pipe.sol +5 -3
- package/peer/Settle.sol +3 -1
- package/queries/Assets.sol +1 -1
- package/queries/Balances.sol +1 -1
- package/queries/Positions.sol +1 -1
- package/utils/Accounts.sol +1 -34
- package/utils/Assets.sol +21 -21
- package/utils/Ids.sol +12 -2
- package/utils/Layout.sol +21 -17
- package/utils/Utils.sol +2 -2
package/utils/Ids.sol
CHANGED
|
@@ -18,6 +18,8 @@ library Ids {
|
|
|
18
18
|
|
|
19
19
|
/// @dev 24-bit family tag shared by all node types (Evm32 + Node category).
|
|
20
20
|
uint24 constant Node = (uint24(Layout.Evm32) << 8) | uint24(Layout.Node);
|
|
21
|
+
/// @dev Full 4-byte type prefix for chain/domain nodes.
|
|
22
|
+
uint32 constant Chain = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Chain);
|
|
21
23
|
/// @dev Full 4-byte type prefix for host nodes.
|
|
22
24
|
uint32 constant Host = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Host);
|
|
23
25
|
/// @dev Full 4-byte type prefix for command nodes.
|
|
@@ -56,7 +58,7 @@ library Ids {
|
|
|
56
58
|
|
|
57
59
|
/// @notice Return true if `id` is a local node ID for this contract.
|
|
58
60
|
function isLocalNode(uint id) internal view returns (bool) {
|
|
59
|
-
return isLocalFamily(id, Node) && address(uint160(id)) == address(this);
|
|
61
|
+
return uint32(id >> 224) != Chain && isLocalFamily(id, Node) && address(uint160(id)) == address(this);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/// @notice Assert that `id` is a command ID and return it unchanged.
|
|
@@ -128,6 +130,14 @@ library Ids {
|
|
|
128
130
|
return id;
|
|
129
131
|
}
|
|
130
132
|
|
|
133
|
+
/// @notice Build the chain node ID for the current chain.
|
|
134
|
+
/// @return Chain node ID with the Chain prefix and `block.chainid` payload.
|
|
135
|
+
function localChain() internal view returns (uint) {
|
|
136
|
+
uint id = block.chainid;
|
|
137
|
+
if (id >> 224 != 0) revert InvalidId();
|
|
138
|
+
return (uint(Chain) << 224) | id;
|
|
139
|
+
}
|
|
140
|
+
|
|
131
141
|
/// @notice Build a chain-local host ID for `target`.
|
|
132
142
|
/// @param target Host contract address.
|
|
133
143
|
/// @return Host node ID on the current chain.
|
|
@@ -180,7 +190,7 @@ library Ids {
|
|
|
180
190
|
/// @param id Node ID (host, command, or peer).
|
|
181
191
|
/// @return Contract address in the lower 160 bits of `id`.
|
|
182
192
|
function nodeAddr(uint id) internal view returns (address) {
|
|
183
|
-
if (!isLocalFamily(id, Node)) revert InvalidId();
|
|
193
|
+
if (uint32(id >> 224) == Chain || !isLocalFamily(id, Node)) revert InvalidId();
|
|
184
194
|
return address(uint160(id));
|
|
185
195
|
}
|
|
186
196
|
|
package/utils/Layout.sol
CHANGED
|
@@ -6,19 +6,24 @@ pragma solidity ^0.8.33;
|
|
|
6
6
|
/// layout of 256-bit IDs used throughout the rootzero protocol.
|
|
7
7
|
///
|
|
8
8
|
/// IDs are structured as:
|
|
9
|
-
/// `[
|
|
10
|
-
/// where
|
|
9
|
+
/// `[uint32 type][uint32 chainid][192-bit payload]`
|
|
10
|
+
/// where `type` is `[uint8 vm][uint8 width][uint8 category][uint8 subtype]`.
|
|
11
11
|
library Layout {
|
|
12
12
|
// -------------------------------------------------------------------------
|
|
13
|
-
//
|
|
13
|
+
// VM and data-width tags (top 2 bytes of the ID type field)
|
|
14
14
|
// -------------------------------------------------------------------------
|
|
15
15
|
|
|
16
|
-
/// @dev
|
|
17
|
-
|
|
16
|
+
/// @dev EVM-compatible value; payloads are built around 20-byte addresses.
|
|
17
|
+
uint8 constant Evm = 0x01;
|
|
18
|
+
/// @dev 32-byte ID; no paired metadata word is required.
|
|
19
|
+
uint8 constant Width32 = 0x20;
|
|
20
|
+
/// @dev 64-byte ID; a paired metadata word completes the identity.
|
|
21
|
+
uint8 constant Width64 = 0x40;
|
|
22
|
+
|
|
18
23
|
/// @dev 32-byte EVM-compatible value; lower 20 bytes hold an address.
|
|
19
|
-
uint16 constant Evm32 =
|
|
24
|
+
uint16 constant Evm32 = (uint16(Evm) << 8) | uint16(Width32);
|
|
20
25
|
/// @dev 64-byte EVM-compatible value; used when a paired metadata word completes the identity.
|
|
21
|
-
uint16 constant Evm64 =
|
|
26
|
+
uint16 constant Evm64 = (uint16(Evm) << 8) | uint16(Width64);
|
|
22
27
|
|
|
23
28
|
// -------------------------------------------------------------------------
|
|
24
29
|
// Category tags (uint8, third byte of the ID type field)
|
|
@@ -41,30 +46,29 @@ library Layout {
|
|
|
41
46
|
uint8 constant Guardian = 0x02;
|
|
42
47
|
/// @dev User account — chain-agnostic, backed by an EVM address.
|
|
43
48
|
uint8 constant User = 0x03;
|
|
44
|
-
/// @dev Keccak account — opaque 28-byte keccak commitment.
|
|
45
|
-
uint8 constant Keccak = 0x04;
|
|
46
|
-
|
|
47
49
|
// -------------------------------------------------------------------------
|
|
48
50
|
// Node subtype tags (uint8, fourth byte of the ID type field)
|
|
49
51
|
// -------------------------------------------------------------------------
|
|
50
52
|
|
|
53
|
+
/// @dev Node is a chain/domain identifier.
|
|
54
|
+
uint8 constant Chain = 0x01;
|
|
51
55
|
/// @dev Node is a host contract.
|
|
52
|
-
uint8 constant Host =
|
|
56
|
+
uint8 constant Host = 0x02;
|
|
53
57
|
/// @dev Node is a command contract.
|
|
54
|
-
uint8 constant Command =
|
|
58
|
+
uint8 constant Command = 0x03;
|
|
55
59
|
/// @dev Node is a peer contract.
|
|
56
|
-
uint8 constant Peer =
|
|
60
|
+
uint8 constant Peer = 0x04;
|
|
57
61
|
/// @dev Node is a query contract.
|
|
58
|
-
uint8 constant Query =
|
|
62
|
+
uint8 constant Query = 0x05;
|
|
59
63
|
/// @dev Node is a guardian-only direct action.
|
|
60
|
-
uint8 constant Guard =
|
|
64
|
+
uint8 constant Guard = 0x06;
|
|
61
65
|
|
|
62
66
|
// -------------------------------------------------------------------------
|
|
63
67
|
// Asset subtype tags (uint8, fourth byte of the ID type field)
|
|
64
68
|
// -------------------------------------------------------------------------
|
|
65
69
|
|
|
66
|
-
/// @dev Native chain
|
|
67
|
-
uint8 constant
|
|
70
|
+
/// @dev Native chain coin/token asset.
|
|
71
|
+
uint8 constant Native = 0x01;
|
|
68
72
|
/// @dev ERC-20 fungible token; lower 20 bytes of the ID hold the contract address.
|
|
69
73
|
uint8 constant Erc20 = 0x02;
|
|
70
74
|
/// @dev ERC-721 non-fungible token; lower 20 bytes of the ID hold the collection address.
|
package/utils/Utils.sol
CHANGED
|
@@ -4,9 +4,9 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
// Basis-points denominator: 10_000 BPS == 100.00%.
|
|
5
5
|
uint16 constant MAX_BPS = 10_000;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/// @dev Thrown by max* helpers when a value exceeds the target integer width.
|
|
8
8
|
error ValueOverflow();
|
|
9
|
-
|
|
9
|
+
/// @dev Thrown by `divisible` when `n` is not evenly divisible by `divisor`.
|
|
10
10
|
error NotDivisible();
|
|
11
11
|
|
|
12
12
|
/// @notice Assert that `value` fits in uint8 and return it unchanged.
|