@lifi/compose-spec 0.8.1 → 0.10.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/dist/index.js CHANGED
@@ -1,1019 +1,956 @@
1
- // src/flowSchema.ts
2
- import { Schema } from "effect";
3
-
4
- // src/chainCapabilities.ts
5
- var EVM_NATIVE_SENTINEL = (
6
- // eslint-disable-next-line @lifi/prefer-utils-constants -- compose-spec is the wire-format leaf and must not import @lifi/utils (enforced by scripts/check-compose-boundaries.mjs); the literal is intentional here
7
- "0x0000000000000000000000000000000000000000"
8
- );
9
- var isNativeSentinel = (address) => address.toLowerCase() === EVM_NATIVE_SENTINEL.toLowerCase();
10
- var TEMPO_CHAIN_ID = 4217;
11
- var TEMPO_NATIVE_ERC20 = {
12
- token: "0x20C0000000000000000000000000000000000000",
13
- symbol: "pathUSD",
14
- decimals: 6
1
+ import { ParseResult, Schema } from "effect";
2
+ import z from "zod";
3
+ //#region src/chainCapabilities.ts
4
+ /**
5
+ * The zero-address sentinel that represents the native gas coin on
6
+ * EVM-native chains. Exported so tests and call-sites can reference it
7
+ * by name rather than inlining 40 zeros.
8
+ *
9
+ * Inlined as a literal rather than imported from `@lifi/utils`: `compose-spec`
10
+ * is the wire-format leaf package and carries no `@lifi/*` dependencies
11
+ * (enforced by `scripts/check-compose-boundaries.mjs`).
12
+ */
13
+ const EVM_NATIVE_SENTINEL = "0x0000000000000000000000000000000000000000";
14
+ /**
15
+ * Whether `address` is the EVM-native zero-address sentinel, compared
16
+ * case-insensitively. Module-local: the two call-sites below share this exact
17
+ * comparison; it is not part of the package's public surface.
18
+ */
19
+ const isNativeSentinel = (address) => address.toLowerCase() === EVM_NATIVE_SENTINEL.toLowerCase();
20
+ const TEMPO_CHAIN_ID = 4217;
21
+ const TEMPO_NATIVE_ERC20 = {
22
+ token: "0x20C0000000000000000000000000000000000000",
23
+ symbol: "pathUSD",
24
+ decimals: 6
15
25
  };
16
- var ARC_CHAIN_ID = 5042;
17
- var ARC_NATIVE_ERC20 = {
18
- token: "0x3600000000000000000000000000000000000000",
19
- symbol: "USDC",
20
- decimals: 6
26
+ const ARC_CHAIN_ID = 5042;
27
+ /**
28
+ * Arc's native gas coin is USDC (18-decimal wei at the EVM level). The USDC
29
+ * ERC-20 at this address is a view over native balances: `balanceOf` returns
30
+ * `native wei / 1e12` and has no balance storage slot; allowances live in
31
+ * regular storage. The composer interacts with USDC exclusively through this
32
+ * facade, never via `msg.value`.
33
+ */
34
+ const ARC_NATIVE_ERC20 = {
35
+ token: "0x3600000000000000000000000000000000000000",
36
+ symbol: "USDC",
37
+ decimals: 6
21
38
  };
22
- var ARC_NATIVE_SCALE = 10n ** BigInt(18 - ARC_NATIVE_ERC20.decimals);
23
- var REGISTRY = /* @__PURE__ */ new Map([
24
- [
25
- TEMPO_CHAIN_ID,
26
- {
27
- kind: "as-erc20",
28
- chainId: TEMPO_CHAIN_ID,
29
- nativeErc20: TEMPO_NATIVE_ERC20
30
- }
31
- ],
32
- [
33
- ARC_CHAIN_ID,
34
- {
35
- kind: "native-mirrored-erc20",
36
- chainId: ARC_CHAIN_ID,
37
- nativeErc20: ARC_NATIVE_ERC20,
38
- nativeScale: ARC_NATIVE_SCALE
39
- }
40
- ]
41
- ]);
42
- var getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? { kind: "evm-native", chainId };
43
- var foldChainCapabilities = (caps, cases) => {
44
- switch (caps.kind) {
45
- case "evm-native":
46
- return cases.evmNative(caps.chainId);
47
- case "as-erc20":
48
- return cases.asErc20(caps.nativeErc20, caps.chainId);
49
- case "native-mirrored-erc20":
50
- return cases.nativeMirroredErc20(
51
- caps.nativeErc20,
52
- caps.nativeScale,
53
- caps.chainId
54
- );
55
- }
39
+ const ARC_NATIVE_SCALE = 10n ** BigInt(18 - ARC_NATIVE_ERC20.decimals);
40
+ const REGISTRY = /* @__PURE__ */ new Map([[TEMPO_CHAIN_ID, {
41
+ kind: "as-erc20",
42
+ chainId: TEMPO_CHAIN_ID,
43
+ nativeErc20: TEMPO_NATIVE_ERC20
44
+ }], [ARC_CHAIN_ID, {
45
+ kind: "native-mirrored-erc20",
46
+ chainId: ARC_CHAIN_ID,
47
+ nativeErc20: ARC_NATIVE_ERC20,
48
+ nativeScale: ARC_NATIVE_SCALE
49
+ }]]);
50
+ const getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? {
51
+ kind: "evm-native",
52
+ chainId
56
53
  };
57
- var nativeCheckPolicy = (chainId) => foldChainCapabilities(getChainCapabilities(chainId), {
58
- evmNative: () => ({ kind: "keep" }),
59
- asErc20: (nativeErc20) => ({ kind: "rewrite", token: nativeErc20.token }),
60
- nativeMirroredErc20: (nativeErc20) => ({
61
- kind: "reject",
62
- reason: `nativeBalanceGte is not accepted on chain ${chainId}: its canonical native asset is an ERC-20 facade whose units differ from native wei \u2014 author the check as erc20BalanceGte of ${nativeErc20.token}`
63
- })
64
- });
65
- var isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
66
- var erc20CanonicalNative = (caps) => caps.kind === "as-erc20" || caps.kind === "native-mirrored-erc20" ? caps.nativeErc20 : void 0;
67
- var hasErc20CanonicalNative = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId)) !== void 0;
68
- var canonicalNativeAddress = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId))?.token ?? EVM_NATIVE_SENTINEL;
69
- var isNativeAddressForChain = (chainId, address) => {
70
- const target = canonicalNativeAddress(chainId);
71
- return address.toLowerCase() === target.toLowerCase();
54
+ /**
55
+ * Structural fold over the `ChainCapabilities` union — the capabilities
56
+ * counterpart of `foldResource`/`foldRef`. Dispatches on `kind` and hands each
57
+ * case its narrowed fields, so consumers that must branch on the native-asset
58
+ * policy (e.g. compose-core's `rewritePreconditions`) do so through one
59
+ * combinator whose exhaustiveness the compiler enforces: adding a new arm to
60
+ * the union above turns every `foldChainCapabilities` call into a type error
61
+ * until it handles the new case.
62
+ */
63
+ const foldChainCapabilities = (caps, cases) => {
64
+ switch (caps.kind) {
65
+ case "evm-native": return cases.evmNative(caps.chainId);
66
+ case "as-erc20": return cases.asErc20(caps.nativeErc20, caps.chainId);
67
+ case "native-mirrored-erc20": return cases.nativeMirroredErc20(caps.nativeErc20, caps.nativeScale, caps.chainId);
68
+ }
72
69
  };
73
- var isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isNativeSentinel(address);
74
- var normalizeResource = (r) => {
75
- if (r.kind !== "native") return r;
76
- const erc202 = erc20CanonicalNative(getChainCapabilities(r.chainId));
77
- if (erc202 === void 0) return r;
78
- return {
79
- kind: "erc20",
80
- chainId: r.chainId,
81
- token: erc202.token
82
- };
70
+ const nativeCheckPolicy = (chainId) => foldChainCapabilities(getChainCapabilities(chainId), {
71
+ evmNative: () => ({ kind: "keep" }),
72
+ asErc20: (nativeErc20) => ({
73
+ kind: "rewrite",
74
+ token: nativeErc20.token
75
+ }),
76
+ nativeMirroredErc20: (nativeErc20) => ({
77
+ kind: "reject",
78
+ reason: `nativeBalanceGte is not accepted on chain ${chainId}: its canonical native asset is an ERC-20 facade whose units differ from native wei — author the check as erc20BalanceGte of ${nativeErc20.token}`
79
+ })
80
+ });
81
+ /**
82
+ * Exact-kind check for `as-erc20` (currently Tempo only) — the rare case that
83
+ * genuinely means "no `msg.value` coin exists on this chain". Most consumers
84
+ * want `hasErc20CanonicalNative` instead, which also covers
85
+ * `native-mirrored-erc20` chains (Arc), where the composer's ERC-20-only
86
+ * policy applies even though `msg.value` works. Code that must treat the two
87
+ * ERC-20-native kinds differently goes through `foldChainCapabilities` or
88
+ * `nativeCheckPolicy`, never a second exact-kind predicate.
89
+ */
90
+ const isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
91
+ /**
92
+ * The chain's stand-in native ERC-20 when its canonical native asset is an
93
+ * ERC-20 (`as-erc20` and `native-mirrored-erc20`), `undefined` on plain
94
+ * `evm-native` chains. Module-local narrowing helper behind the exported
95
+ * predicates and rewrites below.
96
+ */
97
+ const erc20CanonicalNative = (caps) => caps.kind === "as-erc20" || caps.kind === "native-mirrored-erc20" ? caps.nativeErc20 : void 0;
98
+ /**
99
+ * Whether the chain's canonical native asset is an ERC-20 — true for both
100
+ * `as-erc20` chains (Tempo: no `msg.value` coin exists) and
101
+ * `native-mirrored-erc20` chains (Arc: `msg.value` exists but is never used).
102
+ * This is the predicate for the shared resource-level behaviour: native
103
+ * resources are rewritten to the ERC-20, native routing edges are dropped, and
104
+ * a surviving native resource is a compile error.
105
+ */
106
+ const hasErc20CanonicalNative = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId)) !== void 0;
107
+ /**
108
+ * The address that represents the chain's native asset.
109
+ *
110
+ * On EVM-native chains this is the zero-address sentinel `0x0…0`. On chains
111
+ * whose canonical native asset is an ERC-20 it is the chain's stand-in token
112
+ * (PathUSD on Tempo, the USDC facade on Arc).
113
+ */
114
+ const canonicalNativeAddress = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId))?.token ?? "0x0000000000000000000000000000000000000000";
115
+ /**
116
+ * Whether `address` represents the native asset of `chainId`.
117
+ *
118
+ * On EVM-native chains, this is the case-insensitive zero-address check. On
119
+ * chains whose canonical native asset is an ERC-20, the literal zero address
120
+ * returns `false` — only the chain's stand-in ERC-20 address matches.
121
+ */
122
+ const isNativeAddressForChain = (chainId, address) => {
123
+ const target = canonicalNativeAddress(chainId);
124
+ return address.toLowerCase() === target.toLowerCase();
83
125
  };
