@lifi/compose-spec 0.6.2 → 0.7.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/README.md +3 -1
- package/dist/index.cjs +176 -63
- package/dist/index.d.cts +213 -113
- package/dist/index.d.ts +213 -113
- package/dist/index.js +167 -62
- package/package.json +3 -2
- package/src/compile.ts +31 -18
- package/src/constructors.ts +12 -2
- package/src/continuation.ts +78 -31
- package/src/descriptor.ts +10 -7
- package/src/flowSchema.ts +99 -2
- package/src/hexPatterns.ts +26 -5
- package/src/index.ts +16 -2
- package/src/outputFamilies.ts +68 -0
- package/src/zodSchemas.ts +81 -41
package/dist/index.js
CHANGED
|
@@ -83,6 +83,14 @@ var normalizeResource = (r) => {
|
|
|
83
83
|
};
|
|
84
84
|
var normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
|
|
85
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
|
+
|
|
86
94
|
// src/flowSchema.ts
|
|
87
95
|
var SolTypeSchema = Schema.Literal(
|
|
88
96
|
"uint8",
|
|
@@ -104,11 +112,43 @@ var ChainIdSchema = Schema.Number.pipe(
|
|
|
104
112
|
Schema.int(),
|
|
105
113
|
Schema.positive()
|
|
106
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
|
+
);
|
|
107
147
|
var RawResourceSchema = Schema.Union(
|
|
108
148
|
Schema.Struct({ kind: Schema.Literal("native"), chainId: ChainIdSchema }),
|
|
109
149
|
Schema.Struct({
|
|
110
150
|
kind: Schema.Literal("erc20"),
|
|
111
|
-
token:
|
|
151
|
+
token: EVMAddressString,
|
|
112
152
|
chainId: ChainIdSchema
|
|
113
153
|
})
|
|
114
154
|
);
|
|
@@ -149,8 +189,13 @@ var AppliedGuardSchema = Schema.Struct(
|
|
|
149
189
|
{ kind: Schema.String },
|
|
150
190
|
{ key: Schema.String, value: Schema.Unknown }
|
|
151
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
|
+
);
|
|
152
197
|
var CallSchema = Schema.Struct({
|
|
153
|
-
id:
|
|
198
|
+
id: NodeIdSchema,
|
|
154
199
|
op: Schema.String,
|
|
155
200
|
bind: Schema.optionalWith(
|
|
156
201
|
Schema.Record({ key: Schema.String, value: BindValueSchema }),
|
|
@@ -162,21 +207,29 @@ var CallSchema = Schema.Struct({
|
|
|
162
207
|
),
|
|
163
208
|
guards: Schema.optional(Schema.Array(AppliedGuardSchema))
|
|
164
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
|
+
});
|
|
165
217
|
var FlowSchema = Schema.Struct({
|
|
166
218
|
version: Schema.Literal(1),
|
|
167
219
|
id: Schema.String,
|
|
168
220
|
chainId: ChainIdSchema,
|
|
169
221
|
inputs: Schema.Array(FlowInputSchema),
|
|
170
|
-
nodes: Schema.Array(CallSchema)
|
|
222
|
+
nodes: Schema.Array(CallSchema),
|
|
223
|
+
lineage: Schema.optional(LineageSchema)
|
|
171
224
|
});
|
|
172
225
|
|
|
173
226
|
// src/continuation.ts
|
|
174
227
|
import { ParseResult, Schema as Schema2 } from "effect";
|
|
175
228
|
var CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
|
|
176
229
|
var RawContinuationOutcomeSchema = Schema2.Struct({
|
|
177
|
-
token:
|
|
178
|
-
minAmount:
|
|
179
|
-
destination:
|
|
230
|
+
token: EVMAddressString,
|
|
231
|
+
minAmount: IntegerString,
|
|
232
|
+
destination: EVMAddressString,
|
|
180
233
|
chainId: ChainIdSchema
|
|
181
234
|
});
|
|
182
235
|
var ContinuationOutcomeSchema = Schema2.transform(
|
|
@@ -195,13 +248,24 @@ var ContinuationIntentSchema = Schema2.Struct({
|
|
|
195
248
|
// `NonEmptyArray` enforces ≥1 outcome at the parse boundary, so downstream needs no guard.
|
|
196
249
|
outcomes: Schema2.NonEmptyArray(ContinuationOutcomeSchema),
|
|
197
250
|
continuationFlow: Schema2.optional(FlowSchema),
|
|
198
|
-
validity: Schema2.Struct({ expiresAtMs:
|
|
251
|
+
validity: Schema2.Struct({ expiresAtMs: EpochMsSchema }),
|
|
199
252
|
perpetual: Schema2.optional(Schema2.Boolean),
|
|
200
253
|
provider: Schema2.optional(Schema2.String),
|
|
201
254
|
// Funding-path mode. The HTTP wire contract is documented by
|
|
202
255
|
// `ComposeActionsSchema` in `@lifi/api-schemas`.
|
|
203
256
|
funding: Schema2.optional(Schema2.Literal("inline", "external"))
|
|
204
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
|
+
});
|
|
205
269
|
var Phase1ArtifactSchema = Schema2.Union(
|
|
206
270
|
Schema2.Struct({
|
|
207
271
|
kind: Schema2.Literal("transaction"),
|
|
@@ -213,7 +277,8 @@ var Phase1ArtifactSchema = Schema2.Union(
|
|
|
213
277
|
value: Schema2.String,
|
|
214
278
|
chainId: Schema2.Number
|
|
215
279
|
})
|
|
216
|
-
)
|
|
280
|
+
),
|
|
281
|
+
escrow: Schema2.optional(Phase1EscrowSchema)
|
|
217
282
|
}),
|
|
218
283
|
Schema2.Struct({
|
|
219
284
|
kind: Schema2.Literal("signables"),
|
|
@@ -221,31 +286,30 @@ var Phase1ArtifactSchema = Schema2.Union(
|
|
|
221
286
|
}),
|
|
222
287
|
Schema2.Struct({ kind: Schema2.Literal("none") })
|
|
223
288
|
);
|
|
224
|
-
var HexStringSchema = Schema2.String.pipe(Schema2.startsWith("0x"));
|
|
225
289
|
var AssertionOwnerSchema = Schema2.Union(
|
|
226
|
-
|
|
290
|
+
EVMAddressString,
|
|
227
291
|
Schema2.Literal("escrow", "delivery")
|
|
228
292
|
);
|
|
229
293
|
var Erc20BalanceGteSpecSchema = Schema2.Struct({
|
|
230
294
|
kind: Schema2.Literal("erc20BalanceGte"),
|
|
231
295
|
chainId: ChainIdSchema,
|
|
232
|
-
token:
|
|
233
|
-
owner:
|
|
234
|
-
minAmount:
|
|
296
|
+
token: EVMAddressString,
|
|
297
|
+
owner: EVMAddressString,
|
|
298
|
+
minAmount: IntegerString
|
|
235
299
|
});
|
|
236
300
|
var NativeBalanceGteSpecSchema = Schema2.Struct({
|
|
237
301
|
kind: Schema2.Literal("nativeBalanceGte"),
|
|
238
302
|
chainId: ChainIdSchema,
|
|
239
|
-
owner:
|
|
240
|
-
minAmount:
|
|
303
|
+
owner: EVMAddressString,
|
|
304
|
+
minAmount: IntegerString
|
|
241
305
|
});
|
|
242
306
|
var CallCheckSpecSchema = Schema2.Struct({
|
|
243
307
|
kind: Schema2.Literal("call"),
|
|
244
308
|
chainId: ChainIdSchema,
|
|
245
|
-
to:
|
|
246
|
-
calldata:
|
|
309
|
+
to: EVMAddressString,
|
|
310
|
+
calldata: HexBytesString,
|
|
247
311
|
comparator: Schema2.Literal("gte", "eq", "lte"),
|
|
248
|
-
value:
|
|
312
|
+
value: IntegerString
|
|
249
313
|
});
|
|
250
314
|
var asErc20BalanceGteCheck = (check, token) => ({
|
|
251
315
|
kind: "erc20BalanceGte",
|
|
@@ -282,15 +346,15 @@ var CheckSchema = Schema2.transformOrFail(
|
|
|
282
346
|
var Erc20BalanceDeltaGteSpecSchema = Schema2.Struct({
|
|
283
347
|
kind: Schema2.Literal("erc20BalanceDeltaGte"),
|
|
284
348
|
chainId: ChainIdSchema,
|
|
285
|
-
token:
|
|
349
|
+
token: EVMAddressString,
|
|
286
350
|
owner: AssertionOwnerSchema,
|
|
287
|
-
minDelta:
|
|
351
|
+
minDelta: IntegerString
|
|
288
352
|
});
|
|
289
353
|
var NativeBalanceDeltaGteSpecSchema = Schema2.Struct({
|
|
290
354
|
kind: Schema2.Literal("nativeBalanceDeltaGte"),
|
|
291
355
|
chainId: ChainIdSchema,
|
|
292
356
|
owner: AssertionOwnerSchema,
|
|
293
|
-
minDelta:
|
|
357
|
+
minDelta: IntegerString
|
|
294
358
|
});
|
|
295
359
|
var AssertionSpecSchema = Schema2.Union(
|
|
296
360
|
Erc20BalanceGteSpecSchema,
|
|
@@ -303,7 +367,7 @@ var ContinuationPlanSchema = Schema2.Struct({
|
|
|
303
367
|
chainId: ChainIdSchema,
|
|
304
368
|
nextFlow: FlowSchema,
|
|
305
369
|
check: CheckSchema,
|
|
306
|
-
validity: Schema2.Struct({ expiresAtMs:
|
|
370
|
+
validity: Schema2.Struct({ expiresAtMs: EpochMsSchema }),
|
|
307
371
|
correlationId: Schema2.optional(Schema2.String)
|
|
308
372
|
});
|
|
309
373
|
var settledOutcome = (intent) => intent.outcomes[0];
|
|
@@ -313,26 +377,21 @@ var isEQCheck = (check) => check.kind === "call" && check.comparator === "eq";
|
|
|
313
377
|
|
|
314
378
|
// src/descriptor.ts
|
|
315
379
|
import { ParseResult as ParseResult2, Schema as Schema3 } from "effect";
|
|
316
|
-
|
|
317
|
-
// src/hexPatterns.ts
|
|
318
|
-
var BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
319
|
-
|
|
320
|
-
// src/descriptor.ts
|
|
321
380
|
var Bytes32HexSchema = Schema3.String.pipe(
|
|
322
381
|
Schema3.pattern(BYTES32_LOWER_HEX)
|
|
323
382
|
);
|
|
324
383
|
var AssertedErc20BalanceGteSpecSchema = Schema3.Struct({
|
|
325
384
|
kind: Schema3.Literal("erc20BalanceGte"),
|
|
326
385
|
chainId: ChainIdSchema,
|
|
327
|
-
token:
|
|
386
|
+
token: EVMAddressString,
|
|
328
387
|
owner: AssertionOwnerSchema,
|
|
329
|
-
minAmount:
|
|
388
|
+
minAmount: IntegerString
|
|
330
389
|
});
|
|
331
390
|
var AssertedNativeBalanceGteSpecSchema = Schema3.Struct({
|
|
332
391
|
kind: Schema3.Literal("nativeBalanceGte"),
|
|
333
392
|
chainId: ChainIdSchema,
|
|
334
393
|
owner: AssertionOwnerSchema,
|
|
335
|
-
minAmount:
|
|
394
|
+
minAmount: IntegerString
|
|
336
395
|
});
|
|
337
396
|
var RawAssertedPredicateSchema = Schema3.Union(
|
|
338
397
|
AssertedErc20BalanceGteSpecSchema,
|
|
@@ -497,10 +556,35 @@ var resourceOutput = (name, options) => {
|
|
|
497
556
|
...optionalProp("availability", opts?.availability),
|
|
498
557
|
...optionalProp("providesMinimum", opts?.providesMinimum),
|
|
499
558
|
...optionalProp("omitIfZero", opts?.omitIfZero),
|
|
500
|
-
...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput)
|
|
559
|
+
...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput),
|
|
560
|
+
...optionalProp("countFrom", opts?.countFrom)
|
|
501
561
|
};
|
|
502
562
|
};
|
|
503
563
|
|
|
564
|
+
// src/outputFamilies.ts
|
|
565
|
+
var isOutputFamily = (port) => port.kind === "resource_output" && port.countFrom !== void 0;
|
|
566
|
+
var instancePortName = (family, index) => `${family}.${index}`;
|
|
567
|
+
var familySize = (family, config) => {
|
|
568
|
+
const source = config[family.countFrom];
|
|
569
|
+
if (Array.isArray(source)) return source.length;
|
|
570
|
+
if (Number.isSafeInteger(source) && source >= 0) {
|
|
571
|
+
return source;
|
|
572
|
+
}
|
|
573
|
+
throw new Error(
|
|
574
|
+
`Output family '${family.name}' counts from config '${family.countFrom}', which is neither an array nor a non-negative integer`
|
|
575
|
+
);
|
|
576
|
+
};
|
|
577
|
+
var expandFamily = (port, config) => {
|
|
578
|
+
const { countFrom: _countFrom, ...instance } = port;
|
|
579
|
+
return Array.from({ length: familySize(port, config) }, (_, index) => ({
|
|
580
|
+
...instance,
|
|
581
|
+
name: instancePortName(port.name, index)
|
|
582
|
+
}));
|
|
583
|
+
};
|
|
584
|
+
var expandOutputPorts = (declared, config) => declared.some(isOutputFamily) ? declared.flatMap(
|
|
585
|
+
(port) => isOutputFamily(port) ? expandFamily(port, config) : [port]
|
|
586
|
+
) : declared;
|
|
587
|
+
|
|
504
588
|
// src/ref.ts
|
|
505
589
|
var isContextKey = (key) => key === "sender" || key === "executionAddress";
|
|
506
590
|
var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
|
|
@@ -599,6 +683,12 @@ var foldMaterialiserMetadata = (meta, cases) => {
|
|
|
599
683
|
// src/zodSchemas.ts
|
|
600
684
|
import z from "zod";
|
|
601
685
|
var chainIdZod = z.number().int().positive();
|
|
686
|
+
var evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
|
|
687
|
+
var hexBytesZod = z.string().regex(HEX_BYTES);
|
|
688
|
+
var uintStringZod = z.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, {
|
|
689
|
+
message: "expected a uint256 decimal integer string"
|
|
690
|
+
});
|
|
691
|
+
var epochMsZod = z.number().int().min(-MAX_DATE_MS).max(MAX_DATE_MS);
|
|
602
692
|
var SolTypeZod = z.enum([
|
|
603
693
|
"uint8",
|
|
604
694
|
"uint16",
|
|
@@ -664,7 +754,13 @@ var ResourceOutputPortZod = z.object({
|
|
|
664
754
|
availability: z.enum(["now", "future"]).optional(),
|
|
665
755
|
providesMinimum: z.boolean().optional(),
|
|
666
756
|
omitIfZero: z.boolean().optional(),
|
|
667
|
-
deliveryAddressInput: z.string().optional()
|
|
757
|
+
deliveryAddressInput: z.string().optional(),
|
|
758
|
+
// Declares an output *family*: the port expands, when a call's config is
|
|
759
|
+
// bound, into one instance per element of the config array named here, or
|
|
760
|
+
// into as many instances as the non-negative integer named here. Instances
|
|
761
|
+
// are ordinary ports named `<name>.<index>`; see
|
|
762
|
+
// `outputFamilies.ts:expandOutputPorts`.
|
|
763
|
+
countFrom: z.string().optional()
|
|
668
764
|
});
|
|
669
765
|
var OutputPortZod = z.discriminatedUnion("kind", [
|
|
670
766
|
ResourceOutputPortZod,
|
|
@@ -730,45 +826,42 @@ var ComposeManifestZod = z.object({
|
|
|
730
826
|
materialisers: z.array(ManifestMaterialiserZod),
|
|
731
827
|
preconditions: z.array(ManifestPreconditionZod).optional()
|
|
732
828
|
});
|
|
733
|
-
var Phase1ArtifactZod = z.discriminatedUnion("kind", [
|
|
734
|
-
z.object({
|
|
735
|
-
kind: z.literal("transaction"),
|
|
736
|
-
funding: z.enum(["inline", "external"])
|
|
737
|
-
}),
|
|
738
|
-
z.object({
|
|
739
|
-
kind: z.literal("signables"),
|
|
740
|
-
typedData: z.array(z.unknown())
|
|
741
|
-
}),
|
|
742
|
-
z.object({
|
|
743
|
-
kind: z.literal("none")
|
|
744
|
-
})
|
|
745
|
-
]);
|
|
746
829
|
var hexStringZod = z.string().startsWith("0x");
|
|
830
|
+
var SettlementEscrowZod = z.object({
|
|
831
|
+
chainId: chainIdZod,
|
|
832
|
+
address: hexStringZod,
|
|
833
|
+
token: hexStringZod,
|
|
834
|
+
amount: z.string(),
|
|
835
|
+
cap: z.string(),
|
|
836
|
+
owner: hexStringZod,
|
|
837
|
+
refund: hexStringZod,
|
|
838
|
+
expiresAtMs: z.number().int().positive()
|
|
839
|
+
});
|
|
747
840
|
var assertionOwnerZod = z.union([
|
|
748
|
-
|
|
841
|
+
evmAddressZod,
|
|
749
842
|
z.enum(["escrow", "delivery"])
|
|
750
843
|
]);
|
|
751
844
|
var CheckZod = z.discriminatedUnion("kind", [
|
|
752
845
|
z.object({
|
|
753
846
|
kind: z.literal("erc20BalanceGte"),
|
|
754
847
|
chainId: chainIdZod,
|
|
755
|
-
token:
|
|
756
|
-
owner:
|
|
757
|
-
minAmount:
|
|
848
|
+
token: evmAddressZod,
|
|
849
|
+
owner: evmAddressZod,
|
|
850
|
+
minAmount: uintStringZod
|
|
758
851
|
}),
|
|
759
852
|
z.object({
|
|
760
853
|
kind: z.literal("nativeBalanceGte"),
|
|
761
854
|
chainId: chainIdZod,
|
|
762
|
-
owner:
|
|
763
|
-
minAmount:
|
|
855
|
+
owner: evmAddressZod,
|
|
856
|
+
minAmount: uintStringZod
|
|
764
857
|
}),
|
|
765
858
|
z.object({
|
|
766
859
|
kind: z.literal("call"),
|
|
767
860
|
chainId: chainIdZod,
|
|
768
|
-
to:
|
|
769
|
-
calldata:
|
|
861
|
+
to: evmAddressZod,
|
|
862
|
+
calldata: hexBytesZod,
|
|
770
863
|
comparator: z.enum(["gte", "eq", "lte"]),
|
|
771
|
-
value:
|
|
864
|
+
value: uintStringZod
|
|
772
865
|
})
|
|
773
866
|
]);
|
|
774
867
|
var AssertionSpecZod = z.discriminatedUnion("kind", [
|
|
@@ -776,15 +869,15 @@ var AssertionSpecZod = z.discriminatedUnion("kind", [
|
|
|
776
869
|
z.object({
|
|
777
870
|
kind: z.literal("erc20BalanceDeltaGte"),
|
|
778
871
|
chainId: z.number().int().positive(),
|
|
779
|
-
token:
|
|
872
|
+
token: evmAddressZod,
|
|
780
873
|
owner: assertionOwnerZod,
|
|
781
|
-
minDelta:
|
|
874
|
+
minDelta: uintStringZod
|
|
782
875
|
}),
|
|
783
876
|
z.object({
|
|
784
877
|
kind: z.literal("nativeBalanceDeltaGte"),
|
|
785
878
|
chainId: z.number().int().positive(),
|
|
786
879
|
owner: assertionOwnerZod,
|
|
787
|
-
minDelta:
|
|
880
|
+
minDelta: uintStringZod
|
|
788
881
|
})
|
|
789
882
|
]);
|
|
790
883
|
var assertionSpecOptionByKind = (kind) => {
|
|
@@ -800,15 +893,15 @@ var AssertedPredicateZod = z.discriminatedUnion("kind", [
|
|
|
800
893
|
z.object({
|
|
801
894
|
kind: z.literal("erc20BalanceGte"),
|
|
802
895
|
chainId: z.number().int().positive(),
|
|
803
|
-
token:
|
|
896
|
+
token: evmAddressZod,
|
|
804
897
|
owner: assertionOwnerZod,
|
|
805
|
-
minAmount:
|
|
898
|
+
minAmount: uintStringZod
|
|
806
899
|
}),
|
|
807
900
|
z.object({
|
|
808
901
|
kind: z.literal("nativeBalanceGte"),
|
|
809
902
|
chainId: z.number().int().positive(),
|
|
810
903
|
owner: assertionOwnerZod,
|
|
811
|
-
minAmount:
|
|
904
|
+
minAmount: uintStringZod
|
|
812
905
|
}),
|
|
813
906
|
assertionSpecOptionByKind("call"),
|
|
814
907
|
assertionSpecOptionByKind("erc20BalanceDeltaGte"),
|
|
@@ -826,9 +919,13 @@ var ContinuationPlanZod = z.object({
|
|
|
826
919
|
chainId: chainIdZod,
|
|
827
920
|
nextFlow: z.unknown(),
|
|
828
921
|
check: CheckZod,
|
|
829
|
-
validity: z.object({ expiresAtMs:
|
|
922
|
+
validity: z.object({ expiresAtMs: epochMsZod }),
|
|
830
923
|
correlationId: z.string().optional()
|
|
831
924
|
});
|
|
925
|
+
var SettlementZod = z.object({
|
|
926
|
+
escrow: SettlementEscrowZod.optional(),
|
|
927
|
+
continuation: ContinuationPlanZod.optional()
|
|
928
|
+
});
|
|
832
929
|
export {
|
|
833
930
|
ARC_CHAIN_ID,
|
|
834
931
|
ARC_NATIVE_ERC20,
|
|
@@ -855,6 +952,7 @@ export {
|
|
|
855
952
|
ContinuationOutcomeSchema,
|
|
856
953
|
ContinuationPlanSchema,
|
|
857
954
|
ContinuationPlanZod,
|
|
955
|
+
EVMAddressString,
|
|
858
956
|
EVM_NATIVE_SENTINEL,
|
|
859
957
|
Erc20BalanceDeltaGteSpecSchema,
|
|
860
958
|
Erc20BalanceGteSpecSchema,
|
|
@@ -868,6 +966,8 @@ export {
|
|
|
868
966
|
HandleUnitsZod,
|
|
869
967
|
HexStringSchema,
|
|
870
968
|
InputPortZod,
|
|
969
|
+
IntegerString,
|
|
970
|
+
LineageSchema,
|
|
871
971
|
LiteralBindingSchema,
|
|
872
972
|
ManifestGuardZod,
|
|
873
973
|
ManifestMaterialiserZod,
|
|
@@ -878,7 +978,6 @@ export {
|
|
|
878
978
|
OutputPortZod,
|
|
879
979
|
PROVIDER_KIND,
|
|
880
980
|
Phase1ArtifactSchema,
|
|
881
|
-
Phase1ArtifactZod,
|
|
882
981
|
RESERVED_REF_SCOPES,
|
|
883
982
|
RefSchema,
|
|
884
983
|
ResourceInputSchema,
|
|
@@ -888,10 +987,12 @@ export {
|
|
|
888
987
|
SIMULATE_MAX_REQUIREMENTS,
|
|
889
988
|
SIMULATE_MAX_TRACKED_BALANCES,
|
|
890
989
|
STATIC_SOL_TYPES,
|
|
990
|
+
SettlementZod,
|
|
891
991
|
SolTypeSchema,
|
|
892
992
|
StaticSolTypeZod,
|
|
893
993
|
TEMPO_CHAIN_ID,
|
|
894
994
|
TEMPO_NATIVE_ERC20,
|
|
995
|
+
UuidSchema,
|
|
895
996
|
VerificationDescriptorSchema,
|
|
896
997
|
VerificationDescriptorZod,
|
|
897
998
|
canonicalAssertedPredicate,
|
|
@@ -903,6 +1004,8 @@ export {
|
|
|
903
1004
|
erc20Balance,
|
|
904
1005
|
erc20Resource,
|
|
905
1006
|
erc20Token,
|
|
1007
|
+
expandOutputPorts,
|
|
1008
|
+
familySize,
|
|
906
1009
|
flowInputMode,
|
|
907
1010
|
flowInputResource,
|
|
908
1011
|
flowInputType,
|
|
@@ -913,6 +1016,7 @@ export {
|
|
|
913
1016
|
getChainCapabilities,
|
|
914
1017
|
handle,
|
|
915
1018
|
hasErc20CanonicalNative,
|
|
1019
|
+
instancePortName,
|
|
916
1020
|
isAsErc20Chain,
|
|
917
1021
|
isContextKey,
|
|
918
1022
|
isEQCheck,
|
|
@@ -928,6 +1032,7 @@ export {
|
|
|
928
1032
|
isNativeAddressForChain,
|
|
929
1033
|
isNativeBalancePrecondition,
|
|
930
1034
|
isNativeResource,
|
|
1035
|
+
isOutputFamily,
|
|
931
1036
|
isRef,
|
|
932
1037
|
isResourceInput,
|
|
933
1038
|
isResourceOutputPort,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/compose-spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Public wire-format types and schemas for Compose flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"effect": "^3.21.0",
|
|
44
|
-
"zod": "^4.
|
|
44
|
+
"zod": "^4.6.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@eslint/compat": "^1.4.0",
|
|
48
48
|
"@lifi/eslint-plugin": "workspace:^",
|
|
49
|
+
"@lifi/vitest-config": "workspace:^",
|
|
49
50
|
"@typescript-eslint/eslint-plugin": "^8.68.0",
|
|
50
51
|
"@typescript-eslint/parser": "^8.68.0",
|
|
51
52
|
"eslint": "^9.36.0",
|
package/src/compile.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { VerificationDescriptor } from './descriptor.js';
|
|
|
2
2
|
import type { InputSpec, Precondition } from './flow.js';
|
|
3
3
|
import type { Flow } from './flowSchema.js';
|
|
4
4
|
import type { Outputs } from './output.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { SettlementWire } from './zodSchemas.js';
|
|
6
6
|
|
|
7
7
|
export type SimulationPolicy = 'strict' | 'allow-revert';
|
|
8
8
|
|
|
@@ -77,31 +77,44 @@ export interface ComposeTransactionRequest {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Hand-mirrored from `ComposeActionSchema`, the OpenAPI source of truth in
|
|
80
|
-
// `@lifi/api-schemas`.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
// `@lifi/api-schemas`. Discriminated on `purpose`; the settlement-specific
|
|
81
|
+
// actions (`fundEscrow`, `signOrder`) name their settle node. Narrow on `kind`
|
|
82
|
+
// before reading `transactionRequest`.
|
|
83
|
+
export type ComposeAction =
|
|
84
|
+
| {
|
|
85
|
+
readonly kind: 'transaction';
|
|
86
|
+
readonly purpose: 'approval' | 'execute';
|
|
87
|
+
readonly submitter: 'signer' | 'anyone';
|
|
88
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
89
|
+
}
|
|
90
|
+
| {
|
|
91
|
+
readonly kind: 'transaction';
|
|
92
|
+
readonly purpose: 'fundEscrow';
|
|
93
|
+
readonly submitter: 'signer' | 'anyone';
|
|
94
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
95
|
+
readonly nodeId: string;
|
|
96
|
+
}
|
|
97
|
+
| {
|
|
98
|
+
readonly kind: 'typedData';
|
|
99
|
+
readonly purpose: 'signOrder';
|
|
100
|
+
readonly submitter: 'signer';
|
|
101
|
+
readonly nodeId: string;
|
|
102
|
+
readonly typedData: readonly unknown[];
|
|
103
|
+
};
|
|
88
104
|
|
|
89
105
|
// Continuation fields shared by the success and partial-error responses, so the
|
|
90
|
-
// two shapes cannot drift. `
|
|
91
|
-
//
|
|
92
|
-
// to the server contract rather than hand-transcribing them.
|
|
106
|
+
// two shapes cannot drift. `settlements` reuses the Zod-inferred wire type from
|
|
107
|
+
// `zodSchemas.ts`, pinning it to the server contract.
|
|
93
108
|
interface ComposeContinuationData {
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// for providers that hand the next leg back to the caller (manual-relay).
|
|
98
|
-
readonly continuationPlans?: Record<string, ContinuationPlanWire>;
|
|
109
|
+
// How each `continuation.settle` node settles, keyed by node id. Absent for
|
|
110
|
+
// a flow with no settle node.
|
|
111
|
+
readonly settlements?: Record<string, SettlementWire>;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
// One funding leg the compiled fill consumes: the resource input's name, its
|
|
102
115
|
// token (native → zero address) and chain, and the statically resolved amount
|
|
103
116
|
// as a decimal string (verified continuations, plan GD-8, seam C5). `nodeId`
|
|
104
|
-
// names the `continuation.settle` node this input funds (the `
|
|
117
|
+
// names the `continuation.settle` node this input funds (the `settlements` /
|
|
105
118
|
// `actions` key); absent when the input funds no settle leg (e.g. a plain
|
|
106
119
|
// swap's input).
|
|
107
120
|
export interface SpendEntry {
|
package/src/constructors.ts
CHANGED
|
@@ -129,8 +129,17 @@ type ResourceOutputOptions =
|
|
|
129
129
|
readonly providesMinimum?: boolean;
|
|
130
130
|
readonly omitIfZero?: boolean;
|
|
131
131
|
readonly deliveryAddressInput?: string;
|
|
132
|
+
readonly countFrom?: string;
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
// Preserve the `countFrom` literal: `defineOp` reads it to tell family ports
|
|
136
|
+
// from fixed ports and to type their hook results as arrays.
|
|
137
|
+
type OutputCountFrom<O> = O extends {
|
|
138
|
+
readonly countFrom: infer K extends string;
|
|
139
|
+
}
|
|
140
|
+
? { readonly countFrom: K }
|
|
141
|
+
: unknown;
|
|
142
|
+
|
|
134
143
|
// Resolve the *type-level* availability of a resource output from the options
|
|
135
144
|
// the caller passed. Preserving the availability literal is load-bearing:
|
|
136
145
|
// `defineOp` extracts the `'future'` port names from this literal, so widening
|
|
@@ -169,7 +178,7 @@ export const resourceOutput = <
|
|
|
169
178
|
): ResourceOutputPort & {
|
|
170
179
|
readonly name: N;
|
|
171
180
|
readonly availability: OutputAvailability<O>;
|
|
172
|
-
} => {
|
|
181
|
+
} & OutputCountFrom<O> => {
|
|
173
182
|
// Widen away the generic before narrowing: `typeof` cannot narrow a value
|
|
174
183
|
// of generic type `O`, so the union members would keep their string arms.
|
|
175
184
|
const raw: ResourceOutputOptions | undefined = options;
|
|
@@ -182,8 +191,9 @@ export const resourceOutput = <
|
|
|
182
191
|
...optionalProp('providesMinimum', opts?.providesMinimum),
|
|
183
192
|
...optionalProp('omitIfZero', opts?.omitIfZero),
|
|
184
193
|
...optionalProp('deliveryAddressInput', opts?.deliveryAddressInput),
|
|
194
|
+
...optionalProp('countFrom', opts?.countFrom),
|
|
185
195
|
} as ResourceOutputPort & {
|
|
186
196
|
readonly name: N;
|
|
187
197
|
readonly availability: OutputAvailability<O>;
|
|
188
|
-
}
|
|
198
|
+
} & OutputCountFrom<O>;
|
|
189
199
|
};
|