@lifi/compose-spec 0.4.0 → 0.5.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 +1 -1
- package/dist/index.cjs +89 -41
- package/dist/index.d.cts +266 -70
- package/dist/index.d.ts +266 -70
- package/dist/index.js +82 -38
- package/package.json +6 -13
- package/src/compile.ts +87 -21
- package/src/constructors.ts +106 -53
- package/src/continuation.ts +9 -9
- package/src/flow.ts +15 -1
- package/src/flowSchema.ts +0 -7
- package/src/index.ts +32 -6
- package/src/preconditions.ts +51 -0
- package/src/ref.ts +34 -1
- package/src/resource.ts +6 -1
- package/src/route.ts +139 -0
- package/src/simulate.ts +14 -23
- package/src/zodSchemas.ts +5 -13
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @lifi/compose-spec
|
|
|
16
16
|
- **Resource types** — `Resource`, `Availability`, `OutputAmount`, `SimulatedAmounts`, plus helpers like `erc20Token`, `foldResource`, `resourceKey`
|
|
17
17
|
- **Manifest types** — `ComposeManifest`, `ManifestOperation`, `ManifestGuard`, `ManifestMaterialiser`, `ManifestPrecondition`
|
|
18
18
|
- **Port types** — `ResourcePort`, `HandlePort`, `OpInputPort`, `OpOutputPort`, and type guards
|
|
19
|
-
- **Ref utilities** — `parseRef`, `foldRef`, `refKey` for working with flow references
|
|
19
|
+
- **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
|
|
20
20
|
- **Constructors** — `linear`, `copy`, `handle`, `native`, `erc20`, `resource`, `readResource`, `opHandle`, `resourceOutput`
|
|
21
21
|
- **Zod schemas** — Runtime validation for manifests, ports, guards, and operations
|
|
22
22
|
- **Effect schemas** — `FlowSchema`, `ResourceSchema`, `CallSchema`, etc. for flow document validation
|
package/dist/index.cjs
CHANGED
|
@@ -50,7 +50,6 @@ __export(index_exports, {
|
|
|
50
50
|
ContinuationOutcomeSchema: () => ContinuationOutcomeSchema,
|
|
51
51
|
ContinuationPlanSchema: () => ContinuationPlanSchema,
|
|
52
52
|
ContinuationPlanZod: () => ContinuationPlanZod,
|
|
53
|
-
ContinuationSchema: () => ContinuationSchema,
|
|
54
53
|
EVM_NATIVE_SENTINEL: () => EVM_NATIVE_SENTINEL,
|
|
55
54
|
Erc20BalanceDeltaGteSpecSchema: () => Erc20BalanceDeltaGteSpecSchema,
|
|
56
55
|
Erc20BalanceGteSpecSchema: () => Erc20BalanceGteSpecSchema,
|
|
@@ -94,6 +93,8 @@ __export(index_exports, {
|
|
|
94
93
|
canonicalNativeAddress: () => canonicalNativeAddress,
|
|
95
94
|
copy: () => copy,
|
|
96
95
|
erc20: () => erc20,
|
|
96
|
+
erc20Allowance: () => erc20Allowance,
|
|
97
|
+
erc20Balance: () => erc20Balance,
|
|
97
98
|
erc20Resource: () => erc20Resource,
|
|
98
99
|
erc20Token: () => erc20Token,
|
|
99
100
|
flowInputMode: () => flowInputMode,
|
|
@@ -104,17 +105,19 @@ __export(index_exports, {
|
|
|
104
105
|
foldResource: () => foldResource,
|
|
105
106
|
getChainCapabilities: () => getChainCapabilities,
|
|
106
107
|
handle: () => handle,
|
|
107
|
-
inputRef: () => inputRef,
|
|
108
108
|
isAsErc20Chain: () => isAsErc20Chain,
|
|
109
109
|
isContextKey: () => isContextKey,
|
|
110
110
|
isEQCheck: () => isEQCheck,
|
|
111
111
|
isERC20Resource: () => isERC20Resource,
|
|
112
|
+
isErc20AllowancePrecondition: () => isErc20AllowancePrecondition,
|
|
113
|
+
isFutureResourceOutput: () => isFutureResourceOutput,
|
|
112
114
|
isGTECheck: () => isGTECheck,
|
|
113
115
|
isHandlePort: () => isHandlePort,
|
|
114
116
|
isLTECheck: () => isLTECheck,
|
|
115
117
|
isMaterialiserInput: () => isMaterialiserInput,
|
|
116
118
|
isMsgValueNative: () => isMsgValueNative,
|
|
117
119
|
isNativeAddressForChain: () => isNativeAddressForChain,
|
|
120
|
+
isNativeBalancePrecondition: () => isNativeBalancePrecondition,
|
|
118
121
|
isNativeResource: () => isNativeResource,
|
|
119
122
|
isRef: () => isRef,
|
|
120
123
|
isResourceInput: () => isResourceInput,
|
|
@@ -123,15 +126,16 @@ __export(index_exports, {
|
|
|
123
126
|
isStaticSolType: () => isStaticSolType,
|
|
124
127
|
linear: () => linear,
|
|
125
128
|
native: () => native,
|
|
129
|
+
nativeBalance: () => nativeBalance,
|
|
126
130
|
nativeResource: () => nativeResource,
|
|
127
131
|
normalizeNativeTokenAddress: () => normalizeNativeTokenAddress,
|
|
128
132
|
normalizeResource: () => normalizeResource,
|
|
129
133
|
opHandle: () => opHandle,
|
|
130
|
-
outputRef: () => outputRef,
|
|
131
134
|
parseRef: () => parseRef,
|
|
132
135
|
providerKindByName: () => providerKindByName,
|
|
133
136
|
providerKindNames: () => providerKindNames,
|
|
134
137
|
readResource: () => readResource,
|
|
138
|
+
ref: () => ref,
|
|
135
139
|
refKey: () => refKey,
|
|
136
140
|
resource: () => resource,
|
|
137
141
|
resourceKey: () => resourceKey,
|
|
@@ -269,17 +273,12 @@ var CallSchema = import_effect.Schema.Struct({
|
|
|
269
273
|
),
|
|
270
274
|
guards: import_effect.Schema.optional(import_effect.Schema.Array(AppliedGuardSchema))
|
|
271
275
|
});
|
|
272
|
-
var ContinuationSchema = import_effect.Schema.Struct({
|
|
273
|
-
awaits: import_effect.Schema.String,
|
|
274
|
-
flowId: import_effect.Schema.String
|
|
275
|
-
});
|
|
276
276
|
var FlowSchema = import_effect.Schema.Struct({
|
|
277
277
|
version: import_effect.Schema.Literal(1),
|
|
278
278
|
id: import_effect.Schema.String,
|
|
279
279
|
chainId: ChainIdSchema,
|
|
280
280
|
inputs: import_effect.Schema.Array(FlowInputSchema),
|
|
281
|
-
nodes: import_effect.Schema.Array(CallSchema)
|
|
282
|
-
continuations: import_effect.Schema.optional(import_effect.Schema.Array(ContinuationSchema))
|
|
281
|
+
nodes: import_effect.Schema.Array(CallSchema)
|
|
283
282
|
});
|
|
284
283
|
|
|
285
284
|
// src/continuation.ts
|
|
@@ -309,16 +308,21 @@ var ContinuationIntentSchema = import_effect2.Schema.Struct({
|
|
|
309
308
|
continuationFlow: import_effect2.Schema.optional(FlowSchema),
|
|
310
309
|
validity: import_effect2.Schema.Struct({ expiresAtMs: import_effect2.Schema.Number }),
|
|
311
310
|
perpetual: import_effect2.Schema.optional(import_effect2.Schema.Boolean),
|
|
312
|
-
provider: import_effect2.Schema.optional(import_effect2.Schema.String)
|
|
311
|
+
provider: import_effect2.Schema.optional(import_effect2.Schema.String),
|
|
312
|
+
// Funding-path mode. The HTTP wire contract is documented by
|
|
313
|
+
// `ComposeActionsSchema` in `@lifi/api-schemas`.
|
|
314
|
+
funding: import_effect2.Schema.optional(import_effect2.Schema.Literal("inline", "external"))
|
|
313
315
|
});
|
|
314
316
|
var Phase1ArtifactSchema = import_effect2.Schema.Union(
|
|
315
317
|
import_effect2.Schema.Struct({
|
|
316
318
|
kind: import_effect2.Schema.Literal("transaction"),
|
|
319
|
+
funding: import_effect2.Schema.Literal("inline", "external"),
|
|
317
320
|
transactionRequest: import_effect2.Schema.optional(
|
|
318
321
|
import_effect2.Schema.Struct({
|
|
319
322
|
to: import_effect2.Schema.String,
|
|
320
323
|
data: import_effect2.Schema.String,
|
|
321
|
-
value: import_effect2.Schema.String
|
|
324
|
+
value: import_effect2.Schema.String,
|
|
325
|
+
chainId: import_effect2.Schema.Number
|
|
322
326
|
})
|
|
323
327
|
)
|
|
324
328
|
}),
|
|
@@ -478,6 +482,7 @@ var flowInputResource = (input) => isResourceInput(input) ? input.resource : voi
|
|
|
478
482
|
var isResourcePort = (port) => port.kind === "resource";
|
|
479
483
|
var isHandlePort = (port) => port.kind === "handle";
|
|
480
484
|
var isResourceOutputPort = (port) => port.kind === "resource_output";
|
|
485
|
+
var isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
|
|
481
486
|
var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
|
|
482
487
|
|
|
483
488
|
// src/resource.ts
|
|
@@ -537,16 +542,28 @@ var providerKindByName = {
|
|
|
537
542
|
};
|
|
538
543
|
|
|
539
544
|
// src/constructors.ts
|
|
540
|
-
var inputRef = (port) => ({ $ref: `input.${port}` });
|
|
541
|
-
var outputRef = (node, port) => ({
|
|
542
|
-
$ref: `${node}.${port}`
|
|
543
|
-
});
|
|
544
545
|
var optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
|
|
545
|
-
var linear = (name, type) => ({
|
|
546
|
-
|
|
546
|
+
var linear = (name, type) => ({
|
|
547
|
+
name,
|
|
548
|
+
type,
|
|
549
|
+
mode: "linear",
|
|
550
|
+
availability: "now"
|
|
551
|
+
});
|
|
552
|
+
var copy = (name, type) => ({
|
|
553
|
+
name,
|
|
554
|
+
type,
|
|
555
|
+
mode: "copy",
|
|
556
|
+
availability: "now"
|
|
557
|
+
});
|
|
547
558
|
var handle = (name, type) => ({ name, type });
|
|
548
|
-
var native = (name, chainId) => ({
|
|
549
|
-
|
|
559
|
+
var native = (name, chainId) => ({
|
|
560
|
+
name,
|
|
561
|
+
resource: nativeResource(chainId)
|
|
562
|
+
});
|
|
563
|
+
var erc20 = (name, token, chainId) => ({
|
|
564
|
+
name,
|
|
565
|
+
resource: erc20Resource(token, chainId)
|
|
566
|
+
});
|
|
550
567
|
var resource = (name, accepts, options) => ({
|
|
551
568
|
kind: "resource",
|
|
552
569
|
name,
|
|
@@ -554,17 +571,24 @@ var resource = (name, accepts, options) => ({
|
|
|
554
571
|
mode: "linear",
|
|
555
572
|
...optionalProp("optional", options?.optional)
|
|
556
573
|
});
|
|
557
|
-
var readResource = (name, accepts) => ({
|
|
574
|
+
var readResource = (name, accepts) => ({
|
|
575
|
+
kind: "resource",
|
|
576
|
+
name,
|
|
577
|
+
accepts,
|
|
578
|
+
mode: "copy"
|
|
579
|
+
});
|
|
558
580
|
var opHandle = (name, type, options) => ({
|
|
559
581
|
kind: "handle",
|
|
560
582
|
name,
|
|
561
583
|
type,
|
|
562
584
|
mode: "copy",
|
|
563
585
|
...optionalProp("expose", options?.expose),
|
|
564
|
-
...optionalProp("units", options?.units)
|
|
586
|
+
...optionalProp("units", options?.units),
|
|
587
|
+
...optionalProp("optional", options?.optional)
|
|
565
588
|
});
|
|
566
589
|
var resourceOutput = (name, options) => {
|
|
567
|
-
const
|
|
590
|
+
const raw = options;
|
|
591
|
+
const opts = typeof raw === "string" ? { availability: raw } : raw;
|
|
568
592
|
return {
|
|
569
593
|
kind: "resource_output",
|
|
570
594
|
name,
|
|
@@ -584,12 +608,12 @@ var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
|
|
|
584
608
|
"literal"
|
|
585
609
|
]);
|
|
586
610
|
var isRef = (v) => typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string";
|
|
587
|
-
var parseRef = (
|
|
588
|
-
const dot =
|
|
611
|
+
var parseRef = (ref2) => {
|
|
612
|
+
const dot = ref2.$ref.indexOf(".");
|
|
589
613
|
if (dot === -1)
|
|
590
|
-
throw new Error(`Invalid ref: "${
|
|
591
|
-
const prefix =
|
|
592
|
-
const suffix =
|
|
614
|
+
throw new Error(`Invalid ref: "${ref2.$ref}" (must contain a dot)`);
|
|
615
|
+
const prefix = ref2.$ref.slice(0, dot);
|
|
616
|
+
const suffix = ref2.$ref.slice(dot + 1);
|
|
593
617
|
if (prefix === "input") return { scope: "input", port: suffix };
|
|
594
618
|
if (prefix === "context") {
|
|
595
619
|
if (!isContextKey(suffix))
|
|
@@ -598,17 +622,40 @@ var parseRef = (ref) => {
|
|
|
598
622
|
}
|
|
599
623
|
return { scope: "output", node: prefix, port: suffix };
|
|
600
624
|
};
|
|
601
|
-
var
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
|
|
625
|
+
var buildRef = (path) => {
|
|
626
|
+
if (path.indexOf(".") < 1)
|
|
627
|
+
throw new Error(
|
|
628
|
+
`Invalid ref: "${path}" (must be a dotpath like "input.name" or "nodeId.port")`
|
|
629
|
+
);
|
|
630
|
+
const built = { $ref: path };
|
|
631
|
+
parseRef(built);
|
|
632
|
+
return built;
|
|
633
|
+
};
|
|
634
|
+
var ref = Object.assign(buildRef, {
|
|
635
|
+
input: (port) => buildRef(`input.${port}`),
|
|
636
|
+
context: {
|
|
637
|
+
sender: buildRef("context.sender"),
|
|
638
|
+
executionAddress: buildRef("context.executionAddress")
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
var foldRef = (ref2, cases) => {
|
|
642
|
+
if (ref2.scope === "input") return cases.input(ref2.port);
|
|
643
|
+
if (ref2.scope === "context") return cases.context(ref2.key);
|
|
644
|
+
return cases.output(ref2.node, ref2.port);
|
|
605
645
|
};
|
|
606
|
-
var refKey = (
|
|
646
|
+
var refKey = (ref2) => foldRef(parseRef(ref2), {
|
|
607
647
|
input: (port) => `input:${port}`,
|
|
608
648
|
context: (key) => `context:${key}`,
|
|
609
649
|
output: (node, port) => `output:${node}:${port}`
|
|
610
650
|
});
|
|
611
651
|
|
|
652
|
+
// src/preconditions.ts
|
|
653
|
+
var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
|
|
654
|
+
var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
|
|
655
|
+
var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
|
|
656
|
+
var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
|
|
657
|
+
var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
|
|
658
|
+
|
|
612
659
|
// src/simulate.ts
|
|
613
660
|
var SIMULATE_MAX_TRACKED_BALANCES = 40;
|
|
614
661
|
var SIMULATE_MAX_REQUIREMENTS = 40;
|
|
@@ -674,7 +721,8 @@ var HandlePortZod = import_zod.default.object({
|
|
|
674
721
|
type: SolTypeZod,
|
|
675
722
|
mode: import_zod.default.enum(["linear", "copy"]),
|
|
676
723
|
expose: import_zod.default.boolean().optional(),
|
|
677
|
-
units: HandleUnitsZod.optional()
|
|
724
|
+
units: HandleUnitsZod.optional(),
|
|
725
|
+
optional: import_zod.default.boolean().optional()
|
|
678
726
|
});
|
|
679
727
|
var InputPortZod = import_zod.default.discriminatedUnion("kind", [
|
|
680
728
|
ResourcePortZod,
|
|
@@ -756,11 +804,7 @@ var ComposeManifestZod = import_zod.default.object({
|
|
|
756
804
|
var Phase1ArtifactZod = import_zod.default.discriminatedUnion("kind", [
|
|
757
805
|
import_zod.default.object({
|
|
758
806
|
kind: import_zod.default.literal("transaction"),
|
|
759
|
-
|
|
760
|
-
to: import_zod.default.string(),
|
|
761
|
-
data: import_zod.default.string(),
|
|
762
|
-
value: import_zod.default.string()
|
|
763
|
-
}).optional()
|
|
807
|
+
funding: import_zod.default.enum(["inline", "external"])
|
|
764
808
|
}),
|
|
765
809
|
import_zod.default.object({
|
|
766
810
|
kind: import_zod.default.literal("signables"),
|
|
@@ -878,7 +922,6 @@ var ContinuationPlanZod = import_zod.default.object({
|
|
|
878
922
|
ContinuationOutcomeSchema,
|
|
879
923
|
ContinuationPlanSchema,
|
|
880
924
|
ContinuationPlanZod,
|
|
881
|
-
ContinuationSchema,
|
|
882
925
|
EVM_NATIVE_SENTINEL,
|
|
883
926
|
Erc20BalanceDeltaGteSpecSchema,
|
|
884
927
|
Erc20BalanceGteSpecSchema,
|
|
@@ -922,6 +965,8 @@ var ContinuationPlanZod = import_zod.default.object({
|
|
|
922
965
|
canonicalNativeAddress,
|
|
923
966
|
copy,
|
|
924
967
|
erc20,
|
|
968
|
+
erc20Allowance,
|
|
969
|
+
erc20Balance,
|
|
925
970
|
erc20Resource,
|
|
926
971
|
erc20Token,
|
|
927
972
|
flowInputMode,
|
|
@@ -932,17 +977,19 @@ var ContinuationPlanZod = import_zod.default.object({
|
|
|
932
977
|
foldResource,
|
|
933
978
|
getChainCapabilities,
|
|
934
979
|
handle,
|
|
935
|
-
inputRef,
|
|
936
980
|
isAsErc20Chain,
|
|
937
981
|
isContextKey,
|
|
938
982
|
isEQCheck,
|
|
939
983
|
isERC20Resource,
|
|
984
|
+
isErc20AllowancePrecondition,
|
|
985
|
+
isFutureResourceOutput,
|
|
940
986
|
isGTECheck,
|
|
941
987
|
isHandlePort,
|
|
942
988
|
isLTECheck,
|
|
943
989
|
isMaterialiserInput,
|
|
944
990
|
isMsgValueNative,
|
|
945
991
|
isNativeAddressForChain,
|
|
992
|
+
isNativeBalancePrecondition,
|
|
946
993
|
isNativeResource,
|
|
947
994
|
isRef,
|
|
948
995
|
isResourceInput,
|
|
@@ -951,15 +998,16 @@ var ContinuationPlanZod = import_zod.default.object({
|
|
|
951
998
|
isStaticSolType,
|
|
952
999
|
linear,
|
|
953
1000
|
native,
|
|
1001
|
+
nativeBalance,
|
|
954
1002
|
nativeResource,
|
|
955
1003
|
normalizeNativeTokenAddress,
|
|
956
1004
|
normalizeResource,
|
|
957
1005
|
opHandle,
|
|
958
|
-
outputRef,
|
|
959
1006
|
parseRef,
|
|
960
1007
|
providerKindByName,
|
|
961
1008
|
providerKindNames,
|
|
962
1009
|
readResource,
|
|
1010
|
+
ref,
|
|
963
1011
|
refKey,
|
|
964
1012
|
resource,
|
|
965
1013
|
resourceKey,
|