@lifi/composer-sdk 0.8.1 → 0.10.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 (161) hide show
  1. package/README.md +4 -3
  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 +804 -936
  46. package/dist/generated/config.generated.d.ts +804 -936
  47. package/dist/generated/config.generated.js +1 -1
  48. package/dist/generated/guards.generated.cjs +25 -35
  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 +19 -11
  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 -277
  61. package/dist/generated/operations.generated.cjs.map +1 -1
  62. package/dist/generated/operations.generated.d.cts +719 -708
  63. package/dist/generated/operations.generated.d.ts +719 -708
  64. package/dist/generated/operations.generated.js +235 -256
  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 +5 -5
  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 +1 -1
  141. package/src/examples/transferTokens.ts +21 -17
  142. package/src/generated/config.generated.ts +20 -9
  143. package/src/generated/operations.generated.ts +28 -5
  144. package/dist/discovery.cjs.map +0 -1
  145. package/dist/discovery.js.map +0 -1
  146. package/dist/generated/config.generated.cjs.map +0 -1
  147. package/dist/generated/config.generated.js.map +0 -1
  148. package/dist/guards.generated-CDCgYGZo.d.cts +0 -24
  149. package/dist/guards.generated-CdYcs4h0.d.ts +0 -24
  150. package/dist/materialisers.generated-BMkBQgWZ.d.ts +0 -24
  151. package/dist/materialisers.generated-BWq5oePO.d.cts +0 -24
  152. package/dist/preconditions.generated-DblS13Wq.d.cts +0 -24
  153. package/dist/preconditions.generated-U7YpVh30.d.ts +0 -24
  154. package/dist/raw-BvRghN3r.d.ts +0 -20
  155. package/dist/raw-s1rer8X3.d.cts +0 -20
  156. package/dist/resources-BKlFxjo8.d.cts +0 -56
  157. package/dist/resources-CYis1_DS.d.ts +0 -56
  158. package/dist/routeAmount-DdbJYJyM.d.cts +0 -55
  159. package/dist/routeAmount-DdbJYJyM.d.ts +0 -55
  160. package/dist/types.cjs.map +0 -1
  161. package/dist/types.js.map +0 -1
package/dist/sdk.d.cts CHANGED
@@ -1,15 +1,11 @@
1
- import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
- import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.cjs';
3
- import { ComposeClient } from './client.cjs';
4
- import { ChainSummary } from './discovery.cjs';
5
- import { GeneratedOps } from './generated/operations.generated.cjs';
6
- import { ComposeRunInput } from './run/inputs.cjs';
7
- import { InputSchema } from './types.cjs';
8
- import './authoring/handles.cjs';
9
- import './authoring/signatureArgs.cjs';
10
- import 'abitype';
11
- import './generated/config.generated.cjs';
12
-
1
+ import { InputSchema } from "./types.cjs";
2
+ import { FlowBuilderCore, FlowOptions, TypedFlow } from "./authoring/FlowBuilderCore.cjs";
3
+ import { ChainSummary } from "./discovery.cjs";
4
+ import { ComposeClient } from "./client.cjs";
5
+ import { GeneratedOps } from "./generated/operations.generated.cjs";
6
+ import { ComposeRunInput } from "./run/inputs.cjs";
7
+ import { ComposeCompileRequest, ComposeCompileResult, ComposeRouteRequest, SimulateRequest, SimulateResult } from "@lifi/compose-spec";
8
+ //#region src/sdk.d.ts
13
9
  /**
14
10
  * A flow builder augmented with generated operation methods and a `compile` method
15
11
  * that submits the flow to the Compose backend for compilation.
@@ -18,36 +14,36 @@ import './generated/config.generated.cjs';
18
14
  *
19
15
  * @typeParam T - The input schema describing the flow's required inputs.
20
16
  */