84
- var normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
85
-
86
- // src/hexPatterns.ts
87
- var BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
88
- var EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
89
- var HEX_BYTES = /^0x(?:[0-9a-fA-F]{2})*$/;
90
- var DECIMAL_UINT = /^[0-9]+$/;
91
- var MAX_UINT256 = 2n ** 256n - 1n;
92
- var MAX_DATE_MS = 864e13;
93
-
94
- // src/flowSchema.ts
95
- var SolTypeSchema = Schema.Literal(
96
- "uint8",
97
- "uint16",
98
- "uint32",
99
- "uint64",
100
- "uint128",
101
- "uint256",
102
- "int128",
103
- "int256",
104
- "address",
105
- "bool",
106
- "bytes",
107
- "bytes4",
108
- "bytes32",
109
- "string"
110
- );
111
- var ChainIdSchema = Schema.Number.pipe(
112
- Schema.int(),
113
- Schema.positive()
114
- );
115
- var EVMAddressString = Schema.String.pipe(
116
- Schema.pattern(EVM_ADDRESS_HEX, {
117
- message: () => "expected a 0x-prefixed 20-byte EVM address"
118
- })
119
- ).annotations({
120
- description: "EVM address: 0x followed by 40 hex characters"
121
- });
122
- var HexBytesString = Schema.String.pipe(
123
- Schema.pattern(HEX_BYTES, {
124
- message: () => "expected 0x-prefixed hex of whole bytes"
125
- })
126
- ).annotations({
127
- description: "Hex bytes: 0x followed by an even number of hex characters"
128
- });
129
- var EpochMsSchema = Schema.Number.pipe(
130
- Schema.int(),
131
- Schema.between(-MAX_DATE_MS, MAX_DATE_MS)
132
- );
133
- var IntegerString = Schema.String.pipe(
134
- // Both checks live in one filter so the uint256-bound test only ever runs
135
- // `BigInt` on a string the digit check already accepted — order-independent
136
- // and never throws on malformed input.
137
- Schema.filter((value) => {
138
- if (!DECIMAL_UINT.test(value)) {
139
- return "amount must be a decimal integer string";
140
- }
141
- if (BigInt(value) > MAX_UINT256) {
142
- return "amount must not exceed uint256 max";
143
- }
144
- return void 0;
145
- })
146
- );
147
- var RawResourceSchema = Schema.Union(
148
- Schema.Struct({ kind: Schema.Literal("native"), chainId: ChainIdSchema }),
149
- Schema.Struct({
150
- kind: Schema.Literal("erc20"),
151
- token: EVMAddressString,
152
- chainId: ChainIdSchema
153
- })
154
- );
155
- var ResourceSchema = Schema.transform(
156
- RawResourceSchema,
157
- Schema.typeSchema(RawResourceSchema),
158
- {
159
- strict: true,
160
- decode: (raw) => normalizeResource(raw),
161
- encode: (resource2) => resource2
162
- }
163
- );
164
- var ResourceInputSchema = Schema.Struct({
165
- name: Schema.String,
166
- resource: ResourceSchema
167
- });
168
- var HandleInputSchema = Schema.Struct({
169
- name: Schema.String,
170
- type: SolTypeSchema
171
- });
172
- var FlowInputSchema = Schema.Union(
173
- ResourceInputSchema,
174
- HandleInputSchema
175
- );
176
- var RefSchema = Schema.Struct({
177
- $ref: Schema.String.pipe(
178
- Schema.filter((s) => s.indexOf(".") > 0, {
179
- message: () => '$ref must be a dotpath like "input.name" or "nodeId.port"'
180
- })
181
- )
182
- });
183
- var LiteralBindingSchema = Schema.Struct({
184
- kind: SolTypeSchema,
185
- value: Schema.String
186
- });
187
- var BindValueSchema = Schema.Union(RefSchema, LiteralBindingSchema);
188
- var AppliedGuardSchema = Schema.Struct(
189
- { kind: Schema.String },
190
- { key: Schema.String, value: Schema.Unknown }
191
- );
192
- var NodeIdSchema = Schema.String.pipe(
193
- Schema.filter((id) => id !== "__proto__", {
194
- message: () => 'node id "__proto__" is reserved; choose another node id'
195
- })
196
- );
197
- var CallSchema = Schema.Struct({
198
- id: NodeIdSchema,
199
- op: Schema.String,
200
- bind: Schema.optionalWith(
201
- Schema.Record({ key: Schema.String, value: BindValueSchema }),
202
- { default: () => ({}) }
203
- ),
204
- config: Schema.optionalWith(
205
- Schema.Record({ key: Schema.String, value: Schema.Unknown }),
206
- { default: () => ({}) }
207
- ),
208
- guards: Schema.optional(Schema.Array(AppliedGuardSchema))
209
- });
210
- var UuidSchema = Schema.String.pipe(
211
- Schema.pattern(/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/)
212
- );
213
- var LineageSchema = Schema.Struct({
214
- journeyId: UuidSchema,
215
- parentRequestId: UuidSchema
216
- });
217
- var FlowSchema = Schema.Struct({
218
- version: Schema.Literal(1),
219
- id: Schema.String,
220
- chainId: ChainIdSchema,
221
- inputs: Schema.Array(FlowInputSchema),
222
- nodes: Schema.Array(CallSchema),
223
- lineage: Schema.optional(LineageSchema)
224
- });
225
-
226
- // src/continuation.ts
227
- import { ParseResult, Schema as Schema2 } from "effect";
228
- var CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
229
- var RawContinuationOutcomeSchema = Schema2.Struct({
230
- token: EVMAddressString,
231
- minAmount: IntegerString,
232
- destination: EVMAddressString,
233
- chainId: ChainIdSchema
234
- });
235
- var ContinuationOutcomeSchema = Schema2.transform(
236
- RawContinuationOutcomeSchema,
237
- Schema2.typeSchema(RawContinuationOutcomeSchema),
238
- {
239
- strict: true,
240
- decode: (raw) => ({
241
- ...raw,
242
- token: normalizeNativeTokenAddress(raw.token, raw.chainId)
243
- }),
244
- encode: (outcome) => outcome
245
- }
246
- );
247
- var ContinuationIntentSchema = Schema2.Struct({
248
- // `NonEmptyArray` enforces ≥1 outcome at the parse boundary, so downstream needs no guard.
249
- outcomes: Schema2.NonEmptyArray(ContinuationOutcomeSchema),
250
- continuationFlow: Schema2.optional(FlowSchema),
251
- validity: Schema2.Struct({ expiresAtMs: EpochMsSchema }),
252
- perpetual: Schema2.optional(Schema2.Boolean),
253
- provider: Schema2.optional(Schema2.String),
254
- // Funding-path mode. The HTTP wire contract is documented by
255
- // `ComposeActionsSchema` in `@lifi/api-schemas`.
256
- funding: Schema2.optional(Schema2.Literal("inline", "external"))
257
- });
258
- var HexStringSchema = Schema2.String.pipe(Schema2.startsWith("0x"));
259
- var Phase1EscrowSchema = Schema2.Struct({
260
- chainId: ChainIdSchema,
261
- address: HexStringSchema,
262
- token: HexStringSchema,
263
- amount: Schema2.String,
264
- cap: Schema2.String,
265
- owner: HexStringSchema,
266
- refund: HexStringSchema,
267
- expiresAtMs: Schema2.Number.pipe(Schema2.int(), Schema2.positive())
268
- });
269
- var Phase1ArtifactSchema = Schema2.Union(
270
- Schema2.Struct({
271
- kind: Schema2.Literal("transaction"),
272
- funding: Schema2.Literal("inline", "external"),
273
- transactionRequest: Schema2.optional(
274
- Schema2.Struct({
275
- to: Schema2.String,
276
- data: Schema2.String,
277
- value: Schema2.String,
278
- chainId: Schema2.Number
279
- })
280
- ),
281
- escrow: Schema2.optional(Phase1EscrowSchema)
282
- }),
283
- Schema2.Struct({
284
- kind: Schema2.Literal("signables"),
285
- typedData: Schema2.Array(Schema2.Unknown)
286
- }),
287
- Schema2.Struct({ kind: Schema2.Literal("none") })
288
- );
289
- var AssertionOwnerSchema = Schema2.Union(
290
- EVMAddressString,
291
- Schema2.Literal("escrow", "delivery")
292
- );
293
- var Erc20BalanceGteSpecSchema = Schema2.Struct({
294
- kind: Schema2.Literal("erc20BalanceGte"),
295
- chainId: ChainIdSchema,
296
- token: EVMAddressString,
297
- owner: EVMAddressString,
298
- minAmount: IntegerString
299
- });
300
- var NativeBalanceGteSpecSchema = Schema2.Struct({
301
- kind: Schema2.Literal("nativeBalanceGte"),
302
- chainId: ChainIdSchema,
303
- owner: EVMAddressString,
304
- minAmount: IntegerString
305
- });
306
- var CallCheckSpecSchema = Schema2.Struct({
307
- kind: Schema2.Literal("call"),
308
- chainId: ChainIdSchema,
309
- to: EVMAddressString,
310
- calldata: HexBytesString,
311
- comparator: Schema2.Literal("gte", "eq", "lte"),
312
- value: IntegerString
313
- });
314
- var asErc20BalanceGteCheck = (check, token) => ({
315
- kind: "erc20BalanceGte",
316
- chainId: check.chainId,
317
- token,
318
- owner: check.owner,
319
- minAmount: check.minAmount
320
- });
321
- var decodeNativeBalanceGte = (check, ast) => {
322
- const policy = nativeCheckPolicy(check.chainId);
323
- switch (policy.kind) {
324
- case "keep":
325
- return ParseResult.succeed(check);
326
- case "rewrite":
327
- return ParseResult.succeed(asErc20BalanceGteCheck(check, policy.token));
328
- case "reject":
329
- return ParseResult.fail(new ParseResult.Type(ast, check, policy.reason));
330
- }
126
+ /**
127
+ * Whether `address` on `chainId` is the genuine `msg.value`-style native coin:
128
+ * an `evm-native` chain's zero-address sentinel.
129
+ *
130
+ * This is the single predicate that gates `msg.value` semantics — choosing a
131
+ * `NativeBalance` over an `Erc20Balance` simulation requirement, and skipping
132
+ * the ERC-20 approval a native input would otherwise need. It returns `false`
133
+ * for every address on a chain whose canonical native asset is an ERC-20
134
+ * (including the zero sentinel): on `as-erc20` chains the "native" coin is a
135
+ * real ERC-20 moved via `transferFrom`, never `msg.value`, and on
136
+ * `native-mirrored-erc20` chains `msg.value` works but the composer's policy
137
+ * is to move the coin exclusively through the ERC-20 facade. Use this rather
138
+ * than re-deriving the check at call sites, and rather than
139
+ * `isNativeAddressForChain`, which returns `true` for the stand-in ERC-20
140
+ * (PathUSD on Tempo) and would wrongly route it to `msg.value`.
141
+ */
142
+ const isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isNativeSentinel(address);
143
+ /**
144
+ * Rewrite a single `Resource` according to its chain's capabilities.
145
+ *
146
+ * On chains with the default `evm-native` policy, every resource is returned
147
+ * unchanged. On chains whose canonical native asset is an ERC-20 (`as-erc20`
148
+ * Tempo, `native-mirrored-erc20` Arc), a resource of kind `"native"` is
149
+ * rewritten into the equivalent ERC-20 resource pointing at the chain's
150
+ * stand-in token (PathUSD on Tempo, the USDC facade on Arc).
151
+ *
152
+ * This is the rewrite primitive behind the `ResourceSchema` decode transform
153
+ * (see `flowSchema.ts`), which is THE chokepoint: it runs every time a
154
+ * `Resource` is parsed — flow inputs via `FlowSchema`, op configs via
155
+ * `decodeConfig` — so every downstream pass (`normalizeFlow`, `resolve`,
156
+ * `lower`, `simulate`) sees only ERC-20 resources on those chains.
157
+ *
158
+ * The function preserves referential identity when nothing changes (returns the
159
+ * input `r` unchanged on evm-native chains and for ERC-20 resources) and is
160
+ * idempotent: running it on an already-rewritten resource is a no-op.
161
+ */
162
+ const normalizeResource = (r) => {
163
+ if (r.kind !== "native") return r;
164
+ const erc20 = erc20CanonicalNative(getChainCapabilities(r.chainId));
165
+ if (erc20 === void 0) return r;
166
+ return {
167
+ kind: "erc20",
168
+ chainId: r.chainId,
169
+ token: erc20.token
170
+ };
331
171
  };
332
- var Erc20BalanceDeltaGteSpecSchema = Schema2.Struct({
333
- kind: Schema2.Literal("erc20BalanceDeltaGte"),
334
- chainId: ChainIdSchema,
335
- token: EVMAddressString,
336
- owner: AssertionOwnerSchema,
337
- minDelta: IntegerString
338
- });
339
- var NativeBalanceDeltaGteSpecSchema = Schema2.Struct({
340
- kind: Schema2.Literal("nativeBalanceDeltaGte"),
341
- chainId: ChainIdSchema,
342
- owner: AssertionOwnerSchema,
343
- minDelta: IntegerString
344
- });
345
- var AssertionSpecSchema = Schema2.Union(
346
- Erc20BalanceGteSpecSchema,
347
- NativeBalanceGteSpecSchema,
348
- CallCheckSpecSchema,
349
- Erc20BalanceDeltaGteSpecSchema,
350
- NativeBalanceDeltaGteSpecSchema
351
- );
352
- var settledOutcome = (intent) => intent.outcomes[0];
353
-
354
- // src/descriptor.ts
355
- import { ParseResult as ParseResult2, Schema as Schema3 } from "effect";
356
- var Bytes32HexSchema = Schema3.String.pipe(
357
- Schema3.pattern(BYTES32_LOWER_HEX)
358
- );
359
- var AssertedErc20BalanceGteSpecSchema = Schema3.Struct({
360
- kind: Schema3.Literal("erc20BalanceGte"),
361
- chainId: ChainIdSchema,
362
- token: EVMAddressString,
363
- owner: AssertionOwnerSchema,
364
- minAmount: IntegerString
365
- });
366
- var AssertedNativeBalanceGteSpecSchema = Schema3.Struct({
367
- kind: Schema3.Literal("nativeBalanceGte"),
368
- chainId: ChainIdSchema,
369
- owner: AssertionOwnerSchema,
370
- minAmount: IntegerString
371
- });
372
- var RawAssertedPredicateSchema = Schema3.Union(
373
- AssertedErc20BalanceGteSpecSchema,
374
- AssertedNativeBalanceGteSpecSchema,
375
- CallCheckSpecSchema,
376
- Erc20BalanceDeltaGteSpecSchema,
377
- NativeBalanceDeltaGteSpecSchema
378
- );
379
- var AssertedPredicateSchema = Schema3.transformOrFail(
380
- RawAssertedPredicateSchema,
381
- Schema3.typeSchema(RawAssertedPredicateSchema),
382
- {
383
- strict: true,
384
- decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : ParseResult2.succeed(pred),
385
- encode: (pred) => ParseResult2.succeed(pred)
386
- }
387
- );
388
- var VerificationDescriptorSchema = Schema3.Struct({
389
- validationProgramHash: Bytes32HexSchema,
390
- // The C5 echo's second hash (verified continuations, plan GD-8): `keccak256`
391
- // over the canonical params vector (`paramsHash`, GD-2 seam C1). Required and
392
- // jointly necessary with `validationProgramHash` — the program hash is
393
- // value-blind (it never binds the delivery address or amounts), so a descriptor
394
- // that enforces only it is a fund-redirect hole. Empty params still yield a
395
- // present `0x00…00`, so a real descriptor never omits it. Strict 32-byte
396
- // lowercase hex, same rule as `validationProgramHash`.
397
- paramsHash: Bytes32HexSchema,
398
- assertedPredicate: Schema3.Array(AssertedPredicateSchema)
399
- });
400
- var canonicalJson = (value) => {
401
- if (Array.isArray(value)) {
402
- return `[${value.map(canonicalJson).join(",")}]`;
403
- }
404
- if (value !== null && typeof value === "object") {
405
- const record = value;
406
- const entries = Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`);
407
- return `{${entries.join(",")}}`;
408
- }
409
- return JSON.stringify(value);
172
+ /**
173
+ * Address-level counterpart of `normalizeResource` for wire fields that carry a
174
+ * native asset as a bare token string (a continuation outcome's `token`). On
175
+ * chains whose canonical native asset is an ERC-20, the native sentinel is
176
+ * rewritten to the chain's stand-in ERC-20; every other address passes through.
177
+ */
178
+ const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
179
+ //#endregion
180
+ //#region src/hexPatterns.ts
181
+ const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
182
+ const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
183
+ const HEX_BYTES = /^0x(?:[0-9a-fA-F]{2})*$/;
184
+ const DECIMAL_UINT = /^[0-9]+$/;
185
+ const MAX_UINT256 = 2n ** 256n - 1n;
186
+ const MAX_DATE_MS = 864e13;
187
+ //#endregion
188
+ //#region src/flowSchema.ts
189
+ const SolTypeSchema = Schema.Literal("uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string");
190
+ const ChainIdSchema = Schema.Number.pipe(Schema.int(), Schema.positive());
191
+ const EVMAddressString = Schema.String.pipe(Schema.pattern(EVM_ADDRESS_HEX, { message: () => "expected a 0x-prefixed 20-byte EVM address" })).annotations({ description: "EVM address: 0x followed by 40 hex characters" });
192
+ const HexBytesString = Schema.String.pipe(Schema.pattern(HEX_BYTES, { message: () => "expected 0x-prefixed hex of whole bytes" })).annotations({ description: "Hex bytes: 0x followed by an even number of hex characters" });
193
+ const EpochMsSchema = Schema.Number.pipe(Schema.int(), Schema.between(-864e13, MAX_DATE_MS));
194
+ const IntegerString = Schema.String.pipe(Schema.filter((value) => {
195
+ if (!DECIMAL_UINT.test(value)) return "amount must be a decimal integer string";
196
+ if (BigInt(value) > MAX_UINT256) return "amount must not exceed uint256 max";
197
+ }));
198
+ const RawResourceSchema = Schema.Union(Schema.Struct({
199
+ kind: Schema.Literal("native"),
200
+ chainId: ChainIdSchema
201
+ }), Schema.Struct({
202
+ kind: Schema.Literal("erc20"),
203
+ token: EVMAddressString,
204
+ chainId: ChainIdSchema
205
+ }));
206
+ /**
207
+ * THE chain-capabilities chokepoint.
208
+ *
209
+ * `ResourceSchema` is a decode transform: it parses the plain `native | erc20`
210
+ * wire union (`RawResourceSchema`) and then runs `normalizeResource`, so on
211
+ * `as-erc20` chains (e.g. Tempo) a `{ kind: "native", chainId }` resource is
212
+ * rewritten to its ERC-20 form (PathUSD) before any application code sees it.
213
+ * Because every Resource-bearing schema embeds this one — `FlowSchema` for flow
214
+ * inputs, op `configSchema`s for op configs — making the schema itself
215
+ * chain-aware covers every parsed entry point in one place.
216
+ *
217
+ * The `encode` direction is the identity: the ERC-20 form is itself valid wire
218
+ * format, and the rewrite is deliberately not reversible (we never want to
219
+ * re-introduce a `native` resource when serialising). `JSONSchema.make` derives
220
+ * the published wire format from the encoded (`from`) side, so the manifest
221
+ * keeps advertising the plain union with both arms.
222
+ */
223
+ const ResourceSchema = Schema.transform(RawResourceSchema, Schema.typeSchema(RawResourceSchema), {
224
+ strict: true,
225
+ decode: (raw) => normalizeResource(raw),
226
+ encode: (resource) => resource
227
+ });
228
+ const ResourceInputSchema = Schema.Struct({
229
+ name: Schema.String,
230
+ resource: ResourceSchema
231
+ });
232
+ const HandleInputSchema = Schema.Struct({
233
+ name: Schema.String,
234
+ type: SolTypeSchema
235
+ });
236
+ const FlowInputSchema = Schema.Union(ResourceInputSchema, HandleInputSchema);
237
+ const RefSchema = Schema.Struct({ $ref: Schema.String.pipe(Schema.filter((s) => s.indexOf(".") > 0, { message: () => "$ref must be a dotpath like \"input.name\" or \"nodeId.port\"" })) });
238
+ const LiteralBindingSchema = Schema.Struct({
239
+ kind: SolTypeSchema,
240
+ value: Schema.String
241
+ });
242
+ const BindValueSchema = Schema.Union(RefSchema, LiteralBindingSchema);
243
+ const AppliedGuardSchema = Schema.Struct({ kind: Schema.String }, {
244
+ key: Schema.String,
245
+ value: Schema.Unknown
246
+ });
247
+ const NodeIdSchema = Schema.String.pipe(Schema.filter((id) => id !== "__proto__", { message: () => "node id \"__proto__\" is reserved; choose another node id" }), Schema.filter((id) => id.length > 0, { message: () => "node id must not be empty" }));
248
+ const CallSchema = Schema.Struct({
249
+ id: NodeIdSchema,
250
+ op: Schema.String,
251
+ bind: Schema.optionalWith(Schema.Record({
252
+ key: Schema.String,
253
+ value: BindValueSchema
254
+ }), { default: () => ({}) }),
255
+ config: Schema.optionalWith(Schema.Record({
256
+ key: Schema.String,
257
+ value: Schema.Unknown
258
+ }), { default: () => ({}) }),
259
+ guards: Schema.optional(Schema.Array(AppliedGuardSchema))
260
+ });
261
+ const UuidSchema = Schema.String.pipe(Schema.pattern(/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/));
262
+ const LineageSchema = Schema.Struct({
263
+ journeyId: UuidSchema,
264
+ parentRequestId: UuidSchema
265
+ });
266
+ const FlowSchema = Schema.Struct({
267
+ version: Schema.Literal(1),
268
+ id: Schema.String,
269
+ chainId: ChainIdSchema,
270
+ inputs: Schema.Array(FlowInputSchema),
271
+ nodes: Schema.Array(CallSchema),
272
+ lineage: Schema.optional(LineageSchema)
273
+ });
274
+ //#endregion
275
+ //#region src/continuation.ts
276
+ const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
277
+ const RawContinuationOutcomeSchema = Schema.Struct({
278
+ token: EVMAddressString,
279
+ minAmount: IntegerString,
280
+ destination: EVMAddressString,
281
+ chainId: ChainIdSchema
282
+ });
283
+ const ContinuationOutcomeSchema = Schema.transform(RawContinuationOutcomeSchema, Schema.typeSchema(RawContinuationOutcomeSchema), {
284
+ strict: true,
285
+ decode: (raw) => ({
286
+ ...raw,
287
+ token: normalizeNativeTokenAddress(raw.token, raw.chainId)
288
+ }),
289
+ encode: (outcome) => outcome
290
+ });
291
+ const ContinuationIntentSchema = Schema.Struct({
292
+ outcomes: Schema.NonEmptyArray(ContinuationOutcomeSchema),
293
+ continuationFlow: Schema.optional(FlowSchema),
294
+ validity: Schema.Struct({ expiresAtMs: EpochMsSchema }),
295
+ perpetual: Schema.optional(Schema.Boolean),
296
+ provider: Schema.optional(Schema.String),
297
+ funding: Schema.optional(Schema.Literal("inline", "external"))
298
+ });
299
+ const HexStringSchema = Schema.String.pipe(Schema.startsWith("0x"));
300
+ const Phase1EscrowSchema = Schema.Struct({
301
+ chainId: ChainIdSchema,
302
+ address: HexStringSchema,
303
+ token: HexStringSchema,
304
+ amount: Schema.String,
305
+ cap: Schema.String,
306
+ owner: HexStringSchema,
307
+ refund: HexStringSchema,
308
+ expiresAtMs: Schema.Number.pipe(Schema.int(), Schema.positive())
309
+ });
310
+ const Phase1ArtifactSchema = Schema.Union(Schema.Struct({
311
+ kind: Schema.Literal("transaction"),
312
+ funding: Schema.Literal("inline", "external"),
313
+ transactionRequest: Schema.optional(Schema.Struct({
314
+ to: Schema.String,
315
+ data: Schema.String,
316
+ value: Schema.String,
317
+ chainId: Schema.Number
318
+ })),
319
+ escrow: Schema.optional(Phase1EscrowSchema)
320
+ }), Schema.Struct({
321
+ kind: Schema.Literal("signables"),
322
+ typedData: Schema.Array(Schema.Unknown)
323
+ }), Schema.Struct({ kind: Schema.Literal("none") }));
324
+ const AssertionOwnerSchema = Schema.Union(EVMAddressString, Schema.Literal("escrow", "delivery"));
325
+ const Erc20BalanceGteSpecSchema = Schema.Struct({
326
+ kind: Schema.Literal("erc20BalanceGte"),
327
+ chainId: ChainIdSchema,
328
+ token: EVMAddressString,
329
+ owner: EVMAddressString,
330
+ minAmount: IntegerString
331
+ });
332
+ const NativeBalanceGteSpecSchema = Schema.Struct({
333
+ kind: Schema.Literal("nativeBalanceGte"),
334
+ chainId: ChainIdSchema,
335
+ owner: EVMAddressString,
336
+ minAmount: IntegerString
337
+ });
338
+ const CallCheckSpecSchema = Schema.Struct({
339
+ kind: Schema.Literal("call"),
340
+ chainId: ChainIdSchema,
341
+ to: EVMAddressString,
342
+ calldata: HexBytesString,
343
+ comparator: Schema.Literal("gte", "eq", "lte"),
344
+ value: IntegerString
345
+ });
346
+ const asErc20BalanceGteCheck = (check, token) => ({
347
+ kind: "erc20BalanceGte",
348
+ chainId: check.chainId,
349
+ token,
350
+ owner: check.owner,
351
+ minAmount: check.minAmount
352
+ });
353
+ const decodeNativeBalanceGte = (check, ast) => {
354
+ const policy = nativeCheckPolicy(check.chainId);
355
+ switch (policy.kind) {
356
+ case "keep": return ParseResult.succeed(check);
357
+ case "rewrite": return ParseResult.succeed(asErc20BalanceGteCheck(check, policy.token));
358
+ case "reject": return ParseResult.fail(new ParseResult.Type(ast, check, policy.reason));
359
+ }
410
360
  };
411
- var canonicalAssertedPredicate = (specs) => canonicalJson(specs);
412
-
413
- // src/flow.ts
414
- var isResourceInput = (input) => "resource" in input;
415
- var flowInputType = (input) => isResourceInput(input) ? "uint256" : input.type;
416
- var flowInputMode = (input) => isResourceInput(input) ? "linear" : "copy";
417
- var flowInputResource = (input) => isResourceInput(input) ? input.resource : void 0;
418
- var isResourcePort = (port) => port.kind === "resource";
419
- var isHandlePort = (port) => port.kind === "handle";
420
- var isResourceOutputPort = (port) => port.kind === "resource_output";
421
- var isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
422
- var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
423
-
424
- // src/resource.ts
425
- var erc20Resource = (token, chainId) => ({
426
- kind: "erc20",
427
- token,
428
- chainId
429
- });
430
- var nativeResource = (chainId) => ({
431
- kind: "native",
432
- chainId
433
- });
434
- var isERC20Resource = (r) => r.kind === "erc20";
435
- var isNativeResource = (r) => r.kind === "native";
436
- var resourcesEqual = (a, b) => {
437
- if (isNativeResource(a) && isNativeResource(b)) {
438
- return a.chainId === b.chainId;
439
- }
440
- if (isERC20Resource(a) && isERC20Resource(b)) {
441
- return a.chainId === b.chainId && a.token.toLowerCase() === b.token.toLowerCase();
442
- }
443
- return false;
361
+ const Erc20BalanceDeltaGteSpecSchema = Schema.Struct({
362
+ kind: Schema.Literal("erc20BalanceDeltaGte"),
363
+ chainId: ChainIdSchema,
364
+ token: EVMAddressString,
365
+ owner: AssertionOwnerSchema,
366
+ minDelta: IntegerString
367
+ });
368
+ const NativeBalanceDeltaGteSpecSchema = Schema.Struct({
369
+ kind: Schema.Literal("nativeBalanceDeltaGte"),
370
+ chainId: ChainIdSchema,
371
+ owner: AssertionOwnerSchema,
372
+ minDelta: IntegerString
373
+ });
374
+ const AssertionSpecSchema = Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema, Erc20BalanceDeltaGteSpecSchema, NativeBalanceDeltaGteSpecSchema);
375
+ const settledOutcome = (intent) => intent.outcomes[0];
376
+ //#endregion
377
+ //#region src/descriptor.ts
378
+ const Bytes32HexSchema = Schema.String.pipe(Schema.pattern(BYTES32_LOWER_HEX));
379
+ const AssertedErc20BalanceGteSpecSchema = Schema.Struct({
380
+ kind: Schema.Literal("erc20BalanceGte"),
381
+ chainId: ChainIdSchema,
382
+ token: EVMAddressString,
383
+ owner: AssertionOwnerSchema,
384
+ minAmount: IntegerString
385
+ });
386
+ const AssertedNativeBalanceGteSpecSchema = Schema.Struct({
387
+ kind: Schema.Literal("nativeBalanceGte"),
388
+ chainId: ChainIdSchema,
389
+ owner: AssertionOwnerSchema,
390
+ minAmount: IntegerString
391
+ });
392
+ const RawAssertedPredicateSchema = Schema.Union(AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, CallCheckSpecSchema, Erc20BalanceDeltaGteSpecSchema, NativeBalanceDeltaGteSpecSchema);
393
+ const AssertedPredicateSchema = Schema.transformOrFail(RawAssertedPredicateSchema, Schema.typeSchema(RawAssertedPredicateSchema), {
394
+ strict: true,
395
+ decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : ParseResult.succeed(pred),
396
+ encode: (pred) => ParseResult.succeed(pred)
397
+ });
398
+ const VerificationDescriptorSchema = Schema.Struct({
399
+ validationProgramHash: Bytes32HexSchema,
400
+ paramsHash: Bytes32HexSchema,
401
+ assertedPredicate: Schema.Array(AssertedPredicateSchema)
402
+ });
403
+ const canonicalJson = (value) => {
404
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
405
+ if (value !== null && typeof value === "object") {
406
+ const record = value;
407
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(",")}}`;
408
+ }
409
+ return JSON.stringify(value);
444
410
  };
445
- var foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
446
- var resourceToken = (r) => foldResource(r, {
447
- native: () => EVM_NATIVE_SENTINEL,
448
- erc20: (token) => token
449
- });
450
- var resourceKey = (r) => foldResource(r, {
451
- native: (chainId) => `native:${chainId}`,
452
- erc20: (token, chainId) => `erc20:${token.toLowerCase()}:${chainId}`
453
- });
454
- var erc20Token = (r) => {
455
- if (r.kind !== "erc20")
456
- throw new Error(`Expected erc20 resource, got ${r.kind}`);
457
- return r.token;
411
+ const canonicalAssertedPredicate = (specs) => canonicalJson(specs);
412
+ //#endregion
413
+ //#region src/flow.ts
414
+ const isResourceInput = (input) => "resource" in input;
415
+ const flowInputType = (input) => isResourceInput(input) ? "uint256" : input.type;
416
+ const flowInputMode = (input) => isResourceInput(input) ? "linear" : "copy";
417
+ const flowInputResource = (input) => isResourceInput(input) ? input.resource : void 0;
418
+ const isResourcePort = (port) => port.kind === "resource";
419
+ const isHandlePort = (port) => port.kind === "handle";
420
+ const isResourceOutputPort = (port) => port.kind === "resource_output";
421
+ const isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
422
+ const isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
423
+ //#endregion
424
+ //#region src/resource.ts
425
+ const erc20Resource = (token, chainId) => ({
426
+ kind: "erc20",
427
+ token,
428
+ chainId
429
+ });
430
+ const nativeResource = (chainId) => ({
431
+ kind: "native",
432
+ chainId
433
+ });
434
+ const isERC20Resource = (r) => r.kind === "erc20";
435
+ const isNativeResource = (r) => r.kind === "native";
436
+ const resourcesEqual = (a, b) => {
437
+ if (isNativeResource(a) && isNativeResource(b)) return a.chainId === b.chainId;
438
+ if (isERC20Resource(a) && isERC20Resource(b)) return a.chainId === b.chainId && a.token.toLowerCase() === b.token.toLowerCase();
439
+ return false;
458
440
  };
459
-
460
- // src/flashloan.ts
461
- var PROVIDER_KIND = {
462
- AAVE_V3: 0,
463
- ERC3156: 1,
464
- BALANCER_V2: 2,
465
- MORPHO_BLUE: 3
441
+ const foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
442
+ const resourceToken = (r) => foldResource(r, {
443
+ native: () => EVM_NATIVE_SENTINEL,
444
+ erc20: (token) => token
445
+ });
446
+ const resourceKey = (r) => foldResource(r, {
447
+ native: (chainId) => `native:${chainId}`,
448
+ erc20: (token, chainId) => `erc20:${token.toLowerCase()}:${chainId}`
449
+ });
450
+ const erc20Token = (r) => {
451
+ if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
452
+ return r.token;
466
453
  };
467
- var providerKindNames = [
468
- "aave-v3",
469
- "erc3156",
470
- "balancer-v2",
471
- "morpho-blue"
454
+ //#endregion
455
+ //#region src/flashloan.ts
456
+ const PROVIDER_KIND = {
457
+ AAVE_V3: 0,
458
+ ERC3156: 1,
459
+ BALANCER_V2: 2,
460
+ MORPHO_BLUE: 3
461
+ };
462
+ const providerKindNames = [
463
+ "aave-v3",
464
+ "erc3156",
465
+ "balancer-v2",
466
+ "morpho-blue"
472
467
  ];
473
- var providerKindByName = {
474
- "aave-v3": PROVIDER_KIND.AAVE_V3,
475
- erc3156: PROVIDER_KIND.ERC3156,
476
- "balancer-v2": PROVIDER_KIND.BALANCER_V2,
477
- "morpho-blue": PROVIDER_KIND.MORPHO_BLUE
468
+ const providerKindByName = {
469
+ "aave-v3": PROVIDER_KIND.AAVE_V3,
470
+ erc3156: PROVIDER_KIND.ERC3156,
471
+ "balancer-v2": PROVIDER_KIND.BALANCER_V2,
472
+ "morpho-blue": PROVIDER_KIND.MORPHO_BLUE
478
473
  };
479
-
480
- // src/constructors.ts
481
- var optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
482
- var linear = (name, type) => ({
483
- name,
484
- type,
485
- mode: "linear",
486
- availability: "now"
487
- });
488
- var copy = (name, type) => ({
489
- name,
490
- type,
491
- mode: "copy",
492
- availability: "now"
493
- });
494
- var handle = (name, type) => ({ name, type });
495
- var native = (name, chainId) => ({
496
- name,
497
- resource: nativeResource(chainId)
498
- });
499
- var erc20 = (name, token, chainId) => ({
500
- name,
501
- resource: erc20Resource(token, chainId)
502
- });
503
- var resource = (name, accepts, options) => ({
504
- kind: "resource",
505
- name,
506
- accepts,
507
- mode: "linear",
508
- ...optionalProp("optional", options?.optional)
509
- });
510
- var readResource = (name, accepts) => ({
511
- kind: "resource",
512
- name,
513
- accepts,
514
- mode: "copy"
515
- });
516
- var opHandle = (name, type, options) => ({
517
- kind: "handle",
518
- name,
519
- type,
520
- mode: "copy",
521
- ...optionalProp("expose", options?.expose),
522
- ...optionalProp("units", options?.units),
523
- ...optionalProp("optional", options?.optional)
524
- });
525
- var resourceOutput = (name, options) => {
526
- const raw = options;
527
- const opts = typeof raw === "string" ? { availability: raw } : raw;
528
- return {
529
- kind: "resource_output",
530
- name,
531
- mode: "linear",
532
- ...optionalProp("availability", opts?.availability),
533
- ...optionalProp("providesMinimum", opts?.providesMinimum),
534
- ...optionalProp("omitIfZero", opts?.omitIfZero),
535
- ...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput),
536
- ...optionalProp("countFrom", opts?.countFrom)
537
- };
474
+ //#endregion
475
+ //#region src/constructors.ts
476
+ /** Returns `{ [key]: value }` when `value` is not nullish, else `{}`. */
477
+ const optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
478
+ const linear = (name, type) => ({
479
+ name,
480
+ type,
481
+ mode: "linear",
482
+ availability: "now"
483
+ });
484
+ const copy = (name, type) => ({
485
+ name,
486
+ type,
487
+ mode: "copy",
488
+ availability: "now"
489
+ });
490
+ const handle = (name, type) => ({
491
+ name,
492
+ type
493
+ });
494
+ const native = (name, chainId) => ({
495
+ name,
496
+ resource: nativeResource(chainId)
497
+ });
498
+ const erc20 = (name, token, chainId) => ({
499
+ name,
500
+ resource: erc20Resource(token, chainId)
501
+ });
502
+ const resource = (name, accepts, options) => ({
503
+ kind: "resource",
504
+ name,
505
+ accepts,
506
+ mode: "linear",
507
+ ...optionalProp("optional", options?.optional)
508
+ });
509
+ const readResource = (name, accepts) => ({
510
+ kind: "resource",
511
+ name,
512
+ accepts,
513
+ mode: "copy"
514
+ });
515
+ const opHandle = (name, type, options) => ({
516
+ kind: "handle",
517
+ name,
518
+ type,
519
+ mode: "copy",
520
+ ...optionalProp("expose", options?.expose),
521
+ ...optionalProp("units", options?.units),
522
+ ...optionalProp("optional", options?.optional)
523
+ });
524
+ const resourceOutput = (name, options) => {
525
+ const raw = options;
526
+ const opts = typeof raw === "string" ? { availability: raw } : raw;
527
+ return {
528
+ kind: "resource_output",
529
+ name,
530
+ mode: "linear",
531
+ ...optionalProp("availability", opts?.availability),
532
+ ...optionalProp("providesMinimum", opts?.providesMinimum),
533
+ ...optionalProp("omitIfZero", opts?.omitIfZero),
534
+ ...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput),
535
+ ...optionalProp("countFrom", opts?.countFrom)
536
+ };
538
537
  };
539
-
540
- // src/outputFamilies.ts
541
- var isOutputFamily = (port) => port.kind === "resource_output" && port.countFrom !== void 0;
542
- var instancePortName = (family, index) => `${family}.${index}`;
543
- var familySize = (family, config) => {
544
- const source = config[family.countFrom];
545
- if (Array.isArray(source)) return source.length;
546
- if (Number.isSafeInteger(source) && source >= 0) {
547
- return source;
548
- }
549
- throw new Error(
550
- `Output family '${family.name}' counts from config '${family.countFrom}', which is neither an array nor a non-negative integer`
551
- );
538
+ //#endregion
539
+ //#region src/outputFamilies.ts
540
+ const isOutputFamily = (port) => port.kind === "resource_output" && port.countFrom !== void 0;
541
+ const instancePortName = (family, index) => `${family}.${index}`;
542
+ const familySize = (family, config) => {
543
+ const source = config[family.countFrom];
544
+ if (Array.isArray(source)) return source.length;
545
+ if (Number.isSafeInteger(source) && source >= 0) return source;
546
+ throw new Error(`Output family '${family.name}' counts from config '${family.countFrom}', which is neither an array nor a non-negative integer`);
552
547
  };
553
- var expandFamily = (port, config) => {
554
- const { countFrom: _countFrom, ...instance } = port;
555
- return Array.from({ length: familySize(port, config) }, (_, index) => ({
556
- ...instance,
557
- name: instancePortName(port.name, index)
558
- }));
548
+ const expandFamily = (port, config) => {
549
+ const { countFrom: _countFrom, ...instance } = port;
550
+ return Array.from({ length: familySize(port, config) }, (_, index) => ({
551
+ ...instance,
552
+ name: instancePortName(port.name, index)
553
+ }));
559
554
  };
560
- var expandOutputPorts = (declared, config) => declared.some(isOutputFamily) ? declared.flatMap(
561
- (port) => isOutputFamily(port) ? expandFamily(port, config) : [port]
562
- ) : declared;
563
-
564
- // src/ref.ts
565
- var isContextKey = (key) => key === "sender" || key === "executionAddress";
566
- var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
567
- "input",
568
- "context",
569
- "literal"
555
+ const expandOutputPorts = (declared, config) => declared.some(isOutputFamily) ? declared.flatMap((port) => isOutputFamily(port) ? expandFamily(port, config) : [port]) : declared;
556
+ //#endregion
557
+ //#region src/ref.ts
558
+ const isContextKey = (key) => key === "sender" || key === "executionAddress";
559
+ /**
560
+ * Ref prefixes that parseRef intercepts before the fallback `output` scope.
561
+ * A node whose id matches one of these would produce ambiguous refs
562
+ * (e.g. `context.sender` could be a context ref or node-output ref).
563
+ * Validation must reject these as node ids.
564
+ */
565
+ const RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
566
+ "input",
567
+ "context",
568
+ "literal"
570
569
  ]);
571
- var isRef = (v) => typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string";
572
- var parseRef = (ref2) => {
573
- const dot = ref2.$ref.indexOf(".");
574
- if (dot === -1)
575
- throw new Error(`Invalid ref: "${ref2.$ref}" (must contain a dot)`);
576
- const prefix = ref2.$ref.slice(0, dot);
577
- const suffix = ref2.$ref.slice(dot + 1);
578
- if (prefix === "input") return { scope: "input", port: suffix };
579
- if (prefix === "context") {
580
- if (!isContextKey(suffix))
581
- throw new Error(`Unknown context key: "${suffix}"`);
582
- return { scope: "context", key: suffix };
583
- }
584
- return { scope: "output", node: prefix, port: suffix };
570
+ const isRef = (v) => typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string";
571
+ const parseRef = (ref) => {
572
+ const dot = ref.$ref.indexOf(".");
573
+ if (dot === -1) throw new Error(`Invalid ref: "${ref.$ref}" (must contain a dot)`);
574
+ const prefix = ref.$ref.slice(0, dot);
575
+ const suffix = ref.$ref.slice(dot + 1);
576
+ if (prefix === "input") return {
577
+ scope: "input",
578
+ port: suffix
579
+ };
580
+ if (prefix === "context") {
581
+ if (!isContextKey(suffix)) throw new Error(`Unknown context key: "${suffix}"`);
582
+ return {
583
+ scope: "context",
584
+ key: suffix
585
+ };
586
+ }
587
+ return {
588
+ scope: "output",
589
+ node: prefix,
590
+ port: suffix
591
+ };
585
592
  };
586
- var buildRef = (path) => {
587
- if (path.indexOf(".") < 1)
588
- throw new Error(
589
- `Invalid ref: "${path}" (must be a dotpath like "input.name" or "nodeId.port")`
590
- );
591
- const built = { $ref: path };
592
- parseRef(built);
593
- return built;
593
+ const buildRef = (path) => {
594
+ if (path.indexOf(".") < 1) throw new Error(`Invalid ref: "${path}" (must be a dotpath like "input.name" or "nodeId.port")`);
595
+ const built = { $ref: path };
596
+ parseRef(built);
597
+ return built;
594
598
  };
595
- var ref = Object.assign(buildRef, {
596
- input: (port) => buildRef(`input.${port}`),
597
- context: {
598
- sender: buildRef("context.sender"),
599
- executionAddress: buildRef("context.executionAddress")
600
- }
601
- });
602
- var foldRef = (ref2, cases) => {
603
- if (ref2.scope === "input") return cases.input(ref2.port);
604
- if (ref2.scope === "context") return cases.context(ref2.key);
605
- return cases.output(ref2.node, ref2.port);
599
+ const ref = Object.assign(buildRef, {
600
+ input: (port) => buildRef(`input.${port}`),
601
+ context: {
602
+ sender: buildRef("context.sender"),
603
+ executionAddress: buildRef("context.executionAddress")
604
+ }
605
+ });
606
+ const foldRef = (ref, cases) => {
607
+ if (ref.scope === "input") return cases.input(ref.port);
608
+ if (ref.scope === "context") return cases.context(ref.key);
609
+ return cases.output(ref.node, ref.port);
606
610
  };
607
- var refKey = (ref2) => foldRef(parseRef(ref2), {
608
- input: (port) => `input:${port}`,
609
- context: (key) => `context:${key}`,
610
- output: (node, port) => `output:${node}:${port}`
611
- });
612
-
613
- // src/preconditions.ts
614
- var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
615
- var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
616
- var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
617
- var isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
618
- var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
619
- var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
620
-
621
- // src/simulate.ts
622
- var SIMULATE_MAX_TRACKED_BALANCES = 40;
623
- var SIMULATE_MAX_REQUIREMENTS = 40;
624
-
625
- // src/headers.ts
626
- var COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
627
- var COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
628
-
629
- // src/version.ts
630
- var SEMANTIC_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
631
- var parseVersion = (version) => {
632
- const match = SEMANTIC_VERSION_PATTERN.exec(version);
633
- if (!match) return void 0;
634
- const major = Number(match[1]);
635
- const minor = Number(match[2]);
636
- const patch = Number(match[3]);
637
- if (![major, minor, patch].every(Number.isSafeInteger)) return void 0;
638
- return { major, minor, patch };
611
+ const refKey = (ref) => foldRef(parseRef(ref), {
612
+ input: (port) => `input:${port}`,
613
+ context: (key) => `context:${key}`,
614
+ output: (node, port) => `output:${node}:${port}`
615
+ });
616
+ //#endregion
617
+ //#region src/preconditions.ts
618
+ const erc20Balance = (config) => ({
619
+ type: "Erc20Balance",
620
+ ...config
621
+ });
622
+ const nativeBalance = (config) => ({
623
+ type: "NativeBalance",
624
+ ...config
625
+ });
626
+ const erc20Allowance = (config) => ({
627
+ type: "Erc20Allowance",
628
+ ...config
629
+ });
630
+ const isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
631
+ const isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
632
+ const isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
633
+ //#endregion
634
+ //#region src/simulate.ts
635
+ /**
636
+ * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
637
+ *
638
+ * The limit comes from the VM's hard register budget (~123 usable registers,
639
+ * checked on the final ISA layout). Each pair costs two result registers — a
640
+ * before-read and an after-read — that are both live at the closing abi-encode,
641
+ * so the compiler cannot coalesce them; that `2 × N` is the cost that scales.
642
+ * Token and owner address literals do not scale it, since constant-propagation
643
+ * merges identical-valued literals into one register. The cap leaves headroom
644
+ * for the inner-call / gas-measurement / abi-encode scaffolding.
645
+ */
646
+ const SIMULATE_MAX_TRACKED_BALANCES = 40;
647
+ /**
648
+ * Maximum number of funding `requirements` accepted by `POST /simulate`.
649
+ *
650
+ * Each requirement triggers a slot-discovery cycle (access-list probe + sentinel
651
+ * verification + RPC round trips) in slot-finder, so an unbounded array lets a
652
+ * single request amplify into arbitrary upstream RPC work. Bounded here at the
653
+ * trust boundary and re-enforced server-side in `rawSimulation.ts`.
654
+ */
655
+ const SIMULATE_MAX_REQUIREMENTS = 40;
656
+ //#endregion
657
+ //#region src/headers.ts
658
+ /**
659
+ * HTTP header names on the compose wire.
660
+ *
661
+ * Both the SDK (which sends the request header) and the backend (which reads it
662
+ * and answers with the response header) are part of the same handshake, so the
663
+ * names belong to the wire format rather than to either side of it.
664
+ */
665
+ /** Compose contract version the client was built against. Sent on every request. */
666
+ const COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
667
+ /** Compose contract version the backend serves. Returned on every compose response. */
668
+ const COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
669
+ //#endregion
670
+ //#region src/version.ts
671
+ const SEMANTIC_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
672
+ /**
673
+ * Parses the numeric triple of a semantic version. Prerelease and build
674
+ * suffixes are accepted and ignored: `0.5.1-staging.3` compares as `0.5.1`.
675
+ * Returns `undefined` for anything that is not a complete semver string,
676
+ * including the `dev` sentinel the SDK sends when it runs unbundled.
677
+ */
678
+ const parseVersion = (version) => {
679
+ const match = SEMANTIC_VERSION_PATTERN.exec(version);
680
+ if (!match) return void 0;
681
+ const major = Number(match[1]);
682
+ const minor = Number(match[2]);
683
+ const patch = Number(match[3]);
684
+ if (![
685
+ major,
686
+ minor,
687
+ patch
688
+ ].every(Number.isSafeInteger)) return void 0;
689
+ return {
690
+ major,
691
+ minor,
692
+ patch
693
+ };
639
694
  };
640
- var compareVersions = (a, b) => a.major !== b.major ? a.major - b.major : a.minor !== b.minor ? a.minor - b.minor : a.patch - b.patch;
641
- var checkCompatibility = (client, server, minimum = {
642
- major: server.major,
643
- minor: server.minor,
644
- patch: 0
695
+ const compareVersions = (a, b) => a.major !== b.major ? a.major - b.major : a.minor !== b.minor ? a.minor - b.minor : a.patch - b.patch;
696
+ /**
697
+ * Decides whether a client built against `client` may talk to a server that
698
+ * serves `server` and accepts clients down to `minimum`.
699
+ *
700
+ * - A client ahead of the server in any component is `server_outdated`. Even
701
+ * a patch-ahead client may send a field the server has never seen, and the
702
+ * guarantee must not depend on every server schema staying strict. This is
703
+ * the rollout window between an npm publish and the prod image bump.
704
+ * - A client below `minimum` is `sdk_outdated`: the server no longer serves
705
+ * the contract that client speaks.
706
+ * - Anything in between is compatible. Patch releases only add, so a client
707
+ * at or behind the server's patch never emits anything the server lacks;
708
+ * a client on an older minor is served because the server still emits the
709
+ * shapes that minor reads.
710
+ *
711
+ * `minimum` defaults to the server's own `major.minor.0`, which makes every
712
+ * minor bump a hard cutover. The backend passes its explicit floor so a minor
713
+ * bump can ship with the previous line still accepted; the SDK passes no floor
714
+ * because the server, not the client, decides how far back it serves.
715
+ */
716
+ const checkCompatibility = (client, server, minimum = {
717
+ major: server.major,
718
+ minor: server.minor,
719
+ patch: 0
645
720
  }) => {
646
- if (compareVersions(client, server) > 0) return "server_outdated";
647
- if (compareVersions(client, minimum) < 0) return "sdk_outdated";
648
- return "compatible";
721
+ if (compareVersions(client, server) > 0) return "server_outdated";
722
+ if (compareVersions(client, minimum) < 0) return "sdk_outdated";
723
+ return "compatible";
649
724
  };
650
-
651
- // src/materialiserMetadata.ts
652
- var foldMaterialiserMetadata = (meta, cases) => {
653
- if (meta.kind === "exact") return cases.exact(meta.amount);
654
- if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
655
- if (meta.kind === "capped") return cases.capped(meta.amount);
656
- return cases.runtime();
725
+ //#endregion
726
+ //#region src/materialiserMetadata.ts
727
+ const foldMaterialiserMetadata = (meta, cases) => {
728
+ if (meta.kind === "exact") return cases.exact(meta.amount);
729
+ if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
730
+ if (meta.kind === "capped") return cases.capped(meta.amount, meta.min);
731
+ return cases.runtime();
657
732
  };
658
-
659
- // src/zodSchemas.ts
660
- import z from "zod";
661
- var chainIdZod = z.number().int().positive();
662
- var evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
663
- var hexBytesZod = z.string().regex(HEX_BYTES);
664
- var uintStringZod = z.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, {
665
- message: "expected a uint256 decimal integer string"
666
- });
667
- var SolTypeZod = z.enum([
668
- "uint8",
669
- "uint16",
670
- "uint32",
671
- "uint64",
672
- "uint128",
673
- "uint256",
674
- "int128",
675
- "int256",
676
- "address",
677
- "bool",
678
- "bytes",
679
- "bytes4",
680
- "bytes32",
681
- "string"
733
+ //#endregion
734
+ //#region src/zodSchemas.ts
735
+ const chainIdZod = z.number().int().positive();
736
+ const evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
737
+ const hexBytesZod = z.string().regex(HEX_BYTES);
738
+ const uintStringZod = z.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, { message: "expected a uint256 decimal integer string" });
739
+ const SolTypeZod = z.enum([
740
+ "uint8",
741
+ "uint16",
742
+ "uint32",
743
+ "uint64",
744
+ "uint128",
745
+ "uint256",
746
+ "int128",
747
+ "int256",
748
+ "address",
749
+ "bool",
750
+ "bytes",
751
+ "bytes4",
752
+ "bytes32",
753
+ "string"
682
754
  ]);
683
- var ResourcePortZod = z.object({
684
- kind: z.literal("resource"),
685
- name: z.string(),
686
- accepts: z.enum(["erc20", "native", "any"]),
687
- mode: z.enum(["linear", "copy"]),
688
- optional: z.boolean().optional()
689
- });
690
- var HANDLE_UNITS = [
691
- "raw",
692
- "wad",
693
- "ray",
694
- "bps",
695
- "token-decimals"
755
+ const ResourcePortZod = z.object({
756
+ kind: z.literal("resource"),
757
+ name: z.string(),
758
+ accepts: z.enum([
759
+ "erc20",
760
+ "native",
761
+ "any"
762
+ ]),
763
+ mode: z.enum(["linear", "copy"]),
764
+ optional: z.boolean().optional()
765
+ });
766
+ const HANDLE_UNITS = [
767
+ "raw",
768
+ "wad",
769
+ "ray",
770
+ "bps",
771
+ "token-decimals"
696
772
  ];
697
- var STATIC_SOL_TYPES = [
698
- "uint256",
699
- "uint128",
700
- "uint64",
701
- "uint32",
702
- "uint16",
703
- "uint8",
704
- "address",
705
- "bool",
706
- "bytes32"
773
+ const STATIC_SOL_TYPES = [
774
+ "uint256",
775
+ "uint128",
776
+ "uint64",
777
+ "uint32",
778
+ "uint16",
779
+ "uint8",
780
+ "address",
781
+ "bool",
782
+ "bytes32"
707
783
  ];
708
- var HandleUnitsZod = z.enum(HANDLE_UNITS);
709
- var StaticSolTypeZod = z.enum(STATIC_SOL_TYPES);
710
- var STATIC_SOL_TYPE_SET = new Set(STATIC_SOL_TYPES);
711
- var isStaticSolType = (value) => STATIC_SOL_TYPE_SET.has(value);
712
- var HandlePortZod = z.object({
713
- kind: z.literal("handle"),
714
- name: z.string(),
715
- type: SolTypeZod,
716
- mode: z.enum(["linear", "copy"]),
717
- expose: z.boolean().optional(),
718
- units: HandleUnitsZod.optional(),
719
- optional: z.boolean().optional()
720
- });
721
- var InputPortZod = z.discriminatedUnion("kind", [
722
- ResourcePortZod,
723
- HandlePortZod
784
+ const HandleUnitsZod = z.enum(HANDLE_UNITS);
785
+ const StaticSolTypeZod = z.enum(STATIC_SOL_TYPES);
786
+ const STATIC_SOL_TYPE_SET = new Set(STATIC_SOL_TYPES);
787
+ const isStaticSolType = (value) => STATIC_SOL_TYPE_SET.has(value);
788
+ const HandlePortZod = z.object({
789
+ kind: z.literal("handle"),
790
+ name: z.string(),
791
+ type: SolTypeZod,
792
+ mode: z.enum(["linear", "copy"]),
793
+ expose: z.boolean().optional(),
794
+ units: HandleUnitsZod.optional(),
795
+ optional: z.boolean().optional()
796
+ });
797
+ const InputPortZod = z.discriminatedUnion("kind", [ResourcePortZod, HandlePortZod]);
798
+ const ResourceOutputPortZod = z.object({
799
+ kind: z.literal("resource_output"),
800
+ name: z.string(),
801
+ mode: z.enum(["linear", "copy"]),
802
+ availability: z.enum(["now", "future"]).optional(),
803
+ providesMinimum: z.boolean().optional(),
804
+ omitIfZero: z.boolean().optional(),
805
+ deliveryAddressInput: z.string().optional(),
806
+ countFrom: z.string().optional()
807
+ });
808
+ const OutputPortZod = z.discriminatedUnion("kind", [ResourceOutputPortZod, HandlePortZod]);
809
+ const ManifestOperationZod = z.object({
810
+ id: z.string(),
811
+ description: z.string().optional(),
812
+ inputs: z.array(InputPortZod),
813
+ outputs: z.array(OutputPortZod),
814
+ configSchema: z.unknown().optional()
815
+ });
816
+ const PortKindEnum = z.enum([
817
+ "resource",
818
+ "resource_output",
819
+ "handle"
724
820
  ]);
725
- var ResourceOutputPortZod = z.object({
726
- kind: z.literal("resource_output"),
727
- name: z.string(),
728
- mode: z.enum(["linear", "copy"]),
729
- availability: z.enum(["now", "future"]).optional(),
730
- providesMinimum: z.boolean().optional(),
731
- omitIfZero: z.boolean().optional(),
732
- deliveryAddressInput: z.string().optional(),
733
- // Declares an output *family*: the port expands, when a call's config is
734
- // bound, into one instance per element of the config array named here, or
735
- // into as many instances as the non-negative integer named here. Instances
736
- // are ordinary ports named `<name>.<index>`; see
737
- // `outputFamilies.ts:expandOutputPorts`.
738
- countFrom: z.string().optional()
739
- });
740
- var OutputPortZod = z.discriminatedUnion("kind", [
741
- ResourceOutputPortZod,
742
- HandlePortZod
821
+ const SelectorMatchZod = z.object({
822
+ kind: z.union([PortKindEnum, z.array(PortKindEnum)]),
823
+ mode: z.enum(["linear", "copy"]).optional(),
824
+ type: z.enum([
825
+ "erc20",
826
+ "native",
827
+ "any"
828
+ ]).optional()
829
+ });
830
+ const ConfigSelectionZod = z.object({
831
+ kind: z.literal("config"),
832
+ configKey: z.string(),
833
+ cardinality: z.enum(["one", "many"])
834
+ });
835
+ const AllMatchingSelectionZod = z.object({ kind: z.literal("all_matching") });
836
+ const SelectorSelectionZod = z.discriminatedUnion("kind", [ConfigSelectionZod, AllMatchingSelectionZod]);
837
+ const GuardSelectorZod = z.object({
838
+ binding: z.string(),
839
+ source: z.enum(["inputs", "outputs"]),
840
+ match: SelectorMatchZod,
841
+ selection: SelectorSelectionZod
842
+ });
843
+ const GuardCompatibilityZod = z.object({ selectors: z.array(GuardSelectorZod) });
844
+ const ManifestGuardZod = z.object({
845
+ kind: z.string(),
846
+ description: z.string().optional(),
847
+ configSchema: z.unknown().optional(),
848
+ compatibility: GuardCompatibilityZod.optional()
849
+ });
850
+ const ManifestMaterialiserZod = z.object({
851
+ kind: z.string(),
852
+ description: z.string().optional(),
853
+ accepts: z.enum([
854
+ "resource",
855
+ "handle",
856
+ "any"
857
+ ]),
858
+ configSchema: z.unknown().optional()
859
+ });
860
+ const ManifestPreconditionZod = z.object({
861
+ type: z.string(),
862
+ description: z.string().optional(),
863
+ configSchema: z.unknown().optional()
864
+ });
865
+ const ComposeManifestZod = z.object({
866
+ manifestVersion: z.number(),
867
+ manifestHash: z.string(),
868
+ flowSchema: z.object({}).passthrough(),
869
+ operations: z.array(ManifestOperationZod),
870
+ guards: z.array(ManifestGuardZod),
871
+ materialisers: z.array(ManifestMaterialiserZod),
872
+ preconditions: z.array(ManifestPreconditionZod).optional()
873
+ });
874
+ const hexStringZod = z.string().startsWith("0x");
875
+ const SettlementEscrowZod = z.object({
876
+ chainId: chainIdZod,
877
+ address: hexStringZod,
878
+ token: hexStringZod,
879
+ amount: z.string(),
880
+ cap: z.string(),
881
+ owner: hexStringZod,
882
+ refund: hexStringZod,
883
+ expiresAtMs: z.number().int().positive()
884
+ });
885
+ const assertionOwnerZod = z.union([evmAddressZod, z.enum(["escrow", "delivery"])]);
886
+ const AssertionSpecZod = z.discriminatedUnion("kind", [
887
+ z.object({
888
+ kind: z.literal("erc20BalanceGte"),
889
+ chainId: chainIdZod,
890
+ token: evmAddressZod,
891
+ owner: evmAddressZod,
892
+ minAmount: uintStringZod
893
+ }),
894
+ z.object({
895
+ kind: z.literal("nativeBalanceGte"),
896
+ chainId: chainIdZod,
897
+ owner: evmAddressZod,
898
+ minAmount: uintStringZod
899
+ }),
900
+ z.object({
901
+ kind: z.literal("call"),
902
+ chainId: chainIdZod,
903
+ to: evmAddressZod,
904
+ calldata: hexBytesZod,
905
+ comparator: z.enum([
906
+ "gte",
907
+ "eq",
908
+ "lte"
909
+ ]),
910
+ value: uintStringZod
911
+ }),
912
+ z.object({
913
+ kind: z.literal("erc20BalanceDeltaGte"),
914
+ chainId: z.number().int().positive(),
915
+ token: evmAddressZod,
916
+ owner: assertionOwnerZod,
917
+ minDelta: uintStringZod
918
+ }),
919
+ z.object({
920
+ kind: z.literal("nativeBalanceDeltaGte"),
921
+ chainId: z.number().int().positive(),
922
+ owner: assertionOwnerZod,
923
+ minDelta: uintStringZod
924
+ })
743
925
  ]);
744
- var ManifestOperationZod = z.object({
745
- id: z.string(),
746
- description: z.string().optional(),
747
- inputs: z.array(InputPortZod),
748
- outputs: z.array(OutputPortZod),
749
- configSchema: z.unknown().optional()
750
- });
751
- var PortKindEnum = z.enum(["resource", "resource_output", "handle"]);
752
- var SelectorMatchZod = z.object({
753
- kind: z.union([PortKindEnum, z.array(PortKindEnum)]),
754
- mode: z.enum(["linear", "copy"]).optional(),
755
- type: z.enum(["erc20", "native", "any"]).optional()
756
- });
757
- var ConfigSelectionZod = z.object({
758
- kind: z.literal("config"),
759
- configKey: z.string(),
760
- cardinality: z.enum(["one", "many"])
761
- });
762
- var AllMatchingSelectionZod = z.object({
763
- kind: z.literal("all_matching")
764
- });
765
- var SelectorSelectionZod = z.discriminatedUnion("kind", [
766
- ConfigSelectionZod,
767
- AllMatchingSelectionZod
768
- ]);
769
- var GuardSelectorZod = z.object({
770
- binding: z.string(),
771
- source: z.enum(["inputs", "outputs"]),
772
- match: SelectorMatchZod,
773
- selection: SelectorSelectionZod
774
- });
775
- var GuardCompatibilityZod = z.object({
776
- selectors: z.array(GuardSelectorZod)
777
- });
778
- var ManifestGuardZod = z.object({
779
- kind: z.string(),
780
- description: z.string().optional(),
781
- configSchema: z.unknown().optional(),
782
- compatibility: GuardCompatibilityZod.optional()
783
- });
784
- var ManifestMaterialiserZod = z.object({
785
- kind: z.string(),
786
- description: z.string().optional(),
787
- accepts: z.enum(["resource", "handle", "any"]),
788
- configSchema: z.unknown().optional()
789
- });
790
- var ManifestPreconditionZod = z.object({
791
- type: z.string(),
792
- description: z.string().optional(),
793
- configSchema: z.unknown().optional()
794
- });
795
- var ComposeManifestZod = z.object({
796
- manifestVersion: z.number(),
797
- manifestHash: z.string(),
798
- flowSchema: z.object({}).passthrough(),
799
- operations: z.array(ManifestOperationZod),
800
- guards: z.array(ManifestGuardZod),
801
- materialisers: z.array(ManifestMaterialiserZod),
802
- preconditions: z.array(ManifestPreconditionZod).optional()
803
- });
804
- var hexStringZod = z.string().startsWith("0x");
805
- var SettlementEscrowZod = z.object({
806
- chainId: chainIdZod,
807
- address: hexStringZod,
808
- token: hexStringZod,
809
- amount: z.string(),
810
- cap: z.string(),
811
- owner: hexStringZod,
812
- refund: hexStringZod,
813
- expiresAtMs: z.number().int().positive()
814
- });
815
- var assertionOwnerZod = z.union([
816
- evmAddressZod,
817
- z.enum(["escrow", "delivery"])
818
- ]);
819
- var AssertionSpecZod = z.discriminatedUnion("kind", [
820
- z.object({
821
- kind: z.literal("erc20BalanceGte"),
822
- chainId: chainIdZod,
823
- token: evmAddressZod,
824
- owner: evmAddressZod,
825
- minAmount: uintStringZod
826
- }),
827
- z.object({
828
- kind: z.literal("nativeBalanceGte"),
829
- chainId: chainIdZod,
830
- owner: evmAddressZod,
831
- minAmount: uintStringZod
832
- }),
833
- z.object({
834
- kind: z.literal("call"),
835
- chainId: chainIdZod,
836
- to: evmAddressZod,
837
- calldata: hexBytesZod,
838
- comparator: z.enum(["gte", "eq", "lte"]),
839
- value: uintStringZod
840
- }),
841
- z.object({
842
- kind: z.literal("erc20BalanceDeltaGte"),
843
- chainId: z.number().int().positive(),
844
- token: evmAddressZod,
845
- owner: assertionOwnerZod,
846
- minDelta: uintStringZod
847
- }),
848
- z.object({
849
- kind: z.literal("nativeBalanceDeltaGte"),
850
- chainId: z.number().int().positive(),
851
- owner: assertionOwnerZod,
852
- minDelta: uintStringZod
853
- })
854
- ]);
855
- var assertionSpecOptionByKind = (kind) => {
856
- const option = AssertionSpecZod.options.find(
857
- (o) => o.shape.kind.value === kind
858
- );
859
- if (option === void 0) {
860
- throw new Error(`AssertionSpecZod has no member with kind "${kind}"`);
861
- }
862
- return option;
926
+ const assertionSpecOptionByKind = (kind) => {
927
+ const option = AssertionSpecZod.options.find((o) => o.shape.kind.value === kind);
928
+ if (option === void 0) throw new Error(`AssertionSpecZod has no member with kind "${kind}"`);
929
+ return option;
863
930
  };
864
- var AssertedPredicateZod = z.discriminatedUnion("kind", [
865
- z.object({
866
- kind: z.literal("erc20BalanceGte"),
867
- chainId: z.number().int().positive(),
868
- token: evmAddressZod,
869
- owner: assertionOwnerZod,
870
- minAmount: uintStringZod
871
- }),
872
- z.object({
873
- kind: z.literal("nativeBalanceGte"),
874
- chainId: z.number().int().positive(),
875
- owner: assertionOwnerZod,
876
- minAmount: uintStringZod
877
- }),
878
- assertionSpecOptionByKind("call"),
879
- assertionSpecOptionByKind("erc20BalanceDeltaGte"),
880
- assertionSpecOptionByKind("nativeBalanceDeltaGte")
931
+ const AssertedPredicateZod = z.discriminatedUnion("kind", [
932
+ z.object({
933
+ kind: z.literal("erc20BalanceGte"),
934
+ chainId: z.number().int().positive(),
935
+ token: evmAddressZod,
936
+ owner: assertionOwnerZod,
937
+ minAmount: uintStringZod
938
+ }),
939
+ z.object({
940
+ kind: z.literal("nativeBalanceGte"),
941
+ chainId: z.number().int().positive(),
942
+ owner: assertionOwnerZod,
943
+ minAmount: uintStringZod
944
+ }),
945
+ assertionSpecOptionByKind("call"),
946
+ assertionSpecOptionByKind("erc20BalanceDeltaGte"),
947
+ assertionSpecOptionByKind("nativeBalanceDeltaGte")
881
948
  ]);
882
- var VerificationDescriptorZod = z.object({
883
- validationProgramHash: z.string().regex(BYTES32_LOWER_HEX),
884
- // The C5 echo's second hash (GD-8): the params-vector content hash
885
- // (`paramsHash`, C1). Required and jointly necessary with the value-blind
886
- // `validationProgramHash`.
887
- paramsHash: z.string().regex(BYTES32_LOWER_HEX),
888
- assertedPredicate: z.array(AssertedPredicateZod)
889
- });
890
- var SettlementZod = z.object({
891
- escrow: SettlementEscrowZod.optional()
892
- });
893
- export {
894
- ARC_CHAIN_ID,
895
- ARC_NATIVE_ERC20,
896
- ARC_NATIVE_SCALE,
897
- AppliedGuardSchema,
898
- AssertedErc20BalanceGteSpecSchema,
899
- AssertedNativeBalanceGteSpecSchema,
900
- AssertedPredicateSchema,
901
- AssertedPredicateZod,
902
- AssertionOwnerSchema,
903
- AssertionSpecSchema,
904
- AssertionSpecZod,
905
- BindValueSchema,
906
- Bytes32HexSchema,
907
- COMPOSER_SDK_VERSION_HEADER,
908
- COMPOSE_VERSION_HEADER,
909
- CONTINUATION_COMMITMENT_OP_ID,
910
- CallCheckSpecSchema,
911
- CallSchema,
912
- ComposeManifestZod,
913
- ContinuationIntentSchema,
914
- ContinuationOutcomeSchema,
915
- EVMAddressString,
916
- EVM_NATIVE_SENTINEL,
917
- Erc20BalanceDeltaGteSpecSchema,
918
- Erc20BalanceGteSpecSchema,
919
- FlowInputSchema,
920
- FlowSchema,
921
- GuardCompatibilityZod,
922
- GuardSelectorZod,
923
- HANDLE_UNITS,
924
- HandleInputSchema,
925
- HandlePortZod,
926
- HandleUnitsZod,
927
- HexStringSchema,
928
- InputPortZod,
929
- IntegerString,
930
- LineageSchema,
931
- LiteralBindingSchema,
932
- ManifestGuardZod,
933
- ManifestMaterialiserZod,
934
- ManifestOperationZod,
935
- ManifestPreconditionZod,
936
- NativeBalanceDeltaGteSpecSchema,
937
- NativeBalanceGteSpecSchema,
938
- OutputPortZod,
939
- PROVIDER_KIND,
940
- Phase1ArtifactSchema,
941
- RESERVED_REF_SCOPES,
942
- RefSchema,
943
- ResourceInputSchema,
944
- ResourceOutputPortZod,
945
- ResourcePortZod,
946
- ResourceSchema,
947
- SIMULATE_MAX_REQUIREMENTS,
948
- SIMULATE_MAX_TRACKED_BALANCES,
949
- STATIC_SOL_TYPES,
950
- SettlementZod,
951
- SolTypeSchema,
952
- StaticSolTypeZod,
953
- TEMPO_CHAIN_ID,
954
- TEMPO_NATIVE_ERC20,
955
- UuidSchema,
956
- VerificationDescriptorSchema,
957
- VerificationDescriptorZod,
958
- canonicalAssertedPredicate,
959
- canonicalNativeAddress,
960
- checkCompatibility,
961
- copy,
962
- erc20,
963
- erc20Allowance,
964
- erc20Balance,
965
- erc20Resource,
966
- erc20Token,
967
- expandOutputPorts,
968
- familySize,
969
- flowInputMode,
970
- flowInputResource,
971
- flowInputType,
972
- foldChainCapabilities,
973
- foldMaterialiserMetadata,
974
- foldRef,
975
- foldResource,
976
- getChainCapabilities,
977
- handle,
978
- hasErc20CanonicalNative,
979
- instancePortName,
980
- isAsErc20Chain,
981
- isContextKey,
982
- isERC20Resource,
983
- isErc20AllowancePrecondition,
984
- isErc20BalancePrecondition,
985
- isFutureResourceOutput,
986
- isHandlePort,
987
- isMaterialiserInput,
988
- isMsgValueNative,
989
- isNativeAddressForChain,
990
- isNativeBalancePrecondition,
991
- isNativeResource,
992
- isOutputFamily,
993
- isRef,
994
- isResourceInput,
995
- isResourceOutputPort,
996
- isResourcePort,
997
- isStaticSolType,
998
- linear,
999
- native,
1000
- nativeBalance,
1001
- nativeCheckPolicy,
1002
- nativeResource,
1003
- normalizeNativeTokenAddress,
1004
- normalizeResource,
1005
- opHandle,
1006
- parseRef,
1007
- parseVersion,
1008
- providerKindByName,
1009
- providerKindNames,
1010
- readResource,
1011
- ref,
1012
- refKey,
1013
- resource,
1014
- resourceKey,
1015
- resourceOutput,
1016
- resourceToken,
1017
- resourcesEqual,
1018
- settledOutcome
1019
- };
949
+ const VerificationDescriptorZod = z.object({
950
+ validationProgramHash: z.string().regex(BYTES32_LOWER_HEX),
951
+ paramsHash: z.string().regex(BYTES32_LOWER_HEX),
952
+ assertedPredicate: z.array(AssertedPredicateZod)
953
+ });
954
+ const SettlementZod = z.object({ escrow: SettlementEscrowZod.optional() });
955
+ //#endregion
956
+ export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, AppliedGuardSchema, AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, AssertedPredicateSchema, AssertedPredicateZod, AssertionOwnerSchema, AssertionSpecSchema, AssertionSpecZod, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, CallCheckSpecSchema, CallSchema, ComposeManifestZod, ContinuationIntentSchema, ContinuationOutcomeSchema, EVMAddressString, EVM_NATIVE_SENTINEL, Erc20BalanceDeltaGteSpecSchema, Erc20BalanceGteSpecSchema, FlowInputSchema, FlowSchema, GuardCompatibilityZod, GuardSelectorZod, HANDLE_UNITS, HandleInputSchema, HandlePortZod, HandleUnitsZod, HexStringSchema, InputPortZod, IntegerString, LineageSchema, LiteralBindingSchema, ManifestGuardZod, ManifestMaterialiserZod, ManifestOperationZod, ManifestPreconditionZod, NativeBalanceDeltaGteSpecSchema, NativeBalanceGteSpecSchema, OutputPortZod, PROVIDER_KIND, Phase1ArtifactSchema, RESERVED_REF_SCOPES, RefSchema, ResourceInputSchema, ResourceOutputPortZod, ResourcePortZod, ResourceSchema, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, SettlementZod, SolTypeSchema, StaticSolTypeZod, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, UuidSchema, VerificationDescriptorSchema, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, expandOutputPorts, familySize, flowInputMode, flowInputResource, flowInputType, foldChainCapabilities, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, hasErc20CanonicalNative, instancePortName, isAsErc20Chain, isContextKey, isERC20Resource, isErc20AllowancePrecondition, isErc20BalancePrecondition, isFutureResourceOutput, isHandlePort, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isOutputFamily, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeCheckPolicy, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindByName, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual, settledOutcome };