@lifi/compose-spec 0.0.1-alpha → 0.2.0-staging.4
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.cjs +128 -16
- package/dist/index.d.cts +233 -94
- package/dist/index.d.ts +233 -94
- package/dist/index.js +111 -15
- package/package.json +6 -1
- package/src/compile.ts +2 -1
- package/src/constructors.ts +48 -19
- package/src/flashloan.ts +41 -0
- package/src/flow.ts +47 -8
- package/src/index.ts +34 -1
- package/src/ref.ts +6 -0
- package/src/resource.ts +32 -1
- package/src/zodSchemas.ts +37 -0
package/dist/index.cjs
CHANGED
|
@@ -39,8 +39,10 @@ __export(index_exports, {
|
|
|
39
39
|
FlowSchema: () => FlowSchema,
|
|
40
40
|
GuardCompatibilityZod: () => GuardCompatibilityZod,
|
|
41
41
|
GuardSelectorZod: () => GuardSelectorZod,
|
|
42
|
+
HANDLE_UNITS: () => HANDLE_UNITS,
|
|
42
43
|
HandleInputSchema: () => HandleInputSchema,
|
|
43
44
|
HandlePortZod: () => HandlePortZod,
|
|
45
|
+
HandleUnitsZod: () => HandleUnitsZod,
|
|
44
46
|
InputPortZod: () => InputPortZod,
|
|
45
47
|
LiteralBindingSchema: () => LiteralBindingSchema,
|
|
46
48
|
ManifestGuardZod: () => ManifestGuardZod,
|
|
@@ -48,15 +50,19 @@ __export(index_exports, {
|
|
|
48
50
|
ManifestOperationZod: () => ManifestOperationZod,
|
|
49
51
|
ManifestPreconditionZod: () => ManifestPreconditionZod,
|
|
50
52
|
OutputPortZod: () => OutputPortZod,
|
|
53
|
+
PROVIDER_KIND: () => PROVIDER_KIND,
|
|
51
54
|
RESERVED_REF_SCOPES: () => RESERVED_REF_SCOPES,
|
|
52
55
|
RefSchema: () => RefSchema,
|
|
53
56
|
ResourceInputSchema: () => ResourceInputSchema,
|
|
54
57
|
ResourceOutputPortZod: () => ResourceOutputPortZod,
|
|
55
58
|
ResourcePortZod: () => ResourcePortZod,
|
|
56
59
|
ResourceSchema: () => ResourceSchema,
|
|
60
|
+
STATIC_SOL_TYPES: () => STATIC_SOL_TYPES,
|
|
57
61
|
SolTypeSchema: () => SolTypeSchema,
|
|
62
|
+
StaticSolTypeZod: () => StaticSolTypeZod,
|
|
58
63
|
copy: () => copy,
|
|
59
64
|
erc20: () => erc20,
|
|
65
|
+
erc20Resource: () => erc20Resource,
|
|
60
66
|
erc20Token: () => erc20Token,
|
|
61
67
|
flowInputMode: () => flowInputMode,
|
|
62
68
|
flowInputResource: () => flowInputResource,
|
|
@@ -65,21 +71,31 @@ __export(index_exports, {
|
|
|
65
71
|
foldRef: () => foldRef,
|
|
66
72
|
foldResource: () => foldResource,
|
|
67
73
|
handle: () => handle,
|
|
74
|
+
inputRef: () => inputRef,
|
|
68
75
|
isContextKey: () => isContextKey,
|
|
76
|
+
isERC20Resource: () => isERC20Resource,
|
|
69
77
|
isHandlePort: () => isHandlePort,
|
|
70
78
|
isMaterialiserInput: () => isMaterialiserInput,
|
|
79
|
+
isNativeResource: () => isNativeResource,
|
|
80
|
+
isRef: () => isRef,
|
|
71
81
|
isResourceInput: () => isResourceInput,
|
|
72
82
|
isResourceOutputPort: () => isResourceOutputPort,
|
|
73
83
|
isResourcePort: () => isResourcePort,
|
|
84
|
+
isStaticSolType: () => isStaticSolType,
|
|
74
85
|
linear: () => linear,
|
|
75
86
|
native: () => native,
|
|
87
|
+
nativeResource: () => nativeResource,
|
|
76
88
|
opHandle: () => opHandle,
|
|
89
|
+
outputRef: () => outputRef,
|
|
77
90
|
parseRef: () => parseRef,
|
|
91
|
+
providerKindByName: () => providerKindByName,
|
|
92
|
+
providerKindNames: () => providerKindNames,
|
|
78
93
|
readResource: () => readResource,
|
|
79
94
|
refKey: () => refKey,
|
|
80
95
|
resource: () => resource,
|
|
81
96
|
resourceKey: () => resourceKey,
|
|
82
|
-
resourceOutput: () => resourceOutput
|
|
97
|
+
resourceOutput: () => resourceOutput,
|
|
98
|
+
resourcesEqual: () => resourcesEqual
|
|
83
99
|
});
|
|
84
100
|
module.exports = __toCommonJS(index_exports);
|
|
85
101
|
|
|
@@ -175,6 +191,26 @@ var isResourceOutputPort = (port) => port.kind === "resource_output";
|
|
|
175
191
|
var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
|
|
176
192
|
|
|
177
193
|
// src/resource.ts
|
|
194
|
+
var erc20Resource = (token, chainId) => ({
|
|
195
|
+
kind: "erc20",
|
|
196
|
+
token,
|
|
197
|
+
chainId
|
|
198
|
+
});
|
|
199
|
+
var nativeResource = (chainId) => ({
|
|
200
|
+
kind: "native",
|
|
201
|
+
chainId
|
|
202
|
+
});
|
|
203
|
+
var isERC20Resource = (r) => r.kind === "erc20";
|
|
204
|
+
var isNativeResource = (r) => r.kind === "native";
|
|
205
|
+
var resourcesEqual = (a, b) => {
|
|
206
|
+
if (isNativeResource(a) && isNativeResource(b)) {
|
|
207
|
+
return a.chainId === b.chainId;
|
|
208
|
+
}
|
|
209
|
+
if (isERC20Resource(a) && isERC20Resource(b)) {
|
|
210
|
+
return a.chainId === b.chainId && a.token.toLowerCase() === b.token.toLowerCase();
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
};
|
|
178
214
|
var foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
|
|
179
215
|
var resourceKey = (r) => foldResource(r, {
|
|
180
216
|
native: (chainId) => `native:${chainId}`,
|
|
@@ -186,29 +222,63 @@ var erc20Token = (r) => {
|
|
|
186
222
|
return r.token;
|
|
187
223
|
};
|
|
188
224
|
|
|
225
|
+
// src/flashloan.ts
|
|
226
|
+
var PROVIDER_KIND = {
|
|
227
|
+
AAVE_V3: 0,
|
|
228
|
+
ERC3156: 1,
|
|
229
|
+
BALANCER_V2: 2,
|
|
230
|
+
MORPHO_BLUE: 3
|
|
231
|
+
};
|
|
232
|
+
var providerKindNames = [
|
|
233
|
+
"aave-v3",
|
|
234
|
+
"erc3156",
|
|
235
|
+
"balancer-v2",
|
|
236
|
+
"morpho-blue"
|
|
237
|
+
];
|
|
238
|
+
var providerKindByName = {
|
|
239
|
+
"aave-v3": PROVIDER_KIND.AAVE_V3,
|
|
240
|
+
erc3156: PROVIDER_KIND.ERC3156,
|
|
241
|
+
"balancer-v2": PROVIDER_KIND.BALANCER_V2,
|
|
242
|
+
"morpho-blue": PROVIDER_KIND.MORPHO_BLUE
|
|
243
|
+
};
|
|
244
|
+
|
|
189
245
|
// src/constructors.ts
|
|
246
|
+
var inputRef = (port) => ({ $ref: `input.${port}` });
|
|
247
|
+
var outputRef = (node, port) => ({
|
|
248
|
+
$ref: `${node}.${port}`
|
|
249
|
+
});
|
|
250
|
+
var optionalProp = (key, value) => value != null ? { [key]: value } : {};
|
|
190
251
|
var linear = (name, type) => ({ name, type, mode: "linear", availability: "now" });
|
|
191
252
|
var copy = (name, type) => ({ name, type, mode: "copy", availability: "now" });
|
|
192
253
|
var handle = (name, type) => ({ name, type });
|
|
193
|
-
var native = (name, chainId) => ({ name, resource:
|
|
194
|
-
var erc20 = (name, token, chainId) => ({ name, resource:
|
|
195
|
-
var resource = (name, accepts) => ({
|
|
254
|
+
var native = (name, chainId) => ({ name, resource: nativeResource(chainId) });
|
|
255
|
+
var erc20 = (name, token, chainId) => ({ name, resource: erc20Resource(token, chainId) });
|
|
256
|
+
var resource = (name, accepts, options) => ({
|
|
257
|
+
kind: "resource",
|
|
258
|
+
name,
|
|
259
|
+
accepts,
|
|
260
|
+
mode: "linear",
|
|
261
|
+
...optionalProp("optional", options?.optional)
|
|
262
|
+
});
|
|
196
263
|
var readResource = (name, accepts) => ({ kind: "resource", name, accepts, mode: "copy" });
|
|
197
|
-
var opHandle = (name, type) => ({
|
|
264
|
+
var opHandle = (name, type, options) => ({
|
|
265
|
+
kind: "handle",
|
|
266
|
+
name,
|
|
267
|
+
type,
|
|
268
|
+
mode: "copy",
|
|
269
|
+
...optionalProp("expose", options?.expose),
|
|
270
|
+
...optionalProp("units", options?.units)
|
|
271
|
+
});
|
|
198
272
|
var resourceOutput = (name, options) => {
|
|
199
273
|
const opts = typeof options === "string" ? { availability: options } : options;
|
|
200
274
|
return {
|
|
201
275
|
kind: "resource_output",
|
|
202
276
|
name,
|
|
203
277
|
mode: "linear",
|
|
204
|
-
...
|
|
205
|
-
...opts?.providesMinimum
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
...opts?.omitIfZero != null && { omitIfZero: opts.omitIfZero },
|
|
209
|
-
...opts?.deliveryAddressInput != null && {
|
|
210
|
-
deliveryAddressInput: opts.deliveryAddressInput
|
|
211
|
-
}
|
|
278
|
+
...optionalProp("availability", opts?.availability),
|
|
279
|
+
...optionalProp("providesMinimum", opts?.providesMinimum),
|
|
280
|
+
...optionalProp("omitIfZero", opts?.omitIfZero),
|
|
281
|
+
...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput)
|
|
212
282
|
};
|
|
213
283
|
};
|
|
214
284
|
|
|
@@ -219,6 +289,7 @@ var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
|
|
|
219
289
|
"context",
|
|
220
290
|
"literal"
|
|
221
291
|
]);
|
|
292
|
+
var isRef = (v) => typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string";
|
|
222
293
|
var parseRef = (ref) => {
|
|
223
294
|
const dot = ref.$ref.indexOf(".");
|
|
224
295
|
if (dot === -1)
|
|
@@ -273,13 +344,38 @@ var ResourcePortZod = import_zod.default.object({
|
|
|
273
344
|
kind: import_zod.default.literal("resource"),
|
|
274
345
|
name: import_zod.default.string(),
|
|
275
346
|
accepts: import_zod.default.enum(["erc20", "native", "any"]),
|
|
276
|
-
mode: import_zod.default.enum(["linear", "copy"])
|
|
347
|
+
mode: import_zod.default.enum(["linear", "copy"]),
|
|
348
|
+
optional: import_zod.default.boolean().optional()
|
|
277
349
|
});
|
|
350
|
+
var HANDLE_UNITS = [
|
|
351
|
+
"raw",
|
|
352
|
+
"wad",
|
|
353
|
+
"ray",
|
|
354
|
+
"bps",
|
|
355
|
+
"token-decimals"
|
|
356
|
+
];
|
|
357
|
+
var STATIC_SOL_TYPES = [
|
|
358
|
+
"uint256",
|
|
359
|
+
"uint128",
|
|
360
|
+
"uint64",
|
|
361
|
+
"uint32",
|
|
362
|
+
"uint16",
|
|
363
|
+
"uint8",
|
|
364
|
+
"address",
|
|
365
|
+
"bool",
|
|
366
|
+
"bytes32"
|
|
367
|
+
];
|
|
368
|
+
var HandleUnitsZod = import_zod.default.enum(HANDLE_UNITS);
|
|
369
|
+
var StaticSolTypeZod = import_zod.default.enum(STATIC_SOL_TYPES);
|
|
370
|
+
var STATIC_SOL_TYPE_SET = new Set(STATIC_SOL_TYPES);
|
|
371
|
+
var isStaticSolType = (value) => STATIC_SOL_TYPE_SET.has(value);
|
|
278
372
|
var HandlePortZod = import_zod.default.object({
|
|
279
373
|
kind: import_zod.default.literal("handle"),
|
|
280
374
|
name: import_zod.default.string(),
|
|
281
375
|
type: SolTypeZod,
|
|
282
|
-
mode: import_zod.default.enum(["linear", "copy"])
|
|
376
|
+
mode: import_zod.default.enum(["linear", "copy"]),
|
|
377
|
+
expose: import_zod.default.boolean().optional(),
|
|
378
|
+
units: HandleUnitsZod.optional()
|
|
283
379
|
});
|
|
284
380
|
var InputPortZod = import_zod.default.discriminatedUnion("kind", [
|
|
285
381
|
ResourcePortZod,
|
|
@@ -369,8 +465,10 @@ var ComposeManifestZod = import_zod.default.object({
|
|
|
369
465
|
FlowSchema,
|
|
370
466
|
GuardCompatibilityZod,
|
|
371
467
|
GuardSelectorZod,
|
|
468
|
+
HANDLE_UNITS,
|
|
372
469
|
HandleInputSchema,
|
|
373
470
|
HandlePortZod,
|
|
471
|
+
HandleUnitsZod,
|
|
374
472
|
InputPortZod,
|
|
375
473
|
LiteralBindingSchema,
|
|
376
474
|
ManifestGuardZod,
|
|
@@ -378,15 +476,19 @@ var ComposeManifestZod = import_zod.default.object({
|
|
|
378
476
|
ManifestOperationZod,
|
|
379
477
|
ManifestPreconditionZod,
|
|
380
478
|
OutputPortZod,
|
|
479
|
+
PROVIDER_KIND,
|
|
381
480
|
RESERVED_REF_SCOPES,
|
|
382
481
|
RefSchema,
|
|
383
482
|
ResourceInputSchema,
|
|
384
483
|
ResourceOutputPortZod,
|
|
385
484
|
ResourcePortZod,
|
|
386
485
|
ResourceSchema,
|
|
486
|
+
STATIC_SOL_TYPES,
|
|
387
487
|
SolTypeSchema,
|
|
488
|
+
StaticSolTypeZod,
|
|
388
489
|
copy,
|
|
389
490
|
erc20,
|
|
491
|
+
erc20Resource,
|
|
390
492
|
erc20Token,
|
|
391
493
|
flowInputMode,
|
|
392
494
|
flowInputResource,
|
|
@@ -395,19 +497,29 @@ var ComposeManifestZod = import_zod.default.object({
|
|
|
395
497
|
foldRef,
|
|
396
498
|
foldResource,
|
|
397
499
|
handle,
|
|
500
|
+
inputRef,
|
|
398
501
|
isContextKey,
|
|
502
|
+
isERC20Resource,
|
|
399
503
|
isHandlePort,
|
|
400
504
|
isMaterialiserInput,
|
|
505
|
+
isNativeResource,
|
|
506
|
+
isRef,
|
|
401
507
|
isResourceInput,
|
|
402
508
|
isResourceOutputPort,
|
|
403
509
|
isResourcePort,
|
|
510
|
+
isStaticSolType,
|
|
404
511
|
linear,
|
|
405
512
|
native,
|
|
513
|
+
nativeResource,
|
|
406
514
|
opHandle,
|
|
515
|
+
outputRef,
|
|
407
516
|
parseRef,
|
|
517
|
+
providerKindByName,
|
|
518
|
+
providerKindNames,
|
|
408
519
|
readResource,
|
|
409
520
|
refKey,
|
|
410
521
|
resource,
|
|
411
522
|
resourceKey,
|
|
412
|
-
resourceOutput
|
|
523
|
+
resourceOutput,
|
|
524
|
+
resourcesEqual
|
|
413
525
|
});
|