@lifi/compose-spec 0.15.2 → 0.17.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,11 +20,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let effect = require("effect");
25
24
  let zod = require("zod");
26
25
  zod = __toESM(zod, 1);
27
- //#region src/chainCapabilities.ts
26
+ // src/chainCapabilities.ts
28
27
  /**
29
28
  * The zero-address sentinel that represents the native gas coin on
30
29
  * EVM-native chains. Exported so tests and call-sites can reference it
@@ -210,15 +209,13 @@ const normalizeResource = (r) => {
210
209
  * rewritten to the chain's stand-in ERC-20; every other address passes through.
211
210
  */
212
211
  const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isZeroAddress(token) ? canonicalNativeAddress(chainId) : token;
213
- //#endregion
214
- //#region src/hexPatterns.ts
212
+ // src/hexPatterns.ts
215
213
  const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
216
214
  const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
217
215
  const DECIMAL_UINT = /^[0-9]+$/;
218
216
  const MAX_UINT256 = 2n ** 256n - 1n;
219
217
  const MAX_DATE_MS = 864e13;
220
- //#endregion
221
- //#region src/flowSchema.ts
218
+ // src/flowSchema.ts
222
219
  const SolTypeSchema = effect.Schema.Literal("uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string");
223
220
  const ChainIdSchema = effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive());
224
221
  const EVMAddressString = effect.Schema.String.pipe(effect.Schema.pattern(EVM_ADDRESS_HEX, { message: () => "expected a 0x-prefixed 20-byte EVM address" })).annotations({ description: "EVM address: 0x followed by 40 hex characters" });
@@ -313,8 +310,7 @@ const FlowSchema = effect.Schema.Struct({
313
310
  lineage: effect.Schema.optional(LineageSchema),
314
311
  epilogue: effect.Schema.optional(EpilogueSchema)
315
312
  });
316
- //#endregion
317
- //#region src/continuation.ts
313
+ // src/continuation.ts
318
314
  const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
319
315
  const outcomeFields = (minAmount) => ({
320
316
  token: EVMAddressString,
@@ -417,9 +413,7 @@ const decodeNativeBalanceGte = (check, ast) => {
417
413
  }
418
414
  };
419
415
  const AssertionSpecSchema = effect.Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema);
420
- const settledOutcome = (intent) => intent.outcomes[0];
421
- //#endregion
422
- //#region src/descriptor.ts
416
+ // src/descriptor.ts
423
417
  const Bytes32HexSchema = effect.Schema.String.pipe(effect.Schema.pattern(BYTES32_LOWER_HEX));
