@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.
- package/README.md +4 -3
- package/dist/_virtual/_rolldown/runtime.cjs +33 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/authoring/FlowBuilderCore.cjs +102 -120
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
- package/dist/authoring/FlowBuilderCore.d.cts +58 -61
- package/dist/authoring/FlowBuilderCore.d.ts +58 -61
- package/dist/authoring/FlowBuilderCore.js +99 -97
- package/dist/authoring/FlowBuilderCore.js.map +1 -1
- package/dist/authoring/handles.cjs +25 -40
- package/dist/authoring/handles.cjs.map +1 -1
- package/dist/authoring/handles.d.cts +33 -34
- package/dist/authoring/handles.d.ts +33 -34
- package/dist/authoring/handles.js +21 -13
- package/dist/authoring/handles.js.map +1 -1
- package/dist/authoring/raw.cjs +85 -44
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.d.cts +8 -8
- package/dist/authoring/raw.d.ts +8 -8
- package/dist/authoring/raw.js +83 -19
- package/dist/authoring/raw.js.map +1 -1
- package/dist/authoring/signatureArgs.cjs +81 -103
- package/dist/authoring/signatureArgs.cjs.map +1 -1
- package/dist/authoring/signatureArgs.d.cts +63 -64
- package/dist/authoring/signatureArgs.d.ts +63 -64
- package/dist/authoring/signatureArgs.js +76 -75
- package/dist/authoring/signatureArgs.js.map +1 -1
- package/dist/client.cjs +172 -220
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +131 -131
- package/dist/client.d.ts +131 -131
- package/dist/client.js +165 -198
- package/dist/client.js.map +1 -1
- package/dist/discovery.cjs +0 -17
- package/dist/discovery.d.cts +57 -56
- package/dist/discovery.d.ts +57 -56
- package/dist/discovery.js +1 -1
- package/dist/errors.cjs +211 -159
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +84 -84
- package/dist/errors.d.ts +84 -84
- package/dist/errors.js +201 -120
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.cjs +0 -17
- package/dist/generated/config.generated.d.cts +804 -936
- package/dist/generated/config.generated.d.ts +804 -936
- package/dist/generated/config.generated.js +1 -1
- package/dist/generated/guards.generated.cjs +25 -35
- package/dist/generated/guards.generated.cjs.map +1 -1
- package/dist/generated/guards.generated.d.cts +20 -4
- package/dist/generated/guards.generated.d.ts +20 -4
- package/dist/generated/guards.generated.js +19 -11
- package/dist/generated/guards.generated.js.map +1 -1
- package/dist/generated/materialisers.generated.cjs +25 -35
- package/dist/generated/materialisers.generated.cjs.map +1 -1
- package/dist/generated/materialisers.generated.d.cts +17 -4
- package/dist/generated/materialisers.generated.d.ts +17 -4
- package/dist/generated/materialisers.generated.js +19 -11
- package/dist/generated/materialisers.generated.js.map +1 -1
- package/dist/generated/operations.generated.cjs +236 -277
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +719 -708
- package/dist/generated/operations.generated.d.ts +719 -708
- package/dist/generated/operations.generated.js +235 -256
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/generated/preconditions.generated.cjs +25 -35
- package/dist/generated/preconditions.generated.cjs.map +1 -1
- package/dist/generated/preconditions.generated.d.cts +17 -4
- package/dist/generated/preconditions.generated.d.ts +17 -4
- package/dist/generated/preconditions.generated.js +19 -11
- package/dist/generated/preconditions.generated.js.map +1 -1
- package/dist/index.cjs +131 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -43
- package/dist/index.d.ts +29 -43
- package/dist/index.js +96 -45
- package/dist/index.js.map +1 -1
- package/dist/outputs.cjs +11 -32
- package/dist/outputs.cjs.map +1 -1
- package/dist/outputs.d.cts +5 -5
- package/dist/outputs.d.ts +5 -5
- package/dist/outputs.js +10 -8
- package/dist/outputs.js.map +1 -1
- package/dist/raw.cjs +21 -33
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.cts +8 -4
- package/dist/raw.d.ts +8 -4
- package/dist/raw.js +12 -7
- package/dist/raw.js.map +1 -1
- package/dist/reachability.cjs +82 -112
- package/dist/reachability.cjs.map +1 -1
- package/dist/reachability.d.cts +33 -59
- package/dist/reachability.d.ts +33 -59
- package/dist/reachability.js +81 -88
- package/dist/reachability.js.map +1 -1
- package/dist/resources.cjs +47 -32
- package/dist/resources.cjs.map +1 -1
- package/dist/resources.d.cts +50 -3
- package/dist/resources.d.ts +50 -3
- package/dist/resources.js +42 -9
- package/dist/resources.js.map +1 -1
- package/dist/responseSchemas.cjs +99 -111
- package/dist/responseSchemas.cjs.map +1 -1
- package/dist/responseSchemas.d.cts +34 -34
- package/dist/responseSchemas.d.ts +34 -34
- package/dist/responseSchemas.js +85 -66
- package/dist/responseSchemas.js.map +1 -1
- package/dist/routeAmount.cjs +61 -31
- package/dist/routeAmount.cjs.map +1 -1
- package/dist/routeAmount.d.cts +52 -2
- package/dist/routeAmount.d.ts +52 -2
- package/dist/routeAmount.js +56 -8
- package/dist/routeAmount.js.map +1 -1
- package/dist/run/inputs.cjs +56 -48
- package/dist/run/inputs.cjs.map +1 -1
- package/dist/run/inputs.d.cts +70 -74
- package/dist/run/inputs.d.ts +70 -74
- package/dist/run/inputs.js +54 -23
- package/dist/run/inputs.js.map +1 -1
- package/dist/run/simulate.cjs +38 -43
- package/dist/run/simulate.cjs.map +1 -1
- package/dist/run/simulate.d.cts +36 -36
- package/dist/run/simulate.d.ts +36 -36
- package/dist/run/simulate.js +37 -19
- package/dist/run/simulate.js.map +1 -1
- package/dist/sdk.cjs +55 -66
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +108 -111
- package/dist/sdk.d.ts +108 -111
- package/dist/sdk.js +52 -44
- package/dist/sdk.js.map +1 -1
- package/dist/types.cjs +0 -17
- package/dist/types.d.cts +22 -22
- package/dist/types.d.ts +22 -22
- package/dist/types.js +1 -1
- package/package.json +5 -5
- package/src/client.ts +2 -2
- package/src/examples/aaveClaimRewards.ts +2 -1
- package/src/examples/emitCustomEvent.ts +1 -2
- package/src/examples/run.ts +1 -1
- package/src/examples/transferTokens.ts +21 -17
- package/src/generated/config.generated.ts +20 -9
- package/src/generated/operations.generated.ts +28 -5
- package/dist/discovery.cjs.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/generated/config.generated.cjs.map +0 -1
- package/dist/generated/config.generated.js.map +0 -1
- package/dist/guards.generated-CDCgYGZo.d.cts +0 -24
- package/dist/guards.generated-CdYcs4h0.d.ts +0 -24
- package/dist/materialisers.generated-BMkBQgWZ.d.ts +0 -24
- package/dist/materialisers.generated-BWq5oePO.d.cts +0 -24
- package/dist/preconditions.generated-DblS13Wq.d.cts +0 -24
- package/dist/preconditions.generated-U7YpVh30.d.ts +0 -24
- package/dist/raw-BvRghN3r.d.ts +0 -20
- package/dist/raw-s1rer8X3.d.cts +0 -20
- package/dist/resources-BKlFxjo8.d.cts +0 -56
- package/dist/resources-CYis1_DS.d.ts +0 -56
- package/dist/routeAmount-DdbJYJyM.d.cts +0 -55
- package/dist/routeAmount-DdbJYJyM.d.ts +0 -55
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/sdk.d.cts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { GeneratedOps } from
|
|
6
|
-
import { ComposeRunInput } from
|
|
7
|
-
import {
|
|
8
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { GeneratedOps } from
|
|
6
|
-
import { ComposeRunInput } from
|
|
7
|
-
import {
|
|
8
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|