@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/client.d.cts CHANGED
@@ -1,16 +1,16 @@
1
- import { ComposeManifest, ComposeCompileRequest, ComposeCompileResult, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
- import { ChainSummary, GetZapPacksOptions, ZapPackOverview } from './discovery.cjs';
3
-
1
+ import { ChainSummary, GetZapPacksOptions, ZapPackOverview } from "./discovery.cjs";
2
+ import { ComposeCompileRequest, ComposeCompileResult, ComposeManifest, ComposeRouteRequest, SimulateRequest, SimulateResult } from "@lifi/compose-spec";
3
+ //#region src/client.d.ts
4
4
  /**
5
5
  * Configuration for creating a low-level Compose API client.
6
6
  */
7
- interface ComposeClientOptions {
8
- /** Base URL of the Compose API. */
9
- readonly baseUrl: string;
10
- /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
11
- readonly fetch?: typeof globalThis.fetch;
12
- /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
13
- readonly apiKey: string;
7
+ export interface ComposeClientOptions {
8
+ /** Base URL of the Compose API. */
9
+ readonly baseUrl: string;
10
+ /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
11
+ readonly fetch?: typeof globalThis.fetch;
12
+ /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
13
+ readonly apiKey: string;
14
14
  }
15
15
  /**
16
16
  * Low-level HTTP client for the Compose API.
@@ -21,123 +21,123 @@ interface ComposeClientOptions {
21
21
  * build via `sdk.request()` then submit via `client.compile()` with custom
22
22
  * retry logic or request inspection.
23
23
  */
24
- interface ComposeClient {
25
- /**
26
- * Fetches the server's operation manifest describing all supported operations,
27
- * guards, materialisers, and preconditions.
28
- * @returns The manifest document.
29
- * @throws {@link ComposeError} on network, validation, or server errors.
30
- */
31
- readonly getManifest: () => Promise<ComposeManifest>;
32
- /**
33
- * Fetches the chains the Compose API supports, ascending by `chainId`.
34
- *
35
- * A chain is listed once the server confirms the VM contract is deployed on
36
- * it — the same condition {@link compile}, {@link route} and
37
- * {@link simulate} validate against. A chain absent from this list is
38
- * rejected outright by those endpoints.
39
- *
40
- * The converse does not hold: a listed chain can still have no routing edge
41
- * for a given token pair, which {@link route} reports as `no_route_error`.
42
- * Use {@link getZapPacks} to enumerate the pairs that do route.
43
- *
44
- * Each entry carries a display `name` alongside its `chainId`. The name is a
45
- * deployment-maintained label — render it, but key on `chainId`.
46
- *
47
- * The list tracks the server's chain registry, which refreshes periodically.
48
- * Results are not cached by the SDK; callers should cache as appropriate.
49
- *
50
- * @returns The supported chains, ascending by `chainId`.
51
- * @throws {@link ComposeError} on network or server errors.
52
- */
53
- readonly getChains: () => Promise<readonly ChainSummary[]>;
54
- /**
55
- * Submits a compile request and returns the result.
56
- *
57
- * When the caller passes `simulationPolicy: 'allow-revert'` and the transaction
58
- * reverts in simulation, the server responds with HTTP 206 and the SDK returns a
59
- * partial result (`status: 'partial'`) instead of throwing. The partial result
60
- * includes the transaction (without `gasLimit`) and revert diagnostics.
61
- *
62
- * @param request - The full compile request including flow and run inputs.
63
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
64
- * @throws {@link ComposeError} on network, validation, or server errors.
65
- */
66
- readonly compile: (request: ComposeCompileRequest) => Promise<ComposeCompileResult>;
67
- /**
68
- * Compiles a token pair into a submit-ready transaction via
69
- * `POST /compose/route`.
70
- *
71
- * A convenience path that skips flow authoring: the server builds a one-node
72
- * zap flow with a `directDeposit` input from the `fromToken` / `toToken`
73
- * pair and runs it through the same pipeline as {@link compile}. The
74
- * response is therefore the same discriminated result — HTTP 206 under
75
- * `simulationPolicy: 'allow-revert'` yields `status: 'partial'` rather than
76
- * throwing, exactly as it does for {@link compile}.
77
- *
78
- * The server plans a short chain of catalog edges for the pair (a position
79
- * entry or exit, a wrap or unwrap, a mint or burn), optionally opened by a
80
- * `lifi.swap`. {@link getZapPacks} lists the single edges; the pairs the
81
- * planner connects are their closure up to the hop budget, which
82
- * {@link buildReachability} computes locally. A pair the planner cannot
83
- * connect is rejected with `kind: 'no_route_error'`.
84
- *
85
- * Only synchronous edges are considered unless the request sets
86
- * `allowAsyncRoutes: true`, so by default every terminal output comes back
87
- * `delivery.when: 'now'` and a pair reachable only after settlement is a
88
- * `no_route_error`. Opting in adds the `lifi.zapAsync` fallback, which still
89
- * loses to a synchronous edge when the pair has one; read
90
- * `outputs[*].delivery.when` to see which representation you got.
91
- *
92
- * Use {@link compile} for what the server does not author for you: several
93
- * chained operations, splits, explicit preconditions, or per-op guards.
94
- *
95
- * `bigint` amounts in `amount` are serialised to decimal strings
96
- * automatically.
97
- *
98
- * @param request - The from/to token pair, amount, signer, and route options.
99
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
100
- * @throws {@link ComposeError} on network, validation, or server errors —
101
- * including `NOT_FOUND` (HTTP 404) when the planner cannot connect the pair.
102
- */
103
- readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
104
- /**
105
- * Fetches the available routing edges grouped by protocol.
106
- *
107
- * The edge catalog is dynamic — it reflects the current state of the
108
- * backend's routing snapshot (protocols, chains, token blacklists).
109
- * Results are not cached by the SDK; callers should cache as appropriate.
110
- *
111
- * @param options - Optional filter to restrict results to specific protocols.
112
- * @returns An array of {@link ZapPackOverview} objects, one per protocol.
113
- * @throws {@link ComposeError} on network or server errors (503 when the
114
- * routing catalog is not yet initialized).
115
- */
116
- readonly getZapPacks: (options?: GetZapPacksOptions) => Promise<readonly ZapPackOverview[]>;
117
- /**
118
- * Simulates a raw, pre-encoded transaction against `POST /simulate` and
119
- * reports how the watched balances change and how much inner-call gas it
120
- * burns.
121
- *
122
- * The result is a discriminated union on `status`:
123
- * - `'ok'` — the simulation ran successfully; `deltas`/`gasUsed` are populated.
124
- * - `'revert'` — the simulation ran but the transaction reverted on-chain. A
125
- * revert is a *successful simulation*, not a transport error, so it is
126
- * returned (HTTP 200) rather than thrown — mirroring how {@link compile}
127
- * returns `status: 'partial'` on a simulated revert.
128
- * - `'error'` — the request was well-formed but the simulation could not be
129
- * set up or run (HTTP 422); `message` is intentionally generic.
130
- *
131
- * `bigint` amounts in the request (`value`, requirement `balance`/`allowance`)
132
- * are serialised to decimal strings automatically.
133
- *
134
- * @param request - The raw transaction plus funding `requirements` and the
135
- * `trackedBalances` to watch.
136
- * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
137
- * @throws {@link ComposeError} on network failures, HTTP 400 (malformed
138
- * input), 401/403 (auth), 404, 429, and 5xx.
139
- */
140
- readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
24
+ export interface ComposeClient {
25
+ /**
26
+ * Fetches the server's operation manifest describing all supported operations,
27
+ * guards, materialisers, and preconditions.
28
+ * @returns The manifest document.
29
+ * @throws {@link ComposeError} on network, validation, or server errors.
30
+ */
31
+ readonly getManifest: () => Promise<ComposeManifest>;
32
+ /**
33
+ * Fetches the chains the Compose API supports, ascending by `chainId`.
34
+ *
35
+ * A chain is listed once the server confirms the VM contract is deployed on
36
+ * it — the same condition {@link compile}, {@link route} and
37
+ * {@link simulate} validate against. A chain absent from this list is
38
+ * rejected outright by those endpoints.
39
+ *
40
+ * The converse does not hold: a listed chain can still have no routing edge
41
+ * for a given token pair, which {@link route} reports as `no_route_error`.
42
+ * Use {@link getZapPacks} to enumerate the pairs that do route.
43
+ *
44
+ * Each entry carries a display `name` alongside its `chainId`. The name is a
45
+ * deployment-maintained label — render it, but key on `chainId`.
46
+ *
47
+ * The list tracks the server's chain registry, which refreshes periodically.
48
+ * Results are not cached by the SDK; callers should cache as appropriate.
49
+ *
50
+ * @returns The supported chains, ascending by `chainId`.
51
+ * @throws {@link ComposeError} on network or server errors.
52
+ */
53
+ readonly getChains: () => Promise<readonly ChainSummary[]>;
54
+ /**
55
+ * Submits a compile request and returns the result.
56
+ *
57
+ * When the caller passes `simulationPolicy: 'allow-revert'` and the transaction
58
+ * reverts in simulation, the server responds with HTTP 206 and the SDK returns a
59
+ * partial result (`status: 'partial'`) instead of throwing. The partial result
60
+ * includes the transaction (without `gasLimit`) and revert diagnostics.
61
+ *
62
+ * @param request - The full compile request including flow and run inputs.
63
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
64
+ * @throws {@link ComposeError} on network, validation, or server errors.
65
+ */
66
+ readonly compile: (request: ComposeCompileRequest) => Promise<ComposeCompileResult>;
67
+ /**
68
+ * Compiles a token pair into a submit-ready transaction via
69
+ * `POST /compose/route`.
70
+ *
71
+ * A convenience path that skips flow authoring: the server builds a one-node
72
+ * zap flow with a `directDeposit` input from the `fromToken` / `toToken`
73
+ * pair and runs it through the same pipeline as {@link compile}. The
74
+ * response is therefore the same discriminated result — HTTP 206 under
75
+ * `simulationPolicy: 'allow-revert'` yields `status: 'partial'` rather than
76
+ * throwing, exactly as it does for {@link compile}.
77
+ *
78
+ * The server plans a short chain of catalog edges for the pair (a position
79
+ * entry or exit, a wrap or unwrap, a mint or burn), optionally opened by a
80
+ * `lifi.swap`. {@link getZapPacks} lists the single edges; the pairs the
81
+ * planner connects are their closure up to the hop budget, which
82
+ * {@link buildReachability} computes locally. A pair the planner cannot
83
+ * connect is rejected with `kind: 'no_route_error'`.
84
+ *
85
+ * Only synchronous edges are considered unless the request sets
86
+ * `allowAsyncRoutes: true`, so by default every terminal output comes back
87
+ * `delivery.when: 'now'` and a pair reachable only after settlement is a
88
+ * `no_route_error`. Opting in adds the `lifi.zapAsync` fallback, which still
89
+ * loses to a synchronous edge when the pair has one; read
90
+ * `outputs[*].delivery.when` to see which representation you got.
91
+ *
92
+ * Use {@link compile} for what the server does not author for you: several
93
+ * chained operations, splits, explicit preconditions, or per-op guards.
94
+ *
95
+ * `bigint` amounts in `amount` are serialised to decimal strings
96
+ * automatically.
97
+ *
98
+ * @param request - The from/to token pair, amount, signer, and route options.
99
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
100
+ * @throws {@link ComposeError} on network, validation, or server errors —
101
+ * including `NOT_FOUND` (HTTP 404) when the planner cannot connect the pair.
102
+ */
103
+ readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
104
+ /**
105
+ * Fetches the available routing edges grouped by protocol.
106
+ *
107
+ * The edge catalog is dynamic — it reflects the current state of the
108
+ * backend's routing snapshot (protocols, chains, token blacklists).
109
+ * Results are not cached by the SDK; callers should cache as appropriate.
110
+ *
111
+ * @param options - Optional filter to restrict results to specific protocols.
112
+ * @returns An array of {@link ZapPackOverview} objects, one per protocol.
113
+ * @throws {@link ComposeError} on network or server errors (503 when the
114
+ * routing catalog is not yet initialized).
115
+ */
116
+ readonly getZapPacks: (options?: GetZapPacksOptions) => Promise<readonly ZapPackOverview[]>;
117
+ /**
118
+ * Simulates a raw, pre-encoded transaction against `POST /simulate` and
119
+ * reports how the watched balances change and how much inner-call gas it
120
+ * burns.
121
+ *
122
+ * The result is a discriminated union on `status`:
123
+ * - `'ok'` — the simulation ran successfully; `deltas`/`gasUsed` are populated.
124
+ * - `'revert'` — the simulation ran but the transaction reverted on-chain. A
125
+ * revert is a *successful simulation*, not a transport error, so it is
126
+ * returned (HTTP 200) rather than thrown — mirroring how {@link compile}
127
+ * returns `status: 'partial'` on a simulated revert.
128
+ * - `'error'` — the request was well-formed but the simulation could not be
129
+ * set up or run (HTTP 422); `message` is intentionally generic.
130
+ *
131
+ * `bigint` amounts in the request (`value`, requirement `balance`/`allowance`)
132
+ * are serialised to decimal strings automatically.
133
+ *
134
+ * @param request - The raw transaction plus funding `requirements` and the
135
+ * `trackedBalances` to watch.
136
+ * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
137
+ * @throws {@link ComposeError} on network failures, HTTP 400 (malformed
138
+ * input), 401/403 (auth), 404, 429, and 5xx.
139
+ */
140
+ readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
141
141
  }
142
142
  /**
143
143
  * `JSON.stringify` replacer that renders `bigint` amounts as decimal strings.
@@ -146,13 +146,13 @@ interface ComposeClient {
146
146
  * no JSON representation, so every payload this client sends goes through it.
147
147
  * Exported so the example harness prints a request exactly as it is sent.
148
148
  */
149
- declare const bigintReplacer: (_key: string, value: unknown) => unknown;
149
+ export declare const bigintReplacer: (_key: string, value: unknown) => unknown;
150
150
  /**
151
151
  * Creates a low-level Compose API client.
152
152
  *
153
153
  * @param options - Client configuration including the API base URL.
154
154
  * @returns A {@link ComposeClient} instance.
155
155
  */
156
- declare const createComposeClient: (options: ComposeClientOptions) => ComposeClient;
157
-
158
- export { type ComposeClient, type ComposeClientOptions, bigintReplacer, createComposeClient };
156
+ export declare const createComposeClient: (options: ComposeClientOptions) => ComposeClient;
157
+ //#endregion
158
+ //# sourceMappingURL=client.d.cts.map
package/dist/client.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import { ComposeManifest, ComposeCompileRequest, ComposeCompileResult, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
- import { ChainSummary, GetZapPacksOptions, ZapPackOverview } from './discovery.js';
3
-
1
+ import { ChainSummary, GetZapPacksOptions, ZapPackOverview } from "./discovery.js";
2
+ import { ComposeCompileRequest, ComposeCompileResult, ComposeManifest, ComposeRouteRequest, SimulateRequest, SimulateResult } from "@lifi/compose-spec";
3
+ //#region src/client.d.ts
4
4
  /**
5
5
  * Configuration for creating a low-level Compose API client.
6
6
  */
7
- interface ComposeClientOptions {
8
- /** Base URL of the Compose API. */
9
- readonly baseUrl: string;
10
- /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
11
- readonly fetch?: typeof globalThis.fetch;
12
- /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
13
- readonly apiKey: string;
7
+ export interface ComposeClientOptions {
8
+ /** Base URL of the Compose API. */
9
+ readonly baseUrl: string;
10
+ /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
11
+ readonly fetch?: typeof globalThis.fetch;
12
+ /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
13
+ readonly apiKey: string;
14
14
  }
15
15
  /**
16
16
  * Low-level HTTP client for the Compose API.
@@ -21,123 +21,123 @@ interface ComposeClientOptions {
21
21
  * build via `sdk.request()` then submit via `client.compile()` with custom
22
22
  * retry logic or request inspection.
23
23
  */
24
- interface ComposeClient {
25
- /**
26
- * Fetches the server's operation manifest describing all supported operations,
27
- * guards, materialisers, and preconditions.
28
- * @returns The manifest document.
29
- * @throws {@link ComposeError} on network, validation, or server errors.
30
- */
31
- readonly getManifest: () => Promise<ComposeManifest>;
32
- /**
33
- * Fetches the chains the Compose API supports, ascending by `chainId`.
34
- *
35
- * A chain is listed once the server confirms the VM contract is deployed on
36
- * it — the same condition {@link compile}, {@link route} and
37
- * {@link simulate} validate against. A chain absent from this list is
38
- * rejected outright by those endpoints.
39
- *
40
- * The converse does not hold: a listed chain can still have no routing edge
41
- * for a given token pair, which {@link route} reports as `no_route_error`.
42
- * Use {@link getZapPacks} to enumerate the pairs that do route.
43
- *
44
- * Each entry carries a display `name` alongside its `chainId`. The name is a
45
- * deployment-maintained label — render it, but key on `chainId`.
46
- *
47
- * The list tracks the server's chain registry, which refreshes periodically.
48
- * Results are not cached by the SDK; callers should cache as appropriate.
49
- *
50
- * @returns The supported chains, ascending by `chainId`.
51
- * @throws {@link ComposeError} on network or server errors.
52
- */
53
- readonly getChains: () => Promise<readonly ChainSummary[]>;
54
- /**
55
- * Submits a compile request and returns the result.
56
- *
57
- * When the caller passes `simulationPolicy: 'allow-revert'` and the transaction
58
- * reverts in simulation, the server responds with HTTP 206 and the SDK returns a
59
- * partial result (`status: 'partial'`) instead of throwing. The partial result
60
- * includes the transaction (without `gasLimit`) and revert diagnostics.
61
- *
62
- * @param request - The full compile request including flow and run inputs.
63
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
64
- * @throws {@link ComposeError} on network, validation, or server errors.
65
- */
66
- readonly compile: (request: ComposeCompileRequest) => Promise<ComposeCompileResult>;
67
- /**
68
- * Compiles a token pair into a submit-ready transaction via
69
- * `POST /compose/route`.
70
- *
71
- * A convenience path that skips flow authoring: the server builds a one-node
72
- * zap flow with a `directDeposit` input from the `fromToken` / `toToken`
73
- * pair and runs it through the same pipeline as {@link compile}. The
74
- * response is therefore the same discriminated result — HTTP 206 under
75
- * `simulationPolicy: 'allow-revert'` yields `status: 'partial'` rather than
76
- * throwing, exactly as it does for {@link compile}.
77
- *
78
- * The server plans a short chain of catalog edges for the pair (a position
79
- * entry or exit, a wrap or unwrap, a mint or burn), optionally opened by a
80
- * `lifi.swap`. {@link getZapPacks} lists the single edges; the pairs the
81
- * planner connects are their closure up to the hop budget, which
82
- * {@link buildReachability} computes locally. A pair the planner cannot
83
- * connect is rejected with `kind: 'no_route_error'`.
84
- *
85
- * Only synchronous edges are considered unless the request sets
86
- * `allowAsyncRoutes: true`, so by default every terminal output comes back
87
- * `delivery.when: 'now'` and a pair reachable only after settlement is a
88
- * `no_route_error`. Opting in adds the `lifi.zapAsync` fallback, which still
89
- * loses to a synchronous edge when the pair has one; read
90
- * `outputs[*].delivery.when` to see which representation you got.
91
- *
92
- * Use {@link compile} for what the server does not author for you: several
93
- * chained operations, splits, explicit preconditions, or per-op guards.
94
- *
95
- * `bigint` amounts in `amount` are serialised to decimal strings
96
- * automatically.
97
- *
98
- * @param request - The from/to token pair, amount, signer, and route options.
99
- * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
100
- * @throws {@link ComposeError} on network, validation, or server errors —
101
- * including `NOT_FOUND` (HTTP 404) when the planner cannot connect the pair.
102
- */
103
- readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
104
- /**
105
- * Fetches the available routing edges grouped by protocol.
106
- *
107
- * The edge catalog is dynamic — it reflects the current state of the
108
- * backend's routing snapshot (protocols, chains, token blacklists).
109
- * Results are not cached by the SDK; callers should cache as appropriate.
110
- *
111
- * @param options - Optional filter to restrict results to specific protocols.
112
- * @returns An array of {@link ZapPackOverview} objects, one per protocol.
113
- * @throws {@link ComposeError} on network or server errors (503 when the
114
- * routing catalog is not yet initialized).
115
- */
116
- readonly getZapPacks: (options?: GetZapPacksOptions) => Promise<readonly ZapPackOverview[]>;
117
- /**
118
- * Simulates a raw, pre-encoded transaction against `POST /simulate` and
119
- * reports how the watched balances change and how much inner-call gas it
120
- * burns.
121
- *
122
- * The result is a discriminated union on `status`:
123
- * - `'ok'` — the simulation ran successfully; `deltas`/`gasUsed` are populated.
124
- * - `'revert'` — the simulation ran but the transaction reverted on-chain. A
125
- * revert is a *successful simulation*, not a transport error, so it is
126
- * returned (HTTP 200) rather than thrown — mirroring how {@link compile}
127
- * returns `status: 'partial'` on a simulated revert.
128
- * - `'error'` — the request was well-formed but the simulation could not be
129
- * set up or run (HTTP 422); `message` is intentionally generic.
130
- *
131
- * `bigint` amounts in the request (`value`, requirement `balance`/`allowance`)
132
- * are serialised to decimal strings automatically.
133
- *
134
- * @param request - The raw transaction plus funding `requirements` and the
135
- * `trackedBalances` to watch.
136
- * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
137
- * @throws {@link ComposeError} on network failures, HTTP 400 (malformed
138
- * input), 401/403 (auth), 404, 429, and 5xx.
139
- */
140
- readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
24
+ export interface ComposeClient {
25
+ /**
26
+ * Fetches the server's operation manifest describing all supported operations,
27
+ * guards, materialisers, and preconditions.
28
+ * @returns The manifest document.
29
+ * @throws {@link ComposeError} on network, validation, or server errors.
30
+ */
31
+ readonly getManifest: () => Promise<ComposeManifest>;
32
+ /**
33
+ * Fetches the chains the Compose API supports, ascending by `chainId`.
34
+ *
35
+ * A chain is listed once the server confirms the VM contract is deployed on
36
+ * it — the same condition {@link compile}, {@link route} and
37
+ * {@link simulate} validate against. A chain absent from this list is
38
+ * rejected outright by those endpoints.
39
+ *
40
+ * The converse does not hold: a listed chain can still have no routing edge
41
+ * for a given token pair, which {@link route} reports as `no_route_error`.
42
+ * Use {@link getZapPacks} to enumerate the pairs that do route.
43
+ *
44
+ * Each entry carries a display `name` alongside its `chainId`. The name is a
45
+ * deployment-maintained label — render it, but key on `chainId`.
46
+ *
47
+ * The list tracks the server's chain registry, which refreshes periodically.
48
+ * Results are not cached by the SDK; callers should cache as appropriate.
49
+ *
50
+ * @returns The supported chains, ascending by `chainId`.
51
+ * @throws {@link ComposeError} on network or server errors.
52
+ */
53
+ readonly getChains: () => Promise<readonly ChainSummary[]>;
54
+ /**
55
+ * Submits a compile request and returns the result.
56
+ *
57
+ * When the caller passes `simulationPolicy: 'allow-revert'` and the transaction
58
+ * reverts in simulation, the server responds with HTTP 206 and the SDK returns a
59
+ * partial result (`status: 'partial'`) instead of throwing. The partial result
60
+ * includes the transaction (without `gasLimit`) and revert diagnostics.
61
+ *
62
+ * @param request - The full compile request including flow and run inputs.
63
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
64
+ * @throws {@link ComposeError} on network, validation, or server errors.
65
+ */
66
+ readonly compile: (request: ComposeCompileRequest) => Promise<ComposeCompileResult>;
67
+ /**
68
+ * Compiles a token pair into a submit-ready transaction via
69
+ * `POST /compose/route`.
70
+ *
71
+ * A convenience path that skips flow authoring: the server builds a one-node
72
+ * zap flow with a `directDeposit` input from the `fromToken` / `toToken`
73
+ * pair and runs it through the same pipeline as {@link compile}. The
74
+ * response is therefore the same discriminated result — HTTP 206 under
75
+ * `simulationPolicy: 'allow-revert'` yields `status: 'partial'` rather than
76
+ * throwing, exactly as it does for {@link compile}.
77
+ *
78
+ * The server plans a short chain of catalog edges for the pair (a position
79
+ * entry or exit, a wrap or unwrap, a mint or burn), optionally opened by a
80
+ * `lifi.swap`. {@link getZapPacks} lists the single edges; the pairs the
81
+ * planner connects are their closure up to the hop budget, which
82
+ * {@link buildReachability} computes locally. A pair the planner cannot
83
+ * connect is rejected with `kind: 'no_route_error'`.
84
+ *
85
+ * Only synchronous edges are considered unless the request sets
86
+ * `allowAsyncRoutes: true`, so by default every terminal output comes back
87
+ * `delivery.when: 'now'` and a pair reachable only after settlement is a
88
+ * `no_route_error`. Opting in adds the `lifi.zapAsync` fallback, which still
89
+ * loses to a synchronous edge when the pair has one; read
90
+ * `outputs[*].delivery.when` to see which representation you got.
91
+ *
92
+ * Use {@link compile} for what the server does not author for you: several
93
+ * chained operations, splits, explicit preconditions, or per-op guards.
94
+ *
95
+ * `bigint` amounts in `amount` are serialised to decimal strings
96
+ * automatically.
97
+ *
98
+ * @param request - The from/to token pair, amount, signer, and route options.
99
+ * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
100
+ * @throws {@link ComposeError} on network, validation, or server errors —
101
+ * including `NOT_FOUND` (HTTP 404) when the planner cannot connect the pair.
102
+ */
103
+ readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
104
+ /**
105
+ * Fetches the available routing edges grouped by protocol.
106
+ *
107
+ * The edge catalog is dynamic — it reflects the current state of the
108
+ * backend's routing snapshot (protocols, chains, token blacklists).
109
+ * Results are not cached by the SDK; callers should cache as appropriate.
110
+ *
111
+ * @param options - Optional filter to restrict results to specific protocols.
112
+ * @returns An array of {@link ZapPackOverview} objects, one per protocol.
113
+ * @throws {@link ComposeError} on network or server errors (503 when the
114
+ * routing catalog is not yet initialized).
115
+ */
116
+ readonly getZapPacks: (options?: GetZapPacksOptions) => Promise<readonly ZapPackOverview[]>;
117
+ /**
118
+ * Simulates a raw, pre-encoded transaction against `POST /simulate` and
119
+ * reports how the watched balances change and how much inner-call gas it
120
+ * burns.
121
+ *
122
+ * The result is a discriminated union on `status`:
123
+ * - `'ok'` — the simulation ran successfully; `deltas`/`gasUsed` are populated.
124
+ * - `'revert'` — the simulation ran but the transaction reverted on-chain. A
125
+ * revert is a *successful simulation*, not a transport error, so it is
126
+ * returned (HTTP 200) rather than thrown — mirroring how {@link compile}
127
+ * returns `status: 'partial'` on a simulated revert.
128
+ * - `'error'` — the request was well-formed but the simulation could not be
129
+ * set up or run (HTTP 422); `message` is intentionally generic.
130
+ *
131
+ * `bigint` amounts in the request (`value`, requirement `balance`/`allowance`)
132
+ * are serialised to decimal strings automatically.
133
+ *
134
+ * @param request - The raw transaction plus funding `requirements` and the
135
+ * `trackedBalances` to watch.
136
+ * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
137
+ * @throws {@link ComposeError} on network failures, HTTP 400 (malformed
138
+ * input), 401/403 (auth), 404, 429, and 5xx.
139
+ */
140
+ readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
141
141
  }
142
142
  /**
143
143
  * `JSON.stringify` replacer that renders `bigint` amounts as decimal strings.
@@ -146,13 +146,13 @@ interface ComposeClient {
146
146
  * no JSON representation, so every payload this client sends goes through it.
147
147
  * Exported so the example harness prints a request exactly as it is sent.
148
148
  */
149
- declare const bigintReplacer: (_key: string, value: unknown) => unknown;
149
+ export declare const bigintReplacer: (_key: string, value: unknown) => unknown;
150
150
  /**
151
151
  * Creates a low-level Compose API client.
152
152
  *
153
153
  * @param options - Client configuration including the API base URL.
154
154
  * @returns A {@link ComposeClient} instance.
155
155
  */
156
- declare const createComposeClient: (options: ComposeClientOptions) => ComposeClient;
157
-
158
- export { type ComposeClient, type ComposeClientOptions, bigintReplacer, createComposeClient };
156
+ export declare const createComposeClient: (options: ComposeClientOptions) => ComposeClient;
157
+ //#endregion
158
+ //# sourceMappingURL=client.d.ts.map