424
418
  const AssertedPredicateSchema = effect.Schema.transformOrFail(AssertionSpecSchema, effect.Schema.typeSchema(AssertionSpecSchema), {
425
419
  strict: true,
@@ -440,8 +434,7 @@ const canonicalJson = (value) => {
440
434
  return JSON.stringify(value);
441
435
  };
442
436
  const canonicalAssertedPredicate = (specs) => canonicalJson(specs);
443
- //#endregion
444
- //#region src/flow.ts
437
+ // src/flow.ts
445
438
  const isResourceInput = (input) => "resource" in input;
446
439
  const flowInputType = (input) => isResourceInput(input) ? "uint256" : input.type;
447
440
  const flowInputMode = (input) => isResourceInput(input) ? "linear" : "copy";
@@ -451,8 +444,7 @@ const isHandlePort = (port) => port.kind === "handle";
451
444
  const isResourceOutputPort = (port) => port.kind === "resource_output";
452
445
  const isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
453
446
  const isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
454
- //#endregion
455
- //#region src/resource.ts
447
+ // src/resource.ts
456
448
  const erc20Resource = (token, chainId) => ({
457
449
  kind: "erc20",
458
450
  token,
@@ -484,32 +476,38 @@ const resourceKey = (r) => foldResource(r, {
484
476
  native: ({ chainId }) => `native:${chainId}`,
485
477
  erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`
486
478
  });
479
+ const describeResource = (r) => foldResource(r, {
480
+ native: ({ chainId }) => `native coin on chain ${chainId}`,
481
+ erc20: ({ token, chainId }) => `${token} on chain ${chainId}`
482
+ });
487
483
  const erc20Token = (r) => {
488
484
  if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
489
485
  return r.token;
490
486
  };
491
- //#endregion
492
- //#region src/flashloan.ts
493
- const PROVIDER_KIND = {
494
- AAVE_V3: 0,
495
- ERC3156: 1,
496
- BALANCER_V2: 2,
497
- MORPHO_BLUE: 3
498
- };
487
+ // src/flashloan.ts
499
488
  const providerKindNames = [
500
489
  "aave-v3",
501
- "erc3156",
502
490
  "balancer-v2",
503
491
  "morpho-blue"
504
492
  ];
505
- const providerKindByName = {
506
- "aave-v3": PROVIDER_KIND.AAVE_V3,
507
- erc3156: PROVIDER_KIND.ERC3156,
508
- "balancer-v2": PROVIDER_KIND.BALANCER_V2,
509
- "morpho-blue": PROVIDER_KIND.MORPHO_BLUE
493
+ const FlashloanConfigSchema = effect.Schema.Struct({
494
+ providerKind: effect.Schema.Literal(...providerKindNames),
495
+ amount: IntegerString,
496
+ maxFee: effect.Schema.optional(IntegerString)
497
+ });
498
+ const FlashloanMaterialiserInputSchema = effect.Schema.Struct({
499
+ kind: effect.Schema.Literal("flashloan"),
500
+ ...FlashloanConfigSchema.fields
501
+ });
502
+ const isFlashloanMaterialiserInput = effect.Schema.is(FlashloanMaterialiserInputSchema);
503
+ const FLASHLOAN_FEE_BPS = {
504
+ "aave-v3": 5n,
505
+ "balancer-v2": 0n,
506
+ "morpho-blue": 0n
510
507
  };
511
- //#endregion
512
- //#region src/constructors.ts
508
+ const BPS_DENOMINATOR = 10000n;
509
+ const flashloanMaxFee = ({ providerKind, amount, maxFee }) => maxFee !== void 0 ? BigInt(maxFee) : (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] + BPS_DENOMINATOR - 1n) / BPS_DENOMINATOR;
510
+ // src/constructors.ts
513
511
  /** Returns `{ [key]: value }` when `value` is not nullish, else `{}`. */
514
512
  const optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
515
513
  const linear = (name, type) => ({
@@ -572,8 +570,7 @@ const resourceOutput = (name, options) => {
572
570
  ...optionalProp("countFrom", opts?.countFrom)
573
571
  };
574
572
  };
575
- //#endregion
576
- //#region src/outputFamilies.ts
573
+ // src/outputFamilies.ts
577
574
  const isOutputFamily = (port) => port.kind === "resource_output" && port.countFrom !== void 0;
578
575
  const instancePortName = (family, index) => `${family}.${index}`;
579
576
  const familySize = (family, config) => {
@@ -590,8 +587,7 @@ const expandFamily = (port, config) => {
590
587
  }));
591
588
  };
592
589
  const expandOutputPorts = (declared, config) => declared.some(isOutputFamily) ? declared.flatMap((port) => isOutputFamily(port) ? expandFamily(port, config) : [port]) : declared;
593
- //#endregion
594
- //#region src/ref.ts
590
+ // src/ref.ts
595
591
  const isContextKey = (key) => key === "sender" || key === "executionAddress";
596
592
  /**
597
593
  * Ref prefixes that parseRef intercepts before the fallback `output` scope.
@@ -650,8 +646,7 @@ const refKey = (ref) => foldRef(parseRef(ref), {
650
646
  context: (key) => `context:${key}`,
651
647
  output: (node, port) => `output:${node}:${port}`
652
648
  });
653
- //#endregion
654
- //#region src/preconditions.ts
649
+ // src/preconditions.ts
655
650
  const erc20Balance = (config) => ({
656
651
  type: "Erc20Balance",
657
652
  ...config
@@ -667,8 +662,7 @@ const erc20Allowance = (config) => ({
667
662
  const isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
668
663
  const isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
669
664
  const isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
670
- //#endregion
671
- //#region src/simulate.ts
665
+ // src/simulate.ts
672
666
  /**
673
667
  * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
674
668
  *
@@ -690,8 +684,7 @@ const SIMULATE_MAX_TRACKED_BALANCES = 40;
690
684
  * trust boundary and re-enforced server-side in `rawSimulation.ts`.
691
685
  */
692
686
  const SIMULATE_MAX_REQUIREMENTS = 40;
693
- //#endregion
694
- //#region src/headers.ts
687
+ // src/headers.ts
695
688
  /**
696
689
  * HTTP header names on the compose wire.
697
690
  *
@@ -703,8 +696,7 @@ const SIMULATE_MAX_REQUIREMENTS = 40;
703
696
  const COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
704
697
  /** Compose contract version the backend serves. Returned on every compose response. */
705
698
  const COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
706
- //#endregion
707
- //#region src/version.ts
699
+ // src/version.ts
708
700
  const SEMANTIC_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
709
701
  /**
710
702
  * Parses the numeric triple of a semantic version. Prerelease and build
@@ -759,16 +751,14 @@ const checkCompatibility = (client, server, minimum = {
759
751
  if (compareVersions(client, minimum) < 0) return "sdk_outdated";
760
752
  return "compatible";
761
753
  };
762
- //#endregion
763
- //#region src/materialiserMetadata.ts
754
+ // src/materialiserMetadata.ts
764
755
  const foldMaterialiserMetadata = (meta, cases) => {
765
756
  if (meta.kind === "exact") return cases.exact(meta.amount);
766
757
  if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
767
758
  if (meta.kind === "capped") return cases.capped(meta.amount, meta.min);
768
759
  return cases.runtime(meta.min);
769
760
  };
770
- //#endregion
771
- //#region src/zodSchemas.ts
761
+ // src/zodSchemas.ts
772
762
  const chainIdZod = zod.default.number().int().positive();
773
763
  const evmAddressZod = zod.default.string().regex(EVM_ADDRESS_HEX);
774
764
  const uintStringZod = zod.default.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, { message: "expected a uint256 decimal integer string" });
@@ -976,7 +966,6 @@ const ShortfallZod = zod.default.object({
976
966
  required: zod.default.string(),
977
967
  available: zod.default.string()
978
968
  });
979
- //#endregion
980
969
  exports.ARC_CHAIN_ID = ARC_CHAIN_ID;
981
970
  exports.ARC_NATIVE_ERC20 = ARC_NATIVE_ERC20;
982
971
  exports.ARC_NATIVE_SCALE = ARC_NATIVE_SCALE;
@@ -1001,6 +990,8 @@ exports.EVM_NATIVE_SENTINEL = EVM_NATIVE_SENTINEL;
1001
990
  exports.EpilogueForwardSchema = EpilogueForwardSchema;
1002
991
  exports.EpilogueSchema = EpilogueSchema;
1003
992
  exports.Erc20BalanceGteSpecSchema = Erc20BalanceGteSpecSchema;
993
+ exports.FlashloanConfigSchema = FlashloanConfigSchema;
994
+ exports.FlashloanMaterialiserInputSchema = FlashloanMaterialiserInputSchema;
1004
995
  exports.FlowInputSchema = FlowInputSchema;
1005
996
  exports.FlowSchema = FlowSchema;
1006
997
  exports.ForwardToSchema = ForwardToSchema;
@@ -1022,7 +1013,6 @@ exports.ManifestPreconditionZod = ManifestPreconditionZod;
1022
1013
  exports.ManifestRoutingZod = ManifestRoutingZod;
1023
1014
  exports.NativeBalanceGteSpecSchema = NativeBalanceGteSpecSchema;
1024
1015
  exports.OutputPortZod = OutputPortZod;
1025
- exports.PROVIDER_KIND = PROVIDER_KIND;
1026
1016
  exports.Phase1ArtifactSchema = Phase1ArtifactSchema;
1027
1017
  exports.RESERVED_REF_SCOPES = RESERVED_REF_SCOPES;
1028
1018
  exports.RefSchema = RefSchema;
@@ -1046,6 +1036,7 @@ exports.canonicalAssertedPredicate = canonicalAssertedPredicate;
1046
1036
  exports.canonicalNativeAddress = canonicalNativeAddress;
1047
1037
  exports.checkCompatibility = checkCompatibility;
1048
1038
  exports.copy = copy;
1039
+ exports.describeResource = describeResource;
1049
1040
  exports.erc20 = erc20;
1050
1041
  exports.erc20Allowance = erc20Allowance;
1051
1042
  exports.erc20Balance = erc20Balance;
@@ -1053,6 +1044,7 @@ exports.erc20Resource = erc20Resource;
1053
1044
  exports.erc20Token = erc20Token;
1054
1045
  exports.expandOutputPorts = expandOutputPorts;
1055
1046
  exports.familySize = familySize;
1047
+ exports.flashloanMaxFee = flashloanMaxFee;
1056
1048
  exports.flowInputMode = flowInputMode;
1057
1049
  exports.flowInputResource = flowInputResource;
1058
1050
  exports.flowInputType = flowInputType;
@@ -1069,6 +1061,7 @@ exports.isContextKey = isContextKey;
1069
1061
  exports.isERC20Resource = isERC20Resource;
1070
1062
  exports.isErc20AllowancePrecondition = isErc20AllowancePrecondition;
1071
1063
  exports.isErc20BalancePrecondition = isErc20BalancePrecondition;
1064
+ exports.isFlashloanMaterialiserInput = isFlashloanMaterialiserInput;
1072
1065
  exports.isFutureResourceOutput = isFutureResourceOutput;
1073
1066
  exports.isHandlePort = isHandlePort;
1074
1067
  exports.isMaterialiserInput = isMaterialiserInput;
@@ -1092,7 +1085,6 @@ exports.normalizeResource = normalizeResource;
1092
1085
  exports.opHandle = opHandle;
1093
1086
  exports.parseRef = parseRef;
1094
1087
  exports.parseVersion = parseVersion;
1095
- exports.providerKindByName = providerKindByName;
1096
1088
  exports.providerKindNames = providerKindNames;
1097
1089
  exports.readResource = readResource;
1098
1090
  exports.ref = ref;
@@ -1102,4 +1094,3 @@ exports.resourceKey = resourceKey;
1102
1094
  exports.resourceOutput = resourceOutput;
1103
1095
  exports.resourceToken = resourceToken;
1104
1096
  exports.resourcesEqual = resourcesEqual;
1105
- exports.settledOutcome = settledOutcome;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Schema } from "effect";
2
2
  import z from "zod";
3
- //#region src/flowSchema.d.ts
4
3
  export declare const SolTypeSchema: Schema.Literal<["uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string"]>;
5
4
  export declare const EVMAddressString: Schema.refine<string, typeof Schema.String>;
6
5
  export declare const IntegerString: Schema.filter<typeof Schema.String>;
@@ -311,8 +310,6 @@ type ForwardTo = typeof ForwardToSchema.Type;
311
310
  type EpilogueForward = typeof EpilogueForwardSchema.Type;
312
311
  type Epilogue = typeof EpilogueSchema.Type;
313
312
  type Flow = typeof FlowSchema.Type;
314
- //#endregion
315
- //#region src/continuation.d.ts
316
313
  export declare const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
317
314
  export declare const ContinuationOutcomeSchema: Schema.transform<Schema.Schema<{
318
315
  readonly token: string;
@@ -563,11 +560,6 @@ type ContinuationIntent = typeof ContinuationIntentSchema.Type;
563
560
  type Phase1Artifact = typeof Phase1ArtifactSchema.Type;
564
561
  type AssertionSpec = typeof AssertionSpecSchema.Type;
565
562
  type CallCheckSpec = typeof CallCheckSpecSchema.Type;
566
- export declare const settledOutcome: <I extends {
567
- readonly outcomes: readonly unknown[];
568
- }>(intent: I) => I['outcomes'][number] | undefined;
569
- //#endregion
570
- //#region src/descriptor.d.ts
571
563
  export declare const Bytes32HexSchema: Schema.filter<typeof Schema.String>;
572
564
  export declare const AssertedPredicateSchema: Schema.transformOrFail<Schema.Union<[Schema.Struct<{
573
565
  kind: Schema.Literal<["erc20BalanceGte"]>;
@@ -692,8 +684,6 @@ export declare const VerificationDescriptorSchema: Schema.Struct<{
692
684
  export declare const canonicalAssertedPredicate: (specs: readonly AssertionSpec[]) => string;
693
685
  type VerificationDescriptor = typeof VerificationDescriptorSchema.Type;
694
686
  type AssertedPredicate = AssertionSpec;
695
- //#endregion
696
- //#region src/resource.d.ts
697
687
  type Availability = 'now' | 'future';
698
688
  interface OutputAmount {
699
689
  readonly expected: bigint;
@@ -720,9 +710,8 @@ export declare const foldResource: <R>(r: Resource, cases: {
720
710
  }) => R;
721
711
  export declare const resourceToken: (r: Resource) => string;
722
712
  export declare const resourceKey: (r: Resource) => string;
713
+ export declare const describeResource: (r: Resource) => string;
723
714
  export declare const erc20Token: (r: Resource) => string;
724
- //#endregion
725
- //#region src/output.d.ts
726
715
  type EstimateBasis = 'simulated' | 'quoted';
727
716
  type MinimumBasis = 'guard' | 'op' | 'input' | 'declared';
728
717
  interface Estimate {
@@ -760,8 +749,6 @@ interface TerminalOutput extends OutputBase {
760
749
  }
761
750
  type Output = ConsumedOutput | TerminalOutput;
762
751
  type Outputs = Record<string, Output>;
763
- //#endregion
764
- //#region src/zodSchemas.d.ts
765
752
  export declare const ResourcePortZod: z.ZodObject<{
766
753
  kind: z.ZodLiteral<"resource">;
767
754
  name: z.ZodString;
@@ -1484,8 +1471,6 @@ type SettlementEscrowWire = z.infer<typeof SettlementEscrowZod>;
1484
1471
  type SettlementBindingWire = z.infer<typeof SettlementBindingZod>;
1485
1472
  type SettlementWire = z.infer<typeof SettlementZod>;
1486
1473
  type Shortfall = z.infer<typeof ShortfallZod>;
1487
- //#endregion
1488
- //#region src/compile.d.ts
1489
1474
  type SimulationPolicy = 'strict' | 'allow-revert';
1490
1475
  interface ComposeRun {
1491
1476
  readonly inputs: Record<string, InputSpec>;
@@ -1532,6 +1517,8 @@ interface SimulationRevert {
1532
1517
  readonly errorCandidates?: readonly {
1533
1518
  readonly decodedErrorSignature: string;
1534
1519
  readonly decodedParams: readonly string[];
1520
+ /** Human-readable description; present when the selector is in the backend's error registry. */
1521
+ readonly description?: string;
1535
1522
  }[];
1536
1523
  readonly error?: string;
1537
1524
  };
@@ -1627,8 +1614,6 @@ type ComposeCompileResult = (ComposeCompileSuccessData & {
1627
1614
  readonly message: string;
1628
1615
  };
1629
1616
  });
1630
- //#endregion
1631
- //#region src/flow.d.ts
1632
1617
  interface Port {
1633
1618
  readonly name: string;
1634
1619
  readonly type: SolType;
@@ -1648,7 +1633,7 @@ type ComposeErrorKind = 'decode_error' | 'validation_error' | 'linearity_error'
1648
1633
  /**
1649
1634
  * Errors raised by compose routes outside the compile pipeline.
1650
1635
  */
1651
- type ComposeRouteErrorKind = 'chain_validation_error' | 'unsupported_token' | 'zero_output' | 'service_unavailable' | 'verification_unavailable' | 'deployment_check_unavailable' | 'manifest_error' | 'sdk_outdated' | 'server_outdated';
1636
+ type ComposeRouteErrorKind = 'chain_validation_error' | 'unsupported_token' | 'signer_screening_rejected' | 'zero_output' | 'service_unavailable' | 'verification_unavailable' | 'deployment_check_unavailable' | 'manifest_error' | 'sdk_outdated' | 'server_outdated';
1652
1637
  type GenericComposeErrorKind = Exclude<ComposeErrorKind, 'preparation_error' | 'simulation_revert' | 'delivery_error'>;
1653
1638
  interface FailedPreparedOp {
1654
1639
  readonly callId: string;
@@ -1715,24 +1700,31 @@ interface PreconditionBase {
1715
1700
  type Precondition = PreconditionBase & Record<string, unknown>;
1716
1701
  type PreconditionOf<C extends object> = PreconditionBase & C;
1717
1702
  type PreconditionConfigOf<C extends object> = Omit<PreconditionBase, 'type'> & C;
1718
- //#endregion
1719
- //#region src/flashloan.d.ts
1720
- export declare const PROVIDER_KIND: {
1721
- readonly AAVE_V3: 0;
1722
- readonly ERC3156: 1;
1723
- readonly BALANCER_V2: 2;
1724
- readonly MORPHO_BLUE: 3;
1725
- };
1726
- export declare const providerKindNames: readonly ['aave-v3', 'erc3156', 'balancer-v2', 'morpho-blue'];
1703
+ export declare const providerKindNames: readonly ['aave-v3', 'balancer-v2', 'morpho-blue'];
1727
1704
  type ProviderKindName = (typeof providerKindNames)[number];
1728
- export declare const providerKindByName: Record<ProviderKindName, number>;
1729
- interface FlashloanMaterialiserInput {
1730
- readonly kind: 'flashloan';
1731
- readonly providerKind: ProviderKindName;
1705
+ export declare const FlashloanConfigSchema: Schema.Struct<{
1706
+ providerKind: Schema.Literal<["aave-v3", "balancer-v2", "morpho-blue"]>;
1707
+ amount: Schema.filter<typeof Schema.String>;
1708
+ maxFee: Schema.optional<Schema.filter<typeof Schema.String>>;
1709
+ }>;
1710
+ export declare const FlashloanMaterialiserInputSchema: Schema.Struct<{
1711
+ providerKind: Schema.Literal<["aave-v3", "balancer-v2", "morpho-blue"]>;
1712
+ amount: Schema.filter<typeof Schema.String>;
1713
+ maxFee: Schema.optional<Schema.filter<typeof Schema.String>>;
1714
+ kind: Schema.Literal<["flashloan"]>;
1715
+ }>;
1716
+ type FlashloanMaterialiserInput = typeof FlashloanMaterialiserInputSchema.Type;
1717
+ export declare const isFlashloanMaterialiserInput: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is {
1718
+ readonly providerKind: "aave-v3" | "balancer-v2" | "morpho-blue";
1732
1719
  readonly amount: string;
1733
- }
1734
- //#endregion
1735
- //#region src/constructors.d.ts
1720
+ readonly maxFee?: string | undefined;
1721
+ readonly kind: "flashloan";
1722
+ };
1723
+ export declare const flashloanMaxFee: ({ providerKind, amount, maxFee }: {
1724
+ readonly providerKind: ProviderKindName;
1725
+ readonly amount: string | bigint;
1726
+ readonly maxFee?: string | bigint;
1727
+ }) => bigint;
1736
1728
  interface OpHandleOptions<Opt extends boolean = boolean> {
1737
1729
  readonly expose?: boolean;
1738
1730
  readonly units?: HandleUnits;
@@ -1792,8 +1784,6 @@ export declare const resourceOutput: <N extends string, const O extends Resource
1792
1784
  readonly name: N;
1793
1785
  readonly availability: OutputAvailability<O>;
1794
1786
  } & OutputCountFrom<O>;
1795
- //#endregion
1796
- //#region src/outputFamilies.d.ts
1797
1787
  type OutputFamilyPort = ResourceOutputPort & {
1798
1788
  readonly countFrom: string;
1799
1789
  };
@@ -1801,8 +1791,6 @@ export declare const isOutputFamily: (port: OpOutputPort) => port is OutputFamil
1801
1791
  export declare const instancePortName: (family: string, index: number) => string;
1802
1792
  export declare const familySize: (family: Pick<OutputFamilyPort, 'name' | 'countFrom'>, config: Call['config']) => number;
1803
1793
  export declare const expandOutputPorts: (declared: readonly OpOutputPort[], config: Call['config']) => readonly OpOutputPort[];
1804
- //#endregion
1805
- //#region src/ref.d.ts
1806
1794
  type ParsedRef = {
1807
1795
  readonly scope: 'input';
1808
1796
  readonly port: string;
@@ -1846,8 +1834,6 @@ export declare const foldRef: <R>(ref: ParsedRef, cases: {
1846
1834
  readonly output: (node: string, port: string) => R;
1847
1835
  }) => R;
1848
1836
  export declare const refKey: (ref: Ref) => string;
1849
- //#endregion
1850
- //#region src/chainCapabilities.d.ts
1851
1837
  /**
1852
1838
  * Per-chain native-asset semantics.
1853
1839
  *
@@ -2042,8 +2028,6 @@ export declare const normalizeResource: (r: Resource) => Resource;
2042
2028
  * rewritten to the chain's stand-in ERC-20; every other address passes through.
2043
2029
  */
2044
2030
  export declare const normalizeNativeTokenAddress: (token: string, chainId: number) => string;
2045
- //#endregion
2046
- //#region src/route.d.ts
2047
2031
  /**
2048
2032
  * Spend an exact amount of `fromToken`.
2049
2033
  *
@@ -2169,8 +2153,6 @@ interface ComposeRouteRequest {
2169
2153
  */
2170
2154
  readonly allowAsyncRoutes?: boolean;
2171
2155
  }
2172
- //#endregion
2173
- //#region src/preconditions.d.ts
2174
2156
  /**
2175
2157
  * The three concrete precondition shapes the stack exchanges today. One
2176
2158
  * definition serves every producer and consumer: op/materialiser declarations,
@@ -2204,8 +2186,6 @@ export declare const erc20Allowance: (config: Omit<Erc20AllowancePrecondition, '
2204
2186
  export declare const isErc20BalancePrecondition: (p: Precondition) => p is Erc20BalancePrecondition;
2205
2187
  export declare const isErc20AllowancePrecondition: (p: Precondition) => p is Erc20AllowancePrecondition;
2206
2188
  export declare const isNativeBalancePrecondition: (p: Precondition) => p is NativeBalancePrecondition;
2207
- //#endregion
2208
- //#region src/simulate.d.ts
2209
2189
  /**
2210
2190
  * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
2211
2191
  *
@@ -2332,6 +2312,8 @@ interface SimulateRevertDecodeResult {
2332
2312
  readonly errorCandidates?: {
2333
2313
  readonly decodedErrorSignature: string;
2334
2314
  readonly decodedParams: string[];
2315
+ /** Human-readable description; present when the selector is in the backend's error registry. */
2316
+ readonly description?: string;
2335
2317
  }[];
2336
2318
  readonly error?: string;
2337
2319
  }
@@ -2361,8 +2343,6 @@ interface SimulateSetupErrorResult {
2361
2343
  * one member: `ok` and `revert` come back with HTTP 200, `error` with HTTP 422.
2362
2344
  */
2363
2345
  type SimulateResult = SimulateOkResult | SimulateRevertResult | SimulateSetupErrorResult;
2364
- //#endregion
2365
- //#region src/headers.d.ts
2366
2346
  /**
2367
2347
  * HTTP header names on the compose wire.
2368
2348
  *
@@ -2374,8 +2354,6 @@ type SimulateResult = SimulateOkResult | SimulateRevertResult | SimulateSetupErr
2374
2354
  export declare const COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
2375
2355
  /** Compose contract version the backend serves. Returned on every compose response. */
2376
2356
  export declare const COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
2377
- //#endregion
2378
- //#region src/version.d.ts
2379
2357
  /**
2380
2358
  * Compose contract version compatibility.
2381
2359
  *
@@ -2421,8 +2399,6 @@ export declare const parseVersion: (version: string) => ComposeVersion | undefin
2421
2399
  * because the server, not the client, decides how far back it serves.
2422
2400
  */
2423
2401
  export declare const checkCompatibility: (client: ComposeVersion, server: ComposeVersion, minimum?: ComposeVersion) => VersionCompatibility;
2424
- //#endregion
2425
- //#region src/materialiserMetadata.d.ts
2426
2402
  type MaterialiserMetadata = {
2427
2403
  readonly kind: 'exact';
2428
2404
  readonly amount: bigint;
@@ -2447,5 +2423,4 @@ export declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, c
2447
2423
  readonly capped: (amount: bigint, min: bigint | undefined) => R;
2448
2424
  readonly runtime: (min: bigint | undefined) => R;
2449
2425
  }) => R;
2450
- //#endregion
2451
2426
  export type { Amount, AppliedGuard, ApprovalEntry, AssertedPredicate, AssertionOwner, AssertionSpec, AssertionSpecWire, Availability, BindValue, Call, CallCheckSpec, ChainCapabilities, CommittedOutcome, ComposeAction, ComposeCompilePartialData, ComposeCompileRequest, ComposeCompileResult, ComposeCompileSuccessData, ComposeError, ComposeErrorKind, ComposeFill, ComposeManifest, ComposeRouteErrorKind, ComposeRouteRequest, ComposeRun, ComposeTransactionRequest, ComposeUserProgramSimulation, ComposeVersion, ComposeWarning, ConsumedOutput, ContextKey, ContinuationIntent, ContinuationOutcome, Delivery, DeliveryComposeError, DeliveryErrorDetails, DeliveryErrorReason, ERC20Resource, Epilogue, EpilogueForward, Erc20AllowancePrecondition, Erc20AllowanceRequirement, Erc20BalancePrecondition, Erc20BalanceRequirement, Estimate, EstimateBasis, ExecutedEpilogue, ExecutedForward, FailedPreparedOp, FlashloanMaterialiserInput, Flow, FlowInput, ForwardTo, GenericComposeError, GenericComposeErrorKind, GuardCompatibility, GuardSelector, HandleInput, HandlePort, HandleUnits, InputSpec, Lineage, LiteralBinding, ManifestGuard, ManifestMaterialiser, ManifestOperation, ManifestPrecondition, ManifestRouting, MaterialiserConfigOf, MaterialiserInput, MaterialiserInputBase, MaterialiserInputOf, MaterialiserMetadata, MaterialiserResolution, Minimum, MinimumBasis, NativeBalancePrecondition, NativeBalanceRequirement, NativeCheckPolicy, NativeErc20, NativeResource, OpInputPort, OpOutputPort, Output, OutputAmount, OutputFamilyPort, Outputs, ParsedRef, Permit2AllowanceRequirement, Phase1Artifact, Port, Precondition, PreconditionBase, PreconditionConfigOf, PreconditionOf, PreparationComposeError, PriceImpact, ProviderKindName, Ref, RefBuilder, RefPath, RefScope, Resource, ResourceInput, ResourceOutputPort, ResourcePort, RouteAmount, RouteAmountAll, RouteAmountExact, SettlementBindingWire, SettlementEscrowWire, SettlementWire, Shortfall, SimulateBalanceEntry, SimulateOkResult, SimulateRequest, SimulateResult, SimulateRevertDecodeResult, SimulateRevertResult, SimulateSetupErrorResult, SimulationPolicy, SimulationRevert, SimulationRevertComposeError, SlotFinderRequirement, SolType, SpendEntry, StaticSolType, TerminalOutput, TrackedBalance, VerificationDescriptor, VerificationDescriptorWire, VersionCompatibility };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { ParseResult, Schema } from "effect";
1
+ import { Schema } from "effect";
2
2
  import z from "zod";
3
- //#region src/flowSchema.d.ts
4
3
  export declare const SolTypeSchema: Schema.Literal<["uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string"]>;
5
4
  export declare const EVMAddressString: Schema.refine<string, typeof Schema.String>;
6
5
  export declare const IntegerString: Schema.filter<typeof Schema.String>;
@@ -311,8 +310,6 @@ type ForwardTo = typeof ForwardToSchema.Type;
311
310
  type EpilogueForward = typeof EpilogueForwardSchema.Type;
312
311
  type Epilogue = typeof EpilogueSchema.Type;
313
312
  type Flow = typeof FlowSchema.Type;
314
- //#endregion
315
- //#region src/continuation.d.ts
316
313
  export declare const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
317
314
  export declare const ContinuationOutcomeSchema: Schema.transform<Schema.Schema<{
318
315
  readonly token: string;
@@ -563,11 +560,6 @@ type ContinuationIntent = typeof ContinuationIntentSchema.Type;
563
560
  type Phase1Artifact = typeof Phase1ArtifactSchema.Type;
564
561
  type AssertionSpec = typeof AssertionSpecSchema.Type;
565
562
  type CallCheckSpec = typeof CallCheckSpecSchema.Type;
566
- export declare const settledOutcome: <I extends {
567
- readonly outcomes: readonly unknown[];
568
- }>(intent: I) => I['outcomes'][number] | undefined;
569
- //#endregion
570
- //#region src/descriptor.d.ts
571
563
  export declare const Bytes32HexSchema: Schema.filter<typeof Schema.String>;
572
564
  export declare const AssertedPredicateSchema: Schema.transformOrFail<Schema.Union<[Schema.Struct<{
573
565
  kind: Schema.Literal<["erc20BalanceGte"]>;
@@ -692,8 +684,6 @@ export declare const VerificationDescriptorSchema: Schema.Struct<{
692
684
  export declare const canonicalAssertedPredicate: (specs: readonly AssertionSpec[]) => string;
693
685
  type VerificationDescriptor = typeof VerificationDescriptorSchema.Type;
694
686
  type AssertedPredicate = AssertionSpec;
695
- //#endregion
696
- //#region src/resource.d.ts
697
687
  type Availability = 'now' | 'future';
698
688
  interface OutputAmount {
699
689
  readonly expected: bigint;
@@ -720,9 +710,8 @@ export declare const foldResource: <R>(r: Resource, cases: {
720
710
  }) => R;
721
711
  export declare const resourceToken: (r: Resource) => string;
722
712
  export declare const resourceKey: (r: Resource) => string;
713
+ export declare const describeResource: (r: Resource) => string;
723
714
  export declare const erc20Token: (r: Resource) => string;
724
- //#endregion
725
- //#region src/output.d.ts
726
715
  type EstimateBasis = 'simulated' | 'quoted';
727
716
  type MinimumBasis = 'guard' | 'op' | 'input' | 'declared';
728
717
  interface Estimate {
@@ -760,8 +749,6 @@ interface TerminalOutput extends OutputBase {
760
749
  }
761
750
  type Output = ConsumedOutput | TerminalOutput;
762
751
  type Outputs = Record<string, Output>;
763
- //#endregion
764
- //#region src/zodSchemas.d.ts
765
752
  export declare const ResourcePortZod: z.ZodObject<{
766
753
  kind: z.ZodLiteral<"resource">;
767
754
  name: z.ZodString;
@@ -1484,8 +1471,6 @@ type SettlementEscrowWire = z.infer<typeof SettlementEscrowZod>;
1484
1471
  type SettlementBindingWire = z.infer<typeof SettlementBindingZod>;
1485
1472
  type SettlementWire = z.infer<typeof SettlementZod>;
1486
1473
  type Shortfall = z.infer<typeof ShortfallZod>;
1487
- //#endregion
1488
- //#region src/compile.d.ts
1489
1474
  type SimulationPolicy = 'strict' | 'allow-revert';
1490
1475
  interface ComposeRun {
1491
1476
  readonly inputs: Record<string, InputSpec>;
@@ -1532,6 +1517,8 @@ interface SimulationRevert {
1532
1517
  readonly errorCandidates?: readonly {
1533
1518
  readonly decodedErrorSignature: string;
1534
1519
  readonly decodedParams: readonly string[];
1520
+ /** Human-readable description; present when the selector is in the backend's error registry. */
1521
+ readonly description?: string;
1535
1522
  }[];
1536
1523
  readonly error?: string;
1537
1524
  };
@@ -1627,8 +1614,6 @@ type ComposeCompileResult = (ComposeCompileSuccessData & {
1627
1614
  readonly message: string;
1628
1615
  };
1629
1616
  });
1630
- //#endregion
1631
- //#region src/flow.d.ts
1632
1617
  interface Port {
1633
1618
  readonly name: string;
1634
1619
  readonly type: SolType;
@@ -1648,7 +1633,7 @@ type ComposeErrorKind = 'decode_error' | 'validation_error' | 'linearity_error'
1648
1633
  /**
1649
1634
  * Errors raised by compose routes outside the compile pipeline.
1650
1635
  */
1651
- type ComposeRouteErrorKind = 'chain_validation_error' | 'unsupported_token' | 'zero_output' | 'service_unavailable' | 'verification_unavailable' | 'deployment_check_unavailable' | 'manifest_error' | 'sdk_outdated' | 'server_outdated';
1636
+ type ComposeRouteErrorKind = 'chain_validation_error' | 'unsupported_token' | 'signer_screening_rejected' | 'zero_output' | 'service_unavailable' | 'verification_unavailable' | 'deployment_check_unavailable' | 'manifest_error' | 'sdk_outdated' | 'server_outdated';
1652
1637
  type GenericComposeErrorKind = Exclude<ComposeErrorKind, 'preparation_error' | 'simulation_revert' | 'delivery_error'>;
1653
1638
  interface FailedPreparedOp {
1654
1639
  readonly callId: string;
@@ -1715,24 +1700,31 @@ interface PreconditionBase {
1715
1700
  type Precondition = PreconditionBase & Record<string, unknown>;
1716
1701
  type PreconditionOf<C extends object> = PreconditionBase & C;
1717
1702
  type PreconditionConfigOf<C extends object> = Omit<PreconditionBase, 'type'> & C;
1718
- //#endregion
1719
- //#region src/flashloan.d.ts
1720
- export declare const PROVIDER_KIND: {
1721
- readonly AAVE_V3: 0;
1722
- readonly ERC3156: 1;
1723
- readonly BALANCER_V2: 2;
1724
- readonly MORPHO_BLUE: 3;
1725
- };
1726
- export declare const providerKindNames: readonly ['aave-v3', 'erc3156', 'balancer-v2', 'morpho-blue'];
1703
+ export declare const providerKindNames: readonly ['aave-v3', 'balancer-v2', 'morpho-blue'];
1727
1704
  type ProviderKindName = (typeof providerKindNames)[number];
1728
- export declare const providerKindByName: Record<ProviderKindName, number>;
1729
- interface FlashloanMaterialiserInput {
1730
- readonly kind: 'flashloan';
1731
- readonly providerKind: ProviderKindName;
1705
+ export declare const FlashloanConfigSchema: Schema.Struct<{
1706
+ providerKind: Schema.Literal<["aave-v3", "balancer-v2", "morpho-blue"]>;
1707
+ amount: Schema.filter<typeof Schema.String>;
1708
+ maxFee: Schema.optional<Schema.filter<typeof Schema.String>>;
1709
+ }>;
1710
+ export declare const FlashloanMaterialiserInputSchema: Schema.Struct<{
1711
+ providerKind: Schema.Literal<["aave-v3", "balancer-v2", "morpho-blue"]>;
1712
+ amount: Schema.filter<typeof Schema.String>;
1713
+ maxFee: Schema.optional<Schema.filter<typeof Schema.String>>;
1714
+ kind: Schema.Literal<["flashloan"]>;
1715
+ }>;
1716
+ type FlashloanMaterialiserInput = typeof FlashloanMaterialiserInputSchema.Type;
1717
+ export declare const isFlashloanMaterialiserInput: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is {
1718
+ readonly providerKind: "aave-v3" | "balancer-v2" | "morpho-blue";
1732
1719
  readonly amount: string;
1733
- }
1734
- //#endregion
1735
- //#region src/constructors.d.ts
1720
+ readonly maxFee?: string | undefined;
1721
+ readonly kind: "flashloan";
1722
+ };
1723
+ export declare const flashloanMaxFee: ({ providerKind, amount, maxFee }: {
1724
+ readonly providerKind: ProviderKindName;
1725
+ readonly amount: string | bigint;
1726
+ readonly maxFee?: string | bigint;
1727
+ }) => bigint;
1736
1728
  interface OpHandleOptions<Opt extends boolean = boolean> {
1737
1729
  readonly expose?: boolean;
1738
1730
  readonly units?: HandleUnits;
@@ -1792,8 +1784,6 @@ export declare const resourceOutput: <N extends string, const O extends Resource
1792
1784
  readonly name: N;
1793
1785
  readonly availability: OutputAvailability<O>;
1794
1786
  } & OutputCountFrom<O>;
1795
- //#endregion
1796
- //#region src/outputFamilies.d.ts
1797
1787
  type OutputFamilyPort = ResourceOutputPort & {
1798
1788
  readonly countFrom: string;
1799
1789
  };
@@ -1801,8 +1791,6 @@ export declare const isOutputFamily: (port: OpOutputPort) => port is OutputFamil
1801
1791
  export declare const instancePortName: (family: string, index: number) => string;
1802
1792
  export declare const familySize: (family: Pick<OutputFamilyPort, 'name' | 'countFrom'>, config: Call['config']) => number;
1803
1793
  export declare const expandOutputPorts: (declared: readonly OpOutputPort[], config: Call['config']) => readonly OpOutputPort[];
1804
- //#endregion
1805
- //#region src/ref.d.ts
1806
1794
  type ParsedRef = {
1807
1795
  readonly scope: 'input';
1808
1796
  readonly port: string;
@@ -1846,8 +1834,6 @@ export declare const foldRef: <R>(ref: ParsedRef, cases: {
1846
1834
  readonly output: (node: string, port: string) => R;
1847
1835
  }) => R;
1848
1836
  export declare const refKey: (ref: Ref) => string;
1849
- //#endregion
1850
- //#region src/chainCapabilities.d.ts
1851
1837
  /**
1852
1838
  * Per-chain native-asset semantics.
1853
1839
  *
@@ -2042,8 +2028,6 @@ export declare const normalizeResource: (r: Resource) => Resource;
2042
2028
  * rewritten to the chain's stand-in ERC-20; every other address passes through.
2043
2029
  */
2044
2030
  export declare const normalizeNativeTokenAddress: (token: string, chainId: number) => string;
2045
- //#endregion
2046
- //#region src/route.d.ts
2047
2031
  /**
2048
2032
  * Spend an exact amount of `fromToken`.
2049
2033
  *
@@ -2169,8 +2153,6 @@ interface ComposeRouteRequest {
2169
2153
  */
2170
2154
  readonly allowAsyncRoutes?: boolean;
2171
2155
  }
2172
- //#endregion
2173
- //#region src/preconditions.d.ts
2174
2156
  /**
2175
2157
  * The three concrete precondition shapes the stack exchanges today. One
2176
2158
  * definition serves every producer and consumer: op/materialiser declarations,
@@ -2204,8 +2186,6 @@ export declare const erc20Allowance: (config: Omit<Erc20AllowancePrecondition, '
2204
2186
  export declare const isErc20BalancePrecondition: (p: Precondition) => p is Erc20BalancePrecondition;
2205
2187
  export declare const isErc20AllowancePrecondition: (p: Precondition) => p is Erc20AllowancePrecondition;
2206
2188
  export declare const isNativeBalancePrecondition: (p: Precondition) => p is NativeBalancePrecondition;
2207
- //#endregion
2208
- //#region src/simulate.d.ts
2209
2189
  /**
2210
2190
  * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
2211
2191
  *
@@ -2332,6 +2312,8 @@ interface SimulateRevertDecodeResult {
2332
2312
  readonly errorCandidates?: {
2333
2313
  readonly decodedErrorSignature: string;
2334
2314
  readonly decodedParams: string[];
2315
+ /** Human-readable description; present when the selector is in the backend's error registry. */
2316
+ readonly description?: string;
2335
2317
  }[];
2336
2318
  readonly error?: string;
2337
2319
  }
@@ -2361,8 +2343,6 @@ interface SimulateSetupErrorResult {
2361
2343
  * one member: `ok` and `revert` come back with HTTP 200, `error` with HTTP 422.
2362
2344
  */
2363
2345
  type SimulateResult = SimulateOkResult | SimulateRevertResult | SimulateSetupErrorResult;
2364
- //#endregion
2365
- //#region src/headers.d.ts
2366
2346
  /**
2367
2347
  * HTTP header names on the compose wire.
2368
2348
  *
@@ -2374,8 +2354,6 @@ type SimulateResult = SimulateOkResult | SimulateRevertResult | SimulateSetupErr
2374
2354
  export declare const COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
2375
2355
  /** Compose contract version the backend serves. Returned on every compose response. */
2376
2356
  export declare const COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
2377
- //#endregion
2378
- //#region src/version.d.ts
2379
2357
  /**
2380
2358
  * Compose contract version compatibility.
2381
2359
  *
@@ -2421,8 +2399,6 @@ export declare const parseVersion: (version: string) => ComposeVersion | undefin
2421
2399
  * because the server, not the client, decides how far back it serves.
2422
2400
  */
2423
2401
  export declare const checkCompatibility: (client: ComposeVersion, server: ComposeVersion, minimum?: ComposeVersion) => VersionCompatibility;
2424
- //#endregion
2425
- //#region src/materialiserMetadata.d.ts
2426
2402
  type MaterialiserMetadata = {
2427
2403
  readonly kind: 'exact';
2428
2404
  readonly amount: bigint;
@@ -2447,5 +2423,4 @@ export declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, c
2447
2423
  readonly capped: (amount: bigint, min: bigint | undefined) => R;
2448
2424
  readonly runtime: (min: bigint | undefined) => R;
2449
2425
  }) => R;
2450
- //#endregion
2451
2426
  export type { Amount, AppliedGuard, ApprovalEntry, AssertedPredicate, AssertionOwner, AssertionSpec, AssertionSpecWire, Availability, BindValue, Call, CallCheckSpec, ChainCapabilities, CommittedOutcome, ComposeAction, ComposeCompilePartialData, ComposeCompileRequest, ComposeCompileResult, ComposeCompileSuccessData, ComposeError, ComposeErrorKind, ComposeFill, ComposeManifest, ComposeRouteErrorKind, ComposeRouteRequest, ComposeRun, ComposeTransactionRequest, ComposeUserProgramSimulation, ComposeVersion, ComposeWarning, ConsumedOutput, ContextKey, ContinuationIntent, ContinuationOutcome, Delivery, DeliveryComposeError, DeliveryErrorDetails, DeliveryErrorReason, ERC20Resource, Epilogue, EpilogueForward, Erc20AllowancePrecondition, Erc20AllowanceRequirement, Erc20BalancePrecondition, Erc20BalanceRequirement, Estimate, EstimateBasis, ExecutedEpilogue, ExecutedForward, FailedPreparedOp, FlashloanMaterialiserInput, Flow, FlowInput, ForwardTo, GenericComposeError, GenericComposeErrorKind, GuardCompatibility, GuardSelector, HandleInput, HandlePort, HandleUnits, InputSpec, Lineage, LiteralBinding, ManifestGuard, ManifestMaterialiser, ManifestOperation, ManifestPrecondition, ManifestRouting, MaterialiserConfigOf, MaterialiserInput, MaterialiserInputBase, MaterialiserInputOf, MaterialiserMetadata, MaterialiserResolution, Minimum, MinimumBasis, NativeBalancePrecondition, NativeBalanceRequirement, NativeCheckPolicy, NativeErc20, NativeResource, OpInputPort, OpOutputPort, Output, OutputAmount, OutputFamilyPort, Outputs, ParsedRef, Permit2AllowanceRequirement, Phase1Artifact, Port, Precondition, PreconditionBase, PreconditionConfigOf, PreconditionOf, PreparationComposeError, PriceImpact, ProviderKindName, Ref, RefBuilder, RefPath, RefScope, Resource, ResourceInput, ResourceOutputPort, ResourcePort, RouteAmount, RouteAmountAll, RouteAmountExact, SettlementBindingWire, SettlementEscrowWire, SettlementWire, Shortfall, SimulateBalanceEntry, SimulateOkResult, SimulateRequest, SimulateResult, SimulateRevertDecodeResult, SimulateRevertResult, SimulateSetupErrorResult, SimulationPolicy, SimulationRevert, SimulationRevertComposeError, SlotFinderRequirement, SolType, SpendEntry, StaticSolType, TerminalOutput, TrackedBalance, VerificationDescriptor, VerificationDescriptorWire, VersionCompatibility };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ParseResult, Schema } from "effect";
2
2
  import z from "zod";
3
- //#region src/chainCapabilities.ts
3
+ // src/chainCapabilities.ts
4
4
  /**
5
5
  * The zero-address sentinel that represents the native gas coin on
6
6
  * EVM-native chains. Exported so tests and call-sites can reference it
@@ -186,15 +186,13 @@ const normalizeResource = (r) => {
186
186
  * rewritten to the chain's stand-in ERC-20; every other address passes through.
187
187
  */
188
188
  const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isZeroAddress(token) ? canonicalNativeAddress(chainId) : token;
189
- //#endregion
190
- //#region src/hexPatterns.ts
189
+ // src/hexPatterns.ts
191
190
  const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
192
191
  const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
193
192
  const DECIMAL_UINT = /^[0-9]+$/;
194
193
  const MAX_UINT256 = 2n ** 256n - 1n;
195
194
  const MAX_DATE_MS = 864e13;
196
- //#endregion
197
- //#region src/flowSchema.ts
195
+ // src/flowSchema.ts
198
196
  const SolTypeSchema = Schema.Literal("uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string");
199
197
  const ChainIdSchema = Schema.Number.pipe(Schema.int(), Schema.positive());
200
198
  const EVMAddressString = Schema.String.pipe(Schema.pattern(EVM_ADDRESS_HEX, { message: () => "expected a 0x-prefixed 20-byte EVM address" })).annotations({ description: "EVM address: 0x followed by 40 hex characters" });
@@ -289,8 +287,7 @@ const FlowSchema = Schema.Struct({
289
287
  lineage: Schema.optional(LineageSchema),
290
288
  epilogue: Schema.optional(EpilogueSchema)
291
289
  });
292
- //#endregion
293
- //#region src/continuation.ts
290
+ // src/continuation.ts
294
291
  const CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
295
292
  const outcomeFields = (minAmount) => ({
296
293
  token: EVMAddressString,
@@ -393,9 +390,7 @@ const decodeNativeBalanceGte = (check, ast) => {
393
390
  }
394
391
  };
395
392
  const AssertionSpecSchema = Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema);
396
- const settledOutcome = (intent) => intent.outcomes[0];
397
- //#endregion
398
- //#region src/descriptor.ts
393
+ // src/descriptor.ts
399
394
  const Bytes32HexSchema = Schema.String.pipe(Schema.pattern(BYTES32_LOWER_HEX));
400
395
  const AssertedPredicateSchema = Schema.transformOrFail(AssertionSpecSchema, Schema.typeSchema(AssertionSpecSchema), {
401
396
  strict: true,
@@ -416,8 +411,7 @@ const canonicalJson = (value) => {
416
411
  return JSON.stringify(value);
417
412
  };
418
413
  const canonicalAssertedPredicate = (specs) => canonicalJson(specs);
419
- //#endregion
420
- //#region src/flow.ts
414
+ // src/flow.ts
421
415
  const isResourceInput = (input) => "resource" in input;
422
416
  const flowInputType = (input) => isResourceInput(input) ? "uint256" : input.type;
423
417
  const flowInputMode = (input) => isResourceInput(input) ? "linear" : "copy";
@@ -427,8 +421,7 @@ const isHandlePort = (port) => port.kind === "handle";
427
421
  const isResourceOutputPort = (port) => port.kind === "resource_output";
428
422
  const isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
429
423
  const isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
430
- //#endregion
431
- //#region src/resource.ts
424
+ // src/resource.ts
432
425
  const erc20Resource = (token, chainId) => ({
433
426
  kind: "erc20",
434
427
  token,
@@ -460,32 +453,38 @@ const resourceKey = (r) => foldResource(r, {
460
453
  native: ({ chainId }) => `native:${chainId}`,
461
454
  erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`
462
455
  });
456
+ const describeResource = (r) => foldResource(r, {
457
+ native: ({ chainId }) => `native coin on chain ${chainId}`,
458
+ erc20: ({ token, chainId }) => `${token} on chain ${chainId}`
459
+ });
463
460
  const erc20Token = (r) => {
464
461
  if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
465
462
  return r.token;
466
463
  };
467
- //#endregion
468
- //#region src/flashloan.ts
469
- const PROVIDER_KIND = {
470
- AAVE_V3: 0,
471
- ERC3156: 1,
472
- BALANCER_V2: 2,
473
- MORPHO_BLUE: 3
474
- };
464
+ // src/flashloan.ts
475
465
  const providerKindNames = [
476
466
  "aave-v3",
477
- "erc3156",
478
467
  "balancer-v2",
479
468
  "morpho-blue"
480
469
  ];
481
- const providerKindByName = {
482
- "aave-v3": PROVIDER_KIND.AAVE_V3,
483
- erc3156: PROVIDER_KIND.ERC3156,
484
- "balancer-v2": PROVIDER_KIND.BALANCER_V2,
485
- "morpho-blue": PROVIDER_KIND.MORPHO_BLUE
470
+ const FlashloanConfigSchema = Schema.Struct({
471
+ providerKind: Schema.Literal(...providerKindNames),
472
+ amount: IntegerString,
473
+ maxFee: Schema.optional(IntegerString)
474
+ });
475
+ const FlashloanMaterialiserInputSchema = Schema.Struct({
476
+ kind: Schema.Literal("flashloan"),
477
+ ...FlashloanConfigSchema.fields
478
+ });
479
+ const isFlashloanMaterialiserInput = Schema.is(FlashloanMaterialiserInputSchema);
480
+ const FLASHLOAN_FEE_BPS = {
481
+ "aave-v3": 5n,
482
+ "balancer-v2": 0n,
483
+ "morpho-blue": 0n
486
484
  };
487
- //#endregion
488
- //#region src/constructors.ts
485
+ const BPS_DENOMINATOR = 10000n;
486
+ const flashloanMaxFee = ({ providerKind, amount, maxFee }) => maxFee !== void 0 ? BigInt(maxFee) : (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] + BPS_DENOMINATOR - 1n) / BPS_DENOMINATOR;
487
+ // src/constructors.ts
489
488
  /** Returns `{ [key]: value }` when `value` is not nullish, else `{}`. */
490
489
  const optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
491
490
  const linear = (name, type) => ({
@@ -548,8 +547,7 @@ const resourceOutput = (name, options) => {
548
547
  ...optionalProp("countFrom", opts?.countFrom)
549
548
  };
550
549
  };
551
- //#endregion
552
- //#region src/outputFamilies.ts
550
+ // src/outputFamilies.ts
553
551
  const isOutputFamily = (port) => port.kind === "resource_output" && port.countFrom !== void 0;
554
552
  const instancePortName = (family, index) => `${family}.${index}`;
555
553
  const familySize = (family, config) => {
@@ -566,8 +564,7 @@ const expandFamily = (port, config) => {
566
564
  }));
567
565
  };
568
566
  const expandOutputPorts = (declared, config) => declared.some(isOutputFamily) ? declared.flatMap((port) => isOutputFamily(port) ? expandFamily(port, config) : [port]) : declared;
569
- //#endregion
570
- //#region src/ref.ts
567
+ // src/ref.ts
571
568
  const isContextKey = (key) => key === "sender" || key === "executionAddress";
572
569
  /**
573
570
  * Ref prefixes that parseRef intercepts before the fallback `output` scope.
@@ -626,8 +623,7 @@ const refKey = (ref) => foldRef(parseRef(ref), {
626
623
  context: (key) => `context:${key}`,
627
624
  output: (node, port) => `output:${node}:${port}`
628
625
  });
629
- //#endregion
630
- //#region src/preconditions.ts
626
+ // src/preconditions.ts
631
627
  const erc20Balance = (config) => ({
632
628
  type: "Erc20Balance",
633
629
  ...config
@@ -643,8 +639,7 @@ const erc20Allowance = (config) => ({
643
639
  const isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
644
640
  const isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
645
641
  const isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
646
- //#endregion
647
- //#region src/simulate.ts
642
+ // src/simulate.ts
648
643
  /**
649
644
  * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
650
645
  *
@@ -666,8 +661,7 @@ const SIMULATE_MAX_TRACKED_BALANCES = 40;
666
661
  * trust boundary and re-enforced server-side in `rawSimulation.ts`.
667
662
  */
668
663
  const SIMULATE_MAX_REQUIREMENTS = 40;
669
- //#endregion
670
- //#region src/headers.ts
664
+ // src/headers.ts
671
665
  /**
672
666
  * HTTP header names on the compose wire.
673
667
  *
@@ -679,8 +673,7 @@ const SIMULATE_MAX_REQUIREMENTS = 40;
679
673
  const COMPOSER_SDK_VERSION_HEADER = "x-lifi-composer-sdk";
680
674
  /** Compose contract version the backend serves. Returned on every compose response. */
681
675
  const COMPOSE_VERSION_HEADER = "x-lifi-composer-version";
682
- //#endregion
683
- //#region src/version.ts
676
+ // src/version.ts
684
677
  const SEMANTIC_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
685
678
  /**
686
679
  * Parses the numeric triple of a semantic version. Prerelease and build
@@ -735,16 +728,14 @@ const checkCompatibility = (client, server, minimum = {
735
728
  if (compareVersions(client, minimum) < 0) return "sdk_outdated";
736
729
  return "compatible";
737
730
  };
738
- //#endregion
739
- //#region src/materialiserMetadata.ts
731
+ // src/materialiserMetadata.ts
740
732
  const foldMaterialiserMetadata = (meta, cases) => {
741
733
  if (meta.kind === "exact") return cases.exact(meta.amount);
742
734
  if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
743
735
  if (meta.kind === "capped") return cases.capped(meta.amount, meta.min);
744
736
  return cases.runtime(meta.min);
745
737
  };
746
- //#endregion
747
- //#region src/zodSchemas.ts
738
+ // src/zodSchemas.ts
748
739
  const chainIdZod = z.number().int().positive();
749
740
  const evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
750
741
  const uintStringZod = z.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, { message: "expected a uint256 decimal integer string" });
@@ -952,5 +943,4 @@ const ShortfallZod = z.object({
952
943
  required: z.string(),
953
944
  available: z.string()
954
945
  });
955
- //#endregion
956
- export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, AppliedGuardSchema, AssertedPredicateSchema, AssertionOwnerSchema, AssertionSpecSchema, AssertionSpecZod, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, CallCheckSpecSchema, CallSchema, CommittedOutcomeSchema, ComposeManifestZod, ContinuationIntentSchema, ContinuationOutcomeSchema, EVMAddressString, EVM_NATIVE_SENTINEL, EpilogueForwardSchema, EpilogueSchema, Erc20BalanceGteSpecSchema, FlowInputSchema, FlowSchema, ForwardToSchema, GuardCompatibilityZod, GuardSelectorZod, HANDLE_UNITS, HandleInputSchema, HandlePortZod, HandleUnitsZod, HexStringSchema, InputPortZod, IntegerString, LineageSchema, LiteralBindingSchema, ManifestGuardZod, ManifestMaterialiserZod, ManifestOperationZod, ManifestPreconditionZod, ManifestRoutingZod, NativeBalanceGteSpecSchema, OutputPortZod, PROVIDER_KIND, Phase1ArtifactSchema, RESERVED_REF_SCOPES, RefSchema, ResourceInputSchema, ResourceOutputPortZod, ResourcePortZod, ResourceSchema, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, SettlementZod, ShortfallZod, SolTypeSchema, StaticSolTypeZod, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, UuidSchema, VerificationDescriptorSchema, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, expandOutputPorts, familySize, flowInputMode, flowInputResource, flowInputType, foldChainCapabilities, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, hasErc20CanonicalNative, instancePortName, isAsErc20Chain, isContextKey, isERC20Resource, isErc20AllowancePrecondition, isErc20BalancePrecondition, isFutureResourceOutput, isHandlePort, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isOutputFamily, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeCheckPolicy, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindByName, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual, settledOutcome };
946
+ export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, AppliedGuardSchema, AssertedPredicateSchema, AssertionOwnerSchema, AssertionSpecSchema, AssertionSpecZod, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, CallCheckSpecSchema, CallSchema, CommittedOutcomeSchema, ComposeManifestZod, ContinuationIntentSchema, ContinuationOutcomeSchema, EVMAddressString, EVM_NATIVE_SENTINEL, EpilogueForwardSchema, EpilogueSchema, Erc20BalanceGteSpecSchema, FlashloanConfigSchema, FlashloanMaterialiserInputSchema, FlowInputSchema, FlowSchema, ForwardToSchema, GuardCompatibilityZod, GuardSelectorZod, HANDLE_UNITS, HandleInputSchema, HandlePortZod, HandleUnitsZod, HexStringSchema, InputPortZod, IntegerString, LineageSchema, LiteralBindingSchema, ManifestGuardZod, ManifestMaterialiserZod, ManifestOperationZod, ManifestPreconditionZod, ManifestRoutingZod, NativeBalanceGteSpecSchema, OutputPortZod, Phase1ArtifactSchema, RESERVED_REF_SCOPES, RefSchema, ResourceInputSchema, ResourceOutputPortZod, ResourcePortZod, ResourceSchema, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, SettlementZod, ShortfallZod, SolTypeSchema, StaticSolTypeZod, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, UuidSchema, VerificationDescriptorSchema, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, describeResource, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, expandOutputPorts, familySize, flashloanMaxFee, flowInputMode, flowInputResource, flowInputType, foldChainCapabilities, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, hasErc20CanonicalNative, instancePortName, isAsErc20Chain, isContextKey, isERC20Resource, isErc20AllowancePrecondition, isErc20BalancePrecondition, isFlashloanMaterialiserInput, isFutureResourceOutput, isHandlePort, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isOutputFamily, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeCheckPolicy, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/compose-spec",
3
- "version": "0.15.2",
3
+ "version": "0.17.0",
4
4
  "description": "Public wire-format types and schemas for Compose flows",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/compile.ts CHANGED
@@ -58,6 +58,8 @@ export interface SimulationRevert {
58
58
  readonly errorCandidates?: readonly {
59
59
  readonly decodedErrorSignature: string;
60
60
  readonly decodedParams: readonly string[];
61
+ /** Human-readable description; present when the selector is in the backend's error registry. */
62
+ readonly description?: string;
61
63
  }[];
62
64
  readonly error?: string;
63
65
  };
@@ -25,8 +25,9 @@ export const CONTINUATION_COMMITMENT_OP_ID = 'continuation.commitment';
25
25
  // A single outcome of a deferred settlement: `token` must be delivered to
26
26
  // `destination` on `chainId`. Amounts are decimal strings on the wire because
27
27
  // JSON has no bigint; `chainId` reuses the shared `ChainIdSchema` from
28
- // `flowSchema.ts`. `token` becomes a `Resource` in `continuation.settle`'s
29
- // output and `destination` its owner, so both take the address rule.
28
+ // `flowSchema.ts`. Outcome `i` becomes the `Resource` on `continuation.settle`'s
29
+ // `outcomes.i` output and `destination` its owner, so both take the address
30
+ // rule.
30
31
  //
31
32
  // `minAmount` is the floor the author commits to. An author may omit it: a
32
33
  // committed provider proves the floor from the settle's `continuationFlow`,
@@ -92,9 +93,9 @@ export const CommittedOutcomeSchema = normalizingOutcome(
92
93
  // `compose-spec` dependency-free.
93
94
  export const ContinuationIntentSchema = Schema.Struct({
94
95
  // Zero outcomes are admitted only for an exact settle, whose bound leg is its
95
- // only enforcement; compose-core's first two capability gates
96
- // (`resolveContinuationProvider.ts:CAPABILITY_CHECKS`) enforce that pairing
97
- // and the one-outcome maximum, since the schema cannot see `exact`.
96
+ // only enforcement; compose-core's first capability gate
97
+ // (`resolveContinuationProvider.ts:CAPABILITY_CHECKS`) enforces that pairing,
98
+ // since the schema cannot see `exact`.
98
99
  outcomes: Schema.Array(ContinuationOutcomeSchema),
99
100
  continuationFlow: Schema.optional(FlowSchema),
100
101
  validity: Schema.Struct({ expiresAtMs: EpochMsSchema }),
@@ -337,18 +338,3 @@ export type ContinuationIntent = typeof ContinuationIntentSchema.Type;
337
338
  export type Phase1Artifact = typeof Phase1ArtifactSchema.Type;
338
339
  export type AssertionSpec = typeof AssertionSpecSchema.Type;
339
340
  export type CallCheckSpec = typeof CallCheckSpecSchema.Type;
340
-
341
- // The outcome a `continuation.settle` node's single `output` port stands for.
342
- // The wire format admits several outcomes, but the op produces one resource,
343
- // discloses one owner, and every shipped provider rejects a multi-outcome
344
- // intent, so the first outcome is the settled one everywhere. `undefined`
345
- // means a zero-outcome exact settle: the bound leg consumes the funding and
346
- // delivers nothing, so the `output` port carries no resource. Keep this the
347
- // only place that picks `[0]`: a multi-outcome design changes one accessor,
348
- // not a scatter of `[0]`s. Generic over the intent so a `CommittedIntent`
349
- // yields a `CommittedOutcome`.
350
- export const settledOutcome = <
351
- I extends { readonly outcomes: readonly unknown[] },
352
- >(
353
- intent: I,
354
- ): I['outcomes'][number] | undefined => intent.outcomes[0];
package/src/flashloan.ts CHANGED
@@ -1,41 +1,73 @@
1
- // Mirrors the Solidity `ProviderKind` enum in
2
- // `Yggdrasil-VirtualMachine/src/flashloan/FlashloanLeg.sol`. The numeric
3
- // values are wire format; the Rust EVM backend consumes them in
4
- // `executeWithFlashloan(adapter, legs, programBytes)`. Drift between this
5
- // file and the Solidity source is a bug.
6
-
7
- export const PROVIDER_KIND = {
8
- AAVE_V3: 0,
9
- ERC3156: 1,
10
- BALANCER_V2: 2,
11
- MORPHO_BLUE: 3,
12
- } as const;
1
+ import { Schema } from 'effect';
13
2
 
3
+ import { IntegerString } from './flowSchema.js';
4
+
5
+ // The lenders a `flashloan` input can borrow from. Each name selects one
6
+ // lender adapter of the v1.3 flashloan runtime (one adapter contract per
7
+ // kind) and that lender's per-chain address.
14
8
  export const providerKindNames = [
15
9
  'aave-v3',
16
- 'erc3156',
17
10
  'balancer-v2',
18
11
  'morpho-blue',
19
12
  ] as const;
20
13
 
21
14
  export type ProviderKindName = (typeof providerKindNames)[number];
22
15
 
23
- export const providerKindByName: Record<ProviderKindName, number> = {
24
- 'aave-v3': PROVIDER_KIND.AAVE_V3,
25
- erc3156: PROVIDER_KIND.ERC3156,
26
- 'balancer-v2': PROVIDER_KIND.BALANCER_V2,
27
- 'morpho-blue': PROVIDER_KIND.MORPHO_BLUE,
16
+ // The one definition of a `flashloan` input's fields, in the wire form
17
+ // (decimal-integer strings). The materialiser's `configSchema`
18
+ // (compose-builtins), the input type and its guard all derive from it.
19
+ // - `amount`: what the leg borrows, in the token's smallest unit.
20
+ // - `maxFee`: the most the lender may charge for the leg; the runtime reverts
21
+ // `FlashloanFeeTooHigh` above it. Defaults to `flashloanMaxFee`'s rate.
22
+ export const FlashloanConfigSchema = Schema.Struct({
23
+ providerKind: Schema.Literal(...providerKindNames),
24
+ amount: IntegerString,
25
+ maxFee: Schema.optional(IntegerString),
26
+ });
27
+
28
+ // A `flashloan` input as authored: the config under the literal
29
+ // `kind: "flashloan"` that discriminates inside the `MaterialiserInput` union.
30
+ export const FlashloanMaterialiserInputSchema = Schema.Struct({
31
+ kind: Schema.Literal('flashloan'),
32
+ ...FlashloanConfigSchema.fields,
33
+ });
34
+
35
+ export type FlashloanMaterialiserInput =
36
+ typeof FlashloanMaterialiserInputSchema.Type;
37
+
38
+ export const isFlashloanMaterialiserInput = Schema.is(
39
+ FlashloanMaterialiserInputSchema,
40
+ );
41
+
42
+ // Reference fee rates, in basis points of the borrowed amount, that size a
43
+ // leg's default `maxFee`. Aave v3: `FLASHLOAN_PREMIUM_TOTAL` is 5 bps on the
44
+ // markets in the registry.
45
+ const FLASHLOAN_FEE_BPS: Readonly<Record<ProviderKindName, bigint>> = {
46
+ 'aave-v3': 5n,
47
+ 'balancer-v2': 0n,
48
+ 'morpho-blue': 0n,
28
49
  };
29
50
 
30
- // The fully-narrowed JSON shape of a `flashloan` MaterialiserInput once it
31
- // has crossed from untrusted Flow JSON through structural validation. The
32
- // literal `kind: "flashloan"` discriminates inside the `MaterialiserInput`
33
- // union; `providerKind` and `amount` are the two flashloan-specific fields.
34
- // `amount` is the wire form (decimal-integer string); the flashloan
35
- // materialiser's `configSchema` (see compose-builtins/materialisers/flashloan)
36
- // validates the shape before any consumer reads it.
37
- export interface FlashloanMaterialiserInput {
38
- readonly kind: 'flashloan';
51
+ // Local rather than imported: compose-spec may depend on no @lifi/* package.
52
+ const BPS_DENOMINATOR = 10_000n;
53
+
54
+ // The fee cap of one leg: the input's own `maxFee`, else the reference rate
55
+ // rounded up. Rounding up matters: Aave rounds its premium half-up
56
+ // (`percentMul`), so a rounded-down cap can sit one unit below the fee it
57
+ // charges and revert the flight. Amounts are wire strings or bigints, so an
58
+ // author who holds a bigint does not format it first.
59
+ export const flashloanMaxFee = ({
60
+ providerKind,
61
+ amount,
62
+ maxFee,
63
+ }: {
39
64
  readonly providerKind: ProviderKindName;
40
- readonly amount: string;
41
- }
65
+ readonly amount: string | bigint;
66
+ readonly maxFee?: string | bigint;
67
+ }): bigint =>
68
+ maxFee !== undefined
69
+ ? BigInt(maxFee)
70
+ : (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] +
71
+ BPS_DENOMINATOR -
72
+ 1n) /
73
+ BPS_DENOMINATOR;
package/src/flow.ts CHANGED
@@ -94,6 +94,9 @@ export type ComposeErrorKind =
94
94
  export type ComposeRouteErrorKind =
95
95
  | 'chain_validation_error'
96
96
  | 'unsupported_token'
97
+ // The signer is on a threat-intelligence list (zeroShadow) and may not use
98
+ // the service.
99
+ | 'signer_screening_rejected'
97
100
  | 'zero_output'
98
101
  | 'service_unavailable'
99
102
  | 'verification_unavailable'
@@ -151,7 +154,9 @@ export interface SimulationRevertComposeError extends ComposeErrorBase {
151
154
  // - `quote_failed`: the second quote (to the registered escrow) failed;
152
155
  // `cause` is the kind of that failure and `quoted` is the first quote.
153
156
  export type DeliveryErrorReason =
154
- 'floor_drift' | 'eta_exceeds_expiry' | 'quote_failed';
157
+ | 'floor_drift'
158
+ | 'eta_exceeds_expiry'
159
+ | 'quote_failed';
155
160
 
156
161
  // `escrow` is present only when the failure came after the escrow was
157
162
  // registered: the escrow is then abandoned and expires unfunded, and this
package/src/index.ts CHANGED
@@ -56,7 +56,6 @@ export {
56
56
  NativeBalanceGteSpecSchema,
57
57
  CallCheckSpecSchema,
58
58
  AssertionSpecSchema,
59
- settledOutcome,
60
59
  } from './continuation.js';
61
60
 
62
61
  export type {
@@ -118,6 +117,7 @@ export type {
118
117
  Resource,
119
118
  } from './resource.js';
120
119
  export {
120
+ describeResource,
121
121
  erc20Resource,
122
122
  erc20Token,
123
123
  foldResource,
@@ -147,8 +147,10 @@ export type {
147
147
  FlashloanMaterialiserInput,
148
148
  } from './flashloan.js';
149
149
  export {
150
- PROVIDER_KIND,
151
- providerKindByName,
150
+ FlashloanConfigSchema,
151
+ FlashloanMaterialiserInputSchema,
152
+ flashloanMaxFee,
153
+ isFlashloanMaterialiserInput,
152
154
  providerKindNames,
153
155
  } from './flashloan.js';
154
156
 
package/src/resource.ts CHANGED
@@ -84,6 +84,13 @@ export const resourceKey = (r: Resource): string =>
84
84
  erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`,
85
85
  });
86
86
 
87
+ // A resource as an error message names it.
88
+ export const describeResource = (r: Resource): string =>
89
+ foldResource(r, {
90
+ native: ({ chainId }) => `native coin on chain ${chainId}`,
91
+ erc20: ({ token, chainId }) => `${token} on chain ${chainId}`,
92
+ });
93
+
87
94
  export const erc20Token = (r: Resource): string => {
88
95
  if (r.kind !== 'erc20')
89
96
  throw new Error(`Expected erc20 resource, got ${r.kind}`);
package/src/simulate.ts CHANGED
@@ -167,6 +167,8 @@ export interface SimulateRevertDecodeResult {
167
167
  readonly errorCandidates?: {
168
168
  readonly decodedErrorSignature: string;
169
169
  readonly decodedParams: string[];
170
+ /** Human-readable description; present when the selector is in the backend's error registry. */
171
+ readonly description?: string;
170
172
  }[];
171
173
  readonly error?: string;
172
174
  }
@@ -199,4 +201,6 @@ export interface SimulateSetupErrorResult {
199
201
  * one member: `ok` and `revert` come back with HTTP 200, `error` with HTTP 422.
200
202
  */
201
203
  export type SimulateResult =
202
- SimulateOkResult | SimulateRevertResult | SimulateSetupErrorResult;
204
+ | SimulateOkResult
205
+ | SimulateRevertResult
206
+ | SimulateSetupErrorResult;
package/src/version.ts CHANGED
@@ -17,7 +17,9 @@ export interface ComposeVersion {
17
17
  }
18
18
 
19
19
  export type VersionCompatibility =
20
- 'compatible' | 'sdk_outdated' | 'server_outdated';
20
+ | 'compatible'
21
+ | 'sdk_outdated'
22
+ | 'server_outdated';
21
23
 
22
24
  const SEMANTIC_VERSION_PATTERN =
23
25
  /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;