@lifi/compose-spec 0.0.1-alpha → 0.1.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/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.d.ts
CHANGED
|
@@ -161,6 +161,15 @@ type ProducedResource = Resource & {
|
|
|
161
161
|
readonly simulated?: SimulatedAmounts;
|
|
162
162
|
readonly owner: string;
|
|
163
163
|
};
|
|
164
|
+
declare const erc20Resource: (token: string, chainId: number) => Resource;
|
|
165
|
+
declare const nativeResource: (chainId: number) => Resource;
|
|
166
|
+
declare const isERC20Resource: (r: Resource) => r is Extract<Resource, {
|
|
167
|
+
kind: "erc20";
|
|
168
|
+
}>;
|
|
169
|
+
declare const isNativeResource: (r: Resource) => r is Extract<Resource, {
|
|
170
|
+
kind: "native";
|
|
171
|
+
}>;
|
|
172
|
+
declare const resourcesEqual: (a: Resource, b: Resource) => boolean;
|
|
164
173
|
declare const foldResource: <R>(r: Resource, cases: {
|
|
165
174
|
readonly native: (chainId: number) => R;
|
|
166
175
|
readonly erc20: (token: string, chainId: number) => R;
|
|
@@ -168,6 +177,95 @@ declare const foldResource: <R>(r: Resource, cases: {
|
|
|
168
177
|
declare const resourceKey: (r: Resource) => string;
|
|
169
178
|
declare const erc20Token: (r: Resource) => string;
|
|
170
179
|
|
|
180
|
+
type SimulationPolicy = "strict" | "allow-revert";
|
|
181
|
+
/**
|
|
182
|
+
* Destination for sweeping proxy-held terminal resources after execution.
|
|
183
|
+
* Either a literal EVM address or a `{ $ref }` context reference
|
|
184
|
+
* (e.g. `{ $ref: "context.sender" }`).
|
|
185
|
+
*/
|
|
186
|
+
type SweepTo = string | {
|
|
187
|
+
readonly $ref: string;
|
|
188
|
+
};
|
|
189
|
+
interface ComposeRun {
|
|
190
|
+
readonly inputs: Record<string, InputSpec>;
|
|
191
|
+
readonly preconditions?: readonly Precondition[];
|
|
192
|
+
readonly signer: string;
|
|
193
|
+
readonly assumptions?: Record<string, bigint>;
|
|
194
|
+
readonly referrer?: string;
|
|
195
|
+
readonly integratorFeeBps?: number;
|
|
196
|
+
readonly maxPriceImpactBps?: number;
|
|
197
|
+
readonly sweepTo?: SweepTo;
|
|
198
|
+
readonly simulationPolicy?: SimulationPolicy;
|
|
199
|
+
readonly checkOnChainAllowances?: boolean;
|
|
200
|
+
}
|
|
201
|
+
interface ComposeCompileRequest {
|
|
202
|
+
readonly flow: Flow;
|
|
203
|
+
readonly run: ComposeRun;
|
|
204
|
+
}
|
|
205
|
+
interface PriceImpact {
|
|
206
|
+
readonly inputValueUsd: number;
|
|
207
|
+
readonly outputValueUsd: number;
|
|
208
|
+
readonly impactBps: number;
|
|
209
|
+
readonly unpricedInputs: readonly string[];
|
|
210
|
+
readonly unpricedOutputs: readonly string[];
|
|
211
|
+
}
|
|
212
|
+
interface ApprovalEntry {
|
|
213
|
+
readonly token: string;
|
|
214
|
+
readonly spender: string;
|
|
215
|
+
readonly amount: string;
|
|
216
|
+
readonly transactionRequest: {
|
|
217
|
+
readonly to: string;
|
|
218
|
+
readonly data: string;
|
|
219
|
+
readonly value: "0";
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
interface SimulationRevert {
|
|
223
|
+
readonly code: number;
|
|
224
|
+
readonly rawErrorBytes: string;
|
|
225
|
+
readonly decodeResult?: {
|
|
226
|
+
readonly errorCandidates?: readonly {
|
|
227
|
+
readonly decodedErrorSignature: string;
|
|
228
|
+
readonly decodedParams: readonly string[];
|
|
229
|
+
}[];
|
|
230
|
+
readonly error?: string;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
interface ComposeTransactionRequest {
|
|
234
|
+
readonly to: string;
|
|
235
|
+
readonly data: string;
|
|
236
|
+
readonly value: string;
|
|
237
|
+
readonly gasLimit?: string;
|
|
238
|
+
}
|
|
239
|
+
interface ComposeContinuation {
|
|
240
|
+
readonly awaits: string;
|
|
241
|
+
readonly flowId: string;
|
|
242
|
+
}
|
|
243
|
+
interface ComposeCompileSuccessData {
|
|
244
|
+
readonly producedResources: Record<string, ProducedResource>;
|
|
245
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
246
|
+
readonly userProxy: string;
|
|
247
|
+
readonly priceImpact?: PriceImpact;
|
|
248
|
+
readonly approvals?: readonly ApprovalEntry[];
|
|
249
|
+
readonly continuation?: ComposeContinuation;
|
|
250
|
+
}
|
|
251
|
+
interface ComposeCompilePartialData {
|
|
252
|
+
readonly producedResources: Record<string, ProducedResource>;
|
|
253
|
+
readonly transactionRequest: ComposeTransactionRequest;
|
|
254
|
+
readonly userProxy: string;
|
|
255
|
+
readonly simulationRevert: SimulationRevert;
|
|
256
|
+
readonly approvals?: readonly ApprovalEntry[];
|
|
257
|
+
readonly continuation?: ComposeContinuation;
|
|
258
|
+
}
|
|
259
|
+
type ComposeCompileResult = (ComposeCompileSuccessData & {
|
|
260
|
+
readonly status: "success";
|
|
261
|
+
}) | (ComposeCompilePartialData & {
|
|
262
|
+
readonly status: "partial";
|
|
263
|
+
readonly error: {
|
|
264
|
+
readonly kind: string;
|
|
265
|
+
readonly message: string;
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
|
|
171
269
|
declare const ResourcePortZod: z.ZodObject<{
|
|
172
270
|
kind: z.ZodLiteral<"resource">;
|
|
173
271
|
name: z.ZodString;
|
|
@@ -180,7 +278,29 @@ declare const ResourcePortZod: z.ZodObject<{
|
|
|
180
278
|
linear: "linear";
|
|
181
279
|
copy: "copy";
|
|
182
280
|
}>;
|
|
281
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
183
282
|
}, z.core.$strip>;
|
|
283
|
+
declare const HANDLE_UNITS: readonly ["raw", "wad", "ray", "bps", "token-decimals"];
|
|
284
|
+
declare const STATIC_SOL_TYPES: readonly ["uint256", "uint128", "uint64", "uint32", "uint16", "uint8", "address", "bool", "bytes32"];
|
|
285
|
+
declare const HandleUnitsZod: z.ZodEnum<{
|
|
286
|
+
raw: "raw";
|
|
287
|
+
wad: "wad";
|
|
288
|
+
ray: "ray";
|
|
289
|
+
bps: "bps";
|
|
290
|
+
"token-decimals": "token-decimals";
|
|
291
|
+
}>;
|
|
292
|
+
declare const StaticSolTypeZod: z.ZodEnum<{
|
|
293
|
+
uint8: "uint8";
|
|
294
|
+
uint16: "uint16";
|
|
295
|
+
uint32: "uint32";
|
|
296
|
+
uint64: "uint64";
|
|
297
|
+
uint128: "uint128";
|
|
298
|
+
uint256: "uint256";
|
|
299
|
+
address: "address";
|
|
300
|
+
bool: "bool";
|
|
301
|
+
bytes32: "bytes32";
|
|
302
|
+
}>;
|
|
303
|
+
declare const isStaticSolType: (value: string) => value is StaticSolType;
|
|
184
304
|
declare const HandlePortZod: z.ZodObject<{
|
|
185
305
|
kind: z.ZodLiteral<"handle">;
|
|
186
306
|
name: z.ZodString;
|
|
@@ -204,6 +324,14 @@ declare const HandlePortZod: z.ZodObject<{
|
|
|
204
324
|
linear: "linear";
|
|
205
325
|
copy: "copy";
|
|
206
326
|
}>;
|
|
327
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
328
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
329
|
+
raw: "raw";
|
|
330
|
+
wad: "wad";
|
|
331
|
+
ray: "ray";
|
|
332
|
+
bps: "bps";
|
|
333
|
+
"token-decimals": "token-decimals";
|
|
334
|
+
}>>;
|
|
207
335
|
}, z.core.$strip>;
|
|
208
336
|
declare const InputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
209
337
|
kind: z.ZodLiteral<"resource">;
|
|
@@ -217,6 +345,7 @@ declare const InputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
217
345
|
linear: "linear";
|
|
218
346
|
copy: "copy";
|
|
219
347
|
}>;
|
|
348
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
220
349
|
}, z.core.$strip>, z.ZodObject<{
|
|
221
350
|
kind: z.ZodLiteral<"handle">;
|
|
222
351
|
name: z.ZodString;
|
|
@@ -240,6 +369,14 @@ declare const InputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
240
369
|
linear: "linear";
|
|
241
370
|
copy: "copy";
|
|
242
371
|
}>;
|
|
372
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
373
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
374
|
+
raw: "raw";
|
|
375
|
+
wad: "wad";
|
|
376
|
+
ray: "ray";
|
|
377
|
+
bps: "bps";
|
|
378
|
+
"token-decimals": "token-decimals";
|
|
379
|
+
}>>;
|
|
243
380
|
}, z.core.$strip>], "kind">;
|
|
244
381
|
declare const ResourceOutputPortZod: z.ZodObject<{
|
|
245
382
|
kind: z.ZodLiteral<"resource_output">;
|
|
@@ -293,6 +430,14 @@ declare const OutputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
293
430
|
linear: "linear";
|
|
294
431
|
copy: "copy";
|
|
295
432
|
}>;
|
|
433
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
434
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
435
|
+
raw: "raw";
|
|
436
|
+
wad: "wad";
|
|
437
|
+
ray: "ray";
|
|
438
|
+
bps: "bps";
|
|
439
|
+
"token-decimals": "token-decimals";
|
|
440
|
+
}>>;
|
|
296
441
|
}, z.core.$strip>], "kind">;
|
|
297
442
|
declare const ManifestOperationZod: z.ZodObject<{
|
|
298
443
|
id: z.ZodString;
|
|
@@ -309,6 +454,7 @@ declare const ManifestOperationZod: z.ZodObject<{
|
|
|
309
454
|
linear: "linear";
|
|
310
455
|
copy: "copy";
|
|
311
456
|
}>;
|
|
457
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
312
458
|
}, z.core.$strip>, z.ZodObject<{
|
|
313
459
|
kind: z.ZodLiteral<"handle">;
|
|
314
460
|
name: z.ZodString;
|
|
@@ -332,6 +478,14 @@ declare const ManifestOperationZod: z.ZodObject<{
|
|
|
332
478
|
linear: "linear";
|
|
333
479
|
copy: "copy";
|
|
334
480
|
}>;
|
|
481
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
482
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
483
|
+
raw: "raw";
|
|
484
|
+
wad: "wad";
|
|
485
|
+
ray: "ray";
|
|
486
|
+
bps: "bps";
|
|
487
|
+
"token-decimals": "token-decimals";
|
|
488
|
+
}>>;
|
|
335
489
|
}, z.core.$strip>], "kind">>;
|
|
336
490
|
outputs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
337
491
|
kind: z.ZodLiteral<"resource_output">;
|
|
@@ -370,6 +524,14 @@ declare const ManifestOperationZod: z.ZodObject<{
|
|
|
370
524
|
linear: "linear";
|
|
371
525
|
copy: "copy";
|
|
372
526
|
}>;
|
|
527
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
528
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
529
|
+
raw: "raw";
|
|
530
|
+
wad: "wad";
|
|
531
|
+
ray: "ray";
|
|
532
|
+
bps: "bps";
|
|
533
|
+
"token-decimals": "token-decimals";
|
|
534
|
+
}>>;
|
|
373
535
|
}, z.core.$strip>], "kind">>;
|
|
374
536
|
configSchema: z.ZodOptional<z.ZodUnknown>;
|
|
375
537
|
}, z.core.$strip>;
|
|
@@ -527,6 +689,7 @@ declare const ComposeManifestZod: z.ZodObject<{
|
|
|
527
689
|
linear: "linear";
|
|
528
690
|
copy: "copy";
|
|
529
691
|
}>;
|
|
692
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
530
693
|
}, z.core.$strip>, z.ZodObject<{
|
|
531
694
|
kind: z.ZodLiteral<"handle">;
|
|
532
695
|
name: z.ZodString;
|
|
@@ -550,6 +713,14 @@ declare const ComposeManifestZod: z.ZodObject<{
|
|
|
550
713
|
linear: "linear";
|
|
551
714
|
copy: "copy";
|
|
552
715
|
}>;
|
|
716
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
717
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
718
|
+
raw: "raw";
|
|
719
|
+
wad: "wad";
|
|
720
|
+
ray: "ray";
|
|
721
|
+
bps: "bps";
|
|
722
|
+
"token-decimals": "token-decimals";
|
|
723
|
+
}>>;
|
|
553
724
|
}, z.core.$strip>], "kind">>;
|
|
554
725
|
outputs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
555
726
|
kind: z.ZodLiteral<"resource_output">;
|
|
@@ -588,6 +759,14 @@ declare const ComposeManifestZod: z.ZodObject<{
|
|
|
588
759
|
linear: "linear";
|
|
589
760
|
copy: "copy";
|
|
590
761
|
}>;
|
|
762
|
+
expose: z.ZodOptional<z.ZodBoolean>;
|
|
763
|
+
units: z.ZodOptional<z.ZodEnum<{
|
|
764
|
+
raw: "raw";
|
|
765
|
+
wad: "wad";
|
|
766
|
+
ray: "ray";
|
|
767
|
+
bps: "bps";
|
|
768
|
+
"token-decimals": "token-decimals";
|
|
769
|
+
}>>;
|
|
591
770
|
}, z.core.$strip>], "kind">>;
|
|
592
771
|
configSchema: z.ZodOptional<z.ZodUnknown>;
|
|
593
772
|
}, z.core.$strip>>;
|
|
@@ -653,6 +832,8 @@ declare const ComposeManifestZod: z.ZodObject<{
|
|
|
653
832
|
}, z.core.$strip>;
|
|
654
833
|
type ResourcePort = z.infer<typeof ResourcePortZod>;
|
|
655
834
|
type HandlePort = z.infer<typeof HandlePortZod>;
|
|
835
|
+
type HandleUnits = z.infer<typeof HandleUnitsZod>;
|
|
836
|
+
type StaticSolType = z.infer<typeof StaticSolTypeZod>;
|
|
656
837
|
type OpInputPort = z.infer<typeof InputPortZod>;
|
|
657
838
|
type ResourceOutputPort = z.infer<typeof ResourceOutputPortZod>;
|
|
658
839
|
type OpOutputPort = z.infer<typeof OutputPortZod>;
|
|
@@ -678,12 +859,33 @@ declare const flowInputResource: (input: FlowInput) => Resource | undefined;
|
|
|
678
859
|
declare const isResourcePort: (port: OpInputPort) => port is ResourcePort;
|
|
679
860
|
declare const isHandlePort: (port: OpInputPort | OpOutputPort) => port is HandlePort;
|
|
680
861
|
declare const isResourceOutputPort: (port: OpInputPort | OpOutputPort) => port is ResourceOutputPort;
|
|
681
|
-
type ComposeErrorKind = "decode_error" | "validation_error" | "linearity_error" | "resolve_error" | "preparation_error" | "no_route_error" | "lowering_error" | "simulation_error" | "simulation_setup_error" | "simulation_revert" | "guard_error" | "continuation_error" | "compilation_error" | "verification_error" | "price_impact_exceeded";
|
|
682
|
-
|
|
683
|
-
|
|
862
|
+
type ComposeErrorKind = "decode_error" | "validation_error" | "linearity_error" | "resolve_error" | "preparation_error" | "provider_error" | "no_route_error" | "lowering_error" | "simulation_error" | "simulation_setup_error" | "simulation_revert" | "subgraph_simulation_revert" | "guard_error" | "continuation_error" | "compilation_error" | "verification_error" | "price_impact_exceeded" | "fee_resolution_error" | "fee_resolution_unavailable" | "flashloan_unauthorized";
|
|
863
|
+
type GenericComposeErrorKind = Exclude<ComposeErrorKind, "preparation_error" | "simulation_revert">;
|
|
864
|
+
interface FailedPreparedOp {
|
|
865
|
+
readonly callId: string;
|
|
866
|
+
readonly op: string;
|
|
867
|
+
readonly kind: GenericComposeErrorKind;
|
|
684
868
|
readonly message: string;
|
|
685
869
|
readonly path?: string;
|
|
686
870
|
}
|
|
871
|
+
interface ComposeErrorBase {
|
|
872
|
+
readonly message: string;
|
|
873
|
+
readonly path?: string;
|
|
874
|
+
}
|
|
875
|
+
interface PreparationComposeError extends ComposeErrorBase {
|
|
876
|
+
readonly kind: "preparation_error";
|
|
877
|
+
readonly failedOps: readonly FailedPreparedOp[];
|
|
878
|
+
readonly succeededOps: readonly string[];
|
|
879
|
+
}
|
|
880
|
+
interface SimulationRevertComposeError extends ComposeErrorBase {
|
|
881
|
+
readonly kind: "simulation_revert";
|
|
882
|
+
readonly details?: SimulationRevert;
|
|
883
|
+
}
|
|
884
|
+
interface GenericComposeError extends ComposeErrorBase {
|
|
885
|
+
readonly kind: GenericComposeErrorKind;
|
|
886
|
+
readonly [key: string]: unknown;
|
|
887
|
+
}
|
|
888
|
+
type ComposeError = PreparationComposeError | SimulationRevertComposeError | GenericComposeError;
|
|
687
889
|
interface MaterialiserInputBase {
|
|
688
890
|
readonly kind: string;
|
|
689
891
|
}
|
|
@@ -699,6 +901,27 @@ type Precondition = PreconditionBase & Record<string, unknown>;
|
|
|
699
901
|
type PreconditionOf<C extends object> = PreconditionBase & C;
|
|
700
902
|
type PreconditionConfigOf<C extends object> = Omit<PreconditionBase, "type"> & C;
|
|
701
903
|
|
|
904
|
+
declare const PROVIDER_KIND: {
|
|
905
|
+
readonly AAVE_V3: 0;
|
|
906
|
+
readonly ERC3156: 1;
|
|
907
|
+
readonly BALANCER_V2: 2;
|
|
908
|
+
readonly MORPHO_BLUE: 3;
|
|
909
|
+
};
|
|
910
|
+
declare const providerKindNames: readonly ["aave-v3", "erc3156", "balancer-v2", "morpho-blue"];
|
|
911
|
+
type ProviderKindName = (typeof providerKindNames)[number];
|
|
912
|
+
declare const providerKindByName: Record<ProviderKindName, number>;
|
|
913
|
+
interface FlashloanMaterialiserInput {
|
|
914
|
+
readonly kind: "flashloan";
|
|
915
|
+
readonly providerKind: ProviderKindName;
|
|
916
|
+
readonly amount: string;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
interface OpHandleOptions {
|
|
920
|
+
readonly expose?: boolean;
|
|
921
|
+
readonly units?: HandleUnits;
|
|
922
|
+
}
|
|
923
|
+
declare const inputRef: (port: string) => Ref;
|
|
924
|
+
declare const outputRef: (node: string, port: string) => Ref;
|
|
702
925
|
declare const linear: <N extends string, T extends SolType>(name: N, type: T) => Port & {
|
|
703
926
|
readonly name: N;
|
|
704
927
|
readonly type: T;
|
|
@@ -719,14 +942,17 @@ declare const native: <N extends string>(name: N, chainId: number) => ResourceIn
|
|
|
719
942
|
declare const erc20: <N extends string>(name: N, token: string, chainId: number) => ResourceInput & {
|
|
720
943
|
readonly name: N;
|
|
721
944
|
};
|
|
722
|
-
declare const resource: <N extends string>(name: N, accepts: "erc20" | "native" | "any"
|
|
945
|
+
declare const resource: <N extends string, Opt extends boolean = false>(name: N, accepts: "erc20" | "native" | "any", options?: {
|
|
946
|
+
optional?: Opt;
|
|
947
|
+
}) => ResourcePort & {
|
|
723
948
|
readonly name: N;
|
|
949
|
+
readonly optional: Opt;
|
|
724
950
|
};
|
|
725
951
|
declare const readResource: <N extends string>(name: N, accepts: "erc20" | "native" | "any") => ResourcePort & {
|
|
726
952
|
readonly name: N;
|
|
727
953
|
readonly mode: "copy";
|
|
728
954
|
};
|
|
729
|
-
declare const opHandle: <N extends string, T extends SolType>(name: N, type: T) => HandlePort & {
|
|
955
|
+
declare const opHandle: <N extends string, T extends SolType>(name: N, type: T, options?: OpHandleOptions) => HandlePort & {
|
|
730
956
|
readonly name: N;
|
|
731
957
|
readonly type: T;
|
|
732
958
|
};
|
|
@@ -760,6 +986,7 @@ declare const isContextKey: (key: string) => key is ContextKey;
|
|
|
760
986
|
* Validation must reject these as node ids.
|
|
761
987
|
*/
|
|
762
988
|
declare const RESERVED_REF_SCOPES: ReadonlySet<string>;
|
|
989
|
+
declare const isRef: (v: unknown) => v is Ref;
|
|
763
990
|
declare const parseRef: (ref: Ref) => ParsedRef;
|
|
764
991
|
declare const foldRef: <R>(ref: ParsedRef, cases: {
|
|
765
992
|
readonly input: (port: string) => R;
|
|
@@ -768,94 +995,6 @@ declare const foldRef: <R>(ref: ParsedRef, cases: {
|
|
|
768
995
|
}) => R;
|
|
769
996
|
declare const refKey: (ref: Ref) => string;
|
|
770
997
|
|
|
771
|
-
type SimulationPolicy = "strict" | "allow-revert";
|
|
772
|
-
/**
|
|
773
|
-
* Destination for sweeping proxy-held terminal resources after execution.
|
|
774
|
-
* Either a literal EVM address or a `{ $ref }` context reference
|
|
775
|
-
* (e.g. `{ $ref: "context.sender" }`).
|
|
776
|
-
*/
|
|
777
|
-
type SweepTo = string | {
|
|
778
|
-
readonly $ref: string;
|
|
779
|
-
};
|
|
780
|
-
interface ComposeRun {
|
|
781
|
-
readonly inputs: Record<string, InputSpec>;
|
|
782
|
-
readonly preconditions?: readonly Precondition[];
|
|
783
|
-
readonly signer: string;
|
|
784
|
-
readonly assumptions?: Record<string, bigint>;
|
|
785
|
-
readonly referrer?: string;
|
|
786
|
-
readonly maxPriceImpactBps?: number;
|
|
787
|
-
readonly sweepTo?: SweepTo;
|
|
788
|
-
readonly simulationPolicy?: SimulationPolicy;
|
|
789
|
-
readonly checkOnChainAllowances?: boolean;
|
|
790
|
-
}
|
|
791
|
-
interface ComposeCompileRequest {
|
|
792
|
-
readonly flow: Flow;
|
|
793
|
-
readonly run: ComposeRun;
|
|
794
|
-
}
|
|
795
|
-
interface PriceImpact {
|
|
796
|
-
readonly inputValueUsd: number;
|
|
797
|
-
readonly outputValueUsd: number;
|
|
798
|
-
readonly impactBps: number;
|
|
799
|
-
readonly unpricedInputs: readonly string[];
|
|
800
|
-
readonly unpricedOutputs: readonly string[];
|
|
801
|
-
}
|
|
802
|
-
interface ApprovalEntry {
|
|
803
|
-
readonly token: string;
|
|
804
|
-
readonly spender: string;
|
|
805
|
-
readonly amount: string;
|
|
806
|
-
readonly transactionRequest: {
|
|
807
|
-
readonly to: string;
|
|
808
|
-
readonly data: string;
|
|
809
|
-
readonly value: "0";
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
interface SimulationRevert {
|
|
813
|
-
readonly code: number;
|
|
814
|
-
readonly rawErrorBytes: string;
|
|
815
|
-
readonly decodeResult?: {
|
|
816
|
-
readonly errorCandidates?: readonly {
|
|
817
|
-
readonly decodedErrorSignature: string;
|
|
818
|
-
readonly decodedParams: readonly string[];
|
|
819
|
-
}[];
|
|
820
|
-
readonly error?: string;
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
interface ComposeTransactionRequest {
|
|
824
|
-
readonly to: string;
|
|
825
|
-
readonly data: string;
|
|
826
|
-
readonly value: string;
|
|
827
|
-
readonly gasLimit?: string;
|
|
828
|
-
}
|
|
829
|
-
interface ComposeContinuation {
|
|
830
|
-
readonly awaits: string;
|
|
831
|
-
readonly flowId: string;
|
|
832
|
-
}
|
|
833
|
-
interface ComposeCompileSuccessData {
|
|
834
|
-
readonly producedResources: Record<string, ProducedResource>;
|
|
835
|
-
readonly transactionRequest: ComposeTransactionRequest;
|
|
836
|
-
readonly userProxy: string;
|
|
837
|
-
readonly priceImpact?: PriceImpact;
|
|
838
|
-
readonly approvals?: readonly ApprovalEntry[];
|
|
839
|
-
readonly continuation?: ComposeContinuation;
|
|
840
|
-
}
|
|
841
|
-
interface ComposeCompilePartialData {
|
|
842
|
-
readonly producedResources: Record<string, ProducedResource>;
|
|
843
|
-
readonly transactionRequest: ComposeTransactionRequest;
|
|
844
|
-
readonly userProxy: string;
|
|
845
|
-
readonly simulationRevert: SimulationRevert;
|
|
846
|
-
readonly approvals?: readonly ApprovalEntry[];
|
|
847
|
-
readonly continuation?: ComposeContinuation;
|
|
848
|
-
}
|
|
849
|
-
type ComposeCompileResult = (ComposeCompileSuccessData & {
|
|
850
|
-
readonly status: "success";
|
|
851
|
-
}) | (ComposeCompilePartialData & {
|
|
852
|
-
readonly status: "partial";
|
|
853
|
-
readonly error: {
|
|
854
|
-
readonly kind: string;
|
|
855
|
-
readonly message: string;
|
|
856
|
-
};
|
|
857
|
-
});
|
|
858
|
-
|
|
859
998
|
type MaterialiserMetadata = {
|
|
860
999
|
readonly kind: 'exact';
|
|
861
1000
|
readonly amount: bigint;
|
|
@@ -875,4 +1014,4 @@ declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, cases: {
|
|
|
875
1014
|
readonly runtime: () => R;
|
|
876
1015
|
}) => R;
|
|
877
1016
|
|
|
878
|
-
export { type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, type Availability, type BindValue, BindValueSchema, type Call, CallSchema, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeContinuation, type ComposeError, type ComposeErrorKind, type ComposeManifest, ComposeManifestZod, type ComposeRun, type ComposeTransactionRequest, type ContextKey, type Continuation, ContinuationSchema, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, type OpInputPort, type OpOutputPort, type OutputAmount, OutputPortZod, type ParsedRef, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PriceImpact, type ProducedResource, RESERVED_REF_SCOPES, type Ref, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, type SimulatedAmounts, type SimulationPolicy, type SimulationRevert, type SolType, SolTypeSchema, type SweepTo, copy, erc20, erc20Token, flowInputMode, flowInputResource, flowInputType, foldMaterialiserMetadata, foldRef, foldResource, handle, isContextKey, isHandlePort, isMaterialiserInput, isResourceInput, isResourceOutputPort, isResourcePort, linear, native, opHandle, parseRef, readResource, refKey, resource, resourceKey, resourceOutput };
|
|
1017
|
+
export { type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, type Availability, type BindValue, BindValueSchema, type Call, CallSchema, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeContinuation, type ComposeError, type ComposeErrorKind, type ComposeManifest, ComposeManifestZod, type ComposeRun, type ComposeTransactionRequest, type ContextKey, type Continuation, ContinuationSchema, type FailedPreparedOp, type FlashloanMaterialiserInput, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GenericComposeError, type GenericComposeErrorKind, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, HANDLE_UNITS, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, type HandleUnits, HandleUnitsZod, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, type OpInputPort, type OpOutputPort, type OutputAmount, OutputPortZod, PROVIDER_KIND, type ParsedRef, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PreparationComposeError, type PriceImpact, type ProducedResource, type ProviderKindName, RESERVED_REF_SCOPES, type Ref, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, STATIC_SOL_TYPES, type SimulatedAmounts, type SimulationPolicy, type SimulationRevert, type SimulationRevertComposeError, type SolType, SolTypeSchema, type StaticSolType, StaticSolTypeZod, type SweepTo, copy, erc20, erc20Resource, erc20Token, flowInputMode, flowInputResource, flowInputType, foldMaterialiserMetadata, foldRef, foldResource, handle, inputRef, isContextKey, isERC20Resource, isHandlePort, isMaterialiserInput, isNativeResource, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeResource, opHandle, outputRef, parseRef, providerKindByName, providerKindNames, readResource, refKey, resource, resourceKey, resourceOutput, resourcesEqual };
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,26 @@ var isResourceOutputPort = (port) => port.kind === "resource_output";
|
|
|
90
90
|
var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
|
|
91
91
|
|
|
92
92
|
// src/resource.ts
|
|
93
|
+
var erc20Resource = (token, chainId) => ({
|
|
94
|
+
kind: "erc20",
|
|
95
|
+
token,
|
|
96
|
+
chainId
|
|
97
|
+
});
|
|
98
|
+
var nativeResource = (chainId) => ({
|
|
99
|
+
kind: "native",
|
|
100
|
+
chainId
|
|
101
|
+
});
|
|
102
|
+
var isERC20Resource = (r) => r.kind === "erc20";
|
|
103
|
+
var isNativeResource = (r) => r.kind === "native";
|
|
104
|
+
var resourcesEqual = (a, b) => {
|
|
105
|
+
if (isNativeResource(a) && isNativeResource(b)) {
|
|
106
|
+
return a.chainId === b.chainId;
|
|
107
|
+
}
|
|
108
|
+
if (isERC20Resource(a) && isERC20Resource(b)) {
|
|
109
|
+
return a.chainId === b.chainId && a.token.toLowerCase() === b.token.toLowerCase();
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
93
113
|
var foldResource = (r, cases) => r.kind === "native" ? cases.native(r.chainId) : cases.erc20(r.token, r.chainId);
|
|
94
114
|
var resourceKey = (r) => foldResource(r, {
|
|
95
115
|
native: (chainId) => `native:${chainId}`,
|
|
@@ -101,29 +121,63 @@ var erc20Token = (r) => {
|
|
|
101
121
|
return r.token;
|
|
102
122
|
};
|
|
103
123
|
|
|
124
|
+
// src/flashloan.ts
|
|
125
|
+
var PROVIDER_KIND = {
|
|
126
|
+
AAVE_V3: 0,
|
|
127
|
+
ERC3156: 1,
|
|
128
|
+
BALANCER_V2: 2,
|
|
129
|
+
MORPHO_BLUE: 3
|
|
130
|
+
};
|
|
131
|
+
var providerKindNames = [
|
|
132
|
+
"aave-v3",
|
|
133
|
+
"erc3156",
|
|
134
|
+
"balancer-v2",
|
|
135
|
+
"morpho-blue"
|
|
136
|
+
];
|
|
137
|
+
var providerKindByName = {
|
|
138
|
+
"aave-v3": PROVIDER_KIND.AAVE_V3,
|
|
139
|
+
erc3156: PROVIDER_KIND.ERC3156,
|
|
140
|
+
"balancer-v2": PROVIDER_KIND.BALANCER_V2,
|
|
141
|
+
"morpho-blue": PROVIDER_KIND.MORPHO_BLUE
|
|
142
|
+
};
|
|
143
|
+
|
|
104
144
|
// src/constructors.ts
|
|
145
|
+
var inputRef = (port) => ({ $ref: `input.${port}` });
|
|
146
|
+
var outputRef = (node, port) => ({
|
|
147
|
+
$ref: `${node}.${port}`
|
|
148
|
+
});
|
|
149
|
+
var optionalProp = (key, value) => value != null ? { [key]: value } : {};
|
|
105
150
|
var linear = (name, type) => ({ name, type, mode: "linear", availability: "now" });
|
|
106
151
|
var copy = (name, type) => ({ name, type, mode: "copy", availability: "now" });
|
|
107
152
|
var handle = (name, type) => ({ name, type });
|
|
108
|
-
var native = (name, chainId) => ({ name, resource:
|
|
109
|
-
var erc20 = (name, token, chainId) => ({ name, resource:
|
|
110
|
-
var resource = (name, accepts) => ({
|
|
153
|
+
var native = (name, chainId) => ({ name, resource: nativeResource(chainId) });
|
|
154
|
+
var erc20 = (name, token, chainId) => ({ name, resource: erc20Resource(token, chainId) });
|
|
155
|
+
var resource = (name, accepts, options) => ({
|
|
156
|
+
kind: "resource",
|
|
157
|
+
name,
|
|
158
|
+
accepts,
|
|
159
|
+
mode: "linear",
|
|
160
|
+
...optionalProp("optional", options?.optional)
|
|
161
|
+
});
|
|
111
162
|
var readResource = (name, accepts) => ({ kind: "resource", name, accepts, mode: "copy" });
|
|
112
|
-
var opHandle = (name, type) => ({
|
|
163
|
+
var opHandle = (name, type, options) => ({
|
|
164
|
+
kind: "handle",
|
|
165
|
+
name,
|
|
166
|
+
type,
|
|
167
|
+
mode: "copy",
|
|
168
|
+
...optionalProp("expose", options?.expose),
|
|
169
|
+
...optionalProp("units", options?.units)
|
|
170
|
+
});
|
|
113
171
|
var resourceOutput = (name, options) => {
|
|
114
172
|
const opts = typeof options === "string" ? { availability: options } : options;
|
|
115
173
|
return {
|
|
116
174
|
kind: "resource_output",
|
|
117
175
|
name,
|
|
118
176
|
mode: "linear",
|
|
119
|
-
...
|
|
120
|
-
...opts?.providesMinimum
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
...opts?.omitIfZero != null && { omitIfZero: opts.omitIfZero },
|
|
124
|
-
...opts?.deliveryAddressInput != null && {
|
|
125
|
-
deliveryAddressInput: opts.deliveryAddressInput
|
|
126
|
-
}
|
|
177
|
+
...optionalProp("availability", opts?.availability),
|
|
178
|
+
...optionalProp("providesMinimum", opts?.providesMinimum),
|
|
179
|
+
...optionalProp("omitIfZero", opts?.omitIfZero),
|
|
180
|
+
...optionalProp("deliveryAddressInput", opts?.deliveryAddressInput)
|
|
127
181
|
};
|
|
128
182
|
};
|
|
129
183
|
|
|
@@ -134,6 +188,7 @@ var RESERVED_REF_SCOPES = /* @__PURE__ */ new Set([
|
|
|
134
188
|
"context",
|
|
135
189
|
"literal"
|
|
136
190
|
]);
|
|
191
|
+
var isRef = (v) => typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string";
|
|
137
192
|
var parseRef = (ref) => {
|
|
138
193
|
const dot = ref.$ref.indexOf(".");
|
|
139
194
|
if (dot === -1)
|
|
@@ -188,13 +243,38 @@ var ResourcePortZod = z.object({
|
|
|
188
243
|
kind: z.literal("resource"),
|
|
189
244
|
name: z.string(),
|
|
190
245
|
accepts: z.enum(["erc20", "native", "any"]),
|
|
191
|
-
mode: z.enum(["linear", "copy"])
|
|
246
|
+
mode: z.enum(["linear", "copy"]),
|
|
247
|
+
optional: z.boolean().optional()
|
|
192
248
|
});
|
|
249
|
+
var HANDLE_UNITS = [
|
|
250
|
+
"raw",
|
|
251
|
+
"wad",
|
|
252
|
+
"ray",
|
|
253
|
+
"bps",
|
|
254
|
+
"token-decimals"
|
|
255
|
+
];
|
|
256
|
+
var STATIC_SOL_TYPES = [
|
|
257
|
+
"uint256",
|
|
258
|
+
"uint128",
|
|
259
|
+
"uint64",
|
|
260
|
+
"uint32",
|
|
261
|
+
"uint16",
|
|
262
|
+
"uint8",
|
|
263
|
+
"address",
|
|
264
|
+
"bool",
|
|
265
|
+
"bytes32"
|
|
266
|
+
];
|
|
267
|
+
var HandleUnitsZod = z.enum(HANDLE_UNITS);
|
|
268
|
+
var StaticSolTypeZod = z.enum(STATIC_SOL_TYPES);
|
|
269
|
+
var STATIC_SOL_TYPE_SET = new Set(STATIC_SOL_TYPES);
|
|
270
|
+
var isStaticSolType = (value) => STATIC_SOL_TYPE_SET.has(value);
|
|
193
271
|
var HandlePortZod = z.object({
|
|
194
272
|
kind: z.literal("handle"),
|
|
195
273
|
name: z.string(),
|
|
196
274
|
type: SolTypeZod,
|
|
197
|
-
mode: z.enum(["linear", "copy"])
|
|
275
|
+
mode: z.enum(["linear", "copy"]),
|
|
276
|
+
expose: z.boolean().optional(),
|
|
277
|
+
units: HandleUnitsZod.optional()
|
|
198
278
|
});
|
|
199
279
|
var InputPortZod = z.discriminatedUnion("kind", [
|
|
200
280
|
ResourcePortZod,
|
|
@@ -283,8 +363,10 @@ export {
|
|
|
283
363
|
FlowSchema,
|
|
284
364
|
GuardCompatibilityZod,
|
|
285
365
|
GuardSelectorZod,
|
|
366
|
+
HANDLE_UNITS,
|
|
286
367
|
HandleInputSchema,
|
|
287
368
|
HandlePortZod,
|
|
369
|
+
HandleUnitsZod,
|
|
288
370
|
InputPortZod,
|
|
289
371
|
LiteralBindingSchema,
|
|
290
372
|
ManifestGuardZod,
|
|
@@ -292,15 +374,19 @@ export {
|
|
|
292
374
|
ManifestOperationZod,
|
|
293
375
|
ManifestPreconditionZod,
|
|
294
376
|
OutputPortZod,
|
|
377
|
+
PROVIDER_KIND,
|
|
295
378
|
RESERVED_REF_SCOPES,
|
|
296
379
|
RefSchema,
|
|
297
380
|
ResourceInputSchema,
|
|
298
381
|
ResourceOutputPortZod,
|
|
299
382
|
ResourcePortZod,
|
|
300
383
|
ResourceSchema,
|
|
384
|
+
STATIC_SOL_TYPES,
|
|
301
385
|
SolTypeSchema,
|
|
386
|
+
StaticSolTypeZod,
|
|
302
387
|
copy,
|
|
303
388
|
erc20,
|
|
389
|
+
erc20Resource,
|
|
304
390
|
erc20Token,
|
|
305
391
|
flowInputMode,
|
|
306
392
|
flowInputResource,
|
|
@@ -309,19 +395,29 @@ export {
|
|
|
309
395
|
foldRef,
|
|
310
396
|
foldResource,
|
|
311
397
|
handle,
|
|
398
|
+
inputRef,
|
|
312
399
|
isContextKey,
|
|
400
|
+
isERC20Resource,
|
|
313
401
|
isHandlePort,
|
|
314
402
|
isMaterialiserInput,
|
|
403
|
+
isNativeResource,
|
|
404
|
+
isRef,
|
|
315
405
|
isResourceInput,
|
|
316
406
|
isResourceOutputPort,
|
|
317
407
|
isResourcePort,
|
|
408
|
+
isStaticSolType,
|
|
318
409
|
linear,
|
|
319
410
|
native,
|
|
411
|
+
nativeResource,
|
|
320
412
|
opHandle,
|
|
413
|
+
outputRef,
|
|
321
414
|
parseRef,
|
|
415
|
+
providerKindByName,
|
|
416
|
+
providerKindNames,
|
|
322
417
|
readResource,
|
|
323
418
|
refKey,
|
|
324
419
|
resource,
|
|
325
420
|
resourceKey,
|
|
326
|
-
resourceOutput
|
|
421
|
+
resourceOutput,
|
|
422
|
+
resourcesEqual
|
|
327
423
|
};
|