21
- type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
22
- /**
23
- * Builds the flow document from the current builder state and submits it
24
- * to the Compose API for compilation.
25
- *
26
- * @param run - Runtime inputs, preconditions, and signer address.
27
- * @returns The compiled transaction calldata and metadata.
28
- * @throws {@link ComposeError} on network, validation, or server errors.
29
- *
30
- * @example
31
- * ```ts
32
- * const result = await builder.compile({
33
- * inputs: { token: materialisers.balanceOf({}) },
34
- * signer: '0xYourAddress...',
35
- * });
36
- * console.log(result.calldata);
37
- * ```
38
- */
39
- readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
17
+ export type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
18
+ /**
19
+ * Builds the flow document from the current builder state and submits it
20
+ * to the Compose API for compilation.
21
+ *
22
+ * @param run - Runtime inputs, preconditions, and signer address.
23
+ * @returns The compiled transaction calldata and metadata.
24
+ * @throws {@link ComposeError} on network, validation, or server errors.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await builder.compile({
29
+ * inputs: { token: materialisers.balanceOf({}) },
30
+ * signer: '0xYourAddress...',
31
+ * });
32
+ * console.log(result.calldata);
33
+ * ```
34
+ */
35
+ readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
40
36
  };
41
37
  /**
42
38
  * Configuration for creating a Compose SDK instance.
43
39
  */
