@lifi/compose-spec 0.10.0 → 0.11.3
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 +1 -1
- package/dist/index.cjs +54 -23
- package/dist/index.d.cts +323 -111
- package/dist/index.d.ts +323 -111
- package/dist/index.js +50 -24
- package/package.json +1 -1
- package/src/chainCapabilities.ts +6 -6
- package/src/compile.ts +45 -10
- package/src/continuation.ts +74 -29
- package/src/flow.ts +40 -2
- package/src/flowSchema.ts +26 -0
- package/src/index.ts +23 -2
- package/src/manifest.ts +1 -0
- package/src/output.ts +20 -13
- package/src/resource.ts +43 -30
- package/src/route.ts +3 -2
- package/src/zodSchemas.ts +17 -0
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @lifi/compose-spec
|
|
|
16
16
|
- **Continuation types** — `ContinuationIntent`, `ContinuationOutcome`, `AssertionSpec`
|
|
17
17
|
- **Resource types** — `Resource`, `Availability`, plus helpers like `erc20Token`, `foldResource`, `resourceKey`
|
|
18
18
|
- **Output types** — `Outputs`, `Output`, `ConsumedOutput`, `TerminalOutput`, `Amount`, `Estimate`, `Minimum`, `Delivery`, `EstimateBasis`, `MinimumBasis` — the per-port `outputs` record on a compile result
|
|
19
|
-
- **Manifest types** — `ComposeManifest`, `ManifestOperation`, `ManifestGuard`, `ManifestMaterialiser`, `ManifestPrecondition`
|
|
19
|
+
- **Manifest types** — `ComposeManifest`, `ManifestOperation`, `ManifestGuard`, `ManifestMaterialiser`, `ManifestPrecondition`, `ManifestRouting`
|
|
20
20
|
- **Port types** — `ResourcePort`, `HandlePort`, `OpInputPort`, `OpOutputPort`, and type guards
|
|
21
21
|
- **Request/response types** — `ComposeCompileRequest`, `ComposeCompileResult`, `ComposeRouteRequest`, `SimulateRequest`, `SimulateResult`
|
|
22
22
|
- **Ref utilities** — `ref` to build bind refs (`ref.input('amount')`, `ref.context.sender`, `ref('nodeId.port')`), plus `parseRef`, `foldRef`, `refKey` for working with flow references
|
package/dist/index.cjs
CHANGED
|
@@ -36,11 +36,11 @@ zod = __toESM(zod, 1);
|
|
|
36
36
|
*/
|
|
37
37
|
const EVM_NATIVE_SENTINEL = "0x0000000000000000000000000000000000000000";
|
|
38
38
|
/**
|
|
39
|
-
* Whether `address` is the EVM
|
|
40
|
-
* case-insensitively.
|
|
41
|
-
*
|
|
39
|
+
* Whether `address` is the EVM zero address (the native sentinel), compared
|
|
40
|
+
* case-insensitively. Inlined comparison: `compose-spec` cannot import
|
|
41
|
+
* `toAddress` from `@lifi/utils` (see `EVM_NATIVE_SENTINEL`).
|
|
42
42
|
*/
|
|
43
|
-
const
|
|
43
|
+
const isZeroAddress = (address) => address.toLowerCase() === EVM_NATIVE_SENTINEL.toLowerCase();
|
|
44
44
|
const TEMPO_CHAIN_ID = 4217;
|
|
45
45
|
const TEMPO_NATIVE_ERC20 = {
|
|
46
46
|
token: "0x20C0000000000000000000000000000000000000",
|
|
@@ -163,7 +163,7 @@ const isNativeAddressForChain = (chainId, address) => {
|
|
|
163
163
|
* `isNativeAddressForChain`, which returns `true` for the stand-in ERC-20
|
|
164
164
|
* (PathUSD on Tempo) and would wrongly route it to `msg.value`.
|
|
165
165
|
*/
|
|
166
|
-
const isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) &&
|
|
166
|
+
const isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isZeroAddress(address);
|
|
167
167
|
/**
|
|
168
168
|
* Rewrite a single `Resource` according to its chain's capabilities.
|
|
169
169
|
*
|
|
@@ -199,7 +199,7 @@ const normalizeResource = (r) => {
|
|
|
199
199
|
* chains whose canonical native asset is an ERC-20, the native sentinel is
|
|
200
200
|
* rewritten to the chain's stand-in ERC-20; every other address passes through.
|
|
201
201
|
*/
|
|
202
|
-
const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) &&
|
|
202
|
+
const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isZeroAddress(token) ? canonicalNativeAddress(chainId) : token;
|
|
203
203
|
//#endregion
|
|
204
204
|
//#region src/hexPatterns.ts
|
|
205
205
|
const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
@@ -287,38 +287,51 @@ const LineageSchema = effect.Schema.Struct({
|
|
|
287
287
|
journeyId: UuidSchema,
|
|
288
288
|
parentRequestId: UuidSchema
|
|
289
289
|
});
|
|
290
|
+
const ForwardToSchema = effect.Schema.Union(EVMAddressString, RefSchema);
|
|
291
|
+
const EpilogueForwardSchema = effect.Schema.Struct({
|
|
292
|
+
resource: ResourceSchema,
|
|
293
|
+
to: ForwardToSchema
|
|
294
|
+
});
|
|
295
|
+
const EpilogueSchema = effect.Schema.Struct({
|
|
296
|
+
forwards: effect.Schema.optional(effect.Schema.NonEmptyArray(EpilogueForwardSchema)),
|
|
297
|
+
remainder: effect.Schema.optional(ForwardToSchema)
|
|
298
|
+
}).pipe(effect.Schema.filter((e) => e.forwards !== void 0 || e.remainder !== void 0, { message: () => "epilogue needs forwards, a remainder, or both" }));
|
|
290
299
|
const FlowSchema = effect.Schema.Struct({
|
|
291
300
|
version: effect.Schema.Literal(1),
|
|
292
301
|
id: effect.Schema.String,
|
|
293
302
|
chainId: ChainIdSchema,
|
|
294
303
|
inputs: effect.Schema.Array(FlowInputSchema),
|
|
295
304
|
nodes: effect.Schema.Array(CallSchema),
|
|
296
|
-
lineage: effect.Schema.optional(LineageSchema)
|
|
305
|
+
lineage: effect.Schema.optional(LineageSchema),
|
|
306
|
+
epilogue: effect.Schema.optional(EpilogueSchema)
|
|
297
307
|
});
|
|
298
308
|
//#endregion
|
|
299
309
|
//#region src/continuation.ts
|
|
300
310
|
const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
|
|
301
|
-
const
|
|
311
|
+
const outcomeFields = (minAmount) => ({
|
|
302
312
|
token: EVMAddressString,
|
|
303
|
-
minAmount
|
|
313
|
+
minAmount,
|
|
304
314
|
destination: EVMAddressString,
|
|
305
315
|
chainId: ChainIdSchema
|
|
306
316
|
});
|
|
307
|
-
const
|
|
317
|
+
const normalizingOutcome = (raw) => effect.Schema.transform(raw, effect.Schema.typeSchema(raw), {
|
|
308
318
|
strict: true,
|
|
309
|
-
decode: (
|
|
310
|
-
...
|
|
311
|
-
token: normalizeNativeTokenAddress(
|
|
319
|
+
decode: (outcome) => ({
|
|
320
|
+
...outcome,
|
|
321
|
+
token: normalizeNativeTokenAddress(outcome.token, outcome.chainId)
|
|
312
322
|
}),
|
|
313
323
|
encode: (outcome) => outcome
|
|
314
324
|
});
|
|
325
|
+
const ContinuationOutcomeSchema = normalizingOutcome(effect.Schema.Struct(outcomeFields(effect.Schema.optional(IntegerString))));
|
|
326
|
+
const CommittedOutcomeSchema = normalizingOutcome(effect.Schema.Struct(outcomeFields(IntegerString)));
|
|
315
327
|
const ContinuationIntentSchema = effect.Schema.Struct({
|
|
316
328
|
outcomes: effect.Schema.NonEmptyArray(ContinuationOutcomeSchema),
|
|
317
329
|
continuationFlow: effect.Schema.optional(FlowSchema),
|
|
318
330
|
validity: effect.Schema.Struct({ expiresAtMs: EpochMsSchema }),
|
|
319
331
|
perpetual: effect.Schema.optional(effect.Schema.Boolean),
|
|
320
332
|
provider: effect.Schema.optional(effect.Schema.String),
|
|
321
|
-
funding: effect.Schema.optional(effect.Schema.Literal("inline", "external"))
|
|
333
|
+
funding: effect.Schema.optional(effect.Schema.Literal("inline", "external")),
|
|
334
|
+
refund: effect.Schema.optional(EVMAddressString.pipe(effect.Schema.filter((address) => !isZeroAddress(address), { message: () => "refund must not be the zero address" })))
|
|
322
335
|
});
|
|
323
336
|
const HexStringSchema = effect.Schema.String.pipe(effect.Schema.startsWith("0x"));
|
|
324
337
|
const Phase1EscrowSchema = effect.Schema.Struct({
|
|
@@ -327,13 +340,14 @@ const Phase1EscrowSchema = effect.Schema.Struct({
|
|
|
327
340
|
token: HexStringSchema,
|
|
328
341
|
amount: effect.Schema.String,
|
|
329
342
|
cap: effect.Schema.String,
|
|
343
|
+
floor: effect.Schema.String,
|
|
330
344
|
owner: HexStringSchema,
|
|
331
345
|
refund: HexStringSchema,
|
|
332
346
|
expiresAtMs: effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive())
|
|
333
347
|
});
|
|
334
348
|
const Phase1ArtifactSchema = effect.Schema.Union(effect.Schema.Struct({
|
|
335
349
|
kind: effect.Schema.Literal("transaction"),
|
|
336
|
-
funding: effect.Schema.Literal("inline", "external"),
|
|
350
|
+
funding: effect.Schema.Literal("inline", "external", "delivered"),
|
|
337
351
|
transactionRequest: effect.Schema.optional(effect.Schema.Struct({
|
|
338
352
|
to: effect.Schema.String,
|
|
339
353
|
data: effect.Schema.String,
|
|
@@ -458,18 +472,24 @@ const nativeResource = (chainId) => ({
|
|
|
458
472
|
const isERC20Resource = (r) => r.kind === "erc20";
|
|
459
473
|
const isNativeResource = (r) => r.kind === "native";
|
|
460
474
|
const resourcesEqual = (a, b) => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
475
|
+
switch (a.kind) {
|
|
476
|
+
case "native": return b.kind === "native" && a.chainId === b.chainId;
|
|
477
|
+
case "erc20": return b.kind === "erc20" && a.chainId === b.chainId && a.token.toLowerCase() === b.token.toLowerCase();
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
const foldResource = (r, cases) => {
|
|
481
|
+
switch (r.kind) {
|
|
482
|
+
case "native": return cases.native(r);
|
|
483
|
+
case "erc20": return cases.erc20(r);
|
|
484
|
+
}
|
|
464
485
|
};
|
|
465
|
-
const foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
|
|
466
486
|
const resourceToken = (r) => foldResource(r, {
|
|
467
487
|
native: () => EVM_NATIVE_SENTINEL,
|
|
468
|
-
erc20: (token) => token
|
|
488
|
+
erc20: ({ token }) => token
|
|
469
489
|
});
|
|
470
490
|
const resourceKey = (r) => foldResource(r, {
|
|
471
|
-
native: (chainId) => `native:${chainId}`,
|
|
472
|
-
erc20: (token, chainId) => `erc20:${token.toLowerCase()}:${chainId}`
|
|
491
|
+
native: ({ chainId }) => `native:${chainId}`,
|
|
492
|
+
erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`
|
|
473
493
|
});
|
|
474
494
|
const erc20Token = (r) => {
|
|
475
495
|
if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
|
|
@@ -886,6 +906,10 @@ const ManifestPreconditionZod = zod.default.object({
|
|
|
886
906
|
description: zod.default.string().optional(),
|
|
887
907
|
configSchema: zod.default.unknown().optional()
|
|
888
908
|
});
|
|
909
|
+
const ManifestRoutingZod = zod.default.object({
|
|
910
|
+
maxRouteHops: zod.default.number().int().min(1),
|
|
911
|
+
swapHops: zod.default.enum(["head", "none"])
|
|
912
|
+
});
|
|
889
913
|
const ComposeManifestZod = zod.default.object({
|
|
890
914
|
manifestVersion: zod.default.number(),
|
|
891
915
|
manifestHash: zod.default.string(),
|
|
@@ -893,7 +917,8 @@ const ComposeManifestZod = zod.default.object({
|
|
|
893
917
|
operations: zod.default.array(ManifestOperationZod),
|
|
894
918
|
guards: zod.default.array(ManifestGuardZod),
|
|
895
919
|
materialisers: zod.default.array(ManifestMaterialiserZod),
|
|
896
|
-
preconditions: zod.default.array(ManifestPreconditionZod).optional()
|
|
920
|
+
preconditions: zod.default.array(ManifestPreconditionZod).optional(),
|
|
921
|
+
routing: ManifestRoutingZod.optional()
|
|
897
922
|
});
|
|
898
923
|
const hexStringZod = zod.default.string().startsWith("0x");
|
|
899
924
|
const SettlementEscrowZod = zod.default.object({
|
|
@@ -902,6 +927,7 @@ const SettlementEscrowZod = zod.default.object({
|
|
|
902
927
|
token: hexStringZod,
|
|
903
928
|
amount: zod.default.string(),
|
|
904
929
|
cap: zod.default.string(),
|
|
930
|
+
floor: zod.default.string(),
|
|
905
931
|
owner: hexStringZod,
|
|
906
932
|
refund: hexStringZod,
|
|
907
933
|
expiresAtMs: zod.default.number().int().positive()
|
|
@@ -995,15 +1021,19 @@ exports.COMPOSE_VERSION_HEADER = COMPOSE_VERSION_HEADER;
|
|
|
995
1021
|
exports.CONTINUATION_COMMITMENT_OP_ID = CONTINUATION_COMMITMENT_OP_ID;
|
|
996
1022
|
exports.CallCheckSpecSchema = CallCheckSpecSchema;
|
|
997
1023
|
exports.CallSchema = CallSchema;
|
|
1024
|
+
exports.CommittedOutcomeSchema = CommittedOutcomeSchema;
|
|
998
1025
|
exports.ComposeManifestZod = ComposeManifestZod;
|
|
999
1026
|
exports.ContinuationIntentSchema = ContinuationIntentSchema;
|
|
1000
1027
|
exports.ContinuationOutcomeSchema = ContinuationOutcomeSchema;
|
|
1001
1028
|
exports.EVMAddressString = EVMAddressString;
|
|
1002
1029
|
exports.EVM_NATIVE_SENTINEL = EVM_NATIVE_SENTINEL;
|
|
1030
|
+
exports.EpilogueForwardSchema = EpilogueForwardSchema;
|
|
1031
|
+
exports.EpilogueSchema = EpilogueSchema;
|
|
1003
1032
|
exports.Erc20BalanceDeltaGteSpecSchema = Erc20BalanceDeltaGteSpecSchema;
|
|
1004
1033
|
exports.Erc20BalanceGteSpecSchema = Erc20BalanceGteSpecSchema;
|
|
1005
1034
|
exports.FlowInputSchema = FlowInputSchema;
|
|
1006
1035
|
exports.FlowSchema = FlowSchema;
|
|
1036
|
+
exports.ForwardToSchema = ForwardToSchema;
|
|
1007
1037
|
exports.GuardCompatibilityZod = GuardCompatibilityZod;
|
|
1008
1038
|
exports.GuardSelectorZod = GuardSelectorZod;
|
|
1009
1039
|
exports.HANDLE_UNITS = HANDLE_UNITS;
|
|
@@ -1019,6 +1049,7 @@ exports.ManifestGuardZod = ManifestGuardZod;
|
|
|
1019
1049
|
exports.ManifestMaterialiserZod = ManifestMaterialiserZod;
|
|
1020
1050
|
exports.ManifestOperationZod = ManifestOperationZod;
|
|
1021
1051
|
exports.ManifestPreconditionZod = ManifestPreconditionZod;
|
|
1052
|
+
exports.ManifestRoutingZod = ManifestRoutingZod;
|
|
1022
1053
|
exports.NativeBalanceDeltaGteSpecSchema = NativeBalanceDeltaGteSpecSchema;
|
|
1023
1054
|
exports.NativeBalanceGteSpecSchema = NativeBalanceGteSpecSchema;
|
|
1024
1055
|
exports.OutputPortZod = OutputPortZod;
|