@rootzero/contracts 1.3.0 → 1.5.0
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/CHANGELOG.md +37 -0
- package/Endpoints.sol +4 -3
- package/Events.sol +3 -3
- package/README.md +58 -31
- package/Utils.sol +4 -3
- package/blocks/Cursors.sol +83 -143
- package/blocks/Keys.sol +15 -15
- package/blocks/Schema.sol +27 -28
- package/blocks/Writers.sol +26 -33
- package/commands/Base.sol +2 -2
- package/commands/Burn.sol +3 -4
- package/commands/Credit.sol +3 -4
- package/commands/Debit.sol +4 -5
- package/commands/Deposit.sol +8 -10
- package/commands/Payout.sol +3 -6
- package/commands/Withdraw.sol +3 -4
- package/commands/admin/AllowAssets.sol +5 -6
- package/commands/admin/Allowance.sol +3 -4
- package/commands/admin/DenyAssets.sol +5 -6
- package/commands/admin/Execute.sol +2 -2
- package/core/Access.sol +2 -2
- package/core/Balances.sol +10 -11
- package/core/Calls.sol +7 -7
- package/core/Host.sol +2 -2
- package/core/Runtime.sol +3 -3
- package/core/Types.sol +0 -14
- package/docs/Schema.md +29 -10
- package/events/Asset.sol +17 -3
- package/events/Balance.sol +2 -3
- package/events/Commander.sol +19 -0
- package/events/Labeled.sol +6 -6
- package/events/Locked.sol +2 -3
- package/events/Position.sol +2 -3
- package/events/Received.sol +2 -3
- package/events/Route.sol +18 -0
- package/events/Spent.sol +2 -3
- package/events/Unlocked.sol +2 -3
- package/guards/Base.sol +4 -4
- package/package.json +1 -1
- package/peer/AllowAssets.sol +3 -3
- package/peer/Allowance.sol +2 -2
- package/peer/Base.sol +4 -4
- package/peer/Credit.sol +10 -10
- package/peer/Debit.sol +10 -10
- package/peer/DenyAssets.sol +3 -3
- package/peer/Recover.sol +51 -0
- package/peer/Redeem.sol +48 -0
- package/peer/Settle.sol +3 -3
- package/queries/Assets.sol +7 -8
- package/queries/Balances.sol +8 -9
- package/queries/Base.sol +4 -4
- package/queries/Positions.sol +4 -6
- package/utils/Accounts.sol +76 -58
- package/utils/Actions.sol +1 -0
- package/utils/Assets.sol +55 -115
- package/utils/Ids.sol +33 -233
- package/utils/Layout.sol +11 -17
- package/utils/Nodes.sol +263 -0
- package/utils/Utils.sol +9 -24
- package/events/Chain.sol +0 -19
- package/events/Transfer.sol +0 -22
- package/peer/BalancePull.sol +0 -49
package/utils/Nodes.sol
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Layout} from "./Layout.sol";
|
|
5
|
+
import {Ids} from "./Ids.sol";
|
|
6
|
+
import {ensureAddr, isFamily, matchesBase, toLocalBase} from "./Utils.sol";
|
|
7
|
+
|
|
8
|
+
/// @title Nodes
|
|
9
|
+
/// @notice Encoding and decoding helpers for 256-bit node identifiers.
|
|
10
|
+
///
|
|
11
|
+
/// Node IDs share a common layout:
|
|
12
|
+
/// - bits [255:224] — 4-byte type prefix (`Host`, `Command`, or `Peer`)
|
|
13
|
+
/// - bits [223:192] — current `block.chainid` (makes IDs chain-local)
|
|
14
|
+
/// - bits [191:160] — 4-byte ABI selector (commands and peers only)
|
|
15
|
+
/// - bits [159:0] — 160-bit EVM contract address
|
|
16
|
+
///
|
|
17
|
+
/// If the first byte is zero, the node is an opaque
|
|
18
|
+
/// `0x00 || bytes31(hash)` ID. The callable target must be resolved by lookup
|
|
19
|
+
/// or witness data before dispatch.
|
|
20
|
+
///
|
|
21
|
+
/// The helpers in this library validate and deconstruct structured node IDs.
|
|
22
|
+
library Nodes {
|
|
23
|
+
/// @dev Thrown when an ID does not match the expected node type or chain.
|
|
24
|
+
error InvalidId();
|
|
25
|
+
|
|
26
|
+
/// @dev 24-bit family tag shared by all node types (Evm + Node category).
|
|
27
|
+
uint24 constant Family = (uint24(Layout.Evm) << 8) | uint24(Layout.Node);
|
|
28
|
+
/// @dev Full 4-byte type prefix for chain/domain nodes.
|
|
29
|
+
uint32 constant Chain = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Chain);
|
|
30
|
+
/// @dev Full 4-byte type prefix for host nodes.
|
|
31
|
+
uint32 constant Host = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Host);
|
|
32
|
+
/// @dev Full 4-byte type prefix for command nodes.
|
|
33
|
+
uint32 constant Command = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Command);
|
|
34
|
+
/// @dev Full 4-byte type prefix for peer nodes.
|
|
35
|
+
uint32 constant Peer = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Peer);
|
|
36
|
+
/// @dev Full 4-byte type prefix for query nodes.
|
|
37
|
+
uint32 constant Query = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Query);
|
|
38
|
+
/// @dev Full 4-byte type prefix for guard action nodes.
|
|
39
|
+
uint32 constant Guard = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Guard);
|
|
40
|
+
|
|
41
|
+
/// @notice Return true if `node` is a host node ID.
|
|
42
|
+
function isHost(uint node) internal pure returns (bool) {
|
|
43
|
+
return uint32(node >> 224) == Host;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// @notice Return true if `node` is a command node ID.
|
|
47
|
+
function isCommand(uint node) internal pure returns (bool) {
|
|
48
|
+
return uint32(node >> 224) == Command;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// @notice Return true if `node` is a peer node ID.
|
|
52
|
+
function isPeer(uint node) internal pure returns (bool) {
|
|
53
|
+
return uint32(node >> 224) == Peer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// @notice Return true if `node` is a query node ID.
|
|
57
|
+
function isQuery(uint node) internal pure returns (bool) {
|
|
58
|
+
return uint32(node >> 224) == Query;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// @notice Return true if `node` is a guard action node ID.
|
|
62
|
+
function isGuard(uint node) internal pure returns (bool) {
|
|
63
|
+
return uint32(node >> 224) == Guard;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// @notice Return true if `node` belongs to the EVM node family.
|
|
67
|
+
function isEvm(uint node) internal pure returns (bool) {
|
|
68
|
+
return isFamily(node, Family);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// @notice Return true if `node` is opaque.
|
|
72
|
+
function isOpaque(uint node) internal pure returns (bool) {
|
|
73
|
+
return Ids.isOpaque(bytes32(node));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// @notice Return true if `node` belongs to the EVM node family on the current chain.
|
|
77
|
+
function isLocal(uint node) internal view returns (bool) {
|
|
78
|
+
return isEvm(node) && uint32(node >> 192) == block.chainid;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// @notice Assert that `value` is a host node ID and return it as a node.
|
|
82
|
+
/// @param value Value to validate.
|
|
83
|
+
/// @return node The same `value` if it is a host node.
|
|
84
|
+
function host(uint value) internal pure returns (uint node) {
|
|
85
|
+
if (!isHost(value)) revert InvalidId();
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// @notice Assert that `value` is a command node ID and return it as a node.
|
|
90
|
+
/// @param value Value to validate.
|
|
91
|
+
/// @return node The same `value` if it is a command node.
|
|
92
|
+
function command(uint value) internal pure returns (uint node) {
|
|
93
|
+
if (!isCommand(value)) revert InvalidId();
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// @notice Assert that `value` is a peer node ID and return it as a node.
|
|
98
|
+
/// @param value Value to validate.
|
|
99
|
+
/// @return node The same `value` if it is a peer node.
|
|
100
|
+
function peer(uint value) internal pure returns (uint node) {
|
|
101
|
+
if (!isPeer(value)) revert InvalidId();
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// @notice Assert that `value` is a query node ID and return it as a node.
|
|
106
|
+
/// @param value Value to validate.
|
|
107
|
+
/// @return node The same `value` if it is a query node.
|
|
108
|
+
function query(uint value) internal pure returns (uint node) {
|
|
109
|
+
if (!isQuery(value)) revert InvalidId();
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// @notice Assert that `value` is a guard action node ID and return it as a node.
|
|
114
|
+
/// @param value Value to validate.
|
|
115
|
+
/// @return node The same `value` if it is a guard action node.
|
|
116
|
+
function guard(uint value) internal pure returns (uint node) {
|
|
117
|
+
if (!isGuard(value)) revert InvalidId();
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// @notice Assert that `value` belongs to the EVM node family and return it as a node.
|
|
122
|
+
/// @param value Value to validate.
|
|
123
|
+
/// @return node The same `value` if it is an EVM node.
|
|
124
|
+
function evm(uint value) internal pure returns (uint node) {
|
|
125
|
+
if (!isEvm(value)) revert InvalidId();
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// @notice Assert that `value` is an opaque node and return it unchanged.
|
|
130
|
+
/// @param value Node ID to validate.
|
|
131
|
+
/// @return node The same `value` if it is opaque.
|
|
132
|
+
function opaque(uint value) internal pure returns (uint node) {
|
|
133
|
+
if (!Ids.isOpaque(bytes32(value))) revert InvalidId();
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// @notice Assert that `value` belongs to the EVM node family on the current chain and return it as a node.
|
|
138
|
+
/// @param value Value to validate.
|
|
139
|
+
/// @return node The same `value` if it is local.
|
|
140
|
+
function local(uint value) internal view returns (uint node) {
|
|
141
|
+
if (!isLocal(value)) revert InvalidId();
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// @notice Assert that `node` is a command ID and return its embedded ABI selector.
|
|
146
|
+
/// @param node Node ID to validate.
|
|
147
|
+
/// @return selector 4-byte command selector stored in bits [191:160].
|
|
148
|
+
function commandSelector(uint node) internal pure returns (bytes4 selector) {
|
|
149
|
+
return bytes4(uint32(command(node) >> 160));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// @notice Assert that `node` is a peer ID and return its embedded ABI selector.
|
|
153
|
+
/// @param node Node ID to validate.
|
|
154
|
+
/// @return selector 4-byte peer selector stored in bits [191:160].
|
|
155
|
+
function peerSelector(uint node) internal pure returns (bytes4 selector) {
|
|
156
|
+
return bytes4(uint32(peer(node) >> 160));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// @notice Assert that `node` is a query ID and return its embedded ABI selector.
|
|
160
|
+
/// @param node Node ID to validate.
|
|
161
|
+
/// @return selector 4-byte query selector stored in bits [191:160].
|
|
162
|
+
function querySelector(uint node) internal pure returns (bytes4 selector) {
|
|
163
|
+
return bytes4(uint32(query(node) >> 160));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// @notice Assert that `node` is a guard action ID and return its embedded ABI selector.
|
|
167
|
+
/// @param node Node ID to validate.
|
|
168
|
+
/// @return selector 4-byte guard selector stored in bits [191:160].
|
|
169
|
+
function guardSelector(uint node) internal pure returns (bytes4 selector) {
|
|
170
|
+
return bytes4(uint32(guard(node) >> 160));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// @notice Assert that `value` is the host node of `target` on the current chain.
|
|
174
|
+
/// @param value Value to validate.
|
|
175
|
+
/// @param target Expected host contract address.
|
|
176
|
+
/// @return node The same `value` if it matches `target`.
|
|
177
|
+
function matchHost(uint value, address target) internal view returns (uint node) {
|
|
178
|
+
if (value != toHost(target)) revert InvalidId();
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// @notice Build the chain node ID for the current chain.
|
|
183
|
+
/// @return node Chain node ID with zero selector and `address(0)` payload.
|
|
184
|
+
function localChain() internal view returns (uint node) {
|
|
185
|
+
return toLocalBase(Chain);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// @notice Build a chain-local host ID for `target`.
|
|
189
|
+
/// @param target Host contract address.
|
|
190
|
+
/// @return node Host node ID on the current chain.
|
|
191
|
+
function toHost(address target) internal view returns (uint node) {
|
|
192
|
+
return toLocalBase(Host) | uint(uint160(target));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/// @notice Build a chain-local command ID for the given selector and contract.
|
|
196
|
+
/// @param selector 4-byte ABI selector of the command entry point.
|
|
197
|
+
/// @param target Command contract address.
|
|
198
|
+
/// @return node Command node ID embedding both the selector and address.
|
|
199
|
+
function toCommand(bytes4 selector, address target) internal view returns (uint node) {
|
|
200
|
+
node = toLocalBase(Command) | uint(uint160(target));
|
|
201
|
+
node |= uint(uint32(selector)) << 160;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// @notice Build a chain-local peer ID for the given selector and contract.
|
|
205
|
+
/// @param selector 4-byte ABI selector of the peer entry point.
|
|
206
|
+
/// @param target Peer contract address.
|
|
207
|
+
/// @return node Peer node ID embedding both the selector and address.
|
|
208
|
+
function toPeer(bytes4 selector, address target) internal view returns (uint node) {
|
|
209
|
+
node = toLocalBase(Peer) | uint(uint160(target));
|
|
210
|
+
node |= uint(uint32(selector)) << 160;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// @notice Build a chain-local query ID for the given selector and contract.
|
|
214
|
+
/// @param selector 4-byte ABI selector of the query entry point.
|
|
215
|
+
/// @param target Query contract address.
|
|
216
|
+
/// @return node Query node ID embedding both the selector and address.
|
|
217
|
+
function toQuery(bytes4 selector, address target) internal view returns (uint node) {
|
|
218
|
+
node = toLocalBase(Query) | uint(uint160(target));
|
|
219
|
+
node |= uint(uint32(selector)) << 160;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// @notice Build a chain-local guard action ID for the given selector and contract.
|
|
223
|
+
/// @param selector 4-byte ABI selector of the guard action entry point.
|
|
224
|
+
/// @param target Guard action contract address.
|
|
225
|
+
/// @return node Guard action node ID embedding both the selector and address.
|
|
226
|
+
function toGuard(bytes4 selector, address target) internal view returns (uint node) {
|
|
227
|
+
node = toLocalBase(Guard) | uint(uint160(target));
|
|
228
|
+
node |= uint(uint32(selector)) << 160;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/// @notice Derive an opaque node ID from a keccak preimage.
|
|
232
|
+
/// @param preimage Preimage whose first byte is `0x01`.
|
|
233
|
+
/// @return node `0x00 || bytes31(keccak256(preimage))`.
|
|
234
|
+
function toKeccak(bytes memory preimage) internal pure returns (uint node) {
|
|
235
|
+
return uint(Ids.toKeccak(preimage));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// @notice Assert that `node` matches the opaque keccak ID for `preimage`.
|
|
239
|
+
/// @param node Opaque node ID to validate.
|
|
240
|
+
/// @param preimage Preimage whose first byte is `0x01`.
|
|
241
|
+
/// @return The same `node` value if it matches.
|
|
242
|
+
function matchKeccak(uint node, bytes memory preimage) internal pure returns (uint) {
|
|
243
|
+
if (node != uint(Ids.toKeccak(preimage))) revert InvalidId();
|
|
244
|
+
return node;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/// @notice Extract the contract address from any local node ID.
|
|
248
|
+
/// Reverts if `node` does not belong to the local node family or carries `address(0)`.
|
|
249
|
+
/// @param node Node ID.
|
|
250
|
+
/// @return Contract address in the lower 160 bits of `node`.
|
|
251
|
+
function addr(uint node) internal view returns (address) {
|
|
252
|
+
return ensureAddr(address(uint160(local(node))));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// @notice Extract the contract address from a local host ID.
|
|
256
|
+
/// Reverts if `node` does not match the local host base or carries `address(0)`.
|
|
257
|
+
/// @param node Host node ID.
|
|
258
|
+
/// @return Host contract address in the lower 160 bits of `node`.
|
|
259
|
+
function hostAddr(uint node) internal view returns (address) {
|
|
260
|
+
if (!matchesBase(bytes32(node), toLocalBase(Host))) revert InvalidId();
|
|
261
|
+
return ensureAddr(address(uint160(node)));
|
|
262
|
+
}
|
|
263
|
+
}
|
package/utils/Utils.sol
CHANGED
|
@@ -8,6 +8,8 @@ uint16 constant MAX_BPS = 10_000;
|
|
|
8
8
|
error ValueOverflow();
|
|
9
9
|
/// @dev Thrown by `divisible` when `n` is not evenly divisible by `divisor`.
|
|
10
10
|
error NotDivisible();
|
|
11
|
+
/// @dev Thrown when an ID claims to carry an address but the embedded address is zero.
|
|
12
|
+
error ZeroAddress();
|
|
11
13
|
|
|
12
14
|
/// @notice Assert that `value` fits in uint8 and return it unchanged.
|
|
13
15
|
function max8(uint value) pure returns (uint) {
|
|
@@ -92,6 +94,12 @@ function addrOr(address addr, address or) pure returns (address) {
|
|
|
92
94
|
return addr == address(0) ? or : addr;
|
|
93
95
|
}
|
|
94
96
|
|
|
97
|
+
/// @notice Assert that `addr` is non-zero and return it unchanged.
|
|
98
|
+
function ensureAddr(address addr) pure returns (address) {
|
|
99
|
+
if (addr == address(0)) revert ZeroAddress();
|
|
100
|
+
return addr;
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
/// @notice Convert a signed integer to its 32-byte two's-complement representation.
|
|
96
104
|
function intToBytes32(int value) pure returns (bytes32) {
|
|
97
105
|
return bytes32(uint(value));
|
|
@@ -136,20 +144,12 @@ function retryTicket(bytes32 account, bytes calldata state) pure returns (bytes3
|
|
|
136
144
|
|
|
137
145
|
/// @notice Build the chain-local base prefix for a 256-bit ID.
|
|
138
146
|
/// Embeds the current `block.chainid` so IDs are not portable across chains.
|
|
139
|
-
/// @param prefix Four-byte type tag (e.g. `
|
|
147
|
+
/// @param prefix Four-byte type tag (e.g. `Nodes.Host`, `Nodes.Command`).
|
|
140
148
|
/// @return Base value with the type tag in bits [255:224] and chainid in bits [223:192].
|
|
141
149
|
function toLocalBase(uint32 prefix) view returns (uint) {
|
|
142
150
|
return (uint(prefix) << 224) | (uint(max32(block.chainid)) << 192);
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
/// @notice Build the chain-local family prefix for a 256-bit ID.
|
|
146
|
-
/// Uses a 24-bit family tag (the top 3 bytes of the type field).
|
|
147
|
-
/// @param family Three-byte family tag.
|
|
148
|
-
/// @return Family prefix with the family in bits [255:232] and chainid in bits [223:192].
|
|
149
|
-
function toLocalFamily(uint24 family) view returns (uint) {
|
|
150
|
-
return (uint(family) << 232) | (uint(max32(block.chainid)) << 192);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
153
|
/// @notice Build a chain-unspecified base prefix (no chainid embedded).
|
|
154
154
|
/// Used for IDs that must be portable across chains (e.g. user accounts).
|
|
155
155
|
/// @param prefix Four-byte type tag.
|
|
@@ -167,21 +167,6 @@ function isFamily(uint value, uint24 family) pure returns (bool) {
|
|
|
167
167
|
return uint24(value >> 232) == family;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
/// @notice Check whether `value` was created on the current chain.
|
|
171
|
-
/// @param value ID to test.
|
|
172
|
-
/// @return True if bits [223:192] of `value` equal `block.chainid`.
|
|
173
|
-
function isLocalChain(uint value) view returns (bool) {
|
|
174
|
-
return uint32(value >> 192) == block.chainid;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/// @notice Check whether `value` belongs to the given family and was created on the current chain.
|
|
178
|
-
/// @param value ID to test.
|
|
179
|
-
/// @param family Expected 24-bit family tag.
|
|
180
|
-
/// @return True if both the family and chainid fields match.
|
|
181
|
-
function isLocalFamily(uint value, uint24 family) view returns (bool) {
|
|
182
|
-
return isFamily(value, family) && isLocalChain(value);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
170
|
/// @notice Check whether two IDs share the same 64-bit base (type tag + chainid).
|
|
186
171
|
/// Used to verify that an ID matches a locally-constructed base without comparing
|
|
187
172
|
/// the lower 192-bit payload.
|
package/events/Chain.sol
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
/// @notice Emitted when a chain/domain node is announced.
|
|
7
|
-
abstract contract ChainEvent is EventEmitter {
|
|
8
|
-
string private constant ABI = "event Chain(uint indexed chain, bytes32 native, uint commander, bytes32 admin)";
|
|
9
|
-
|
|
10
|
-
/// @param chain Chain node ID.
|
|
11
|
-
/// @param native Native asset ID for the chain.
|
|
12
|
-
/// @param commander Commander host node ID for the chain.
|
|
13
|
-
/// @param admin Admin account for the commander host on the chain.
|
|
14
|
-
event Chain(uint indexed chain, bytes32 native, uint commander, bytes32 admin);
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
emit EventAbi(ABI);
|
|
18
|
-
}
|
|
19
|
-
}
|
package/events/Transfer.sol
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
/// @notice Emitted when an asset moves from one account to another.
|
|
7
|
-
abstract contract TransferEvent is EventEmitter {
|
|
8
|
-
string private constant ABI = "event Transfer(bytes32 indexed account, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
|
|
9
|
-
|
|
10
|
-
/// @param account Source account identifier.
|
|
11
|
-
/// @param to Destination account identifier.
|
|
12
|
-
/// @param asset Asset identifier.
|
|
13
|
-
/// @param meta Asset metadata slot.
|
|
14
|
-
/// @param amount Amount transferred.
|
|
15
|
-
/// @param action Primary operation hint from `Actions`.
|
|
16
|
-
/// @param context Reserved context value for future use.
|
|
17
|
-
event Transfer(bytes32 indexed account, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
emit EventAbi(ABI);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/peer/BalancePull.sol
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
interface IPeerBalancePull {
|
|
10
|
-
function peerBalancePull(bytes calldata request) external returns (bytes memory);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
abstract contract BalancePullHook {
|
|
14
|
-
/// @notice Override to process one incoming balance-based pull request from a peer host.
|
|
15
|
-
/// @param peer Peer host node ID for this request.
|
|
16
|
-
/// @param asset Requested asset identifier.
|
|
17
|
-
/// @param meta Requested asset metadata slot.
|
|
18
|
-
/// @param amount Requested amount in the asset's native units.
|
|
19
|
-
function balancePull(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// @title PeerBalancePull
|
|
23
|
-
/// @notice Peer that pulls requested balances from a peer host into this one.
|
|
24
|
-
/// Each BALANCE block in the request calls `balancePull(peer, asset, meta, amount)`.
|
|
25
|
-
/// Restricted to trusted peers.
|
|
26
|
-
abstract contract PeerBalancePull is PeerBase, BalancePullHook, IPeerBalancePull {
|
|
27
|
-
uint internal immutable peerBalancePullId = peerId(this.peerBalancePull.selector);
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
emit Peer(host, peerBalancePullId, "1:0", Schemas.Balance, "", false);
|
|
31
|
-
emit Labeled(peerBalancePullId, bytes32(0), "peerBalancePull");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/// @notice Execute the balance-pull peer call.
|
|
35
|
-
/// @param request BALANCE block stream requested by the trusted peer.
|
|
36
|
-
/// @return Empty response bytes.
|
|
37
|
-
function peerBalancePull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
38
|
-
(Cur memory input, , ) = Cursors.init(request, 1);
|
|
39
|
-
uint peer = caller();
|
|
40
|
-
|
|
41
|
-
while (input.i < input.len) {
|
|
42
|
-
(bytes32 asset, bytes32 meta, uint amount) = input.unpackBalance();
|
|
43
|
-
balancePull(peer, asset, meta, amount);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
input.complete();
|
|
47
|
-
return "";
|
|
48
|
-
}
|
|
49
|
-
}
|