44
- interface ComposeSdkOptions {
45
- /** Base URL of the Compose API (e.g. `"https://li.quest"`). */
46
- readonly baseUrl: string;
47
- /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
48
- readonly fetch?: typeof globalThis.fetch;
49
- /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
50
- readonly apiKey: string;
40
+ export interface ComposeSdkOptions {
41
+ /** Base URL of the Compose API (e.g. `"https://li.quest"`). */
42
+ readonly baseUrl: string;
43
+ /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
44
+ readonly fetch?: typeof globalThis.fetch;
45
+ /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
46
+ readonly apiKey: string;
51
47
  }
52
48
  /**
53
49
  * The top-level Compose SDK interface.
@@ -76,76 +72,76 @@ interface ComposeSdkOptions {
76
72
  * });
77
73
  * ```
78
74
  */
79
- interface ComposeSdk {
80
- /** Low-level HTTP client for the Compose API. */
81
- readonly client: ComposeClient;
82
- /**
83
- * Creates a new flow builder targeting the given chain.
84
- * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
85
- * @param options - Flow configuration including input declarations.
86
- * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
87
- * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
88
- */
89
- readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
90
- /**
91
- * Fetches the chains this Compose deployment supports, ascending by
92
- * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
93
- * for what "supported" means and for the caching caveat.
94
- *
95
- * Each entry pairs the `chainId` with a display `name`, so one call both
96
- * gates a chain selector and labels it. Key on `chainId`; `name` is a
97
- * deployment-maintained label that can change.
98
- *
99
- * Use it to fail fast before building a flow for a chain the server would
100
- * reject.
101
- *
102
- * @returns The supported chains, ascending by `chainId`.
103
- * @throws {@link ComposeError} on network or server errors.
104
- *
105
- * @example
106
- * ```ts
107
- * const chains = await sdk.getSupportedChains();
108
- * if (!chains.some((c) => c.chainId === 8453)) {
109
- * throw new Error('Base is not supported');
110
- * }
111
- * for (const { chainId, name } of chains) {
112
- * console.log(`${name} (${chainId})`);
113
- * }
114
- * ```
115
- */
116
- readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
117
- /**
118
- * Builds a raw compile request without sending it. Useful for inspecting the
119
- * request payload or submitting it through a custom transport.
120
- * @param flow - A built flow document (from `builder.build()`).
121
- * @param run - Runtime inputs, preconditions, and signer address.
122
- * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
123
- */
124
- readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
125
- /**
126
- * Compiles a token pair on one chain into a submit-ready transaction. Thin
127
- * pass-through to {@link ComposeClient.route}; see it for the short chain of
128
- * catalog edges the server plans, when to prefer `flow(...).compile(...)`,
129
- * the `success` / `partial` discrimination, and error behaviour. Build the
130
- * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.
131
- *
132
- * @param request - The from/to token pair, amount, signer, and route options.
133
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
134
- * @throws {@link ComposeError} on network, validation, or server errors.
135
- */
136
- readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
137
- /**
138
- * Simulates a raw, pre-encoded transaction. Thin pass-through to
139
- * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
140
- * result discrimination and error behaviour. Pair with `buildSimulateRequest`
141
- * to assemble the request from a compile result.
142
- *
143
- * @param request - The raw transaction plus funding `requirements` and
144
- * `trackedBalances`.
145
- * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
146
- * @throws {@link ComposeError} on network, validation, or server errors.
147
- */
148
- readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
75
+ export interface ComposeSdk {
76
+ /** Low-level HTTP client for the Compose API. */
77
+ readonly client: ComposeClient;
78
+ /**
79
+ * Creates a new flow builder targeting the given chain.
80
+ * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
81
+ * @param options - Flow configuration including input declarations.
82
+ * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
83
+ * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
84
+ */
85
+ readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
86
+ /**
87
+ * Fetches the chains this Compose deployment supports, ascending by
88
+ * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
89
+ * for what "supported" means and for the caching caveat.
90
+ *
91
+ * Each entry pairs the `chainId` with a display `name`, so one call both
92
+ * gates a chain selector and labels it. Key on `chainId`; `name` is a
93
+ * deployment-maintained label that can change.
94
+ *
95
+ * Use it to fail fast before building a flow for a chain the server would
96
+ * reject.
97
+ *
98
+ * @returns The supported chains, ascending by `chainId`.
99
+ * @throws {@link ComposeError} on network or server errors.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const chains = await sdk.getSupportedChains();
104
+ * if (!chains.some((c) => c.chainId === 8453)) {
105
+ * throw new Error('Base is not supported');
106
+ * }
107
+ * for (const { chainId, name } of chains) {
108
+ * console.log(`${name} (${chainId})`);
109
+ * }
110
+ * ```
111
+ */
112
+ readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
113
+ /**
114
+ * Builds a raw compile request without sending it. Useful for inspecting the
115
+ * request payload or submitting it through a custom transport.
116
+ * @param flow - A built flow document (from `builder.build()`).
117
+ * @param run - Runtime inputs, preconditions, and signer address.
118
+ * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
119
+ */
120
+ readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
121
+ /**
122
+ * Compiles a token pair on one chain into a submit-ready transaction. Thin
123
+ * pass-through to {@link ComposeClient.route}; see it for the short chain of
124
+ * catalog edges the server plans, when to prefer `flow(...).compile(...)`,
125
+ * the `success` / `partial` discrimination, and error behaviour. Build the
126
+ * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.
127
+ *
128
+ * @param request - The from/to token pair, amount, signer, and route options.
129
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
130
+ * @throws {@link ComposeError} on network, validation, or server errors.
131
+ */
132
+ readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
133
+ /**
134
+ * Simulates a raw, pre-encoded transaction. Thin pass-through to
135
+ * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
136
+ * result discrimination and error behaviour. Pair with `buildSimulateRequest`
137
+ * to assemble the request from a compile result.
138
+ *
139
+ * @param request - The raw transaction plus funding `requirements` and
140
+ * `trackedBalances`.
141
+ * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
142
+ * @throws {@link ComposeError} on network, validation, or server errors.
143
+ */
144
+ readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
149
145
  }
150
146
  /**
151
147
  * Creates a new Compose SDK instance.
@@ -158,6 +154,7 @@ interface ComposeSdk {
158
154
  * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
159
155
  * ```
160
156
  */
161
- declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
162
-
163
- export { ComposeRunInput, type ComposeSdk, type ComposeSdkOptions, type FlowBuilder, createComposeSdk };
157
+ export declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
158
+ //#endregion
159
+ export type { ComposeRunInput };
160
+ //# sourceMappingURL=sdk.d.cts.map
package/dist/sdk.d.ts CHANGED
@@ -1,15 +1,11 @@
1
- import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
- import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.js';
3
- import { ComposeClient } from './client.js';
4
- import { ChainSummary } from './discovery.js';
5
- import { GeneratedOps } from './generated/operations.generated.js';
6
- import { ComposeRunInput } from './run/inputs.js';
7
- import { InputSchema } from './types.js';
8
- import './authoring/handles.js';
9
- import './authoring/signatureArgs.js';
10
- import 'abitype';
11
- import './generated/config.generated.js';
12
-
1
+ import { InputSchema } from "./types.js";
2
+ import { FlowBuilderCore, FlowOptions, TypedFlow } from "./authoring/FlowBuilderCore.js";
3
+ import { ChainSummary } from "./discovery.js";
4
+ import { ComposeClient } from "./client.js";
5
+ import { GeneratedOps } from "./generated/operations.generated.js";
6
+ import { ComposeRunInput } from "./run/inputs.js";
7
+ import { ComposeCompileRequest, ComposeCompileResult, ComposeRouteRequest, SimulateRequest, SimulateResult } from "@lifi/compose-spec";
8
+ //#region src/sdk.d.ts
13
9
  /**
14
10
  * A flow builder augmented with generated operation methods and a `compile` method
15
11
  * that submits the flow to the Compose backend for compilation.
@@ -18,36 +14,36 @@ import './generated/config.generated.js';
18
14
  *
19
15
  * @typeParam T - The input schema describing the flow's required inputs.
20
16
  */
21
- type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
22
- /**
23
- * Builds the flow document from the current builder state and submits it
24
- * to the Compose API for compilation.
25
- *
26
- * @param run - Runtime inputs, preconditions, and signer address.
27
- * @returns The compiled transaction calldata and metadata.
28
- * @throws {@link ComposeError} on network, validation, or server errors.
29
- *
30
- * @example
31
- * ```ts
32
- * const result = await builder.compile({
33
- * inputs: { token: materialisers.balanceOf({}) },
34
- * signer: '0xYourAddress...',
35
- * });
36
- * console.log(result.calldata);
37
- * ```
38
- */
39
- readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
17
+ export type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
18
+ /**
19
+ * Builds the flow document from the current builder state and submits it
20
+ * to the Compose API for compilation.
21
+ *
22
+ * @param run - Runtime inputs, preconditions, and signer address.
23
+ * @returns The compiled transaction calldata and metadata.
24
+ * @throws {@link ComposeError} on network, validation, or server errors.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await builder.compile({
29
+ * inputs: { token: materialisers.balanceOf({}) },
30
+ * signer: '0xYourAddress...',
31
+ * });
32
+ * console.log(result.calldata);
33
+ * ```
34
+ */
35
+ readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
40
36
  };
41
37
  /**
42
38
  * Configuration for creating a Compose SDK instance.
43
39
  */
44
- interface ComposeSdkOptions {
45
- /** Base URL of the Compose API (e.g. `"https://li.quest"`). */
46
- readonly baseUrl: string;
47
- /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
48
- readonly fetch?: typeof globalThis.fetch;
49
- /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
50
- readonly apiKey: string;
40
+ export interface ComposeSdkOptions {
41
+ /** Base URL of the Compose API (e.g. `"https://li.quest"`). */
42
+ readonly baseUrl: string;
43
+ /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
44
+ readonly fetch?: typeof globalThis.fetch;
45
+ /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
46
+ readonly apiKey: string;
51
47
  }
52
48
  /**
53
49
  * The top-level Compose SDK interface.
@@ -76,76 +72,76 @@ interface ComposeSdkOptions {
76
72
  * });
77
73
  * ```
78
74
  */
79
- interface ComposeSdk {
80
- /** Low-level HTTP client for the Compose API. */
81
- readonly client: ComposeClient;
82
- /**
83
- * Creates a new flow builder targeting the given chain.
84
- * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
85
- * @param options - Flow configuration including input declarations.
86
- * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
87
- * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
88
- */
89
- readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
90
- /**
91
- * Fetches the chains this Compose deployment supports, ascending by
92
- * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
93
- * for what "supported" means and for the caching caveat.
94
- *
95
- * Each entry pairs the `chainId` with a display `name`, so one call both
96
- * gates a chain selector and labels it. Key on `chainId`; `name` is a
97
- * deployment-maintained label that can change.
98
- *
99
- * Use it to fail fast before building a flow for a chain the server would
100
- * reject.
101
- *
102
- * @returns The supported chains, ascending by `chainId`.
103
- * @throws {@link ComposeError} on network or server errors.
104
- *
105
- * @example
106
- * ```ts
107
- * const chains = await sdk.getSupportedChains();
108
- * if (!chains.some((c) => c.chainId === 8453)) {
109
- * throw new Error('Base is not supported');
110
- * }
111
- * for (const { chainId, name } of chains) {
112
- * console.log(`${name} (${chainId})`);
113
- * }
114
- * ```
115
- */
116
- readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
117
- /**
118
- * Builds a raw compile request without sending it. Useful for inspecting the
119
- * request payload or submitting it through a custom transport.
120
- * @param flow - A built flow document (from `builder.build()`).
121
- * @param run - Runtime inputs, preconditions, and signer address.
122
- * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
123
- */
124
- readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
125
- /**
126
- * Compiles a token pair on one chain into a submit-ready transaction. Thin
127
- * pass-through to {@link ComposeClient.route}; see it for the short chain of
128
- * catalog edges the server plans, when to prefer `flow(...).compile(...)`,
129
- * the `success` / `partial` discrimination, and error behaviour. Build the
130
- * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.
131
- *
132
- * @param request - The from/to token pair, amount, signer, and route options.
133
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
134
- * @throws {@link ComposeError} on network, validation, or server errors.
135
- */
136
- readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
137
- /**
138
- * Simulates a raw, pre-encoded transaction. Thin pass-through to
139
- * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
140
- * result discrimination and error behaviour. Pair with `buildSimulateRequest`
141
- * to assemble the request from a compile result.
142
- *
143
- * @param request - The raw transaction plus funding `requirements` and
144
- * `trackedBalances`.
145
- * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
146
- * @throws {@link ComposeError} on network, validation, or server errors.
147
- */
148
- readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
75
+ export interface ComposeSdk {
76
+ /** Low-level HTTP client for the Compose API. */
77
+ readonly client: ComposeClient;
78
+ /**
79
+ * Creates a new flow builder targeting the given chain.
80
+ * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
81
+ * @param options - Flow configuration including input declarations.
82
+ * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
83
+ * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
84
+ */
85
+ readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
86
+ /**
87
+ * Fetches the chains this Compose deployment supports, ascending by
88
+ * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
89
+ * for what "supported" means and for the caching caveat.
90
+ *
91
+ * Each entry pairs the `chainId` with a display `name`, so one call both
92
+ * gates a chain selector and labels it. Key on `chainId`; `name` is a
93
+ * deployment-maintained label that can change.
94
+ *
95
+ * Use it to fail fast before building a flow for a chain the server would
96
+ * reject.
97
+ *
98
+ * @returns The supported chains, ascending by `chainId`.
99
+ * @throws {@link ComposeError} on network or server errors.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const chains = await sdk.getSupportedChains();
104
+ * if (!chains.some((c) => c.chainId === 8453)) {
105
+ * throw new Error('Base is not supported');
106
+ * }
107
+ * for (const { chainId, name } of chains) {
108
+ * console.log(`${name} (${chainId})`);
109
+ * }
110
+ * ```
111
+ */
112
+ readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
113
+ /**
114
+ * Builds a raw compile request without sending it. Useful for inspecting the
115
+ * request payload or submitting it through a custom transport.
116
+ * @param flow - A built flow document (from `builder.build()`).
117
+ * @param run - Runtime inputs, preconditions, and signer address.
118
+ * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
119
+ */
120
+ readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
121
+ /**
122
+ * Compiles a token pair on one chain into a submit-ready transaction. Thin
123
+ * pass-through to {@link ComposeClient.route}; see it for the short chain of
124
+ * catalog edges the server plans, when to prefer `flow(...).compile(...)`,
125
+ * the `success` / `partial` discrimination, and error behaviour. Build the
126
+ * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.
127
+ *
128
+ * @param request - The from/to token pair, amount, signer, and route options.
129
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
130
+ * @throws {@link ComposeError} on network, validation, or server errors.
131
+ */
132
+ readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
133
+ /**
134
+ * Simulates a raw, pre-encoded transaction. Thin pass-through to
135
+ * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
136
+ * result discrimination and error behaviour. Pair with `buildSimulateRequest`
137
+ * to assemble the request from a compile result.
138
+ *
139
+ * @param request - The raw transaction plus funding `requirements` and
140
+ * `trackedBalances`.
141
+ * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
142
+ * @throws {@link ComposeError} on network, validation, or server errors.
143
+ */
144
+ readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
149
145
  }
150
146
  /**
151
147
  * Creates a new Compose SDK instance.
@@ -158,6 +154,7 @@ interface ComposeSdk {
158
154
  * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
159
155
  * ```
160
156
  */
161
- declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
162
-
163
- export { ComposeRunInput, type ComposeSdk, type ComposeSdkOptions, type FlowBuilder, createComposeSdk };
157
+ export declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
158
+ //#endregion
159
+ export type { ComposeRunInput };
160
+ //# sourceMappingURL=sdk.d.ts.map
package/dist/sdk.js CHANGED
@@ -1,49 +1,57 @@
1
- import {
2
- createFlowBuilderCore
3
- } from "./authoring/FlowBuilderCore.js";
4
1
  import { createComposeClient } from "./client.js";
5
- import {
6
- bindGeneratedOps
7
- } from "./generated/operations.generated.js";
8
2
  import { buildRun } from "./run/inputs.js";
3
+ import { createFlowBuilderCore } from "./authoring/FlowBuilderCore.js";
4
+ import { bindGeneratedOps } from "./generated/operations.generated.js";
5
+ //#region src/sdk.ts
6
+ /**
7
+ * Creates a new Compose SDK instance.
8
+ *
9
+ * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.
10
+ * @returns A {@link ComposeSdk} instance.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
15
+ * ```
16
+ */
9
17
  const createComposeSdk = (options) => {
10
- const composeClient = createComposeClient(options);
11
- const request = (flowDoc, run) => ({
12
- flow: flowDoc,
13
- run: buildRun({
14
- inputs: run.inputs,
15
- preconditions: run.preconditions,
16
- signer: run.signer,
17
- assumptions: run.assumptions,
18
- referrer: run.referrer,
19
- integratorFeeBps: run.integratorFeeBps,
20
- maxPriceImpactBps: run.maxPriceImpactBps,
21
- sweepTo: run.sweepTo,
22
- simulationPolicy: run.simulationPolicy,
23
- simulateUserProgram: run.simulateUserProgram,
24
- checkOnChainAllowances: run.checkOnChainAllowances
25
- })
26
- });
27
- const flow = (chainId, opts) => {
28
- const core = createFlowBuilderCore(chainId, opts);
29
- const builder = Object.assign(core, bindGeneratedOps(core));
30
- const compile = async (run) => {
31
- const flowDoc = builder.build();
32
- const req = request(flowDoc, run);
33
- return composeClient.compile(req);
34
- };
35
- return Object.assign(builder, { compile });
36
- };
37
- return {
38
- client: composeClient,
39
- flow,
40
- getSupportedChains: composeClient.getChains,
41
- request,
42
- route: composeClient.route,
43
- simulate: composeClient.simulate
44
- };
45
- };
46
- export {
47
- createComposeSdk
18
+ const composeClient = createComposeClient(options);
19
+ const request = (flowDoc, run) => ({
20
+ flow: flowDoc,
21
+ run: buildRun({
22
+ inputs: run.inputs,
23
+ preconditions: run.preconditions,
24
+ signer: run.signer,
25
+ assumptions: run.assumptions,
26
+ referrer: run.referrer,
27
+ integratorFeeBps: run.integratorFeeBps,
28
+ maxPriceImpactBps: run.maxPriceImpactBps,
29
+ sweepTo: run.sweepTo,
30
+ simulationPolicy: run.simulationPolicy,
31
+ simulateUserProgram: run.simulateUserProgram,
32
+ checkOnChainAllowances: run.checkOnChainAllowances
33
+ })
34
+ });
35
+ const flow = (chainId, opts) => {
36
+ const core = createFlowBuilderCore(chainId, opts);
37
+ const builder = Object.assign(core, bindGeneratedOps(core));
38
+ const compile = async (run) => {
39
+ const flowDoc = builder.build();
40
+ const req = request(flowDoc, run);
41
+ return composeClient.compile(req);
42
+ };
43
+ return Object.assign(builder, { compile });
44
+ };
45
+ return {
46
+ client: composeClient,
47
+ flow,
48
+ getSupportedChains: composeClient.getChains,
49
+ request,
50
+ route: composeClient.route,
51
+ simulate: composeClient.simulate
52
+ };
48
53
  };
54
+ //#endregion
55
+ export { createComposeSdk };
56
+
49
57
  //# sourceMappingURL=sdk.js.map