@fastish/contracts 0.1.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 +134 -0
- package/contracts/Blocks.sol +73 -0
- package/contracts/Commands.sol +47 -0
- package/contracts/Core.sol +10 -0
- package/contracts/Events.sol +18 -0
- package/contracts/Schema.sol +57 -0
- package/contracts/Utils.sol +105 -0
- package/contracts/blocks/Data.sol +646 -0
- package/contracts/blocks/Errors.sol +10 -0
- package/contracts/blocks/Mem.sol +122 -0
- package/contracts/blocks/Readers.sol +938 -0
- package/contracts/blocks/Schema.sol +148 -0
- package/contracts/blocks/Writers.sol +187 -0
- package/contracts/combinators/AmountToBalance.sol +26 -0
- package/contracts/combinators/AmountToCustody.sol +37 -0
- package/contracts/combinators/CustodyToBalance.sol +27 -0
- package/contracts/combinators/EachRoute.sol +19 -0
- package/contracts/combinators/MapBalance.sol +26 -0
- package/contracts/combinators/MapCustody.sol +26 -0
- package/contracts/combinators/RouteToBalance.sol +27 -0
- package/contracts/commands/Base.sol +39 -0
- package/contracts/commands/Borrow.sol +86 -0
- package/contracts/commands/Burn.sol +32 -0
- package/contracts/commands/Create.sol +31 -0
- package/contracts/commands/CreditTo.sol +36 -0
- package/contracts/commands/DebitFrom.sol +44 -0
- package/contracts/commands/Deposit.sol +46 -0
- package/contracts/commands/Fund.sol +37 -0
- package/contracts/commands/Liquidate.sol +93 -0
- package/contracts/commands/Liquidity.sol +171 -0
- package/contracts/commands/Mint.sol +41 -0
- package/contracts/commands/Pipe.sol +54 -0
- package/contracts/commands/Provision.sol +48 -0
- package/contracts/commands/Reclaim.sol +46 -0
- package/contracts/commands/Redeem.sol +93 -0
- package/contracts/commands/Remove.sol +31 -0
- package/contracts/commands/Repay.sol +93 -0
- package/contracts/commands/Settle.sol +32 -0
- package/contracts/commands/Stake.sol +114 -0
- package/contracts/commands/Supply.sol +32 -0
- package/contracts/commands/Swap.sol +86 -0
- package/contracts/commands/Transfer.sol +41 -0
- package/contracts/commands/Unstake.sol +49 -0
- package/contracts/commands/Withdraw.sol +37 -0
- package/contracts/commands/admin/Allocate.sol +33 -0
- package/contracts/commands/admin/AllowAssets.sol +34 -0
- package/contracts/commands/admin/Authorize.sol +32 -0
- package/contracts/commands/admin/DenyAssets.sol +34 -0
- package/contracts/commands/admin/Destroy.sol +26 -0
- package/contracts/commands/admin/Init.sol +26 -0
- package/contracts/commands/admin/Relocate.sol +32 -0
- package/contracts/commands/admin/Unauthorize.sol +32 -0
- package/contracts/core/Access.sol +49 -0
- package/contracts/core/Balances.sol +9 -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/Fastish.sol +14 -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/Withdraw.sol +14 -0
- package/contracts/interfaces/IHostDiscovery.sol +6 -0
- package/contracts/peer/AllowAssets.sol +31 -0
- package/contracts/peer/Base.sol +19 -0
- package/contracts/peer/DenyAssets.sol +31 -0
- package/contracts/peer/Pull.sol +30 -0
- package/contracts/peer/Push.sol +30 -0
- package/contracts/test/TestBlockHelper.sol +256 -0
- package/contracts/test/TestBorrowHost.sol +46 -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 +215 -0
- package/contracts/test/TestLiquidityHost.sol +149 -0
- package/contracts/test/TestMintHost.sol +40 -0
- package/contracts/test/TestPeerHost.sol +34 -0
- package/contracts/test/TestReclaimHost.sol +47 -0
- package/contracts/test/TestRejectEther.sol +8 -0
- package/contracts/test/TestRemoveHost.sol +26 -0
- package/contracts/test/TestSwapHost.sol +45 -0
- package/contracts/test/TestUtils.sol +180 -0
- package/contracts/test/TestValidator.sol +10 -0
- package/contracts/utils/Accounts.sol +42 -0
- package/contracts/utils/Assets.sol +71 -0
- package/contracts/utils/Channels.sol +9 -0
- package/contracts/utils/ECDSA.sol +36 -0
- package/contracts/utils/Ids.sol +75 -0
- package/contracts/utils/Layout.sol +20 -0
- package/contracts/utils/Strings.sol +16 -0
- package/contracts/utils/Utils.sol +117 -0
- package/contracts/utils/Value.sol +18 -0
- package/package.json +29 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {ALLOCATION_KEY, AMOUNT_KEY, ASSET_KEY, AUTH_KEY, BALANCE_KEY, BOUNTY_KEY, CUSTODY_KEY, DataPairRef, DataRef, FUNDING_KEY, Listing, LISTING_KEY, MAXIMUM_KEY, MINIMUM_KEY, NODE_KEY, PARTY_KEY, QUANTITY_KEY, RATE_KEY, RECIPIENT_KEY, ROUTE_KEY, STEP_KEY, TX_KEY, AssetAmount, HostAmount, Tx} from "./Schema.sol";
|
|
5
|
+
import {InvalidBlock, MalformedBlocks, UnexpectedAsset, UnexpectedHost, UnexpectedMeta} from "./Errors.sol";
|
|
6
|
+
|
|
7
|
+
using Data for DataRef;
|
|
8
|
+
|
|
9
|
+
library Data {
|
|
10
|
+
// ── infrastructure ────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
function at(uint i) internal pure returns (DataRef memory ref) {
|
|
13
|
+
uint eod = msg.data.length;
|
|
14
|
+
if (i == eod) return DataRef(bytes4(0), 0, 0, i);
|
|
15
|
+
if (i > eod) revert MalformedBlocks();
|
|
16
|
+
|
|
17
|
+
unchecked {
|
|
18
|
+
ref.i = i + 12;
|
|
19
|
+
}
|
|
20
|
+
if (ref.i > eod) revert MalformedBlocks();
|
|
21
|
+
ref.key = bytes4(msg.data[i:i + 4]);
|
|
22
|
+
ref.bound = ref.i + uint32(bytes4(msg.data[i + 4:i + 8]));
|
|
23
|
+
ref.end = ref.i + uint32(bytes4(msg.data[i + 8:ref.i]));
|
|
24
|
+
|
|
25
|
+
if (ref.bound > ref.end || ref.end > eod) revert MalformedBlocks();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function from(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
29
|
+
uint base;
|
|
30
|
+
uint eod = source.length;
|
|
31
|
+
assembly ("memory-safe") {
|
|
32
|
+
base := source.offset
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (i == eod) return (DataRef(bytes4(0), 0, 0, base + i), i);
|
|
36
|
+
if (i > eod) revert MalformedBlocks();
|
|
37
|
+
|
|
38
|
+
uint start;
|
|
39
|
+
unchecked {
|
|
40
|
+
start = i + 12;
|
|
41
|
+
}
|
|
42
|
+
if (start > eod) revert MalformedBlocks();
|
|
43
|
+
|
|
44
|
+
ref.key = bytes4(source[i:i + 4]);
|
|
45
|
+
ref.i = base + start;
|
|
46
|
+
ref.bound = ref.i + uint32(bytes4(source[i + 4:i + 8]));
|
|
47
|
+
ref.end = ref.i + uint32(bytes4(source[i + 8:start]));
|
|
48
|
+
|
|
49
|
+
uint eos = base + eod;
|
|
50
|
+
if (ref.bound > ref.end || ref.end > eos) revert MalformedBlocks();
|
|
51
|
+
next = i + (ref.end - ref.i) + 12;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function twoFrom(bytes calldata source, uint i) internal pure returns (DataPairRef memory ref, uint next) {
|
|
55
|
+
(ref.a, i) = from(source, i);
|
|
56
|
+
(ref.b, next) = from(source, i);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function childAt(DataRef memory parent, uint i) internal pure returns (DataRef memory ref) {
|
|
60
|
+
if (i < parent.bound || i >= parent.end) revert MalformedBlocks();
|
|
61
|
+
ref = at(i);
|
|
62
|
+
if (ref.end > parent.end) revert MalformedBlocks();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function findFrom(
|
|
66
|
+
bytes calldata source,
|
|
67
|
+
uint i,
|
|
68
|
+
uint limit,
|
|
69
|
+
bytes4 key
|
|
70
|
+
) internal pure returns (DataRef memory ref) {
|
|
71
|
+
if (limit > source.length) revert MalformedBlocks();
|
|
72
|
+
while (i < limit) {
|
|
73
|
+
uint next;
|
|
74
|
+
(ref, next) = from(source, i);
|
|
75
|
+
if (next > limit) revert MalformedBlocks();
|
|
76
|
+
if (ref.key == key) return ref;
|
|
77
|
+
i = next;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return DataRef(bytes4(0), limit, limit, limit);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function findChild(DataRef memory parent, bytes4 key) internal pure returns (DataRef memory ref) {
|
|
84
|
+
return findFrom(msg.data, parent.bound, parent.end, key);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ensure(DataRef memory ref, bytes4 key) internal pure {
|
|
88
|
+
if (key == 0 || key != ref.key) revert InvalidBlock();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ensure(DataRef memory ref, bytes4 key, uint len) internal pure {
|
|
92
|
+
if (key == 0 || key != ref.key || len != (ref.bound - ref.i)) revert InvalidBlock();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function ensure(DataRef memory ref, bytes4 key, uint min, uint max) internal pure {
|
|
96
|
+
uint len = ref.bound - ref.i;
|
|
97
|
+
if (key == 0 || key != ref.key || len < min || (max != 0 && len > max)) revert InvalidBlock();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function ensure(DataPairRef memory ref, bytes4 key, uint len) internal pure {
|
|
101
|
+
ensure(ref.a, key, len);
|
|
102
|
+
ensure(ref.b, key, len);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function ensure(DataPairRef memory ref, bytes4 key, uint min, uint max) internal pure {
|
|
106
|
+
ensure(ref.a, key, min, max);
|
|
107
|
+
ensure(ref.b, key, min, max);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ── *From ─────────────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
function routeFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
113
|
+
(ref, next) = from(source, i);
|
|
114
|
+
ensure(ref, ROUTE_KEY);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function nodeFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
118
|
+
(ref, next) = from(source, i);
|
|
119
|
+
ensure(ref, NODE_KEY, 32);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function recipientFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
123
|
+
(ref, next) = from(source, i);
|
|
124
|
+
ensure(ref, RECIPIENT_KEY, 32);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function partyFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
128
|
+
(ref, next) = from(source, i);
|
|
129
|
+
ensure(ref, PARTY_KEY, 32);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function rateFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
133
|
+
(ref, next) = from(source, i);
|
|
134
|
+
ensure(ref, RATE_KEY, 32);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function quantityFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
138
|
+
(ref, next) = from(source, i);
|
|
139
|
+
ensure(ref, QUANTITY_KEY, 32);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function assetFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
143
|
+
(ref, next) = from(source, i);
|
|
144
|
+
ensure(ref, ASSET_KEY, 64);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function fundingFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
148
|
+
(ref, next) = from(source, i);
|
|
149
|
+
ensure(ref, FUNDING_KEY, 64);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function bountyFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
153
|
+
(ref, next) = from(source, i);
|
|
154
|
+
ensure(ref, BOUNTY_KEY, 64);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function amountFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
158
|
+
(ref, next) = from(source, i);
|
|
159
|
+
ensure(ref, AMOUNT_KEY, 96);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function amountTwoFrom(bytes calldata source, uint i) internal pure returns (DataPairRef memory ref, uint next) {
|
|
163
|
+
(ref, next) = twoFrom(source, i);
|
|
164
|
+
ensure(ref, AMOUNT_KEY, 96);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function balanceFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
168
|
+
(ref, next) = from(source, i);
|
|
169
|
+
ensure(ref, BALANCE_KEY, 96);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function balanceTwoFrom(bytes calldata source, uint i) internal pure returns (DataPairRef memory ref, uint next) {
|
|
173
|
+
(ref, next) = twoFrom(source, i);
|
|
174
|
+
ensure(ref, BALANCE_KEY, 96);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function minimumFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
178
|
+
(ref, next) = from(source, i);
|
|
179
|
+
ensure(ref, MINIMUM_KEY, 96);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function maximumFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
183
|
+
(ref, next) = from(source, i);
|
|
184
|
+
ensure(ref, MAXIMUM_KEY, 96);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function listingFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
188
|
+
(ref, next) = from(source, i);
|
|
189
|
+
ensure(ref, LISTING_KEY, 96);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function stepFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
193
|
+
(ref, next) = from(source, i);
|
|
194
|
+
ensure(ref, STEP_KEY, 64, 0);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function authFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
198
|
+
(ref, next) = from(source, i);
|
|
199
|
+
ensure(ref, AUTH_KEY, 149, 0);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function custodyFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
203
|
+
(ref, next) = from(source, i);
|
|
204
|
+
ensure(ref, CUSTODY_KEY, 128);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function custodyTwoFrom(bytes calldata source, uint i) internal pure returns (DataPairRef memory ref, uint next) {
|
|
208
|
+
(ref, next) = twoFrom(source, i);
|
|
209
|
+
ensure(ref, CUSTODY_KEY, 128);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function allocationFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
213
|
+
(ref, next) = from(source, i);
|
|
214
|
+
ensure(ref, ALLOCATION_KEY, 128);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function txFrom(bytes calldata source, uint i) internal pure returns (DataRef memory ref, uint next) {
|
|
218
|
+
(ref, next) = from(source, i);
|
|
219
|
+
ensure(ref, TX_KEY, 160);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ── inner* ────────────────────────────────────────────────────────────────
|
|
223
|
+
|
|
224
|
+
function innerPair(DataRef memory parent) internal pure returns (DataPairRef memory ref) {
|
|
225
|
+
ref.a = childAt(parent, parent.bound);
|
|
226
|
+
ref.b = childAt(parent, ref.a.end);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function innerRoute(DataRef memory parent) internal pure returns (bytes calldata data) {
|
|
230
|
+
return unpackRoute(childAt(parent, parent.bound));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function innerNode(DataRef memory parent) internal pure returns (uint id) {
|
|
234
|
+
return unpackNode(childAt(parent, parent.bound));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function innerRecipient(DataRef memory parent) internal pure returns (bytes32 account) {
|
|
238
|
+
return unpackRecipient(childAt(parent, parent.bound));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function innerParty(DataRef memory parent) internal pure returns (bytes32 account) {
|
|
242
|
+
return unpackParty(childAt(parent, parent.bound));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function innerRate(DataRef memory parent) internal pure returns (uint value) {
|
|
246
|
+
return unpackRate(childAt(parent, parent.bound));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function innerQuantity(DataRef memory parent) internal pure returns (uint amount) {
|
|
250
|
+
return unpackQuantity(childAt(parent, parent.bound));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function innerAsset(DataRef memory parent) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
254
|
+
return unpackAsset(childAt(parent, parent.bound));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function innerFunding(DataRef memory parent) internal pure returns (uint host, uint amount) {
|
|
258
|
+
return unpackFunding(childAt(parent, parent.bound));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function innerBounty(DataRef memory parent) internal pure returns (uint amount, bytes32 relayer) {
|
|
262
|
+
return unpackBounty(childAt(parent, parent.bound));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function innerAmount(DataRef memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
266
|
+
return unpackAmount(childAt(parent, parent.bound));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function innerAmountValue(DataRef memory parent) internal pure returns (AssetAmount memory) {
|
|
270
|
+
return toAmountValue(childAt(parent, parent.bound));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function innerBalance(DataRef memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
274
|
+
return unpackBalance(childAt(parent, parent.bound));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function innerMinimum(DataRef memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
278
|
+
return unpackMinimum(childAt(parent, parent.bound));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function innerMaximum(DataRef memory parent) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
282
|
+
return unpackMaximum(childAt(parent, parent.bound));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function innerListing(DataRef memory parent) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
286
|
+
return unpackListing(childAt(parent, parent.bound));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function innerStep(DataRef memory parent) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
290
|
+
return unpackStep(childAt(parent, parent.bound));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function innerAuth(DataRef memory parent) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
294
|
+
return unpackAuth(childAt(parent, parent.bound));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function innerCustody(DataRef memory parent) internal pure returns (HostAmount memory value) {
|
|
298
|
+
return toCustodyValue(childAt(parent, parent.bound));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function innerAllocation(DataRef memory parent) internal pure returns (HostAmount memory value) {
|
|
302
|
+
return toAllocationValue(childAt(parent, parent.bound));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function innerTx(DataRef memory parent) internal pure returns (Tx memory value) {
|
|
306
|
+
return toTxValue(childAt(parent, parent.bound));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ── inner*At ──────────────────────────────────────────────────────────────
|
|
310
|
+
|
|
311
|
+
function innerPairAt(DataRef memory parent, uint i) internal pure returns (DataPairRef memory ref) {
|
|
312
|
+
ref.a = childAt(parent, i);
|
|
313
|
+
ref.b = childAt(parent, ref.a.end);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function innerRouteAt(DataRef memory parent, uint i) internal pure returns (bytes calldata data) {
|
|
317
|
+
return unpackRoute(childAt(parent, i));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function innerNodeAt(DataRef memory parent, uint i) internal pure returns (uint id) {
|
|
321
|
+
return unpackNode(childAt(parent, i));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function innerRecipientAt(DataRef memory parent, uint i) internal pure returns (bytes32 account) {
|
|
325
|
+
return unpackRecipient(childAt(parent, i));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function innerPartyAt(DataRef memory parent, uint i) internal pure returns (bytes32 account) {
|
|
329
|
+
return unpackParty(childAt(parent, i));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function innerRateAt(DataRef memory parent, uint i) internal pure returns (uint value) {
|
|
333
|
+
return unpackRate(childAt(parent, i));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function innerQuantityAt(DataRef memory parent, uint i) internal pure returns (uint amount) {
|
|
337
|
+
return unpackQuantity(childAt(parent, i));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function innerAssetAt(DataRef memory parent, uint i) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
341
|
+
return unpackAsset(childAt(parent, i));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function innerFundingAt(DataRef memory parent, uint i) internal pure returns (uint host, uint amount) {
|
|
345
|
+
return unpackFunding(childAt(parent, i));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function innerBountyAt(DataRef memory parent, uint i) internal pure returns (uint amount, bytes32 relayer) {
|
|
349
|
+
return unpackBounty(childAt(parent, i));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function innerAmountAt(
|
|
353
|
+
DataRef memory parent,
|
|
354
|
+
uint i
|
|
355
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
356
|
+
return unpackAmount(childAt(parent, i));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function innerBalanceAt(
|
|
360
|
+
DataRef memory parent,
|
|
361
|
+
uint i
|
|
362
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
363
|
+
return unpackBalance(childAt(parent, i));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function innerMinimumAt(
|
|
367
|
+
DataRef memory parent,
|
|
368
|
+
uint i
|
|
369
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
370
|
+
return unpackMinimum(childAt(parent, i));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function innerMaximumAt(
|
|
374
|
+
DataRef memory parent,
|
|
375
|
+
uint i
|
|
376
|
+
) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
377
|
+
return unpackMaximum(childAt(parent, i));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function innerListingAt(
|
|
381
|
+
DataRef memory parent,
|
|
382
|
+
uint i
|
|
383
|
+
) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
384
|
+
return unpackListing(childAt(parent, i));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function innerStepAt(
|
|
388
|
+
DataRef memory parent,
|
|
389
|
+
uint i
|
|
390
|
+
) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
391
|
+
return unpackStep(childAt(parent, i));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function innerAuthAt(
|
|
395
|
+
DataRef memory parent,
|
|
396
|
+
uint i
|
|
397
|
+
) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
398
|
+
return unpackAuth(childAt(parent, i));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function innerCustodyAt(DataRef memory parent, uint i) internal pure returns (HostAmount memory value) {
|
|
402
|
+
return toCustodyValue(childAt(parent, i));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function innerAllocationAt(DataRef memory parent, uint i) internal pure returns (HostAmount memory value) {
|
|
406
|
+
return toAllocationValue(childAt(parent, i));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function innerTxAt(DataRef memory parent, uint i) internal pure returns (Tx memory value) {
|
|
410
|
+
return toTxValue(childAt(parent, i));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// ── unpack* ───────────────────────────────────────────────────────────────
|
|
414
|
+
|
|
415
|
+
function unpackRoute(DataRef memory ref) internal pure returns (bytes calldata data) {
|
|
416
|
+
ensure(ref, ROUTE_KEY);
|
|
417
|
+
return msg.data[ref.i:ref.bound];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function unpackRouteUint(DataRef memory ref) internal pure returns (uint) {
|
|
421
|
+
ensure(ref, ROUTE_KEY, 32);
|
|
422
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function unpackRoute2Uint(DataRef memory ref) internal pure returns (uint a, uint b) {
|
|
426
|
+
ensure(ref, ROUTE_KEY, 96);
|
|
427
|
+
a = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
428
|
+
b = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function unpackRoute3Uint(DataRef memory ref) internal pure returns (uint a, uint b, uint c) {
|
|
432
|
+
ensure(ref, ROUTE_KEY, 96);
|
|
433
|
+
a = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
434
|
+
b = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
435
|
+
c = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function unpackRoute32(DataRef memory ref) internal pure returns (bytes32) {
|
|
439
|
+
ensure(ref, ROUTE_KEY, 32);
|
|
440
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function unpackRoute64(DataRef memory ref) internal pure returns (bytes32 a, bytes32 b) {
|
|
444
|
+
ensure(ref, ROUTE_KEY, 64);
|
|
445
|
+
a = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
446
|
+
b = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function unpackRoute96(DataRef memory ref) internal pure returns (bytes32 a, bytes32 b, bytes32 c) {
|
|
450
|
+
ensure(ref, ROUTE_KEY, 96);
|
|
451
|
+
a = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
452
|
+
b = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
453
|
+
c = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function unpackNode(DataRef memory ref) internal pure returns (uint id) {
|
|
457
|
+
ensure(ref, NODE_KEY, 32);
|
|
458
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function unpackRecipient(DataRef memory ref) internal pure returns (bytes32 account) {
|
|
462
|
+
ensure(ref, RECIPIENT_KEY, 32);
|
|
463
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function unpackParty(DataRef memory ref) internal pure returns (bytes32 account) {
|
|
467
|
+
ensure(ref, PARTY_KEY, 32);
|
|
468
|
+
return bytes32(msg.data[ref.i:ref.i + 32]);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function unpackRate(DataRef memory ref) internal pure returns (uint value) {
|
|
472
|
+
ensure(ref, RATE_KEY, 32);
|
|
473
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function unpackQuantity(DataRef memory ref) internal pure returns (uint amount) {
|
|
477
|
+
ensure(ref, QUANTITY_KEY, 32);
|
|
478
|
+
return uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function unpackAsset(DataRef memory ref) internal pure returns (bytes32 asset, bytes32 meta) {
|
|
482
|
+
ensure(ref, ASSET_KEY, 64);
|
|
483
|
+
return (bytes32(msg.data[ref.i:ref.i + 32]), bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function unpackFunding(DataRef memory ref) internal pure returns (uint host, uint amount) {
|
|
487
|
+
ensure(ref, FUNDING_KEY, 64);
|
|
488
|
+
host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
489
|
+
amount = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function unpackBounty(DataRef memory ref) internal pure returns (uint amount, bytes32 relayer) {
|
|
493
|
+
ensure(ref, BOUNTY_KEY, 64);
|
|
494
|
+
amount = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
495
|
+
relayer = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function unpackAmount(DataRef memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
499
|
+
ensure(ref, AMOUNT_KEY, 96);
|
|
500
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
501
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
502
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function unpackBalance(DataRef memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
506
|
+
ensure(ref, BALANCE_KEY, 96);
|
|
507
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
508
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
509
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function unpackMinimum(DataRef memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
513
|
+
ensure(ref, MINIMUM_KEY, 96);
|
|
514
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
515
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
516
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function unpackMaximum(DataRef memory ref) internal pure returns (bytes32 asset, bytes32 meta, uint amount) {
|
|
520
|
+
ensure(ref, MAXIMUM_KEY, 96);
|
|
521
|
+
asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
522
|
+
meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
523
|
+
amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function unpackListing(DataRef memory ref) internal pure returns (uint host, bytes32 asset, bytes32 meta) {
|
|
527
|
+
ensure(ref, LISTING_KEY, 96);
|
|
528
|
+
host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
529
|
+
asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
530
|
+
meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function unpackStep(DataRef memory ref) internal pure returns (uint target, uint value, bytes calldata req) {
|
|
534
|
+
ensure(ref, STEP_KEY, 64, 0);
|
|
535
|
+
target = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
536
|
+
value = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
537
|
+
req = msg.data[ref.i + 64:ref.bound];
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function unpackAuth(DataRef memory ref) internal pure returns (uint cid, uint deadline, bytes calldata proof) {
|
|
541
|
+
ensure(ref, AUTH_KEY, 149);
|
|
542
|
+
cid = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
543
|
+
deadline = uint(bytes32(msg.data[ref.i + 32:ref.i + 64]));
|
|
544
|
+
proof = msg.data[ref.i + 64:ref.bound];
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ── expect* ───────────────────────────────────────────────────────────────
|
|
548
|
+
|
|
549
|
+
function expectAmount(DataRef memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
550
|
+
ensure(ref, AMOUNT_KEY, 96);
|
|
551
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
552
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
553
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function expectBalance(DataRef memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
557
|
+
ensure(ref, BALANCE_KEY, 96);
|
|
558
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
559
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
560
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function expectMinimum(DataRef memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
564
|
+
ensure(ref, MINIMUM_KEY, 96);
|
|
565
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
566
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
567
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function expectMaximum(DataRef memory ref, bytes32 asset, bytes32 meta) internal pure returns (uint amount) {
|
|
571
|
+
ensure(ref, MAXIMUM_KEY, 96);
|
|
572
|
+
if (bytes32(msg.data[ref.i:ref.i + 32]) != asset) revert UnexpectedAsset();
|
|
573
|
+
if (bytes32(msg.data[ref.i + 32:ref.i + 64]) != meta) revert UnexpectedMeta();
|
|
574
|
+
return uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function expectCustody(DataRef memory ref, uint host) internal pure returns (AssetAmount memory value) {
|
|
578
|
+
ensure(ref, CUSTODY_KEY, 128);
|
|
579
|
+
if (uint(bytes32(msg.data[ref.i:ref.i + 32])) != host) revert UnexpectedHost();
|
|
580
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
581
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
582
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// ── to*Value ──────────────────────────────────────────────────────────────
|
|
586
|
+
|
|
587
|
+
function toAmountValue(DataRef memory ref) internal pure returns (AssetAmount memory value) {
|
|
588
|
+
ensure(ref, AMOUNT_KEY, 96);
|
|
589
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
590
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
591
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function toBalanceValue(DataRef memory ref) internal pure returns (AssetAmount memory value) {
|
|
595
|
+
ensure(ref, BALANCE_KEY, 96);
|
|
596
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
597
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
598
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function toMinimumValue(DataRef memory ref) internal pure returns (AssetAmount memory value) {
|
|
602
|
+
ensure(ref, MINIMUM_KEY, 96);
|
|
603
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
604
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
605
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function toMaximumValue(DataRef memory ref) internal pure returns (AssetAmount memory value) {
|
|
609
|
+
ensure(ref, MAXIMUM_KEY, 96);
|
|
610
|
+
value.asset = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
611
|
+
value.meta = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
612
|
+
value.amount = uint(bytes32(msg.data[ref.i + 64:ref.i + 96]));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function toListingValue(DataRef memory ref) internal pure returns (Listing memory value) {
|
|
616
|
+
ensure(ref, LISTING_KEY, 96);
|
|
617
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
618
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
619
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function toCustodyValue(DataRef memory ref) internal pure returns (HostAmount memory value) {
|
|
623
|
+
ensure(ref, CUSTODY_KEY, 128);
|
|
624
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
625
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
626
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
627
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function toAllocationValue(DataRef memory ref) internal pure returns (HostAmount memory value) {
|
|
631
|
+
ensure(ref, ALLOCATION_KEY, 128);
|
|
632
|
+
value.host = uint(bytes32(msg.data[ref.i:ref.i + 32]));
|
|
633
|
+
value.asset = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
634
|
+
value.meta = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
635
|
+
value.amount = uint(bytes32(msg.data[ref.i + 96:ref.i + 128]));
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function toTxValue(DataRef memory ref) internal pure returns (Tx memory value) {
|
|
639
|
+
ensure(ref, TX_KEY, 160);
|
|
640
|
+
value.from = bytes32(msg.data[ref.i:ref.i + 32]);
|
|
641
|
+
value.to = bytes32(msg.data[ref.i + 32:ref.i + 64]);
|
|
642
|
+
value.asset = bytes32(msg.data[ref.i + 64:ref.i + 96]);
|
|
643
|
+
value.meta = bytes32(msg.data[ref.i + 96:ref.i + 128]);
|
|
644
|
+
value.amount = uint(bytes32(msg.data[ref.i + 128:ref.i + 160]));
|
|
645
|
+
}
|
|
646
|
+
}
|