@lifi/composer-sdk 0.7.1 → 0.9.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.
Files changed (165) hide show
  1. package/README.md +5 -2
  2. package/dist/_virtual/_rolldown/runtime.cjs +33 -0
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/authoring/FlowBuilderCore.cjs +102 -120
  5. package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
  6. package/dist/authoring/FlowBuilderCore.d.cts +58 -61
  7. package/dist/authoring/FlowBuilderCore.d.ts +58 -61
  8. package/dist/authoring/FlowBuilderCore.js +99 -97
  9. package/dist/authoring/FlowBuilderCore.js.map +1 -1
  10. package/dist/authoring/handles.cjs +25 -40
  11. package/dist/authoring/handles.cjs.map +1 -1
  12. package/dist/authoring/handles.d.cts +33 -34
  13. package/dist/authoring/handles.d.ts +33 -34
  14. package/dist/authoring/handles.js +21 -13
  15. package/dist/authoring/handles.js.map +1 -1
  16. package/dist/authoring/raw.cjs +85 -44
  17. package/dist/authoring/raw.cjs.map +1 -1
  18. package/dist/authoring/raw.d.cts +8 -8
  19. package/dist/authoring/raw.d.ts +8 -8
  20. package/dist/authoring/raw.js +83 -19
  21. package/dist/authoring/raw.js.map +1 -1
  22. package/dist/authoring/signatureArgs.cjs +81 -103
  23. package/dist/authoring/signatureArgs.cjs.map +1 -1
  24. package/dist/authoring/signatureArgs.d.cts +63 -64
  25. package/dist/authoring/signatureArgs.d.ts +63 -64
  26. package/dist/authoring/signatureArgs.js +76 -75
  27. package/dist/authoring/signatureArgs.js.map +1 -1
  28. package/dist/client.cjs +172 -220
  29. package/dist/client.cjs.map +1 -1
  30. package/dist/client.d.cts +131 -131
  31. package/dist/client.d.ts +131 -131
  32. package/dist/client.js +165 -198
  33. package/dist/client.js.map +1 -1
  34. package/dist/discovery.cjs +0 -17
  35. package/dist/discovery.d.cts +57 -56
  36. package/dist/discovery.d.ts +57 -56
  37. package/dist/discovery.js +1 -1
  38. package/dist/errors.cjs +211 -159
  39. package/dist/errors.cjs.map +1 -1
  40. package/dist/errors.d.cts +84 -84
  41. package/dist/errors.d.ts +84 -84
  42. package/dist/errors.js +201 -120
  43. package/dist/errors.js.map +1 -1
  44. package/dist/generated/config.generated.cjs +0 -17
  45. package/dist/generated/config.generated.d.cts +805 -895
  46. package/dist/generated/config.generated.d.ts +805 -895
  47. package/dist/generated/config.generated.js +1 -1
  48. package/dist/generated/guards.generated.cjs +27 -31
  49. package/dist/generated/guards.generated.cjs.map +1 -1
  50. package/dist/generated/guards.generated.d.cts +20 -4
  51. package/dist/generated/guards.generated.d.ts +20 -4
  52. package/dist/generated/guards.generated.js +21 -8
  53. package/dist/generated/guards.generated.js.map +1 -1
  54. package/dist/generated/materialisers.generated.cjs +25 -35
  55. package/dist/generated/materialisers.generated.cjs.map +1 -1
  56. package/dist/generated/materialisers.generated.d.cts +17 -4
  57. package/dist/generated/materialisers.generated.d.ts +17 -4
  58. package/dist/generated/materialisers.generated.js +19 -11
  59. package/dist/generated/materialisers.generated.js.map +1 -1
  60. package/dist/generated/operations.generated.cjs +236 -250
  61. package/dist/generated/operations.generated.cjs.map +1 -1
  62. package/dist/generated/operations.generated.d.cts +740 -657
  63. package/dist/generated/operations.generated.d.ts +740 -657
  64. package/dist/generated/operations.generated.js +235 -229
  65. package/dist/generated/operations.generated.js.map +1 -1
  66. package/dist/generated/preconditions.generated.cjs +25 -35
  67. package/dist/generated/preconditions.generated.cjs.map +1 -1
  68. package/dist/generated/preconditions.generated.d.cts +17 -4
  69. package/dist/generated/preconditions.generated.d.ts +17 -4
  70. package/dist/generated/preconditions.generated.js +19 -11
  71. package/dist/generated/preconditions.generated.js.map +1 -1
  72. package/dist/index.cjs +131 -97
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +29 -43
  75. package/dist/index.d.ts +29 -43
  76. package/dist/index.js +96 -45
  77. package/dist/index.js.map +1 -1
  78. package/dist/outputs.cjs +11 -32
  79. package/dist/outputs.cjs.map +1 -1
  80. package/dist/outputs.d.cts +5 -5
  81. package/dist/outputs.d.ts +5 -5
  82. package/dist/outputs.js +10 -8
  83. package/dist/outputs.js.map +1 -1
  84. package/dist/raw.cjs +21 -33
  85. package/dist/raw.cjs.map +1 -1
  86. package/dist/raw.d.cts +8 -4
  87. package/dist/raw.d.ts +8 -4
  88. package/dist/raw.js +12 -7
  89. package/dist/raw.js.map +1 -1
  90. package/dist/reachability.cjs +82 -112
  91. package/dist/reachability.cjs.map +1 -1
  92. package/dist/reachability.d.cts +33 -59
  93. package/dist/reachability.d.ts +33 -59
  94. package/dist/reachability.js +81 -88
  95. package/dist/reachability.js.map +1 -1
  96. package/dist/resources.cjs +47 -32
  97. package/dist/resources.cjs.map +1 -1
  98. package/dist/resources.d.cts +50 -3
  99. package/dist/resources.d.ts +50 -3
  100. package/dist/resources.js +42 -9
  101. package/dist/resources.js.map +1 -1
  102. package/dist/responseSchemas.cjs +99 -111
  103. package/dist/responseSchemas.cjs.map +1 -1
  104. package/dist/responseSchemas.d.cts +34 -34
  105. package/dist/responseSchemas.d.ts +34 -34
  106. package/dist/responseSchemas.js +85 -66
  107. package/dist/responseSchemas.js.map +1 -1
  108. package/dist/routeAmount.cjs +61 -31
  109. package/dist/routeAmount.cjs.map +1 -1
  110. package/dist/routeAmount.d.cts +52 -2
  111. package/dist/routeAmount.d.ts +52 -2
  112. package/dist/routeAmount.js +56 -8
  113. package/dist/routeAmount.js.map +1 -1
  114. package/dist/run/inputs.cjs +56 -48
  115. package/dist/run/inputs.cjs.map +1 -1
  116. package/dist/run/inputs.d.cts +70 -74
  117. package/dist/run/inputs.d.ts +70 -74
  118. package/dist/run/inputs.js +54 -23
  119. package/dist/run/inputs.js.map +1 -1
  120. package/dist/run/simulate.cjs +38 -43
  121. package/dist/run/simulate.cjs.map +1 -1
  122. package/dist/run/simulate.d.cts +36 -36
  123. package/dist/run/simulate.d.ts +36 -36
  124. package/dist/run/simulate.js +37 -19
  125. package/dist/run/simulate.js.map +1 -1
  126. package/dist/sdk.cjs +55 -66
  127. package/dist/sdk.cjs.map +1 -1
  128. package/dist/sdk.d.cts +108 -111
  129. package/dist/sdk.d.ts +108 -111
  130. package/dist/sdk.js +52 -44
  131. package/dist/sdk.js.map +1 -1
  132. package/dist/types.cjs +0 -17
  133. package/dist/types.d.cts +22 -22
  134. package/dist/types.d.ts +22 -22
  135. package/dist/types.js +1 -1
  136. package/package.json +4 -4
  137. package/src/client.ts +2 -2
  138. package/src/examples/aaveClaimRewards.ts +2 -1
  139. package/src/examples/emitCustomEvent.ts +1 -2
  140. package/src/examples/run.ts +14 -1
  141. package/src/examples/transferTokens.ts +21 -17
  142. package/src/examples/uniswapV2AddLiquidity.ts +106 -0
  143. package/src/examples/uniswapV3Mint.ts +95 -0
  144. package/src/generated/config.generated.ts +102 -47
  145. package/src/generated/guards.generated.ts +9 -0
  146. package/src/generated/operations.generated.ts +161 -5
  147. package/src/index.ts +0 -3
  148. package/dist/discovery.cjs.map +0 -1
  149. package/dist/discovery.js.map +0 -1
  150. package/dist/generated/config.generated.cjs.map +0 -1
  151. package/dist/generated/config.generated.js.map +0 -1
  152. package/dist/guards.generated-BPLFwe7y.d.ts +0 -19
  153. package/dist/guards.generated-M3VAIevI.d.cts +0 -19
  154. package/dist/materialisers.generated-BMkBQgWZ.d.ts +0 -24
  155. package/dist/materialisers.generated-BWq5oePO.d.cts +0 -24
  156. package/dist/preconditions.generated-DblS13Wq.d.cts +0 -24
  157. package/dist/preconditions.generated-U7YpVh30.d.ts +0 -24
  158. package/dist/raw-BvRghN3r.d.ts +0 -20
  159. package/dist/raw-s1rer8X3.d.cts +0 -20
  160. package/dist/resources-BKlFxjo8.d.cts +0 -56
  161. package/dist/resources-CYis1_DS.d.ts +0 -56
  162. package/dist/routeAmount-DdbJYJyM.d.cts +0 -55
  163. package/dist/routeAmount-DdbJYJyM.d.ts +0 -55
  164. package/dist/types.cjs.map +0 -1
  165. package/dist/types.js.map +0 -1
