@lifi/compose-spec 0.0.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +51 -0
- package/dist/index.cjs +413 -0
- package/dist/index.d.cts +878 -0
- package/dist/index.d.ts +878 -0
- package/dist/index.js +327 -0
- package/package.json +52 -0
- package/src/compile.ts +97 -0
- package/src/constructors.ts +105 -0
- package/src/flow.ts +101 -0
- package/src/flowSchema.ts +105 -0
- package/src/index.ts +133 -0
- package/src/manifest.ts +9 -0
- package/src/materialiserMetadata.ts +24 -0
- package/src/ref.ts +60 -0
- package/src/resource.ts +48 -0
- package/src/zodSchemas.ts +137 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// src/flowSchema.ts
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
var SolTypeSchema = Schema.Literal(
|
|
4
|
+
"uint8",
|
|
5
|
+
"uint16",
|
|
6
|
+
"uint32",
|
|
7
|
+
"uint64",
|
|
8
|
+
"uint128",
|
|
9
|
+
"uint256",
|
|
10
|
+
"int128",
|
|
11
|
+
"int256",
|
|
12
|
+
"address",
|
|
13
|
+
"bool",
|
|
14
|
+
"bytes",
|
|
15
|
+
"bytes4",
|
|
16
|
+
"bytes32",
|
|
17
|
+
"string"
|
|
18
|
+
);
|
|
19
|
+
var ChainIdSchema = Schema.Number.pipe(Schema.int(), Schema.positive());
|
|
20
|
+
var ResourceSchema = Schema.Union(
|
|
21
|
+
Schema.Struct({ kind: Schema.Literal("native"), chainId: ChainIdSchema }),
|
|
22
|
+
Schema.Struct({
|
|
23
|
+
kind: Schema.Literal("erc20"),
|
|
24
|
+
token: Schema.String,
|
|
25
|
+
chainId: ChainIdSchema
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
var ResourceInputSchema = Schema.Struct({
|
|
29
|
+
name: Schema.String,
|
|
30
|
+
resource: ResourceSchema
|
|
31
|
+
});
|
|
32
|
+
var HandleInputSchema = Schema.Struct({
|
|
33
|
+
name: Schema.String,
|
|
34
|
+
type: SolTypeSchema
|
|
35
|
+
});
|
|
36
|
+
var FlowInputSchema = Schema.Union(
|
|
37
|
+
ResourceInputSchema,
|
|
38
|
+
HandleInputSchema
|
|
39
|
+
);
|
|
40
|
+
var RefSchema = Schema.Struct({
|
|
41
|
+
$ref: Schema.String.pipe(
|
|
42
|
+
Schema.filter((s) => s.indexOf(".") > 0, {
|
|
43
|
+
message: () => '$ref must be a dotpath like "input.name" or "nodeId.port"'
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
});
|
|
47
|
+
var LiteralBindingSchema = Schema.Struct({
|
|
48
|
+
kind: SolTypeSchema,
|
|
49
|
+
value: Schema.String
|
|
50
|
+
});
|
|
51
|
+
var BindValueSchema = Schema.Union(RefSchema, LiteralBindingSchema);
|
|
52
|
+
var AppliedGuardSchema = Schema.Struct(
|
|
53
|
+
{ kind: Schema.String },
|
|
54
|
+
{ key: Schema.String, value: Schema.Unknown }
|
|
55
|
+
);
|
|
56
|
+
var CallSchema = Schema.Struct({
|
|
57
|
+
id: Schema.String,
|
|
58
|
+
op: Schema.String,
|
|
59
|
+
bind: Schema.optionalWith(
|
|
60
|
+
Schema.Record({ key: Schema.String, value: BindValueSchema }),
|
|
61
|
+
{ default: () => ({}) }
|
|
62
|
+
),
|
|
63
|
+
config: Schema.optionalWith(
|
|
64
|
+
Schema.Record({ key: Schema.String, value: Schema.Unknown }),
|
|
65
|
+
{ default: () => ({}) }
|
|
66
|
+
),
|
|
67
|
+
guards: Schema.optional(Schema.Array(AppliedGuardSchema))
|
|
68
|
+
});
|
|
69
|
+
var ContinuationSchema = Schema.Struct({
|
|
70
|
+
awaits: Schema.String,
|
|
71
|
+
flowId: Schema.String
|
|
72
|
+
});
|
|
73
|
+
var FlowSchema = Schema.Struct({
|
|
74
|
+
version: Schema.Literal(1),
|
|
75
|
+
id: Schema.String,
|
|
76
|
+
chainId: ChainIdSchema,
|
|
77
|
+
inputs: Schema.Array(FlowInputSchema),
|
|
78
|
+
nodes: Schema.Array(CallSchema),
|
|
79
|
+
continuation: Schema.optional(ContinuationSchema)
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// src/flow.ts
|
|
83
|
+
var isResourceInput = (input) => "resource" in input;
|
|
84
|
+
var flowInputType = (input) => isResourceInput(input) ? "uint256" : input.type;
|
|
85
|
+
var flowInputMode = (input) => isResourceInput(input) ? "linear" : "copy";
|
|
86
|
+
var flowInputResource = (input) => isResourceInput(input) ? input.resource : void 0;
|
|
87
|
+
var isResourcePort = (port) => port.kind === "resource";
|
|
88
|
+
var isHandlePort = (port) => port.kind === "handle";
|
|
89
|
+
var isResourceOutputPort = (port) => port.kind === "resource_output";
|
|
90
|
+
var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
|
|
91
|
+
|
|
92
|
+
// src/resource.ts
|
|
93
|
+
var foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
|
|
94
|
+
var resourceKey = (r) => foldResource(r, {
|
|
95
|
+
native: (chainId) => `native:${chainId}`,
|
|
96
|
+
erc20: (token, chainId) => `erc20:${token.toLowerCase()}:${chainId}`
|
|
97
|
+
});
|
|
98
|
+
var erc20Token = (r) => {
|
|
99
|
+
if (r.kind !== "erc20")
|
|
100
|
+
throw new Error(`Expected erc20 resource, got ${r.kind}`);
|
|
101
|
+
return r.token;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/constructors.ts
|
|
105
|
+
var linear = (name, type) => ({ name, type, mode: "linear", availability: "now" });
|
|
106
|
+
var copy = (name, type) => ({ name, type, mode: "copy", availability: "now" });
|
|
107
|
+
var handle = (name, type) => ({ name, type });
|
|
108
|
+
var native = (name, chainId) => ({ name, resource: { kind: "native", chainId } });
|
|
109
|
+
var erc20 = (name, token, chainId) => ({ name, resource: { kind: "erc20", token, chainId } });
|
|
110
|
+
var resource = (name, accepts) => ({ kind: "resource", name, accepts, mode: "linear" });
|
|
111
|
+
var readResource = (name, accepts) => ({ kind: "resource", name, accepts, mode: "copy" });
|
|
112
|
+
var opHandle = (name, type) => ({ kind: "handle", name, type, mode: "copy" });
|
|
113
|
+
var resourceOutput = (name, options) => {
|
|
114
|
+
const opts = typeof options === "string" ? { availability: options } : options;
|
|
115
|
+
return {
|
|
116
|
+
kind: "resource_output",
|
|
117
|
+
name,
|
|
118
|
+
mode: "linear",
|
|
119
|
+
...opts?.availability != null && { availability: opts.availability },
|
|
120
|
+
...opts?.providesMinimum != null && {
|
|
121
|
+
providesMinimum: opts.providesMinimum
|
|
122
|
+
},
|
|
123
|
+
...opts?.omitIfZero != null && { omitIfZero: opts.omitIfZero },
|
|
124
|
+
...opts?.deliveryAddressInput != null && {
|
|
125
|
+
deliveryAddressInput: opts.deliveryAddressInput
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/ref.ts
|
|
131
|
+
var isContextKey = (key) => key === "sender" || key === "executionAddress";
|
|
132
|
+
var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
|
|
133
|
+
"input",
|
|
134
|
+
"context",
|
|
135
|
+
"literal"
|
|
136
|
+
]);
|
|
137
|
+
var parseRef = (ref) => {
|
|
138
|
+
const dot = ref.$ref.indexOf(".");
|
|
139
|
+
if (dot === -1)
|
|
140
|
+
throw new Error(`Invalid ref: "${ref.$ref}" (must contain a dot)`);
|
|
141
|
+
const prefix = ref.$ref.slice(0, dot);
|
|
142
|
+
const suffix = ref.$ref.slice(dot + 1);
|
|
143
|
+
if (prefix === "input") return { scope: "input", port: suffix };
|
|
144
|
+
if (prefix === "context") {
|
|
145
|
+
if (!isContextKey(suffix))
|
|
146
|
+
throw new Error(`Unknown context key: "${suffix}"`);
|
|
147
|
+
return { scope: "context", key: suffix };
|
|
148
|
+
}
|
|
149
|
+
return { scope: "output", node: prefix, port: suffix };
|
|
150
|
+
};
|
|
151
|
+
var foldRef = (ref, cases) => {
|
|
152
|
+
if (ref.scope === "input") return cases.input(ref.port);
|
|
153
|
+
if (ref.scope === "context") return cases.context(ref.key);
|
|
154
|
+
return cases.output(ref.node, ref.port);
|
|
155
|
+
};
|
|
156
|
+
var refKey = (ref) => foldRef(parseRef(ref), {
|
|
157
|
+
input: (port) => `input:${port}`,
|
|
158
|
+
context: (key) => `context:${key}`,
|
|
159
|
+
output: (node, port) => `output:${node}:${port}`
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// src/materialiserMetadata.ts
|
|
163
|
+
var foldMaterialiserMetadata = (meta, cases) => {
|
|
164
|
+
if (meta.kind === "exact") return cases.exact(meta.amount);
|
|
165
|
+
if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
|
|
166
|
+
return cases.runtime();
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/zodSchemas.ts
|
|
170
|
+
import z from "zod";
|
|
171
|
+
var SolTypeZod = z.enum([
|
|
172
|
+
"uint8",
|
|
173
|
+
"uint16",
|
|
174
|
+
"uint32",
|
|
175
|
+
"uint64",
|
|
176
|
+
"uint128",
|
|
177
|
+
"uint256",
|
|
178
|
+
"int128",
|
|
179
|
+
"int256",
|
|
180
|
+
"address",
|
|
181
|
+
"bool",
|
|
182
|
+
"bytes",
|
|
183
|
+
"bytes4",
|
|
184
|
+
"bytes32",
|
|
185
|
+
"string"
|
|
186
|
+
]);
|
|
187
|
+
var ResourcePortZod = z.object({
|
|
188
|
+
kind: z.literal("resource"),
|
|
189
|
+
name: z.string(),
|
|
190
|
+
accepts: z.enum(["erc20", "native", "any"]),
|
|
191
|
+
mode: z.enum(["linear", "copy"])
|
|
192
|
+
});
|
|
193
|
+
var HandlePortZod = z.object({
|
|
194
|
+
kind: z.literal("handle"),
|
|
195
|
+
name: z.string(),
|
|
196
|
+
type: SolTypeZod,
|
|
197
|
+
mode: z.enum(["linear", "copy"])
|
|
198
|
+
});
|
|
199
|
+
var InputPortZod = z.discriminatedUnion("kind", [
|
|
200
|
+
ResourcePortZod,
|
|
201
|
+
HandlePortZod
|
|
202
|
+
]);
|
|
203
|
+
var ResourceOutputPortZod = z.object({
|
|
204
|
+
kind: z.literal("resource_output"),
|
|
205
|
+
name: z.string(),
|
|
206
|
+
mode: z.enum(["linear", "copy"]),
|
|
207
|
+
availability: z.enum(["now", "future"]).optional(),
|
|
208
|
+
providesMinimum: z.boolean().optional(),
|
|
209
|
+
omitIfZero: z.boolean().optional(),
|
|
210
|
+
deliveryAddressInput: z.string().optional()
|
|
211
|
+
});
|
|
212
|
+
var OutputPortZod = z.discriminatedUnion("kind", [
|
|
213
|
+
ResourceOutputPortZod,
|
|
214
|
+
HandlePortZod
|
|
215
|
+
]);
|
|
216
|
+
var ManifestOperationZod = z.object({
|
|
217
|
+
id: z.string(),
|
|
218
|
+
description: z.string().optional(),
|
|
219
|
+
inputs: z.array(InputPortZod),
|
|
220
|
+
outputs: z.array(OutputPortZod),
|
|
221
|
+
configSchema: z.unknown().optional()
|
|
222
|
+
});
|
|
223
|
+
var PortKindEnum = z.enum(["resource", "resource_output", "handle"]);
|
|
224
|
+
var SelectorMatchZod = z.object({
|
|
225
|
+
kind: z.union([PortKindEnum, z.array(PortKindEnum)]),
|
|
226
|
+
mode: z.enum(["linear", "copy"]).optional(),
|
|
227
|
+
type: z.enum(["erc20", "native", "any"]).optional()
|
|
228
|
+
});
|
|
229
|
+
var ConfigSelectionZod = z.object({
|
|
230
|
+
kind: z.literal("config"),
|
|
231
|
+
configKey: z.string(),
|
|
232
|
+
cardinality: z.enum(["one", "many"])
|
|
233
|
+
});
|
|
234
|
+
var AllMatchingSelectionZod = z.object({
|
|
235
|
+
kind: z.literal("all_matching")
|
|
236
|
+
});
|
|
237
|
+
var SelectorSelectionZod = z.discriminatedUnion("kind", [
|
|
238
|
+
ConfigSelectionZod,
|
|
239
|
+
AllMatchingSelectionZod
|
|
240
|
+
]);
|
|
241
|
+
var GuardSelectorZod = z.object({
|
|
242
|
+
binding: z.string(),
|
|
243
|
+
source: z.enum(["inputs", "outputs"]),
|
|
244
|
+
match: SelectorMatchZod,
|
|
245
|
+
selection: SelectorSelectionZod
|
|
246
|
+
});
|
|
247
|
+
var GuardCompatibilityZod = z.object({
|
|
248
|
+
selectors: z.array(GuardSelectorZod)
|
|
249
|
+
});
|
|
250
|
+
var ManifestGuardZod = z.object({
|
|
251
|
+
kind: z.string(),
|
|
252
|
+
description: z.string().optional(),
|
|
253
|
+
configSchema: z.unknown().optional(),
|
|
254
|
+
compatibility: GuardCompatibilityZod.optional()
|
|
255
|
+
});
|
|
256
|
+
var ManifestMaterialiserZod = z.object({
|
|
257
|
+
kind: z.string(),
|
|
258
|
+
description: z.string().optional(),
|
|
259
|
+
accepts: z.enum(["resource", "handle", "any"]),
|
|
260
|
+
configSchema: z.unknown().optional()
|
|
261
|
+
});
|
|
262
|
+
var ManifestPreconditionZod = z.object({
|
|
263
|
+
type: z.string(),
|
|
264
|
+
description: z.string().optional(),
|
|
265
|
+
configSchema: z.unknown().optional()
|
|
266
|
+
});
|
|
267
|
+
var ComposeManifestZod = z.object({
|
|
268
|
+
manifestVersion: z.number(),
|
|
269
|
+
manifestHash: z.string(),
|
|
270
|
+
flowSchema: z.object({}).passthrough(),
|
|
271
|
+
operations: z.array(ManifestOperationZod),
|
|
272
|
+
guards: z.array(ManifestGuardZod),
|
|
273
|
+
materialisers: z.array(ManifestMaterialiserZod),
|
|
274
|
+
preconditions: z.array(ManifestPreconditionZod).optional()
|
|
275
|
+
});
|
|
276
|
+
export {
|
|
277
|
+
AppliedGuardSchema,
|
|
278
|
+
BindValueSchema,
|
|
279
|
+
CallSchema,
|
|
280
|
+
ComposeManifestZod,
|
|
281
|
+
ContinuationSchema,
|
|
282
|
+
FlowInputSchema,
|
|
283
|
+
FlowSchema,
|
|
284
|
+
GuardCompatibilityZod,
|
|
285
|
+
GuardSelectorZod,
|
|
286
|
+
HandleInputSchema,
|
|
287
|
+
HandlePortZod,
|
|
288
|
+
InputPortZod,
|
|
289
|
+
LiteralBindingSchema,
|
|
290
|
+
ManifestGuardZod,
|
|
291
|
+
ManifestMaterialiserZod,
|
|
292
|
+
ManifestOperationZod,
|
|
293
|
+
ManifestPreconditionZod,
|
|
294
|
+
OutputPortZod,
|
|
295
|
+
RESERVED_REF_SCOPES,
|
|
296
|
+
RefSchema,
|
|
297
|
+
ResourceInputSchema,
|
|
298
|
+
ResourceOutputPortZod,
|
|
299
|
+
ResourcePortZod,
|
|
300
|
+
ResourceSchema,
|
|
301
|
+
SolTypeSchema,
|
|
302
|
+
copy,
|
|
303
|
+
erc20,
|
|
304
|
+
erc20Token,
|
|
305
|
+
flowInputMode,
|
|
306
|
+
flowInputResource,
|
|
307
|
+
flowInputType,
|
|
308
|
+
foldMaterialiserMetadata,
|
|
309
|
+
foldRef,
|
|
310
|
+
foldResource,
|
|
311
|
+
handle,
|
|
312
|
+
isContextKey,
|
|
313
|
+
isHandlePort,
|
|
314
|
+
isMaterialiserInput,
|
|
315
|
+
isResourceInput,
|
|
316
|
+
isResourceOutputPort,
|
|
317
|
+
isResourcePort,
|
|
318
|
+
linear,
|
|
319
|
+
native,
|
|
320
|
+
opHandle,
|
|
321
|
+
parseRef,
|
|
322
|
+
readResource,
|
|
323
|
+
refKey,
|
|
324
|
+
resource,
|
|
325
|
+
resourceKey,
|
|
326
|
+
resourceOutput
|
|
327
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lifi/compose-spec",
|
|
3
|
+
"version": "0.0.1-alpha",
|
|
4
|
+
"description": "Public wire-format types and schemas for Compose flows",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "yarn check:types && tsup",
|
|
28
|
+
"check:types": "tsc --noEmit",
|
|
29
|
+
"clean": "rm -rf dist out",
|
|
30
|
+
"pack:local": "yarn build && mkdir -p out && yarn pack --out 'out/%s-%v.tgz'",
|
|
31
|
+
"test": "vitest run --config vitest.config.ts"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"effect": "^3.21.0",
|
|
35
|
+
"zod": "^4.1.11"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsup": "^8.5.1",
|
|
39
|
+
"typescript": "^5.9.2",
|
|
40
|
+
"vitest": "^3.2.4"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/**",
|
|
44
|
+
"!dist/**/*.tsbuildinfo",
|
|
45
|
+
"src/**/*.ts",
|
|
46
|
+
"!src/**/*.spec.ts",
|
|
47
|
+
"!src/**/*.test.ts",
|
|
48
|
+
"!src/**/*.mock.ts",
|
|
49
|
+
"!src/**/*.typecheck.ts",
|
|
50
|
+
"!dist/**/*.typecheck.*"
|
|
51
|
+
]
|
|
52
|
+
}
|
package/src/compile.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Flow } from "./flowSchema.js";
|
|
2
|
+
import type { InputSpec, Precondition } from "./flow.js";
|
|
3
|
+
import type { ProducedResource } from "./resource.js";
|
|
4
|
+
|
|
5
|
+
export type SimulationPolicy = "strict" | "allow-revert";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Destination for sweeping proxy-held terminal resources after execution.
|
|
9
|
+
* Either a literal EVM address or a `{ $ref }` context reference
|
|
10
|
+
* (e.g. `{ $ref: "context.sender" }`).
|
|
11
|
+
*/
|
|
12
|
+
export type SweepTo = string | { readonly $ref: string };
|
|
13
|
+
|
|
14
|
+
export interface ComposeRun {
|
|
15
|
+
readonly inputs: Record<string, InputSpec>;
|
|
16
|
+
readonly preconditions?: readonly Precondition[];
|
|
17
|
+
readonly signer: string;
|
|
18
|
+
readonly assumptions?: Record<string, bigint>;
|
|
19
|
+
readonly referrer?: string;
|
|
20
|
+
readonly maxPriceImpactBps?: number;
|
|
21
|
+
readonly sweepTo?: SweepTo;
|
|
22
|
+
readonly simulationPolicy?: SimulationPolicy;
|
|
23
|
+
readonly checkOnChainAllowances?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ComposeCompileRequest {
|
|
27
|
+
readonly flow: Flow;
|
|
28
|
+
readonly run: ComposeRun;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PriceImpact {
|
|
32
|
+
readonly inputValueUsd: number;
|
|
33
|
+
readonly outputValueUsd: number;
|
|
34
|
+
readonly impactBps: number;
|
|
35
|
+
readonly unpricedInputs: readonly string[];
|
|
36
|
+
readonly unpricedOutputs: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ApprovalEntry {
|
|
40
|
+
readonly token: string;
|
|
41
|
+
readonly spender: string;
|
|
42
|
+
readonly amount: string;
|
|
43
|
+
readonly transactionRequest: {
|
|
44
|
+
readonly to: string;
|
|
45
|
+
readonly data: string;
|
|
46
|
+
readonly value: "0";
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SimulationRevert {
|
|
51
|
+
readonly code: number;
|
|
52
|
+
readonly rawErrorBytes: string;
|
|
53
|
+
readonly decodeResult?: {
|
|
54
|
+
readonly errorCandidates?: readonly {
|
|
55
|
+
readonly decodedErrorSignature: string;
|
|
56
|
+
readonly decodedParams: readonly string[];
|
|
57
|
+
}[];
|
|
58
|
+
readonly error?: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ComposeTransactionRequest {
|
|
63
|
+
readonly to: string;
|
|
64
|
+
readonly data: string;
|
|
65
|
+
readonly value: string;
|
|
66
|
+
readonly gasLimit?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ComposeContinuation {
|
|
70
|
+
readonly awaits: string;
|
|
71
|
+
readonly flowId: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ComposeCompileSuccessData {
|
|
75
|
+
readonly producedResources: Record<string, ProducedResource>;
|
|
76
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
77
|
+
readonly userProxy: string;
|
|
78
|
+
readonly priceImpact?: PriceImpact;
|
|
79
|
+
readonly approvals?: readonly ApprovalEntry[];
|
|
80
|
+
readonly continuation?: ComposeContinuation;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ComposeCompilePartialData {
|
|
84
|
+
readonly producedResources: Record<string, ProducedResource>;
|
|
85
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
86
|
+
readonly userProxy: string;
|
|
87
|
+
readonly simulationRevert: SimulationRevert;
|
|
88
|
+
readonly approvals?: readonly ApprovalEntry[];
|
|
89
|
+
readonly continuation?: ComposeContinuation;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type ComposeCompileResult =
|
|
93
|
+
| (ComposeCompileSuccessData & { readonly status: "success" })
|
|
94
|
+
| (ComposeCompilePartialData & {
|
|
95
|
+
readonly status: "partial";
|
|
96
|
+
readonly error: { readonly kind: string; readonly message: string };
|
|
97
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { HandleInput, ResourceInput, SolType } from "./flowSchema.js";
|
|
2
|
+
import type {
|
|
3
|
+
Port,
|
|
4
|
+
ResourcePort,
|
|
5
|
+
HandlePort,
|
|
6
|
+
ResourceOutputPort,
|
|
7
|
+
} from "./flow.js";
|
|
8
|
+
import type { Availability } from "./resource.js";
|
|
9
|
+
|
|
10
|
+
export const linear = <N extends string, T extends SolType>(
|
|
11
|
+
name: N,
|
|
12
|
+
type: T
|
|
13
|
+
): Port & { readonly name: N; readonly type: T; readonly mode: "linear" } =>
|
|
14
|
+
({ name, type, mode: "linear", availability: "now" } as Port & {
|
|
15
|
+
readonly name: N;
|
|
16
|
+
readonly type: T;
|
|
17
|
+
readonly mode: "linear";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const copy = <N extends string, T extends SolType>(
|
|
21
|
+
name: N,
|
|
22
|
+
type: T
|
|
23
|
+
): Port & { readonly name: N; readonly type: T; readonly mode: "copy" } =>
|
|
24
|
+
({ name, type, mode: "copy", availability: "now" } as Port & {
|
|
25
|
+
readonly name: N;
|
|
26
|
+
readonly type: T;
|
|
27
|
+
readonly mode: "copy";
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const handle = <N extends string, T extends SolType>(
|
|
31
|
+
name: N,
|
|
32
|
+
type: T
|
|
33
|
+
): HandleInput & { readonly name: N; readonly type: T } =>
|
|
34
|
+
({ name, type } as HandleInput & { readonly name: N; readonly type: T });
|
|
35
|
+
|
|
36
|
+
export const native = <N extends string>(
|
|
37
|
+
name: N,
|
|
38
|
+
chainId: number
|
|
39
|
+
): ResourceInput & { readonly name: N } =>
|
|
40
|
+
({ name, resource: { kind: "native", chainId } } as ResourceInput & {
|
|
41
|
+
readonly name: N;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const erc20 = <N extends string>(
|
|
45
|
+
name: N,
|
|
46
|
+
token: string,
|
|
47
|
+
chainId: number
|
|
48
|
+
): ResourceInput & { readonly name: N } =>
|
|
49
|
+
({ name, resource: { kind: "erc20", token, chainId } } as ResourceInput & {
|
|
50
|
+
readonly name: N;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const resource = <N extends string>(
|
|
54
|
+
name: N,
|
|
55
|
+
accepts: "erc20" | "native" | "any"
|
|
56
|
+
): ResourcePort & { readonly name: N } =>
|
|
57
|
+
({ kind: "resource", name, accepts, mode: "linear" } as ResourcePort & {
|
|
58
|
+
readonly name: N;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const readResource = <N extends string>(
|
|
62
|
+
name: N,
|
|
63
|
+
accepts: "erc20" | "native" | "any"
|
|
64
|
+
): ResourcePort & { readonly name: N; readonly mode: "copy" } =>
|
|
65
|
+
({ kind: "resource", name, accepts, mode: "copy" } as ResourcePort & {
|
|
66
|
+
readonly name: N;
|
|
67
|
+
readonly mode: "copy";
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const opHandle = <N extends string, T extends SolType>(
|
|
71
|
+
name: N,
|
|
72
|
+
type: T
|
|
73
|
+
): HandlePort & { readonly name: N; readonly type: T } =>
|
|
74
|
+
({ kind: "handle", name, type, mode: "copy" } as HandlePort & {
|
|
75
|
+
readonly name: N;
|
|
76
|
+
readonly type: T;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const resourceOutput = <N extends string>(
|
|
80
|
+
name: N,
|
|
81
|
+
options?:
|
|
82
|
+
| Availability
|
|
83
|
+
| {
|
|
84
|
+
availability?: Availability;
|
|
85
|
+
providesMinimum?: boolean;
|
|
86
|
+
omitIfZero?: boolean;
|
|
87
|
+
deliveryAddressInput?: string;
|
|
88
|
+
}
|
|
89
|
+
): ResourceOutputPort & { readonly name: N } => {
|
|
90
|
+
const opts =
|
|
91
|
+
typeof options === "string" ? { availability: options } : options;
|
|
92
|
+
return {
|
|
93
|
+
kind: "resource_output",
|
|
94
|
+
name,
|
|
95
|
+
mode: "linear",
|
|
96
|
+
...(opts?.availability != null && { availability: opts.availability }),
|
|
97
|
+
...(opts?.providesMinimum != null && {
|
|
98
|
+
providesMinimum: opts.providesMinimum,
|
|
99
|
+
}),
|
|
100
|
+
...(opts?.omitIfZero != null && { omitIfZero: opts.omitIfZero }),
|
|
101
|
+
...(opts?.deliveryAddressInput != null && {
|
|
102
|
+
deliveryAddressInput: opts.deliveryAddressInput,
|
|
103
|
+
}),
|
|
104
|
+
} as ResourceOutputPort & { readonly name: N };
|
|
105
|
+
};
|
package/src/flow.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Availability, Resource } from "./resource.js";
|
|
2
|
+
import type { FlowInput, ResourceInput, SolType } from "./flowSchema.js";
|
|
3
|
+
|
|
4
|
+
export type {
|
|
5
|
+
ResourcePort,
|
|
6
|
+
HandlePort,
|
|
7
|
+
OpInputPort,
|
|
8
|
+
ResourceOutputPort,
|
|
9
|
+
OpOutputPort,
|
|
10
|
+
} from "./zodSchemas.js";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
OpInputPort,
|
|
14
|
+
OpOutputPort,
|
|
15
|
+
ResourcePort,
|
|
16
|
+
HandlePort,
|
|
17
|
+
ResourceOutputPort,
|
|
18
|
+
} from "./zodSchemas.js";
|
|
19
|
+
|
|
20
|
+
export interface Port {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly type: SolType;
|
|
23
|
+
readonly mode: "linear" | "copy";
|
|
24
|
+
readonly availability?: Availability;
|
|
25
|
+
readonly resource?: Resource;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const isResourceInput = (input: FlowInput): input is ResourceInput =>
|
|
29
|
+
"resource" in input;
|
|
30
|
+
|
|
31
|
+
export const flowInputType = (input: FlowInput): SolType =>
|
|
32
|
+
isResourceInput(input) ? "uint256" : input.type;
|
|
33
|
+
|
|
34
|
+
export const flowInputMode = (input: FlowInput): "linear" | "copy" =>
|
|
35
|
+
isResourceInput(input) ? "linear" : "copy";
|
|
36
|
+
|
|
37
|
+
export const flowInputResource = (input: FlowInput): Resource | undefined =>
|
|
38
|
+
isResourceInput(input) ? input.resource : undefined;
|
|
39
|
+
|
|
40
|
+
export const isResourcePort = (port: OpInputPort): port is ResourcePort =>
|
|
41
|
+
port.kind === "resource";
|
|
42
|
+
|
|
43
|
+
export const isHandlePort = (
|
|
44
|
+
port: OpInputPort | OpOutputPort
|
|
45
|
+
): port is HandlePort => port.kind === "handle";
|
|
46
|
+
|
|
47
|
+
export const isResourceOutputPort = (
|
|
48
|
+
port: OpInputPort | OpOutputPort
|
|
49
|
+
): port is ResourceOutputPort => port.kind === "resource_output";
|
|
50
|
+
|
|
51
|
+
export type ComposeErrorKind =
|
|
52
|
+
| "decode_error"
|
|
53
|
+
| "validation_error"
|
|
54
|
+
| "linearity_error"
|
|
55
|
+
| "resolve_error"
|
|
56
|
+
| "preparation_error"
|
|
57
|
+
| "no_route_error"
|
|
58
|
+
| "lowering_error"
|
|
59
|
+
| "simulation_error"
|
|
60
|
+
| "simulation_setup_error"
|
|
61
|
+
| "simulation_revert"
|
|
62
|
+
| "guard_error"
|
|
63
|
+
| "continuation_error"
|
|
64
|
+
| "compilation_error"
|
|
65
|
+
| "verification_error"
|
|
66
|
+
| "price_impact_exceeded";
|
|
67
|
+
|
|
68
|
+
export interface ComposeError {
|
|
69
|
+
readonly kind: ComposeErrorKind;
|
|
70
|
+
readonly message: string;
|
|
71
|
+
readonly path?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface MaterialiserInputBase {
|
|
75
|
+
readonly kind: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type MaterialiserInput = MaterialiserInputBase & Record<string, unknown>;
|
|
79
|
+
|
|
80
|
+
export type MaterialiserInputOf<C extends object> = MaterialiserInputBase & C;
|
|
81
|
+
|
|
82
|
+
export type MaterialiserConfigOf<C extends object> = C;
|
|
83
|
+
|
|
84
|
+
export const isMaterialiserInput = (s: InputSpec): s is MaterialiserInput =>
|
|
85
|
+
typeof s === "object" && s !== null && "kind" in s;
|
|
86
|
+
|
|
87
|
+
export type InputSpec = bigint | string | MaterialiserInput;
|
|
88
|
+
|
|
89
|
+
export interface PreconditionBase {
|
|
90
|
+
readonly type: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type Precondition = PreconditionBase & Record<string, unknown>;
|
|
94
|
+
|
|
95
|
+
export type PreconditionOf<C extends object> = PreconditionBase & C;
|
|
96
|
+
|
|
97
|
+
export type PreconditionConfigOf<C extends object> = Omit<
|
|
98
|
+
PreconditionBase,
|
|
99
|
+
"type"
|
|
100
|
+
> &
|
|
101
|
+
C;
|