@rootzero/contracts 0.2.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/LICENSE +648 -0
- package/README.md +135 -0
- package/contracts/Blocks.sol +9 -0
- package/contracts/Commands.sol +41 -0
- package/contracts/Core.sol +10 -0
- package/contracts/Events.sol +18 -0
- package/contracts/Utils.sol +12 -0
- package/contracts/blocks/Blocks.sol +818 -0
- package/contracts/blocks/Keys.sol +24 -0
- package/contracts/blocks/Mem.sol +129 -0
- package/contracts/blocks/Schema.sol +105 -0
- package/contracts/blocks/Writers.sol +209 -0
- package/contracts/combinators/AmountToBalance.sol +25 -0
- package/contracts/combinators/AmountToCustody.sol +36 -0
- package/contracts/combinators/CustodyToBalance.sol +25 -0
- package/contracts/combinators/EachRoute.sol +18 -0
- package/contracts/combinators/MapBalance.sol +25 -0
- package/contracts/combinators/MapCustody.sol +25 -0
- package/contracts/combinators/RouteToBalance.sol +27 -0
- package/contracts/commands/Base.sol +40 -0
- package/contracts/commands/Borrow.sol +89 -0
- package/contracts/commands/Burn.sol +33 -0
- package/contracts/commands/Create.sol +32 -0
- package/contracts/commands/Credit.sol +36 -0
- package/contracts/commands/Debit.sol +46 -0
- package/contracts/commands/Deposit.sol +45 -0
- package/contracts/commands/Liquidate.sol +101 -0
- package/contracts/commands/Liquidity.sol +179 -0
- package/contracts/commands/Mint.sol +42 -0
- package/contracts/commands/Pipe.sol +55 -0
- package/contracts/commands/Provision.sol +73 -0
- package/contracts/commands/Reclaim.sol +48 -0
- package/contracts/commands/Redeem.sol +101 -0
- package/contracts/commands/Remove.sol +32 -0
- package/contracts/commands/Repay.sol +101 -0
- package/contracts/commands/Settle.sol +32 -0
- package/contracts/commands/Stake.sol +121 -0
- package/contracts/commands/Supply.sol +33 -0
- package/contracts/commands/Swap.sol +88 -0
- package/contracts/commands/Transfer.sol +44 -0
- package/contracts/commands/Unstake.sol +49 -0
- package/contracts/commands/Withdraw.sol +37 -0
- package/contracts/commands/admin/Allocate.sol +32 -0
- package/contracts/commands/admin/AllowAssets.sol +34 -0
- package/contracts/commands/admin/Authorize.sol +30 -0
- package/contracts/commands/admin/DenyAssets.sol +34 -0
- package/contracts/commands/admin/Destroy.sol +27 -0
- package/contracts/commands/admin/Init.sol +26 -0
- package/contracts/commands/admin/Relocate.sol +30 -0
- package/contracts/commands/admin/Unauthorize.sol +30 -0
- package/contracts/core/Access.sol +50 -0
- package/contracts/core/Balances.sol +23 -0
- package/contracts/core/Host.sol +25 -0
- package/contracts/core/Operation.sol +32 -0
- package/contracts/core/Validator.sol +31 -0
- package/contracts/events/Access.sol +14 -0
- package/contracts/events/Asset.sol +14 -0
- package/contracts/events/Balance.sol +14 -0
- package/contracts/events/Collateral.sol +15 -0
- package/contracts/events/Command.sol +14 -0
- package/contracts/events/Debt.sol +15 -0
- package/contracts/events/Deposit.sol +14 -0
- package/contracts/events/Emitter.sol +7 -0
- package/contracts/events/Governed.sol +14 -0
- package/contracts/events/HostAnnounced.sol +14 -0
- package/contracts/events/Listing.sol +14 -0
- package/contracts/events/Peer.sol +14 -0
- package/contracts/events/Quote.sol +14 -0
- package/contracts/events/RootZero.sol +14 -0
- package/contracts/events/Withdraw.sol +14 -0
- package/contracts/interfaces/IHostDiscovery.sol +6 -0
- package/contracts/peer/AllowAssets.sol +30 -0
- package/contracts/peer/Base.sol +17 -0
- package/contracts/peer/DenyAssets.sol +30 -0
- package/contracts/peer/Pull.sol +30 -0
- package/contracts/peer/Push.sol +30 -0
- package/contracts/test/TestBlockHelper.sol +261 -0
- package/contracts/test/TestBorrowHost.sol +47 -0
- package/contracts/test/TestBurnHost.sol +28 -0
- package/contracts/test/TestCreateHost.sol +26 -0
- package/contracts/test/TestDiscovery.sol +6 -0
- package/contracts/test/TestECDSA.sol +16 -0
- package/contracts/test/TestHost.sol +199 -0
- package/contracts/test/TestLiquidityHost.sol +145 -0
- package/contracts/test/TestMintHost.sol +40 -0
- package/contracts/test/TestPeerHost.sol +34 -0
- package/contracts/test/TestReclaimHost.sol +48 -0
- package/contracts/test/TestRejectEther.sol +8 -0
- package/contracts/test/TestRemoveHost.sol +26 -0
- package/contracts/test/TestSwapHost.sol +44 -0
- package/contracts/test/TestUtils.sol +169 -0
- package/contracts/test/TestValidator.sol +10 -0
- package/contracts/utils/Accounts.sol +40 -0
- package/contracts/utils/Assets.sol +76 -0
- package/contracts/utils/Channels.sol +11 -0
- package/contracts/utils/ECDSA.sol +36 -0
- package/contracts/utils/Ids.sol +75 -0
- package/contracts/utils/Layout.sol +22 -0
- package/contracts/utils/Utils.sol +126 -0
- package/contracts/utils/Value.sol +20 -0
- package/package.json +33 -0
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AUTH_PROOF_LEN, AUTH_TOTAL_LEN, HostAsset, AssetAmount, HostAmount, Tx, Keys} from "./Schema.sol";
|
|
5
|
+
import {BALANCE_BLOCK_LEN, BOUNTY_BLOCK_LEN, CUSTODY_BLOCK_LEN, TX_BLOCK_LEN, Writer, Writers} from "./Writers.sol";
|
|
6
|
+
|
|
7
|
+
struct Block {
|
|
8
|
+
bytes4 key;
|
|
9
|
+
uint i;
|
|
10
|
+
uint bound;
|
|
11
|
+
uint end;
|
|
12
|
+
uint cursor;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
struct BlockPair {
|
|
16
|
+
Block a;
|
|
17
|
+
Block b;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
using Blocks for Block;
|
|
21
|
+
|
|
22
|
+
library Blocks {
|
|
23
|
+
error MalformedBlocks();
|
|
24
|
+
error InvalidBlock();
|
|
25
|
+
error ZeroRecipient();
|
|
26
|
+
error ZeroNode();
|
|
27
|
+
error UnexpectedHost();
|
|
28
|
+
error UnexpectedAsset();
|
|
29
|
+
error UnexpectedMeta();
|
|
30
|
+
|
|
31
|
+
// ── infrastructure ────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
function at(uint i) internal pure returns (Block memory ref) {
|
|
34
|
+
uint eod = msg.data.length;
|
|
35
|
+
if (i == eod) return Block(bytes4(0), 0, 0, i, i);
|
|
36
|
+
if (i > eod) revert MalformedBlocks();
|
|
37
|
+
|
|
38
|
+
unchecked {
|
|
39
|
+
ref.i = i + 12;
|
|
40
|
+
}
|
|
41
|
+
if (ref.i > eod) revert MalformedBlocks();
|
|
42
|
+
ref.key = bytes4(msg.data[i:i + 4]);
|
|
43
|
+
ref.bound = ref.i + uint32(bytes4(msg.data[i + 4:i + 8]));
|
|
44
|
+
ref.end = ref.i + uint32(bytes4(msg.data[i + 8:ref.i]));
|
|
45
|
+
|
|
46
|
+
if (ref.bound > ref.end || ref.end > eod) revert MalformedBlocks();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function from(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
50
|
+
uint base;
|
|
51
|
+
uint eod = source.length;
|
|
52
|
+
assembly ("memory-safe") {
|
|
53
|
+
base := source.offset
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (i == eod) return Block(bytes4(0), 0, 0, base + i, i);
|
|
57
|
+
if (i > eod) revert MalformedBlocks();
|
|
58
|
+
|
|
59
|
+
uint start;
|
|
60
|
+
unchecked {
|
|
61
|
+
start = i + 12;
|
|
62
|
+
}
|
|
63
|
+
if (start > eod) revert MalformedBlocks();
|
|
64
|
+
|
|
65
|
+
ref.key = bytes4(source[i:i + 4]);
|
|
66
|
+
ref.i = base + start;
|
|
67
|
+
ref.bound = ref.i + uint32(bytes4(source[i + 4:i + 8]));
|
|
68
|
+
ref.end = ref.i + uint32(bytes4(source[i + 8:start]));
|
|
69
|
+
ref.cursor = i + (ref.end - ref.i) + 12;
|
|
70
|
+
|
|
71
|
+
uint eos = base + eod;
|
|
72
|
+
if (ref.bound > ref.end || ref.end > eos) revert MalformedBlocks();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function twoFrom(bytes calldata source, uint i) internal pure returns (BlockPair memory ref) {
|
|
76
|
+
ref.a = from(source, i);
|
|
77
|
+
ref.b = from(source, ref.a.cursor);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function count(bytes calldata source, uint i, bytes4 key) internal pure returns (uint count_, uint next) {
|
|
81
|
+
next = i;
|
|
82
|
+
while (next < source.length) {
|
|
83
|
+
Block memory ref = from(source, next);
|
|
84
|
+
if (ref.key != key) break;
|
|
85
|
+
unchecked {
|
|
86
|
+
++count_;
|
|
87
|
+
}
|
|
88
|
+
next = ref.cursor;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function childAt(Block memory parent, uint i) internal pure returns (Block memory ref) {
|
|
93
|
+
if (i < parent.bound || i >= parent.end) revert MalformedBlocks();
|
|
94
|
+
ref = at(i);
|
|
95
|
+
if (ref.end > parent.end) revert MalformedBlocks();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function findFrom(bytes calldata source, uint i, uint limit, bytes4 key) internal pure returns (Block memory ref) {
|
|
99
|
+
if (limit > source.length) revert MalformedBlocks();
|
|
100
|
+
while (i < limit) {
|
|
101
|
+
ref = from(source, i);
|
|
102
|
+
if (ref.cursor > limit) revert MalformedBlocks();
|
|
103
|
+
if (ref.key == key) return ref;
|
|
104
|
+
i = ref.cursor;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Block(bytes4(0), limit, limit, limit, limit);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function findChild(Block memory parent, bytes4 key) internal pure returns (Block memory ref) {
|
|
111
|
+
return findFrom(msg.data, parent.bound, parent.end, key);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function create32(bytes4 key, bytes32 value) internal pure returns (bytes memory) {
|
|
115
|
+
return bytes.concat(key, bytes4(uint32(0x20)), bytes4(uint32(0x20)), value);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function create64(bytes4 key, bytes32 a, bytes32 b) internal pure returns (bytes memory) {
|
|
119
|
+
return bytes.concat(key, bytes4(uint32(0x40)), bytes4(uint32(0x40)), a, b);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function create96(bytes4 key, bytes32 a, bytes32 b, bytes32 c) internal pure returns (bytes memory) {
|
|
123
|
+
return bytes.concat(key, bytes4(uint32(0x60)), bytes4(uint32(0x60)), a, b, c);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function create128(bytes4 key, bytes32 a, bytes32 b, bytes32 c, bytes32 d) internal pure returns (bytes memory) {
|
|
127
|
+
return bytes.concat(key, bytes4(uint32(0x80)), bytes4(uint32(0x80)), a, b, c, d);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function toBountyBlock(uint bounty, bytes32 relayer) internal pure returns (bytes memory) {
|
|
131
|
+
return create64(Keys.Bounty, bytes32(bounty), relayer);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function toBalanceBlock(bytes32 asset, bytes32 meta, uint amount) internal pure returns (bytes memory) {
|
|
135
|
+
return create96(Keys.Balance, asset, meta, bytes32(amount));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function toCustodyBlock(uint host, bytes32 asset, bytes32 meta, uint amount) internal pure returns (bytes memory) {
|
|
139
|
+
return create128(Keys.Custody, bytes32(host), asset, meta, bytes32(amount));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isBalance(Block memory ref) internal pure returns (bool) {
|
|
143
|
+
return ref.key == Keys.Balance;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isCustody(Block memory ref) internal pure returns (bool) {
|
|
147
|
+
return ref.key == Keys.Custody;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function resolveRecipient(
|
|
151
|
+
bytes calldata source,
|
|
152
|
+
uint i,
|
|
153
|
+
uint limit,
|
|
154
|
+
bytes32 backup
|
|
155
|
+
) internal pure returns (bytes32) {
|
|
156
|
+
Block memory ref = findFrom(source, i, limit, Keys.Recipient);
|
|
157
|
+
bytes32 to = ref.key != 0 ? ref.unpackRecipient() : backup;
|
|
158
|
+
if (to == 0) revert ZeroRecipient();
|
|
159
|
+
return to;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function resolveNode(bytes calldata source, uint i, uint limit, uint backup) internal pure returns (uint) {
|
|
163
|
+
Block memory ref = findFrom(source, i, limit, Keys.Node);
|
|
164
|
+
uint node = ref.key != 0 ? ref.unpackNode() : backup;
|
|
165
|
+
if (node == 0) revert ZeroNode();
|
|
166
|
+
return node;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function verifyAuth(
|
|
170
|
+
Block memory ref,
|
|
171
|
+
uint expectedCid
|
|
172
|
+
) internal pure returns (bytes32 hash, uint deadline, bytes calldata proof) {
|
|
173
|
+
if (ref.end - ref.bound < AUTH_TOTAL_LEN) revert MalformedBlocks();
|
|
174
|
+
uint cid;
|
|
175
|
+
(cid, deadline, proof) = innerAuthAt(ref, ref.end - AUTH_TOTAL_LEN);
|
|
176
|
+
if (cid != expectedCid) revert MalformedBlocks();
|
|
177
|
+
hash = keccak256(msg.data[ref.i - 12:ref.end - AUTH_PROOF_LEN]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function ensure(Block memory ref, bytes4 key) internal pure {
|
|
181
|
+
if (key == 0 || key != ref.key) revert InvalidBlock();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function ensure(Block memory ref, bytes4 key, uint len) internal pure {
|
|
185
|
+
if (key == 0 || key != ref.key || len != (ref.bound - ref.i)) revert InvalidBlock();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function ensure(Block memory ref, bytes4 key, uint min, uint max) internal pure {
|
|
189
|
+
uint len = ref.bound - ref.i;
|
|
190
|
+
if (key == 0 || key != ref.key || len < min || (max != 0 && len > max)) revert InvalidBlock();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function ensure(BlockPair memory ref, bytes4 key, uint len) internal pure {
|
|
194
|
+
ensure(ref.a, key, len);
|
|
195
|
+
ensure(ref.b, key, len);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function ensure(BlockPair memory ref, bytes4 key, uint min, uint max) internal pure {
|
|
199
|
+
ensure(ref.a, key, min, max);
|
|
200
|
+
ensure(ref.b, key, min, max);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── *From ─────────────────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
function routeFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
206
|
+
ref = from(source, i);
|
|
207
|
+
ensure(ref, Keys.Route);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function nodeFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
211
|
+
ref = from(source, i);
|
|
212
|
+
ensure(ref, Keys.Node, 32);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function recipientFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
216
|
+
ref = from(source, i);
|
|
217
|
+
ensure(ref, Keys.Recipient, 32);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function partyFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
221
|
+
ref = from(source, i);
|
|
222
|
+
ensure(ref, Keys.Party, 32);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function rateFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
226
|
+
ref = from(source, i);
|
|
227
|
+
ensure(ref, Keys.Rate, 32);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function quantityFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
231
|
+
ref = from(source, i);
|
|
232
|
+
ensure(ref, Keys.Quantity, 32);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function assetFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
236
|
+
ref = from(source, i);
|
|
237
|
+
ensure(ref, Keys.Asset, 64);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function fundingFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
241
|
+
ref = from(source, i);
|
|
242
|
+
ensure(ref, Keys.Funding, 64);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function bountyFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
246
|
+
ref = from(source, i);
|
|
247
|
+
ensure(ref, Keys.Bounty, 64);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function amountFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
251
|
+
ref = from(source, i);
|
|
252
|
+
ensure(ref, Keys.Amount, 96);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function amountTwoFrom(bytes calldata source, uint i) internal pure returns (BlockPair memory ref) {
|
|
256
|
+
ref = twoFrom(source, i);
|
|
257
|
+
ensure(ref, Keys.Amount, 96);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function balanceFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
261
|
+
ref = from(source, i);
|
|
262
|
+
ensure(ref, Keys.Balance, 96);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function balanceTwoFrom(bytes calldata source, uint i) internal pure returns (BlockPair memory ref) {
|
|
266
|
+
ref = twoFrom(source, i);
|
|
267
|
+
ensure(ref, Keys.Balance, 96);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function minimumFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
271
|
+
ref = from(source, i);
|
|
272
|
+
ensure(ref, Keys.Minimum, 96);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function maximumFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
276
|
+
ref = from(source, i);
|
|
277
|
+
ensure(ref, Keys.Maximum, 96);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function listingFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
281
|
+
ref = from(source, i);
|
|
282
|
+
ensure(ref, Keys.Listing, 96);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function stepFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
286
|
+
ref = from(source, i);
|
|
287
|
+
ensure(ref, Keys.Step, 64, 0);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function authFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
291
|
+
ref = from(source, i);
|
|
292
|
+
ensure(ref, Keys.Auth, 149, 0);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function custodyFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
296
|
+
ref = from(source, i);
|
|
297
|
+
ensure(ref, Keys.Custody, 128);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function custodyTwoFrom(bytes calldata source, uint i) internal pure returns (BlockPair memory ref) {
|
|
301
|
+
ref = twoFrom(source, i);
|
|
302
|
+
ensure(ref, Keys.Custody, 128);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function allocationFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
306
|
+
ref = from(source, i);
|
|
307
|
+
ensure(ref, Keys.Allocation, 128);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function txFrom(bytes calldata source, uint i) internal pure returns (Block memory ref) {
|
|
311
|
+
ref = from(source, i);
|
|
312
|
+
ensure(ref, Keys.Transaction, 160);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ── inner* ────────────────────────────────────────────────────────────────
|
|
316
|
+
|
|
317
|
+
function innerPair(Block memory parent) internal pure returns (BlockPair memory ref) {
|
|
318
|
+
ref.a = childAt(parent, parent.bound);
|
|
319
|
+
ref.b = childAt(parent, ref.a.end);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function innerRoute(Block memory parent) internal pure returns (bytes calldata data) {
|
|
323
|
+
return unpackRoute(childAt(parent, parent.bound));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function innerNode(Block memory parent) internal pure returns (uint id) {
|
|
327
|
+
return unpackNode(childAt(parent, parent.bound));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function innerRecipient(Block memory parent) internal pure returns (bytes32 account) {
|
|
331
|
+
return unpackRecipient(childAt(parent, parent.bound));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function innerParty(Block memory parent) internal pure returns (bytes32 account) {
|
|
335
|
+
return unpackParty(childAt(parent, parent.bound));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function innerRate(Block memory parent) internal pure returns (uint value) {
|
|
339
|
+
return unpackRate(childAt(parent, parent.bound));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function innerQuantity(Block memory parent) internal pure returns (uint amount) {
|
|
343
|
+
return unpackQuantity(childAt(parent, parent.bound));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function innerAsset(Block memory parent) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
347
|
+
return unpackAsset(childAt(parent, parent.bound));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function innerFunding(Block memory parent) internal pure returns (uint host, uint amount) {
|
|
351
|
+
return unpackFunding(childAt(parent, parent.bound));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function innerBounty(Block memory parent) internal pure returns (uint amount, bytes32 relayer) {
|
|
355
|
+
return unpackBounty(childAt(parent, parent.bound));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function innerAmount(Block memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
359
|
+
return unpackAmount(childAt(parent, parent.bound));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function innerAmountValue(Block memory parent) internal pure returns (AssetAmount memory) {
|
|
363
|
+
return toAmountValue(childAt(parent, parent.bound));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function innerBalance(Block memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
367
|
+
return unpackBalance(childAt(parent, parent.bound));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function innerMinimum(Block memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
371
|
+
return unpackMinimum(childAt(parent, parent.bound));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function innerMaximum(Block memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
375
|
+
return unpackMaximum(childAt(parent, parent.bound));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function innerListing(Block memory parent) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
379
|
+
return unpackListing(childAt(parent, parent.bound));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function innerStep(Block memory parent) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
383
|
+
return unpackStep(childAt(parent, parent.bound));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function innerAuth(Block memory parent) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
387
|
+
return unpackAuth(childAt(parent, parent.bound));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function innerCustody(Block memory parent) internal pure returns (HostAmount memory value) {
|
|
391
|
+
return toCustodyValue(childAt(parent, parent.bound));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function innerAllocation(Block memory parent) internal pure returns (HostAmount memory value) {
|
|
395
|
+
return toAllocationValue(childAt(parent, parent.bound));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function innerTx(Block memory parent) internal pure returns (Tx memory value) {
|
|
399
|
+
return toTxValue(childAt(parent, parent.bound));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ── inner*At ──────────────────────────────────────────────────────────────
|
|
403
|
+
|
|
404
|
+
function innerPairAt(Block memory parent, uint i) internal pure returns (BlockPair memory ref) {
|
|
405
|
+
ref.a = childAt(parent, i);
|
|
406
|
+
ref.b = childAt(parent, ref.a.end);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function innerRouteAt(Block memory parent, uint i) internal pure returns (bytes calldata data) {
|
|
410
|
+
return unpackRoute(childAt(parent, i));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function innerNodeAt(Block memory parent, uint i) internal pure returns (uint id) {
|
|
414
|
+
return unpackNode(childAt(parent, i));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function innerRecipientAt(Block memory parent, uint i) internal pure returns (bytes32 account) {
|
|
418
|
+
return unpackRecipient(childAt(parent, i));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function innerPartyAt(Block memory parent, uint i) internal pure returns (bytes32 account) {
|
|
422
|
+
return unpackParty(childAt(parent, i));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function innerRateAt(Block memory parent, uint i) internal pure returns (uint value) {
|
|
426
|
+
return unpackRate(childAt(parent, i));
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function innerQuantityAt(Block memory parent, uint i) internal pure returns (uint amount) {
|
|
430
|
+
return unpackQuantity(childAt(parent, i));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function innerAssetAt(Block memory parent, uint i) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
434
|
+
return unpackAsset(childAt(parent, i));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function innerFundingAt(Block memory parent, uint i) internal pure returns (uint host, uint amount) {
|
|
438
|
+
return unpackFunding(childAt(parent, i));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function innerBountyAt(Block memory parent, uint i) internal pure returns (uint amount, bytes32 relayer) {
|
|
442
|
+
return unpackBounty(childAt(parent, i));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function innerAmountAt(
|
|
446
|
+
Block memory parent,
|
|
447
|
+
uint i
|
|
448
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
449
|
+
return unpackAmount(childAt(parent, i));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function innerBalanceAt(
|
|
453
|
+
Block memory parent,
|
|
454
|
+
uint i
|
|
455
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
456
|
+
return unpackBalance(childAt(parent, i));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function innerMinimumAt(
|
|
460
|
+
Block memory parent,
|
|
461
|
+
uint i
|
|
462
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
463
|
+
return unpackMinimum(childAt(parent, i));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function innerMaximumAt(
|
|
467
|
+
Block memory parent,
|
|
468
|
+
uint i
|
|
469
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
470
|
+
return unpackMaximum(childAt(parent, i));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function innerListingAt(
|
|
474
|
+
Block memory parent,
|
|
475
|
+
uint i
|
|
476
|
+
) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
477
|
+
return unpackListing(childAt(parent, i));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function innerStepAt(
|
|
481
|
+
Block memory parent,
|
|
482
|
+
uint i
|
|
483
|
+
) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
484
|
+
return unpackStep(childAt(parent, i));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function innerAuthAt(
|
|
488
|
+
Block memory parent,
|
|
489
|
+
uint i
|
|
490
|
+
) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
491
|
+
return unpackAuth(childAt(parent, i));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function innerCustodyAt(Block memory parent, uint i) internal pure returns (HostAmount memory value) {
|
|
495
|
+
return toCustodyValue(childAt(parent, i));
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function innerAllocationAt(Block memory parent, uint i) internal pure returns (HostAmount memory value) {
|
|
499
|
+
return toAllocationValue(childAt(parent, i));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function innerTxAt(Block memory parent, uint i) internal pure returns (Tx memory value) {
|
|
503
|
+
return toTxValue(childAt(parent, i));
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function unpackNodeAt(bytes calldata source, uint i) internal pure returns (uint id) {
|
|
507
|
+
return nodeFrom(source, i).unpackNode();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function unpackRecipientAt(bytes calldata source, uint i) internal pure returns (bytes32 account) {
|
|
511
|
+
return recipientFrom(source, i).unpackRecipient();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function unpackPartyAt(bytes calldata source, uint i) internal pure returns (bytes32 account) {
|
|
515
|
+
return partyFrom(source, i).unpackParty();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function unpackRateAt(bytes calldata source, uint i) internal pure returns (uint value) {
|
|
519
|
+
return rateFrom(source, i).unpackRate();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function unpackQuantityAt(bytes calldata source, uint i) internal pure returns (uint amount) {
|
|
523
|
+
return quantityFrom(source, i).unpackQuantity();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function unpackAssetAt(bytes calldata source, uint i) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
527
|
+
return assetFrom(source, i).unpackAsset();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function unpackFundingAt(bytes calldata source, uint i) internal pure returns (uint host, uint amount) {
|
|
531
|
+
return fundingFrom(source, i).unpackFunding();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function unpackBountyAt(bytes calldata source, uint i) internal pure returns (uint amount, bytes32 relayer) {
|
|
535
|
+
return bountyFrom(source, i).unpackBounty();
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function unpackAmountAt(
|
|
539
|
+
bytes calldata source,
|
|
540
|
+
uint i
|
|
541
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
542
|
+
return amountFrom(source, i).unpackAmount();
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function unpackBalanceAt(
|
|
546
|
+
bytes calldata source,
|
|
547
|
+
uint i
|
|
548
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
549
|
+
return balanceFrom(source, i).unpackBalance();
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function unpackMinimumAt(
|
|
553
|
+
bytes calldata source,
|
|
554
|
+
uint i
|
|
555
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
556
|
+
return minimumFrom(source, i).unpackMinimum();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function unpackMaximumAt(
|
|
560
|
+
bytes calldata source,
|
|
561
|
+
uint i
|
|
562
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
563
|
+
return maximumFrom(source, i).unpackMaximum();
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function unpackListingAt(
|
|
567
|
+
bytes calldata source,
|
|
568
|
+
uint i
|
|
569
|
+
) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
570
|
+
return listingFrom(source, i).unpackListing();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function unpackCustodyAt(bytes calldata source, uint i) internal pure returns (HostAmount memory value) {
|
|
574
|
+
return custodyFrom(source, i).toCustodyValue();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function unpackAllocationAt(bytes calldata source, uint i) internal pure returns (HostAmount memory value) {
|
|
578
|
+
return allocationFrom(source, i).toAllocationValue();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function unpackTxAt(bytes calldata source, uint i) internal pure returns (Tx memory value) {
|
|
582
|
+
return txFrom(source, i).toTxValue();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// ── unpack* ───────────────────────────────────────────────────────────────
|
|
586
|
+
|
|
587
|
+
function unpackRoute(Block memory ref) internal pure returns (bytes calldata data) {
|
|
588
|
+
ensure(ref, Keys.Route);
|
|
589
|
+
return msg.data[ref.i:ref.bound];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function unpackRouteUint(Block memory ref) internal pure returns (uint) {
|
|
593
|
+
ensure(ref, Keys.Route, 32);
|
|
594
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function unpackRoute2Uint(Block memory ref) internal pure returns (uint a, uint b) {
|
|
598
|
+
ensure(ref, Keys.Route, 96);
|
|
599
|
+
a = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
600
|
+
b = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function unpackRoute3Uint(Block memory ref) internal pure returns (uint a, uint b, uint c) {
|
|
604
|
+
ensure(ref, Keys.Route, 96);
|
|
605
|
+
a = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
606
|
+
b = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
607
|
+
c = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function unpackRoute32(Block memory ref) internal pure returns (bytes32) {
|
|
611
|
+
ensure(ref, Keys.Route, 32);
|
|
612
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function unpackRoute64(Block memory ref) internal pure returns (bytes32 a, bytes32 b) {
|
|
616
|
+
ensure(ref, Keys.Route, 64);
|
|
617
|
+
a = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
618
|
+
b = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function unpackRoute96(Block memory ref) internal pure returns (bytes32 a, bytes32 b, bytes32 c) {
|
|
622
|
+
ensure(ref, Keys.Route, 96);
|
|
623
|
+
a = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
624
|
+
b = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
625
|
+
c = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function unpackNode(Block memory ref) internal pure returns (uint id) {
|
|
629
|
+
ensure(ref, Keys.Node, 32);
|
|
630
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function unpackRecipient(Block memory ref) internal pure returns (bytes32 account) {
|
|
634
|
+
ensure(ref, Keys.Recipient, 32);
|
|
635
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function unpackParty(Block memory ref) internal pure returns (bytes32 account) {
|
|
639
|
+
ensure(ref, Keys.Party, 32);
|
|
640
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function unpackRate(Block memory ref) internal pure returns (uint value) {
|
|
644
|
+
ensure(ref, Keys.Rate, 32);
|
|
645
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function unpackQuantity(Block memory ref) internal pure returns (uint amount) {
|
|
649
|
+
ensure(ref, Keys.Quantity, 32);
|
|
650
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function unpackAsset(Block memory ref) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
654
|
+
ensure(ref, Keys.Asset, 64);
|
|
655
|
+
return (bytes32(msg.data[ref.i:ref.i + 32]), bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function unpackFunding(Block memory ref) internal pure returns (uint host, uint amount) {
|
|
659
|
+
ensure(ref, Keys.Funding, 64);
|
|
660
|
+
host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
661
|
+
amount = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function unpackBounty(Block memory ref) internal pure returns (uint amount, bytes32 relayer) {
|
|
665
|
+
ensure(ref, Keys.Bounty, 64);
|
|
666
|
+
amount = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
667
|
+
relayer = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function unpackAmount(Block memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
671
|
+
ensure(ref, Keys.Amount, 96);
|
|
672
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
673
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
674
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function unpackBalance(Block memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
678
|
+
ensure(ref, Keys.Balance, 96);
|
|
679
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
680
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
681
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function unpackMinimum(Block memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
685
|
+
ensure(ref, Keys.Minimum, 96);
|
|
686
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
687
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
688
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function unpackMaximum(Block memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
692
|
+
ensure(ref, Keys.Maximum, 96);
|
|
693
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
694
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
695
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function unpackListing(Block memory ref) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
699
|
+
ensure(ref, Keys.Listing, 96);
|
|
700
|
+
host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
701
|
+
asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
702
|
+
meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function unpackStep(Block memory ref) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
706
|
+
ensure(ref, Keys.Step, 64, 0);
|
|
707
|
+
target = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
708
|
+
value = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
709
|
+
req = msg.data[ref.i + 64:ref.bound];
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function unpackAuth(Block memory ref) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
713
|
+
ensure(ref, Keys.Auth, 149);
|
|
714
|
+
cid = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
715
|
+
deadline = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
716
|
+
proof = msg.data[ref.i + 64:ref.bound];
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// ── expect* ───────────────────────────────────────────────────────────────
|
|
720
|
+
|
|
721
|
+
function expectAmount(Block memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
722
|
+
ensure(ref, Keys.Amount, 96);
|
|
723
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
724
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
725
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function expectBalance(Block memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
729
|
+
ensure(ref, Keys.Balance, 96);
|
|
730
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
731
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
732
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function expectMinimum(Block memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
736
|
+
ensure(ref, Keys.Minimum, 96);
|
|
737
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
738
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
739
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function expectMaximum(Block memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
743
|
+
ensure(ref, Keys.Maximum, 96);
|
|
744
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
745
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
746
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function expectCustody(Block memory ref, uint host) internal pure returns (AssetAmount memory value) {
|
|
750
|
+
ensure(ref, Keys.Custody, 128);
|
|
751
|
+
if (uint(bytes32(msg.data[ref.i:ref.i + 32])) != host) revert UnexpectedHost();
|
|
752
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
753
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
754
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// ── to*Value ──────────────────────────────────────────────────────────────
|
|
758
|
+
|
|
759
|
+
function toAmountValue(Block memory ref) internal pure returns (AssetAmount memory value) {
|
|
760
|
+
ensure(ref, Keys.Amount, 96);
|
|
761
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
762
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
763
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function toBalanceValue(Block memory ref) internal pure returns (AssetAmount memory value) {
|
|
767
|
+
ensure(ref, Keys.Balance, 96);
|
|
768
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
769
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
770
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function toMinimumValue(Block memory ref) internal pure returns (AssetAmount memory value) {
|
|
774
|
+
ensure(ref, Keys.Minimum, 96);
|
|
775
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
776
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
777
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function toMaximumValue(Block memory ref) internal pure returns (AssetAmount memory value) {
|
|
781
|
+
ensure(ref, Keys.Maximum, 96);
|
|
782
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
783
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
784
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function toListingValue(Block memory ref) internal pure returns (HostAsset memory value) {
|
|
788
|
+
ensure(ref, Keys.Listing, 96);
|
|
789
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
790
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
791
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function toCustodyValue(Block memory ref) internal pure returns (HostAmount memory value) {
|
|
795
|
+
ensure(ref, Keys.Custody, 128);
|
|
796
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
797
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
798
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
799
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function toAllocationValue(Block memory ref) internal pure returns (HostAmount memory value) {
|
|
803
|
+
ensure(ref, Keys.Allocation, 128);
|
|
804
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
805
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
806
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
807
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function toTxValue(Block memory ref) internal pure returns (Tx memory value) {
|
|
811
|
+
ensure(ref, Keys.Transaction, 160);
|
|
812
|
+
value.from = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
813
|
+
value.to = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
814
|
+
value.asset = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
815
|
+
value.meta = bytes32(msg.data[ref.i + 96:ref.i + 128]);
|
|
816
|
+
value.amount = uint(bytes32(msg.data[ref.i + 128:ref.i + 160]));
|
|
817
|
+
}
|
|
818
|
+
}
|