@@ -1,46 +1,41 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var simulate_exports = {};
20
- __export(simulate_exports, {
21
- buildSimulateRequest: () => buildSimulateRequest
22
- });
23
- module.exports = __toCommonJS(simulate_exports);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/run/simulate.ts
3
+ /**
4
+ * Assembles a {@link SimulateRequest} from a compile result and the
5
+ * caller-supplied chain, signer, and tracked balances. Pure: performs no
6
+ * network I/O, does not mutate its input, and returns a fresh object.
7
+ *
8
+ * Bridges the common case — simulate the transaction you just compiled —
9
+ * without coupling raw-transaction simulation to the flow builder. The
10
+ * `value` defaults to the compiled transaction's value unless overridden.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });
15
+ * const req = buildSimulateRequest({
16
+ * result: compiled,
17
+ * chainId: 1,
18
+ * signer: '0x1111111111111111111111111111111111111111',
19
+ * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],
20
+ * });
21
+ * const sim = await sdk.client.simulate(req);
22
+ * ```
23
+ */
24
24
  const buildSimulateRequest = (input) => {
25
- const { result, chainId, signer, trackedBalances, requirements, block } = input;
26
- if (result.transactionRequest === void 0) {
27
- throw new Error(
28
- "buildSimulateRequest: the compile result has no transactionRequest (empty compiled program \u2014 a settle-only external-funding flow); submit the `actions` entries instead of simulating"
29
- );
30
- }
31
- return {
32
- chainId,
33
- from: signer,
34
- to: result.transactionRequest.to,
35
- data: result.transactionRequest.data,
36
- value: input.value ?? result.transactionRequest.value,
37
- block,
38
- requirements,
39
- trackedBalances
40
- };
25
+ const { result, chainId, signer, trackedBalances, requirements, block } = input;
26
+ if (result.transactionRequest === void 0) throw new Error("buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating");
27
+ return {
28
+ chainId,
29
+ from: signer,
30
+ to: result.transactionRequest.to,
31
+ data: result.transactionRequest.data,
32
+ value: input.value ?? result.transactionRequest.value,
33
+ block,
34
+ requirements,
35
+ trackedBalances
36
+ };
41
37
  };
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- buildSimulateRequest
45
- });
38
+ //#endregion
39
+ exports.buildSimulateRequest = buildSimulateRequest;
40
+
46
41
  //# sourceMappingURL=simulate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AAKF,MAAI,OAAO,uBAAuB,QAAW;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"simulate.cjs","names":[],"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,wBACX,UACoB;CACpB,MAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,UAC9D;CAKF,IAAI,OAAO,uBAAuB,KAAA,GAChC,MAAM,IAAI,MACR,uLACF;CAEF,OAAO;EACL;EACA,MAAM;EACN,IAAI,OAAO,mBAAmB;EAC9B,MAAM,OAAO,mBAAmB;EAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;EAChD;EACA;EACA;CACF;AACF"}
