@lifi/composer-sdk 0.4.0 → 0.4.1
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 +95 -5
- package/dist/authoring/raw.cjs +3 -1
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.js +3 -1
- package/dist/authoring/raw.js.map +1 -1
- package/dist/client.cjs +26 -24
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +31 -1
- package/dist/client.d.ts +31 -1
- package/dist/client.js +26 -24
- package/dist/client.js.map +1 -1
- package/dist/discovery.cjs.map +1 -1
- package/dist/discovery.d.cts +13 -0
- package/dist/discovery.d.ts +13 -0
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +15 -3
- package/dist/generated/config.generated.d.ts +15 -3
- package/dist/generated/operations.generated.cjs +3 -0
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +17 -2
- package/dist/generated/operations.generated.d.ts +17 -2
- package/dist/generated/operations.generated.js +3 -0
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/routeAmount-DdbJYJyM.d.cts +55 -0
- package/dist/routeAmount-DdbJYJyM.d.ts +55 -0
- package/dist/routeAmount.cjs +38 -0
- package/dist/routeAmount.cjs.map +1 -0
- package/dist/routeAmount.d.cts +2 -0
- package/dist/routeAmount.d.ts +2 -0
- package/dist/routeAmount.js +13 -0
- package/dist/routeAmount.js.map +1 -0
- package/dist/sdk.cjs +1 -0
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +14 -1
- package/dist/sdk.d.ts +14 -1
- package/dist/sdk.js +1 -0
- package/dist/sdk.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring/raw.ts +3 -2
- package/src/client.ts +75 -23
- package/src/discovery.ts +13 -0
- package/src/examples/lifiZap.ts +4 -0
- package/src/examples/lifiZapAsync.ts +88 -0
- package/src/examples/routeTokenPair.ts +58 -0
- package/src/examples/run.ts +30 -5
- package/src/generated/config.generated.ts +21 -3
- package/src/generated/operations.generated.ts +30 -8
- package/src/index.ts +23 -0
- package/src/routeAmount.ts +61 -0
- package/src/sdk.ts +17 -0
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n} from './types.js';\n\nexport type {\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type {\n ComposeError,\n ComposeErrorCode,\n ComposePreparationOps,\n} from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeContinuation,\n ComposeErrorKind,\n ComposeTransactionRequest,\n FailedPreparedOp,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n SimulationPolicy,\n SimulationRevert,\n SolType,\n SweepTo,\n SimulateRequest,\n SimulateResult,\n SimulateOkResult,\n SimulateRevertResult,\n SimulateRevertDecodeResult,\n SimulateSetupErrorResult,\n SimulateBalanceEntry,\n TrackedBalance,\n SlotFinderRequirement,\n Erc20BalanceRequirement,\n NativeBalanceRequirement,\n Erc20AllowanceRequirement,\n ContinuationIntent,\n ContinuationOutcome,\n Check,\n CheckComparator,\n Phase1ArtifactWire,\n ContinuationPlanWire,\n} from '@lifi/compose-spec';\nexport {\n SIMULATE_MAX_TRACKED_BALANCES,\n SIMULATE_MAX_REQUIREMENTS,\n} from '@lifi/compose-spec';\nexport { isComposeError, isComposePreparationError } from './errors.js';\n\nexport type {\n Bindable,\n InputHandle,\n ResourceInputHandle,\n OutputHandle,\n AnyHandle,\n} from './authoring/handles.js';\nexport { isInputHandle, isOutputHandle } from './authoring/handles.js';\nexport { ref } from './authoring/raw.js';\n\nexport type { AnyBindable } from './authoring/FlowBuilderCore.js';\nexport type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';\n\nexport type { ComposeRunInput } from './run/inputs.js';\nexport { materialiser } from './run/inputs.js';\n\nexport { buildSimulateRequest } from './run/simulate.js';\nexport type { BuildSimulateRequestInput } from './run/simulate.js';\n\nexport { createComposeSdk } from './sdk.js';\nexport type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';\n\nimport * as guardsMod from './generated/guards.generated.js';\nimport * as materialisersMod from './generated/materialisers.generated.js';\nimport * as preconditionsMod from './generated/preconditions.generated.js';\nimport * as rawMod from './raw.js';\nimport * as resourcesMod from './resources.js';\n\n/**\n * Guard factories for protecting operation outputs (e.g. slippage tolerance).\n * Pass guards to an operation's `guards` array.\n *\n * @example\n * ```ts\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.token },\n * config: { resourceOut: resources.native(1) },\n * guards: [guards.slippage({ port: 'amountOut', bps: 300 })],\n * });\n * ```\n */\nexport const guards: typeof guardsMod = guardsMod;\n/**\n * Materialiser factories that tell the runtime how to resolve token input\n * amounts on-chain (e.g. read a wallet balance, accept a direct deposit).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0x...',\n * });\n * ```\n */\nexport const materialisers: typeof materialisersMod = materialisersMod;\n/**\n * Precondition factories for asserting on-chain state before a flow executes\n * (e.g. minimum token balances, ERC-20 allowances).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * preconditions: [\n * preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),\n * ],\n * signer: '0x...',\n * });\n * ```\n */\nexport const preconditions: typeof preconditionsMod = preconditionsMod;\n/**\n * Resource declaration helpers for defining token inputs in a flow schema.\n * Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}\n * for the chain's native coin (ETH, MATIC, etc.).\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: {\n * usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),\n * eth: resources.native(1),\n * },\n * });\n * ```\n */\nexport const resources: typeof resourcesMod = resourcesMod;\nexport * from './generated/config.generated.js';\n\n/**\n * Low-level escape hatch for constructing flow nodes, guards, and materialiser\n * inputs without the typed builder API. Prefer the generated operation methods\n * on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces\n * for most use cases.\n */\nexport const raw: typeof rawMod = rawMod;\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n} from './types.js';\n\nexport type {\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type {\n ComposeError,\n ComposeErrorCode,\n ComposePreparationOps,\n} from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeContinuation,\n ComposeErrorKind,\n ComposeRouteRequest,\n ComposeTransactionRequest,\n FailedPreparedOp,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n RouteAmount,\n RouteAmountAll,\n RouteAmountExact,\n SimulationPolicy,\n SimulationRevert,\n SolType,\n SweepTo,\n SimulateRequest,\n SimulateResult,\n SimulateOkResult,\n SimulateRevertResult,\n SimulateRevertDecodeResult,\n SimulateSetupErrorResult,\n SimulateBalanceEntry,\n TrackedBalance,\n SlotFinderRequirement,\n Erc20BalanceRequirement,\n NativeBalanceRequirement,\n Erc20AllowanceRequirement,\n ContinuationIntent,\n ContinuationOutcome,\n Check,\n CheckComparator,\n Phase1ArtifactWire,\n ContinuationPlanWire,\n} from '@lifi/compose-spec';\nexport {\n SIMULATE_MAX_TRACKED_BALANCES,\n SIMULATE_MAX_REQUIREMENTS,\n} from '@lifi/compose-spec';\nexport { isComposeError, isComposePreparationError } from './errors.js';\n\nexport type {\n Bindable,\n InputHandle,\n ResourceInputHandle,\n OutputHandle,\n AnyHandle,\n} from './authoring/handles.js';\nexport { isInputHandle, isOutputHandle } from './authoring/handles.js';\nexport { ref } from './authoring/raw.js';\n\nexport type { AnyBindable } from './authoring/FlowBuilderCore.js';\nexport type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';\n\nexport type { ComposeRunInput } from './run/inputs.js';\nexport { materialiser } from './run/inputs.js';\n\nexport { buildSimulateRequest } from './run/simulate.js';\nexport type { BuildSimulateRequestInput } from './run/simulate.js';\n\nexport { createComposeSdk } from './sdk.js';\nexport type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';\n\nimport * as guardsMod from './generated/guards.generated.js';\nimport * as materialisersMod from './generated/materialisers.generated.js';\nimport * as preconditionsMod from './generated/preconditions.generated.js';\nimport * as rawMod from './raw.js';\nimport * as resourcesMod from './resources.js';\nimport * as routeAmountMod from './routeAmount.js';\n\n/**\n * Guard factories for protecting operation outputs (e.g. slippage tolerance).\n * Pass guards to an operation's `guards` array.\n *\n * @example\n * ```ts\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.token },\n * config: { resourceOut: resources.native(1) },\n * guards: [guards.slippage({ port: 'amountOut', bps: 300 })],\n * });\n * ```\n */\nexport const guards: typeof guardsMod = guardsMod;\n/**\n * Materialiser factories that tell the runtime how to resolve token input\n * amounts on-chain (e.g. read a wallet balance, accept a direct deposit).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0x...',\n * });\n * ```\n */\nexport const materialisers: typeof materialisersMod = materialisersMod;\n/**\n * Precondition factories for asserting on-chain state before a flow executes\n * (e.g. minimum token balances, ERC-20 allowances).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * preconditions: [\n * preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),\n * ],\n * signer: '0x...',\n * });\n * ```\n */\nexport const preconditions: typeof preconditionsMod = preconditionsMod;\n/**\n * Resource declaration helpers for defining token inputs in a flow schema.\n * Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}\n * for the chain's native coin (ETH, MATIC, etc.).\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: {\n * usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),\n * eth: resources.native(1),\n * },\n * });\n * ```\n */\nexport const resources: typeof resourcesMod = resourcesMod;\n/**\n * Amount constructors for {@link ComposeSdk.route}. Use\n * {@link routeAmount.exact} to spend a fixed amount of the `fromToken`, and\n * {@link routeAmount.all} to spend the signer's whole balance.\n *\n * @example\n * ```ts\n * // USDC into the Aave v3 aEthUSDC position — one routing-catalog edge.\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n * toToken: '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c',\n * amount: routeAmount.exact(1_000_000n),\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport const routeAmount: typeof routeAmountMod = routeAmountMod;\nexport * from './generated/config.generated.js';\n\n/**\n * Low-level escape hatch for constructing flow nodes, guards, and materialiser\n * inputs without the typed builder API. Prefer the generated operation methods\n * on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces\n * for most use cases.\n */\nexport const raw: typeof rawMod = rawMod;\n"],"mappings":"AAiFA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB,iCAAiC;AAS1D,SAAS,eAAe,sBAAsB;AAC9C,SAAS,WAAW;AAMpB,SAAS,oBAAoB;AAE7B,SAAS,4BAA4B;AAGrC,SAAS,wBAAwB;AAGjC,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,sBAAsB;AAClC,YAAY,YAAY;AACxB,YAAY,kBAAkB;AAC9B,YAAY,oBAAoB;AAezB,MAAM,SAA2B;AAajC,MAAM,gBAAyC;AAgB/C,MAAM,gBAAyC;AAgB/C,MAAM,YAAiC;AAkBvC,MAAM,cAAqC;AAClD,cAAc;AAQP,MAAM,MAAqB;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
5
|
+
*
|
|
6
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
7
|
+
* to a decimal string when the request is sent.
|
|
8
|
+
* @returns The `EXACT` member of the route amount union.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result = await sdk.route({
|
|
13
|
+
* chainId: 1,
|
|
14
|
+
* fromToken: NATIVE_ETH,
|
|
15
|
+
* toToken: WETH,
|
|
16
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
17
|
+
* signer: OWNER,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const exact: (amount: bigint | string) => RouteAmountExact;
|
|
22
|
+
/**
|
|
23
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
24
|
+
* time.
|
|
25
|
+
*
|
|
26
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
27
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
28
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
29
|
+
*
|
|
30
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
31
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
32
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
33
|
+
* is whatever the balance turns out to be.
|
|
34
|
+
* @returns The `ALL` member of the route amount union.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const result = await sdk.route({
|
|
39
|
+
* chainId: 1,
|
|
40
|
+
* fromToken: USDC,
|
|
41
|
+
* toToken: A_ETH_USDC,
|
|
42
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
43
|
+
* signer: OWNER,
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare const all: (simAmount: bigint | string) => RouteAmountAll;
|
|
48
|
+
|
|
49
|
+
declare const routeAmountMod_all: typeof all;
|
|
50
|
+
declare const routeAmountMod_exact: typeof exact;
|
|
51
|
+
declare namespace routeAmountMod {
|
|
52
|
+
export { routeAmountMod_all as all, routeAmountMod_exact as exact };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { all as a, exact as e, routeAmountMod as r };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
5
|
+
*
|
|
6
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
7
|
+
* to a decimal string when the request is sent.
|
|
8
|
+
* @returns The `EXACT` member of the route amount union.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result = await sdk.route({
|
|
13
|
+
* chainId: 1,
|
|
14
|
+
* fromToken: NATIVE_ETH,
|
|
15
|
+
* toToken: WETH,
|
|
16
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
17
|
+
* signer: OWNER,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const exact: (amount: bigint | string) => RouteAmountExact;
|
|
22
|
+
/**
|
|
23
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
24
|
+
* time.
|
|
25
|
+
*
|
|
26
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
27
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
28
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
29
|
+
*
|
|
30
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
31
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
32
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
33
|
+
* is whatever the balance turns out to be.
|
|
34
|
+
* @returns The `ALL` member of the route amount union.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const result = await sdk.route({
|
|
39
|
+
* chainId: 1,
|
|
40
|
+
* fromToken: USDC,
|
|
41
|
+
* toToken: A_ETH_USDC,
|
|
42
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
43
|
+
* signer: OWNER,
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare const all: (simAmount: bigint | string) => RouteAmountAll;
|
|
48
|
+
|
|
49
|
+
declare const routeAmountMod_all: typeof all;
|
|
50
|
+
declare const routeAmountMod_exact: typeof exact;
|
|
51
|
+
declare namespace routeAmountMod {
|
|
52
|
+
export { routeAmountMod_all as all, routeAmountMod_exact as exact };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { all as a, exact as e, routeAmountMod as r };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all2) => {
|
|
7
|
+
for (var name in all2)
|
|
8
|
+
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var routeAmount_exports = {};
|
|
20
|
+
__export(routeAmount_exports, {
|
|
21
|
+
all: () => all,
|
|
22
|
+
exact: () => exact
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(routeAmount_exports);
|
|
25
|
+
const exact = (amount) => ({
|
|
26
|
+
type: "EXACT",
|
|
27
|
+
amount
|
|
28
|
+
});
|
|
29
|
+
const all = (simAmount) => ({
|
|
30
|
+
type: "ALL",
|
|
31
|
+
simAmount
|
|
32
|
+
});
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
all,
|
|
36
|
+
exact
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=routeAmount.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BO,MAAM,QAAQ,CAAC,YAA+C;AAAA,EACnE,MAAM;AAAA,EACN;AACF;AA2BO,MAAM,MAAM,CAAC,eAAgD;AAAA,EAClE,MAAM;AAAA,EACN;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":"AA2BO,MAAM,QAAQ,CAAC,YAA+C;AAAA,EACnE,MAAM;AAAA,EACN;AACF;AA2BO,MAAM,MAAM,CAAC,eAAgD;AAAA,EAClE,MAAM;AAAA,EACN;AACF;","names":[]}
|
package/dist/sdk.cjs
CHANGED
package/dist/sdk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain — as of today a single zap step over\n * one routing-catalog edge. Thin pass-through to\n * {@link ComposeClient.route}; see it for the current single-step limit,\n * when to prefer `flow(...).compile(...)`, the `success` / `partial`\n * discrimination, and error behaviour. Build the `amount` with\n * `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,6BAKO;AACP,oBAAwD;AACxD,kCAGO;AACP,oBAA+C;AA8IxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/sdk.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComposeCompileResult, ComposeCompileRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
|
|
1
|
+
import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
|
|
2
2
|
import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.cjs';
|
|
3
3
|
import { ComposeClient } from './client.cjs';
|
|
4
4
|
import { GeneratedOps } from './generated/operations.generated.cjs';
|
|
@@ -95,6 +95,19 @@ interface ComposeSdk {
|
|
|
95
95
|
* @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
|
|
96
96
|
*/
|
|
97
97
|
readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Compiles a token pair on one chain — as of today a single zap step over
|
|
100
|
+
* one routing-catalog edge. Thin pass-through to
|
|
101
|
+
* {@link ComposeClient.route}; see it for the current single-step limit,
|
|
102
|
+
* when to prefer `flow(...).compile(...)`, the `success` / `partial`
|
|
103
|
+
* discrimination, and error behaviour. Build the `amount` with
|
|
104
|
+
* `routeAmount.exact(...)` / `routeAmount.all(...)`.
|
|
105
|
+
*
|
|
106
|
+
* @param request - The from/to token pair, amount, signer, and route options.
|
|
107
|
+
* @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
|
|
108
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
109
|
+
*/
|
|
110
|
+
readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
|
|
98
111
|
/**
|
|
99
112
|
* Simulates a raw, pre-encoded transaction. Thin pass-through to
|
|
100
113
|
* {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComposeCompileResult, ComposeCompileRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
|
|
1
|
+
import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
|
|
2
2
|
import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.js';
|
|
3
3
|
import { ComposeClient } from './client.js';
|
|
4
4
|
import { GeneratedOps } from './generated/operations.generated.js';
|
|
@@ -95,6 +95,19 @@ interface ComposeSdk {
|
|
|
95
95
|
* @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
|
|
96
96
|
*/
|
|
97
97
|
readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Compiles a token pair on one chain — as of today a single zap step over
|
|
100
|
+
* one routing-catalog edge. Thin pass-through to
|
|
101
|
+
* {@link ComposeClient.route}; see it for the current single-step limit,
|
|
102
|
+
* when to prefer `flow(...).compile(...)`, the `success` / `partial`
|
|
103
|
+
* discrimination, and error behaviour. Build the `amount` with
|
|
104
|
+
* `routeAmount.exact(...)` / `routeAmount.all(...)`.
|
|
105
|
+
*
|
|
106
|
+
* @param request - The from/to token pair, amount, signer, and route options.
|
|
107
|
+
* @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
|
|
108
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
109
|
+
*/
|
|
110
|
+
readonly route: (request: ComposeRouteRequest) => Promise<ComposeCompileResult>;
|
|
98
111
|
/**
|
|
99
112
|
* Simulates a raw, pre-encoded transaction. Thin pass-through to
|
|
100
113
|
* {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
|
package/dist/sdk.js
CHANGED
package/dist/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain — as of today a single zap step over\n * one routing-catalog edge. Thin pass-through to\n * {@link ComposeClient.route}; see it for the current single-step limit,\n * when to prefer `flow(...).compile(...)`, the `success` / `partial`\n * discrimination, and error behaviour. Build the `amount` with\n * `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":"AASA;AAAA,EACE;AAAA,OAIK;AACP,SAA6B,2BAA2B;AACxD;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gBAAsC;AA8IxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,gBAAgB,oBAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,KAAK,SAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,OAAO,sBAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,MAAM,iBAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/composer-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Public Composer SDK for building and submitting flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"example:staged": "tsx src/examples/run.ts --staged"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@lifi/compose-spec": "0.4.
|
|
54
|
+
"@lifi/compose-spec": "0.4.1"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"abitype": "^1.2.3",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"@eslint/compat": "^1.4.0",
|
|
63
63
|
"@lifi/compose-spec": "workspace:^",
|
|
64
64
|
"@types/node": "^25.6.0",
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
66
|
-
"@typescript-eslint/parser": "^8.
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.68.0",
|
|
66
|
+
"@typescript-eslint/parser": "^8.68.0",
|
|
67
67
|
"eslint": "^9.36.0",
|
|
68
68
|
"eslint-config-prettier": "^9.0.0",
|
|
69
69
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"prettier": "^3.9.4",
|
|
75
75
|
"tsup": "^8.5.1",
|
|
76
76
|
"tsx": "^4.20.4",
|
|
77
|
-
"typescript": "^
|
|
77
|
+
"typescript": "^6.0.3",
|
|
78
78
|
"vitest": "^3.2.4"
|
|
79
79
|
},
|
|
80
80
|
"files": [
|
package/src/authoring/raw.ts
CHANGED
|
@@ -35,8 +35,9 @@ import type { OutputKind, TypedRef } from '../types.js';
|
|
|
35
35
|
* });
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export const ref = <T extends OutputKind>(path: string): TypedRef<T> =>
|
|
39
|
-
|
|
38
|
+
export const ref = <T extends OutputKind>(path: string): TypedRef<T> => ({
|
|
39
|
+
$ref: path,
|
|
40
|
+
});
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Creates a raw guard object for use in the `guards` array of an operation call.
|
package/src/client.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ComposeCompileResult,
|
|
5
5
|
ComposeCompileSuccessData,
|
|
6
6
|
ComposeManifest,
|
|
7
|
+
ComposeRouteRequest,
|
|
7
8
|
SimulateRequest,
|
|
8
9
|
SimulateResult,
|
|
9
10
|
} from '@lifi/compose-spec';
|
|
@@ -69,6 +70,38 @@ export interface ComposeClient {
|
|
|
69
70
|
readonly compile: (
|
|
70
71
|
request: ComposeCompileRequest,
|
|
71
72
|
) => Promise<ComposeCompileResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Compiles a token pair into a submit-ready transaction via
|
|
75
|
+
* `POST /compose/route`.
|
|
76
|
+
*
|
|
77
|
+
* A convenience path that skips flow authoring: the server builds a one-node
|
|
78
|
+
* `lifi.zap` flow with a `directDeposit` input from the `fromToken` /
|
|
79
|
+
* `toToken` pair and runs it through the same pipeline as {@link compile}.
|
|
80
|
+
* The response is therefore the same discriminated result — HTTP 206 under
|
|
81
|
+
* `simulationPolicy: 'allow-revert'` yields `status: 'partial'` rather than
|
|
82
|
+
* throwing, exactly as it does for {@link compile}.
|
|
83
|
+
*
|
|
84
|
+
* As of today that flow is a single zap step: one edge of the backend's
|
|
85
|
+
* routing catalog (a position entry or exit, a wrap or unwrap, a mint or
|
|
86
|
+
* burn). Enumerate the pairs it covers with {@link getZapPacks}; a pair with
|
|
87
|
+
* no edge is rejected with `kind: 'no_route_error'`. The endpoint is meant to
|
|
88
|
+
* author richer flows later, so the single-step limit is the current state of
|
|
89
|
+
* the server, not the shape of this contract.
|
|
90
|
+
*
|
|
91
|
+
* Use {@link compile} for what the server does not author for you: several
|
|
92
|
+
* chained operations, splits, explicit preconditions, or per-op guards.
|
|
93
|
+
*
|
|
94
|
+
* `bigint` amounts in `amount` are serialised to decimal strings
|
|
95
|
+
* automatically.
|
|
96
|
+
*
|
|
97
|
+
* @param request - The from/to token pair, amount, signer, and route options.
|
|
98
|
+
* @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
|
|
99
|
+
* @throws {@link ComposeError} on network, validation, or server errors —
|
|
100
|
+
* including `NOT_FOUND` (HTTP 404) when no catalog edge covers the pair.
|
|
101
|
+
*/
|
|
102
|
+
readonly route: (
|
|
103
|
+
request: ComposeRouteRequest,
|
|
104
|
+
) => Promise<ComposeCompileResult>;
|
|
72
105
|
/**
|
|
73
106
|
* Fetches the available routing edges grouped by protocol.
|
|
74
107
|
*
|
|
@@ -173,6 +206,39 @@ const parseSimulateBody = async (
|
|
|
173
206
|
}
|
|
174
207
|
return result;
|
|
175
208
|
};
|
|
209
|
+
// `POST /compose` and `POST /compose/route` differ only in path and request
|
|
210
|
+
// shape: both return the enveloped success data on 200 and the partial
|
|
211
|
+
// envelope on 206, so they share one transport.
|
|
212
|
+
type ComposeTransport = {
|
|
213
|
+
readonly fetchFn: typeof fetch;
|
|
214
|
+
readonly baseHeaders: Record<string, string>;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const postCompile = async (
|
|
218
|
+
{ fetchFn, baseHeaders }: ComposeTransport,
|
|
219
|
+
url: string,
|
|
220
|
+
request: ComposeCompileRequest | ComposeRouteRequest,
|
|
221
|
+
): Promise<ComposeCompileResult> => {
|
|
222
|
+
let res: Response;
|
|
223
|
+
try {
|
|
224
|
+
res = await fetchFn(url, {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
headers: { ...baseHeaders, 'Content-Type': 'application/json' },
|
|
227
|
+
body: JSON.stringify(request, bigintReplacer),
|
|
228
|
+
});
|
|
229
|
+
} catch (err) {
|
|
230
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
231
|
+
throw new ComposeError('NETWORK_ERROR', message, { cause: err });
|
|
232
|
+
}
|
|
233
|
+
if (res.status === 206) {
|
|
234
|
+
return await parsePartialBody(res, url);
|
|
235
|
+
}
|
|
236
|
+
if (!res.ok) {
|
|
237
|
+
const body = await res.text();
|
|
238
|
+
throw errorFromHttpResponse(res.status, body, url);
|
|
239
|
+
}
|
|
240
|
+
return await parseCompileSuccessBody(res, url);
|
|
241
|
+
};
|
|
176
242
|
|
|
177
243
|
/**
|
|
178
244
|
* Creates a low-level Compose API client.
|
|
@@ -204,6 +270,7 @@ export const createComposeClient = (
|
|
|
204
270
|
'x-lifi-composer-sdk': SDK_VERSION,
|
|
205
271
|
'x-lifi-api-key': trimmedApiKey,
|
|
206
272
|
};
|
|
273
|
+
const transport: ComposeTransport = { fetchFn, baseHeaders };
|
|
207
274
|
|
|
208
275
|
const getManifest = async (): Promise<ComposeManifest> => {
|
|
209
276
|
const url = `${base}/compose/manifest`;
|
|
@@ -226,28 +293,13 @@ export const createComposeClient = (
|
|
|
226
293
|
|
|
227
294
|
const compile = async (
|
|
228
295
|
request: ComposeCompileRequest,
|
|
229
|
-
): Promise<ComposeCompileResult> =>
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
body: JSON.stringify(request, bigintReplacer),
|
|
237
|
-
});
|
|
238
|
-
} catch (err) {
|
|
239
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
240
|
-
throw new ComposeError('NETWORK_ERROR', message, { cause: err });
|
|
241
|
-
}
|
|
242
|
-
if (res.status === 206) {
|
|
243
|
-
return await parsePartialBody(res, url);
|
|
244
|
-
}
|
|
245
|
-
if (!res.ok) {
|
|
246
|
-
const body = await res.text();
|
|
247
|
-
throw errorFromHttpResponse(res.status, body, url);
|
|
248
|
-
}
|
|
249
|
-
return await parseCompileSuccessBody(res, url);
|
|
250
|
-
};
|
|
296
|
+
): Promise<ComposeCompileResult> =>
|
|
297
|
+
postCompile(transport, `${base}/compose`, request);
|
|
298
|
+
|
|
299
|
+
const route = async (
|
|
300
|
+
request: ComposeRouteRequest,
|
|
301
|
+
): Promise<ComposeCompileResult> =>
|
|
302
|
+
postCompile(transport, `${base}/compose/route`, request);
|
|
251
303
|
|
|
252
304
|
const getZapPacks = async (
|
|
253
305
|
options?: GetZapPacksOptions,
|
|
@@ -306,5 +358,5 @@ export const createComposeClient = (
|
|
|
306
358
|
throw errorFromHttpResponse(res.status, body, url);
|
|
307
359
|
};
|
|
308
360
|
|
|
309
|
-
return { getManifest, compile, getZapPacks, simulate };
|
|
361
|
+
return { getManifest, compile, route, getZapPacks, simulate };
|
|
310
362
|
};
|
package/src/discovery.ts
CHANGED
|
@@ -26,6 +26,19 @@ export interface ZapPackEdge {
|
|
|
26
26
|
readonly inAmountMin?: string;
|
|
27
27
|
/** Maximum input amount accepted (stringified integer), if constrained. */
|
|
28
28
|
readonly inAmountMax?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Recipient binding obligation. `"required"` means the zap must bind its
|
|
31
|
+
* `recipient` input. The output is externally owned, terminal, and unswept.
|
|
32
|
+
* The loose string type preserves forward compatibility with new values.
|
|
33
|
+
*/
|
|
34
|
+
readonly recipient?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Output availability. `"future"` means the output becomes available only
|
|
37
|
+
* after the initiating transaction settles; route via `lifi.zapAsync` with
|
|
38
|
+
* a bound recipient. Absent means the output is available synchronously.
|
|
39
|
+
* The loose string type preserves forward compatibility with new values.
|
|
40
|
+
*/
|
|
41
|
+
readonly availability?: string;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
/**
|
package/src/examples/lifiZap.ts
CHANGED
|
@@ -53,6 +53,10 @@ export const buildLifiZapExample = (): {
|
|
|
53
53
|
inputs: {
|
|
54
54
|
amountIn: materialisers.directDeposit({ amount: '1000000000' }),
|
|
55
55
|
},
|
|
56
|
+
// This zap's edge keeps `amountOut` inside the execution VM, so sweeping
|
|
57
|
+
// leftovers back to the sender is safe. Omit `sweepTo` for an edge that
|
|
58
|
+
// delivers externally (`recipient: 'required'` in discovery): the output
|
|
59
|
+
// never enters the VM, so a sweep would find nothing to move.
|
|
56
60
|
sweepTo: builder.context.sender,
|
|
57
61
|
});
|
|
58
62
|
|