@@ -1,40 +1,40 @@
1
- import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRequest } from '@lifi/compose-spec';
2
-
1
+ import { ComposeCompileResult, SimulateRequest, SlotFinderRequirement, TrackedBalance } from "@lifi/compose-spec";
2
+ //#region src/run/simulate.d.ts
3
3
  /**
4
4
  * Input for {@link buildSimulateRequest}: a compile result plus the fields a
5
5
  * simulation needs that a compiled flow does not carry.
6
6
  */
7
- interface BuildSimulateRequestInput {
8
- /**
9
- * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
- * `success` and `partial` results are valid input — the helper does not
11
- * discriminate on `status`. A success result for an empty compiled program
12
- * (a settle-only `funding: 'external'` flow) carries no
13
- * `transactionRequest`; there is nothing to simulate and this helper
14
- * throws — submit the result's `actions` entries directly instead.
15
- */
16
- readonly result: ComposeCompileResult;
17
- /** EVM chain id. A compile result does not carry the target chain. */
18
- readonly chainId: number;
19
- /**
20
- * The transaction sender (`from`). A compile result does not carry the
21
- * signer, so it must be supplied here.
22
- */
23
- readonly signer: string;
24
- /**
25
- * Balances to watch across the simulation. These cannot be inferred from a
26
- * flow and must be supplied by the caller.
27
- */
28
- readonly trackedBalances: readonly TrackedBalance[];
29
- /** Optional funding instructions applied before simulation. */
30
- readonly requirements?: readonly SlotFinderRequirement[];
31
- /** Optional block to pin the simulation to. Omitted ⇒ chain head. */
32
- readonly block?: number;
33
- /**
34
- * Optional native value override. Defaults to the compiled
35
- * `transactionRequest.value` when omitted.
36
- */
37
- readonly value?: bigint | string;
7
+ export interface BuildSimulateRequestInput {
8
+ /**
9
+ * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
+ * `success` and `partial` results are valid input — the helper does not
11
+ * discriminate on `status`. A success result for an empty compiled program
12
+ * (a settle-only `funding: 'external'` flow) carries no
13
+ * `transactionRequest`; there is nothing to simulate and this helper
14
+ * throws — submit the result's `actions` entries directly instead.
15
+ */
16
+ readonly result: ComposeCompileResult;
17
+ /** EVM chain id. A compile result does not carry the target chain. */
18
+ readonly chainId: number;
19
+ /**
20
+ * The transaction sender (`from`). A compile result does not carry the
21
+ * signer, so it must be supplied here.
22
+ */
23
+ readonly signer: string;
24
+ /**
25
+ * Balances to watch across the simulation. These cannot be inferred from a
26
+ * flow and must be supplied by the caller.
27
+ */
28
+ readonly trackedBalances: readonly TrackedBalance[];
29
+ /** Optional funding instructions applied before simulation. */
30
+ readonly requirements?: readonly SlotFinderRequirement[];
31
+ /** Optional block to pin the simulation to. Omitted ⇒ chain head. */
32
+ readonly block?: number;
33
+ /**
34
+ * Optional native value override. Defaults to the compiled
35
+ * `transactionRequest.value` when omitted.
36
+ */
37
+ readonly value?: bigint | string;
38
38
  }
39
39
  /**
40
40
  * Assembles a {@link SimulateRequest} from a compile result and the
@@ -57,6 +57,6 @@ interface BuildSimulateRequestInput {
57
57
  * const sim = await sdk.client.simulate(req);
58
58
  * ```
59
59
  */
60
- declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
61
-
62
- export { type BuildSimulateRequestInput, buildSimulateRequest };
60
+ export declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
61
+ //#endregion
62
+ //# sourceMappingURL=simulate.d.cts.map
@@ -1,40 +1,40 @@
1
- import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRequest } from '@lifi/compose-spec';
2
-
1
+ import { ComposeCompileResult, SimulateRequest, SlotFinderRequirement, TrackedBalance } from "@lifi/compose-spec";
2
+ //#region src/run/simulate.d.ts
3
3
  /**
4
4
  * Input for {@link buildSimulateRequest}: a compile result plus the fields a
5
5
  * simulation needs that a compiled flow does not carry.
6
6
  */
7
- interface BuildSimulateRequestInput {
8
- /**
9
- * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
- * `success` and `partial` results are valid input — the helper does not
11
- * discriminate on `status`. A success result for an empty compiled program
12
- * (a settle-only `funding: 'external'` flow) carries no
13
- * `transactionRequest`; there is nothing to simulate and this helper
14
- * throws — submit the result's `actions` entries directly instead.
15
- */
16
- readonly result: ComposeCompileResult;
17
- /** EVM chain id. A compile result does not carry the target chain. */
18
- readonly chainId: number;
19
- /**
20
- * The transaction sender (`from`). A compile result does not carry the
21
- * signer, so it must be supplied here.
22
- */
23
- readonly signer: string;
24
- /**
25
- * Balances to watch across the simulation. These cannot be inferred from a
26
- * flow and must be supplied by the caller.
27
- */
28
- readonly trackedBalances: readonly TrackedBalance[];
29
- /** Optional funding instructions applied before simulation. */
30
- readonly requirements?: readonly SlotFinderRequirement[];
31
- /** Optional block to pin the simulation to. Omitted ⇒ chain head. */
32
- readonly block?: number;
33
- /**
34
- * Optional native value override. Defaults to the compiled
35
- * `transactionRequest.value` when omitted.
36
- */
37
- readonly value?: bigint | string;
7
+ export interface BuildSimulateRequestInput {
8
+ /**
9
+ * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
+ * `success` and `partial` results are valid input — the helper does not
11
+ * discriminate on `status`. A success result for an empty compiled program
12
+ * (a settle-only `funding: 'external'` flow) carries no
13
+ * `transactionRequest`; there is nothing to simulate and this helper
14
+ * throws — submit the result's `actions` entries directly instead.
15
+ */
16
+ readonly result: ComposeCompileResult;
17
+ /** EVM chain id. A compile result does not carry the target chain. */
18
+ readonly chainId: number;
19
+ /**
20
+ * The transaction sender (`from`). A compile result does not carry the
21
+ * signer, so it must be supplied here.
22
+ */
23
+ readonly signer: string;
24
+ /**
25
+ * Balances to watch across the simulation. These cannot be inferred from a
26
+ * flow and must be supplied by the caller.
27
+ */
28
+ readonly trackedBalances: readonly TrackedBalance[];
29
+ /** Optional funding instructions applied before simulation. */
30
+ readonly requirements?: readonly SlotFinderRequirement[];
31
+ /** Optional block to pin the simulation to. Omitted ⇒ chain head. */
32
+ readonly block?: number;
33
+ /**
34
+ * Optional native value override. Defaults to the compiled
35
+ * `transactionRequest.value` when omitted.
36
+ */
37
+ readonly value?: bigint | string;
38
38
  }
39
39
  /**
40
40
  * Assembles a {@link SimulateRequest} from a compile result and the
@@ -57,6 +57,6 @@ interface BuildSimulateRequestInput {
57
57
  * const sim = await sdk.client.simulate(req);
58
58
  * ```
59
59
  */
60
- declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
61
-
62
- export { type BuildSimulateRequestInput, buildSimulateRequest };
60
+ export declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
61
+ //#endregion
62
+ //# sourceMappingURL=simulate.d.ts.map
@@ -1,22 +1,40 @@
1
+ //#region src/run/simulate.ts
2
+ /**
3
+ * Assembles a {@link SimulateRequest} from a compile result and the
4
+ * caller-supplied chain, signer, and tracked balances. Pure: performs no
5
+ * network I/O, does not mutate its input, and returns a fresh object.
6
+ *
7
+ * Bridges the common case — simulate the transaction you just compiled —
8
+ * without coupling raw-transaction simulation to the flow builder. The
9
+ * `value` defaults to the compiled transaction's value unless overridden.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });
14
+ * const req = buildSimulateRequest({
15
+ * result: compiled,
16
+ * chainId: 1,
17
+ * signer: '0x1111111111111111111111111111111111111111',
18
+ * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],
19
+ * });
20
+ * const sim = await sdk.client.simulate(req);
21
+ * ```
22
+ */
1
23
  const buildSimulateRequest = (input) => {
2
- const { result, chainId, signer, trackedBalances, requirements, block } = input;
3
- if (result.transactionRequest === void 0) {
4
- throw new Error(
5
- "buildSimulateRequest: the compile result has no transactionRequest (empty compiled program \u2014 a settle-only external-funding flow); submit the `actions` entries instead of simulating"
6
- );
7
- }
8
- return {
9
- chainId,
10
- from: signer,
11
- to: result.transactionRequest.to,
12
- data: result.transactionRequest.data,
13
- value: input.value ?? result.transactionRequest.value,
14
- block,
15
- requirements,
16
- trackedBalances
17
- };
18
- };
19
- export {
20
- buildSimulateRequest
24
+ const { result, chainId, signer, trackedBalances, requirements, block } = input;
25
+ if (result.transactionRequest === void 0) throw new Error("buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating");
26
+ return {
27
+ chainId,
28
+ from: signer,
29
+ to: result.transactionRequest.to,
30
+ data: result.transactionRequest.data,
31
+ value: input.value ?? result.transactionRequest.value,
32
+ block,
33
+ requirements,
34
+ trackedBalances
35
+ };
21
36
  };
37
+ //#endregion
38
+ export { buildSimulateRequest };
39
+
22
40
  //# sourceMappingURL=simulate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":"AAiEO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AAKF,MAAI,OAAO,uBAAuB,QAAW;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"simulate.js","names":[],"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,wBACX,UACoB;CACpB,MAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,UAC9D;CAKF,IAAI,OAAO,uBAAuB,KAAA,GAChC,MAAM,IAAI,MACR,uLACF;CAEF,OAAO;EACL;EACA,MAAM;EACN,IAAI,OAAO,mBAAmB;EAC9B,MAAM,OAAO,mBAAmB;EAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;EAChD;EACA;EACA;CACF;AACF"}
package/dist/sdk.cjs CHANGED
@@ -1,69 +1,58 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var sdk_exports = {};
20
- __export(sdk_exports, {
21
- createComposeSdk: () => createComposeSdk
22
- });
23
- module.exports = __toCommonJS(sdk_exports);
24
- var import_FlowBuilderCore = require("./authoring/FlowBuilderCore.js");
25
- var import_client = require("./client.js");
26
- var import_operations_generated = require("./generated/operations.generated.js");
27
- var import_inputs = require("./run/inputs.js");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_client = require("./client.cjs");
3
+ const require_run_inputs = require("./run/inputs.cjs");
4
+ const require_authoring_FlowBuilderCore = require("./authoring/FlowBuilderCore.cjs");
5
+ const require_generated_operations_generated = require("./generated/operations.generated.cjs");
6
+ //#region src/sdk.ts
7
+ /**
8
+ * Creates a new Compose SDK instance.
9
+ *
10
+ * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.
11
+ * @returns A {@link ComposeSdk} instance.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
16
+ * ```
17
+ */
28
18
  const createComposeSdk = (options) => {
29
- const composeClient = (0, import_client.createComposeClient)(options);
30
- const request = (flowDoc, run) => ({
31
- flow: flowDoc,
32
- run: (0, import_inputs.buildRun)({
33
- inputs: run.inputs,
34
- preconditions: run.preconditions,
35
- signer: run.signer,
36
- assumptions: run.assumptions,
37
- referrer: run.referrer,
38
- integratorFeeBps: run.integratorFeeBps,
39
- maxPriceImpactBps: run.maxPriceImpactBps,
40
- sweepTo: run.sweepTo,
41
- simulationPolicy: run.simulationPolicy,
42
- simulateUserProgram: run.simulateUserProgram,
43
- checkOnChainAllowances: run.checkOnChainAllowances
44
- })
45
- });
46
- const flow = (chainId, opts) => {
47
- const core = (0, import_FlowBuilderCore.createFlowBuilderCore)(chainId, opts);
48
- const builder = Object.assign(core, (0, import_operations_generated.bindGeneratedOps)(core));
49
- const compile = async (run) => {
50
- const flowDoc = builder.build();
51
- const req = request(flowDoc, run);
52
- return composeClient.compile(req);
53
- };
54
- return Object.assign(builder, { compile });
55
- };
56
- return {
57
- client: composeClient,
58
- flow,
59
- getSupportedChains: composeClient.getChains,
60
- request,
61
- route: composeClient.route,
62
- simulate: composeClient.simulate
63
- };
19
+ const composeClient = require_client.createComposeClient(options);
20
+ const request = (flowDoc, run) => ({
21
+ flow: flowDoc,
22
+ run: require_run_inputs.buildRun({
23
+ inputs: run.inputs,
24
+ preconditions: run.preconditions,
25
+ signer: run.signer,
26
+ assumptions: run.assumptions,
27
+ referrer: run.referrer,
28
+ integratorFeeBps: run.integratorFeeBps,
29
+ maxPriceImpactBps: run.maxPriceImpactBps,
30
+ sweepTo: run.sweepTo,
31
+ simulationPolicy: run.simulationPolicy,
32
+ simulateUserProgram: run.simulateUserProgram,
33
+ checkOnChainAllowances: run.checkOnChainAllowances
34
+ })
35
+ });
36
+ const flow = (chainId, opts) => {
37
+ const core = require_authoring_FlowBuilderCore.createFlowBuilderCore(chainId, opts);
38
+ const builder = Object.assign(core, require_generated_operations_generated.bindGeneratedOps(core));
39
+ const compile = async (run) => {
40
+ const flowDoc = builder.build();
41
+ const req = request(flowDoc, run);
42
+ return composeClient.compile(req);
43
+ };
44
+ return Object.assign(builder, { compile });
45
+ };
46
+ return {
47
+ client: composeClient,
48
+ flow,
49
+ getSupportedChains: composeClient.getChains,
50
+ request,
51
+ route: composeClient.route,
52
+ simulate: composeClient.simulate
53
+ };
64
54
  };
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- createComposeSdk
68
- });
55
+ //#endregion
56
+ exports.createComposeSdk = createComposeSdk;
57
+
69
58
  //# sourceMappingURL=sdk.cjs.map
package/dist/sdk.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport type { ChainSummary } from './discovery.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Fetches the chains this Compose deployment supports, ascending by\n * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it\n * for what \"supported\" means and for the caching caveat.\n *\n * Each entry pairs the `chainId` with a display `name`, so one call both\n * gates a chain selector and labels it. Key on `chainId`; `name` is a\n * deployment-maintained label that can change.\n *\n * Use it to fail fast before building a flow for a chain the server would\n * reject.\n *\n * @returns The supported chains, ascending by `chainId`.\n * @throws {@link ComposeError} on network or server errors.\n *\n * @example\n * ```ts\n * const chains = await sdk.getSupportedChains();\n * if (!chains.some((c) => c.chainId === 8453)) {\n * throw new Error('Base is not supported');\n * }\n * for (const { chainId, name } of chains) {\n * console.log(`${name} (${chainId})`);\n * }\n * ```\n */\n readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain into a submit-ready transaction. Thin\n * pass-through to {@link ComposeClient.route}; see it for the short chain of\n * catalog edges the server plans, when to prefer `flow(...).compile(...)`,\n * the `success` / `partial` discrimination, and error behaviour. Build the\n * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n getSupportedChains: composeClient.getChains,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,6BAKO;AACP,oBAAwD;AAExD,kCAGO;AACP,oBAA+C;AAwKxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,qBAAqB,IAAI;AAAA,MACzB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,oBAAoB,cAAc;AAAA,IAClC;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"file":"sdk.cjs","names":["createComposeClient","buildRun","createFlowBuilderCore","bindGeneratedOps"],"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport type { ChainSummary } from './discovery.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Fetches the chains this Compose deployment supports, ascending by\n * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it\n * for what \"supported\" means and for the caching caveat.\n *\n * Each entry pairs the `chainId` with a display `name`, so one call both\n * gates a chain selector and labels it. Key on `chainId`; `name` is a\n * deployment-maintained label that can change.\n *\n * Use it to fail fast before building a flow for a chain the server would\n * reject.\n *\n * @returns The supported chains, ascending by `chainId`.\n * @throws {@link ComposeError} on network or server errors.\n *\n * @example\n * ```ts\n * const chains = await sdk.getSupportedChains();\n * if (!chains.some((c) => c.chainId === 8453)) {\n * throw new Error('Base is not supported');\n * }\n * for (const { chainId, name } of chains) {\n * console.log(`${name} (${chainId})`);\n * }\n * ```\n */\n readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain into a submit-ready transaction. Thin\n * pass-through to {@link ComposeClient.route}; see it for the short chain of\n * catalog edges the server plans, when to prefer `flow(...).compile(...)`,\n * the `success` / `partial` discrimination, and error behaviour. Build the\n * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n getSupportedChains: composeClient.getChains,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA6LA,MAAa,oBAAoB,YAA2C;CAC1E,MAAM,gBAAgBA,eAAAA,oBAAoB,OAAO;CAEjD,MAAM,WACJ,SACA,SAC2B;EAC3B,MAAM;EACN,KAAKC,mBAAAA,SAAS;GACZ,QAAQ,IAAI;GACZ,eAAe,IAAI;GACnB,QAAQ,IAAI;GACZ,aAAa,IAAI;GACjB,UAAU,IAAI;GACd,kBAAkB,IAAI;GACtB,mBAAmB,IAAI;GACvB,SAAS,IAAI;GACb,kBAAkB,IAAI;GACtB,qBAAqB,IAAI;GACzB,wBAAwB,IAAI;EAC9B,CAAC;CACH;CAEA,MAAM,QACJ,SACA,SACmB;EACnB,MAAM,OAAOC,kCAAAA,sBAAsB,SAAS,IAAI;EAChD,MAAM,UAAU,OAAO,OAAO,MAAMC,uCAAAA,iBAAiB,IAAI,CAAC;EAE1D,MAAM,UAAU,OACd,QACkC;GAClC,MAAM,UAAU,QAAQ,MAAM;GAC9B,MAAM,MAAM,QAAQ,SAAS,GAAG;GAChC,OAAO,cAAc,QAAQ,GAAG;EAClC;EAEA,OAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;CAC3C;CAEA,OAAO;EACL,QAAQ;EACR;EACA,oBAAoB,cAAc;EAClC;EACA,OAAO,cAAc;EACrB,UAAU,cAAc;CAC1B;AACF"}