@lifi/composer-sdk 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- 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 +4 -4
- 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.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport type { ChainSummary } from './discovery.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Fetches the chains this Compose deployment supports, ascending by\n * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it\n * for what \"supported\" means and for the caching caveat.\n *\n * Each entry pairs the `chainId` with a display `name`, so one call both\n * gates a chain selector and labels it. Key on `chainId`; `name` is a\n * deployment-maintained label that can change.\n *\n * Use it to fail fast before building a flow for a chain the server would\n * reject.\n *\n * @returns The supported chains, ascending by `chainId`.\n * @throws {@link ComposeError} on network or server errors.\n *\n * @example\n * ```ts\n * const chains = await sdk.getSupportedChains();\n * if (!chains.some((c) => c.chainId === 8453)) {\n * throw new Error('Base is not supported');\n * }\n * for (const { chainId, name } of chains) {\n * console.log(`${name} (${chainId})`);\n * }\n * ```\n */\n readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain into a submit-ready transaction. Thin\n * pass-through to {@link ComposeClient.route}; see it for the short chain of\n * catalog edges the server plans, when to prefer `flow(...).compile(...)`,\n * the `success` / `partial` discrimination, and error behaviour. Build the\n * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n getSupportedChains: composeClient.getChains,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sdk.js","names":[],"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport type { ChainSummary } from './discovery.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Fetches the chains this Compose deployment supports, ascending by\n * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it\n * for what \"supported\" means and for the caching caveat.\n *\n * Each entry pairs the `chainId` with a display `name`, so one call both\n * gates a chain selector and labels it. Key on `chainId`; `name` is a\n * deployment-maintained label that can change.\n *\n * Use it to fail fast before building a flow for a chain the server would\n * reject.\n *\n * @returns The supported chains, ascending by `chainId`.\n * @throws {@link ComposeError} on network or server errors.\n *\n * @example\n * ```ts\n * const chains = await sdk.getSupportedChains();\n * if (!chains.some((c) => c.chainId === 8453)) {\n * throw new Error('Base is not supported');\n * }\n * for (const { chainId, name } of chains) {\n * console.log(`${name} (${chainId})`);\n * }\n * ```\n */\n readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain into a submit-ready transaction. Thin\n * pass-through to {@link ComposeClient.route}; see it for the short chain of\n * catalog edges the server plans, when to prefer `flow(...).compile(...)`,\n * the `success` / `partial` discrimination, and error behaviour. Build the\n * `amount` with `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n getSupportedChains: composeClient.getChains,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA6LA,MAAa,oBAAoB,YAA2C;CAC1E,MAAM,gBAAgB,oBAAoB,OAAO;CAEjD,MAAM,WACJ,SACA,SAC2B;EAC3B,MAAM;EACN,KAAK,SAAS;GACZ,QAAQ,IAAI;GACZ,eAAe,IAAI;GACnB,QAAQ,IAAI;GACZ,aAAa,IAAI;GACjB,UAAU,IAAI;GACd,kBAAkB,IAAI;GACtB,mBAAmB,IAAI;GACvB,SAAS,IAAI;GACb,kBAAkB,IAAI;GACtB,qBAAqB,IAAI;GACzB,wBAAwB,IAAI;EAC9B,CAAC;CACH;CAEA,MAAM,QACJ,SACA,SACmB;EACnB,MAAM,OAAO,sBAAsB,SAAS,IAAI;EAChD,MAAM,UAAU,OAAO,OAAO,MAAM,iBAAiB,IAAI,CAAC;EAE1D,MAAM,UAAU,OACd,QACkC;GAClC,MAAM,UAAU,QAAQ,MAAM;GAC9B,MAAM,MAAM,QAAQ,SAAS,GAAG;GAChC,OAAO,cAAc,QAAQ,GAAG;EAClC;EAEA,OAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;CAC3C;CAEA,OAAO;EACL,QAAQ;EACR;EACA,oBAAoB,cAAc;EAClC;EACA,OAAO,cAAc;EACrB,UAAU,cAAc;CAC1B;AACF"}
|
package/dist/types.cjs
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var types_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(types_exports);
|
|
17
|
-
//# sourceMappingURL=types.cjs.map
|
package/dist/types.d.cts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { InputSpec, LiteralBinding, MaterialiserInput, Ref, Resource, SolType } from "@lifi/compose-spec";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
5
5
|
* Uses a template literal type so that only numeric-looking strings
|
|
6
6
|
* are assignable at compile time.
|
|
7
7
|
*/
|
|
8
|
-
type IntegerString = `${bigint}`;
|
|
8
|
+
export type IntegerString = `${bigint}`;
|
|
9
9
|
/**
|
|
10
10
|
* Accepted input for integer-string config fields.
|
|
11
11
|
* Callers may pass either a numeric string ("1000000000") or a native bigint
|
|
12
12
|
* (1000000000n). Bigint values are stringified automatically during JSON
|
|
13
13
|
* serialization via the SDK's `bigintReplacer`.
|
|
14
14
|
*/
|
|
15
|
-
type IntegerStringInput = IntegerString | bigint;
|
|
15
|
+
export type IntegerStringInput = IntegerString | bigint;
|
|
16
16
|
/**
|
|
17
17
|
* A `0x`-prefixed hex string representing an Ethereum address.
|
|
18
18
|
* Template literal type catches obviously wrong values at compile time.
|
|
19
19
|
*/
|
|
20
|
-
type Address = `0x${string}`;
|
|
20
|
+
export type Address = `0x${string}`;
|
|
21
21
|
/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */
|
|
22
|
-
type OutputKind = SolType |
|
|
22
|
+
export type OutputKind = SolType | "resource";
|
|
23
23
|
/**
|
|
24
24
|
* Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the
|
|
25
25
|
* closest `OutputKind`. When the ABI type is one of the supported `SolType`
|
|
@@ -34,7 +34,7 @@ type OutputKind = SolType | 'resource';
|
|
|
34
34
|
* Extending `SolType` with new members automatically widens the exact-match
|
|
35
35
|
* branch — no changes needed here.
|
|
36
36
|
*/
|
|
37
|
-
type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
37
|
+
export type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
38
38
|
/**
|
|
39
39
|
* Phantom brand key for {@link TypedRef}.
|
|
40
40
|
*
|
|
@@ -42,7 +42,7 @@ type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
|
42
42
|
* typed ref from an arbitrary `{ $ref }` object. Keying it on a `unique
|
|
43
43
|
* symbol` means no caller can produce one by writing an object literal.
|
|
44
44
|
*/
|
|
45
|
-
declare const typedRefKind: unique symbol;
|
|
45
|
+
export declare const typedRefKind: unique symbol;
|
|
46
46
|
/**
|
|
47
47
|
* A typed `$ref` pointer carrying a phantom type parameter.
|
|
48
48
|
*
|
|
@@ -52,8 +52,8 @@ declare const typedRefKind: unique symbol;
|
|
|
52
52
|
* advertises: an untyped `{ $ref }` never enters a typed bind slot. Build one
|
|
53
53
|
* with `raw.ref<T>()`.
|
|
54
54
|
*/
|
|
55
|
-
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
56
|
-
|
|
55
|
+
export interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
56
|
+
readonly [typedRefKind]: T;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* A literal bind value carrying a phantom type parameter.
|
|
@@ -67,35 +67,35 @@ interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
|
67
67
|
*
|
|
68
68
|
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
69
69
|
*/
|
|
70
|
-
interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
export interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
71
|
+
readonly kind: T;
|
|
72
|
+
readonly __outputKind?: T;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* An input declaration in a flow schema.
|
|
76
76
|
* `Resource` values become resource inputs (token amounts);
|
|
77
77
|
* `SolType` strings become handle inputs (scalars like addresses).
|
|
78
78
|
*/
|
|
79
|
-
type InputDecl = Resource | SolType;
|
|
79
|
+
export type InputDecl = Resource | SolType;
|
|
80
80
|
/**
|
|
81
81
|
* A record mapping input names to their declarations.
|
|
82
82
|
* Used as the type parameter for generic flow builders and requests.
|
|
83
83
|
*/
|
|
84
|
-
type InputSchema = Record<string, InputDecl>;
|
|
84
|
+
export type InputSchema = Record<string, InputDecl>;
|
|
85
85
|
/**
|
|
86
86
|
* Maps an input declaration to the allowed runtime value type.
|
|
87
87
|
* Resource inputs accept materialisers or literal amounts.
|
|
88
88
|
* Handle inputs accept the scalar type matching their SolType.
|
|
89
89
|
*/
|
|
90
|
-
type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends
|
|
90
|
+
export type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends "address" ? Address : D extends "bool" ? boolean : D extends `${"u" | ""}int${string}` ? IntegerStringInput : D extends `bytes${string}` ? `0x${string}` : D extends "string" ? string : InputSpec;
|
|
91
91
|
/**
|
|
92
92
|
* A guard applied to an operation, with the `port` field constrained
|
|
93
93
|
* to a specific set of output port names.
|
|
94
94
|
*/
|
|
95
|
-
interface TypedGuard<Port extends string = string> {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
export interface TypedGuard<Port extends string = string> {
|
|
96
|
+
readonly kind: string;
|
|
97
|
+
readonly port: Port;
|
|
98
|
+
readonly [key: string]: unknown;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { InputSpec, LiteralBinding, MaterialiserInput, Ref, Resource, SolType } from "@lifi/compose-spec";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
5
5
|
* Uses a template literal type so that only numeric-looking strings
|
|
6
6
|
* are assignable at compile time.
|
|
7
7
|
*/
|
|
8
|
-
type IntegerString = `${bigint}`;
|
|
8
|
+
export type IntegerString = `${bigint}`;
|
|
9
9
|
/**
|
|
10
10
|
* Accepted input for integer-string config fields.
|
|
11
11
|
* Callers may pass either a numeric string ("1000000000") or a native bigint
|
|
12
12
|
* (1000000000n). Bigint values are stringified automatically during JSON
|
|
13
13
|
* serialization via the SDK's `bigintReplacer`.
|
|
14
14
|
*/
|
|
15
|
-
type IntegerStringInput = IntegerString | bigint;
|
|
15
|
+
export type IntegerStringInput = IntegerString | bigint;
|
|
16
16
|
/**
|
|
17
17
|
* A `0x`-prefixed hex string representing an Ethereum address.
|
|
18
18
|
* Template literal type catches obviously wrong values at compile time.
|
|
19
19
|
*/
|
|
20
|
-
type Address = `0x${string}`;
|
|
20
|
+
export type Address = `0x${string}`;
|
|
21
21
|
/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */
|
|
22
|
-
type OutputKind = SolType |
|
|
22
|
+
export type OutputKind = SolType | "resource";
|
|
23
23
|
/**
|
|
24
24
|
* Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the
|
|
25
25
|
* closest `OutputKind`. When the ABI type is one of the supported `SolType`
|
|
@@ -34,7 +34,7 @@ type OutputKind = SolType | 'resource';
|
|
|
34
34
|
* Extending `SolType` with new members automatically widens the exact-match
|
|
35
35
|
* branch — no changes needed here.
|
|
36
36
|
*/
|
|
37
|
-
type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
37
|
+
export type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
38
38
|
/**
|
|
39
39
|
* Phantom brand key for {@link TypedRef}.
|
|
40
40
|
*
|
|
@@ -42,7 +42,7 @@ type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
|
42
42
|
* typed ref from an arbitrary `{ $ref }` object. Keying it on a `unique
|
|
43
43
|
* symbol` means no caller can produce one by writing an object literal.
|
|
44
44
|
*/
|
|
45
|
-
declare const typedRefKind: unique symbol;
|
|
45
|
+
export declare const typedRefKind: unique symbol;
|
|
46
46
|
/**
|
|
47
47
|
* A typed `$ref` pointer carrying a phantom type parameter.
|
|
48
48
|
*
|
|
@@ -52,8 +52,8 @@ declare const typedRefKind: unique symbol;
|
|
|
52
52
|
* advertises: an untyped `{ $ref }` never enters a typed bind slot. Build one
|
|
53
53
|
* with `raw.ref<T>()`.
|
|
54
54
|
*/
|
|
55
|
-
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
56
|
-
|
|
55
|
+
export interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
56
|
+
readonly [typedRefKind]: T;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* A literal bind value carrying a phantom type parameter.
|
|
@@ -67,35 +67,35 @@ interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
|
67
67
|
*
|
|
68
68
|
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
69
69
|
*/
|
|
70
|
-
interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
export interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
71
|
+
readonly kind: T;
|
|
72
|
+
readonly __outputKind?: T;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* An input declaration in a flow schema.
|
|
76
76
|
* `Resource` values become resource inputs (token amounts);
|
|
77
77
|
* `SolType` strings become handle inputs (scalars like addresses).
|
|
78
78
|
*/
|
|
79
|
-
type InputDecl = Resource | SolType;
|
|
79
|
+
export type InputDecl = Resource | SolType;
|
|
80
80
|
/**
|
|
81
81
|
* A record mapping input names to their declarations.
|
|
82
82
|
* Used as the type parameter for generic flow builders and requests.
|
|
83
83
|
*/
|
|
84
|
-
type InputSchema = Record<string, InputDecl>;
|
|
84
|
+
export type InputSchema = Record<string, InputDecl>;
|
|
85
85
|
/**
|
|
86
86
|
* Maps an input declaration to the allowed runtime value type.
|
|
87
87
|
* Resource inputs accept materialisers or literal amounts.
|
|
88
88
|
* Handle inputs accept the scalar type matching their SolType.
|
|
89
89
|
*/
|
|
90
|
-
type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends
|
|
90
|
+
export type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends "address" ? Address : D extends "bool" ? boolean : D extends `${"u" | ""}int${string}` ? IntegerStringInput : D extends `bytes${string}` ? `0x${string}` : D extends "string" ? string : InputSpec;
|
|
91
91
|
/**
|
|
92
92
|
* A guard applied to an operation, with the `port` field constrained
|
|
93
93
|
* to a specific set of output port names.
|
|
94
94
|
*/
|
|
95
|
-
interface TypedGuard<Port extends string = string> {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
export interface TypedGuard<Port extends string = string> {
|
|
96
|
+
readonly kind: string;
|
|
97
|
+
readonly port: Port;
|
|
98
|
+
readonly [key: string]: unknown;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/composer-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Public Composer SDK for building and submitting flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsc --noEmit &&
|
|
32
|
+
"build": "tsc --noEmit && tsdown",
|
|
33
33
|
"clean": "rm -rf dist out",
|
|
34
34
|
"pack:local": "yarn build && mkdir -p out && yarn pack --out 'out/%s-%v.tgz'",
|
|
35
35
|
"generate": "tsx scripts/generate-sdk/index.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"example:staged": "tsx src/examples/run.ts --staged"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@lifi/compose-spec": "0.
|
|
50
|
+
"@lifi/compose-spec": "0.9.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"abitype": "^1.2.3",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"eslint-plugin-import": "^2.22.0",
|
|
68
68
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
69
69
|
"json-schema-to-typescript": "^15.0.4",
|
|
70
|
-
"
|
|
70
|
+
"tsdown": "^0.23.0",
|
|
71
71
|
"tsx": "^4.20.4",
|
|
72
72
|
"typescript": "^6.0.3",
|
|
73
73
|
"vitest": "^3.2.4"
|
package/src/client.ts
CHANGED
|
@@ -26,11 +26,11 @@ import {
|
|
|
26
26
|
parseSimulateResult,
|
|
27
27
|
} from './responseSchemas.js';
|
|
28
28
|
|
|
29
|
-
// __SDK_VERSION__ is a compile-time constant injected by
|
|
29
|
+
// __SDK_VERSION__ is a compile-time constant injected by tsdown (via `define` in tsdown.config.ts)
|
|
30
30
|
// and by vitest (via `define` in vitest.config.ts). Both read the version from package.json
|
|
31
31
|
// at build/test time and replace this identifier with the literal string value.
|
|
32
32
|
// It is sent as the `COMPOSER_SDK_VERSION_HEADER` request header so the server can identify the caller.
|
|
33
|
-
// Falls back to 'dev' when running via tsx without
|
|
33
|
+
// Falls back to 'dev' when running via tsx without tsdown substitution (e.g. the example harness).
|
|
34
34
|
declare const __SDK_VERSION__: string;
|
|
35
35
|
|
|
36
36
|
const SDK_VERSION: string =
|
|
@@ -64,8 +64,7 @@ export const buildEmitCustomEvent = ({
|
|
|
64
64
|
const flow = builder.build();
|
|
65
65
|
|
|
66
66
|
// No `sweepTo`: this flow only reads and emits a log — it moves no funds, so
|
|
67
|
-
// there are no proxy-held terminal resources to sweep.
|
|
68
|
-
// here would fail compilation with "no ... terminal resources ... to sweep".
|
|
67
|
+
// there are no proxy-held terminal resources to sweep.
|
|
69
68
|
const request = sdk.request(flow, {
|
|
70
69
|
signer: owner,
|
|
71
70
|
inputs: {},
|
package/src/examples/run.ts
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* redeem — redeem ERC-4626 vault shares via core.call
|
|
37
37
|
* wrap-eth — wrap native ETH into WETH via ValueCall
|
|
38
38
|
* transfer — transfer full token balance to a recipient
|
|
39
|
-
* partial-transfer —
|
|
39
|
+
* partial-transfer — split off a fixed amount with core.splitAt, transfer it, swap the rest
|
|
40
40
|
* untyped-ref — mix untypedOp with typed handles via raw.ref
|
|
41
41
|
* uniswap-v2-add — split USDC, swap half to WETH, add both to the Uniswap V2 pair
|
|
42
42
|
* uniswap-v3-mint — open a full-range Uniswap V3 USDC/WETH position
|
|
@@ -17,11 +17,9 @@ export interface TransferTokensInput {
|
|
|
17
17
|
* Transfer ERC-20 tokens from the proxy to an arbitrary recipient.
|
|
18
18
|
*
|
|
19
19
|
* Demonstrates:
|
|
20
|
-
* - `core.transfer` to move
|
|
20
|
+
* - `core.transfer` to move the whole input to a recipient address
|
|
21
21
|
* - Binding a scalar handle input (`recipient`) alongside a resource input
|
|
22
|
-
* -
|
|
23
|
-
* (omit to transfer the full balance)
|
|
24
|
-
* - The `transferred` and `remainder` output ports
|
|
22
|
+
* - The `transferred` output port
|
|
25
23
|
*/
|
|
26
24
|
export const buildTransferTokens = ({
|
|
27
25
|
owner,
|
|
@@ -41,8 +39,8 @@ export const buildTransferTokens = ({
|
|
|
41
39
|
},
|
|
42
40
|
});
|
|
43
41
|
|
|
44
|
-
// Transfer the full input amount to the recipient.
|
|
45
|
-
//
|
|
42
|
+
// Transfer the full input amount to the recipient. The `transferred` port
|
|
43
|
+
// tracks what the recipient received.
|
|
46
44
|
builder.core.transfer('send', {
|
|
47
45
|
bind: {
|
|
48
46
|
amount: builder.inputs.amountIn,
|
|
@@ -65,11 +63,12 @@ export const buildTransferTokens = ({
|
|
|
65
63
|
};
|
|
66
64
|
|
|
67
65
|
/**
|
|
68
|
-
* Transfer a
|
|
66
|
+
* Transfer a fixed amount and swap the rest.
|
|
69
67
|
*
|
|
70
68
|
* Demonstrates:
|
|
71
|
-
* - `
|
|
72
|
-
*
|
|
69
|
+
* - `core.splitAt` to carve a fixed sub-amount (`head`) out of a resource,
|
|
70
|
+
* leaving the rest in `tail`
|
|
71
|
+
* - Sending `head` with `core.transfer` and using `tail` in a later operation
|
|
73
72
|
*/
|
|
74
73
|
export const buildPartialTransfer = ({
|
|
75
74
|
owner,
|
|
@@ -89,19 +88,24 @@ export const buildPartialTransfer = ({
|
|
|
89
88
|
},
|
|
90
89
|
});
|
|
91
90
|
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
const
|
|
91
|
+
// Carve out a fixed 0.5 USDC (500000 base units at 6 decimals). Below that
|
|
92
|
+
// amount, `head` takes the whole input and `tail` is 0.
|
|
93
|
+
const { head, tail } = builder.core.splitAt('split', {
|
|
94
|
+
bind: { source: builder.inputs.amountIn },
|
|
95
|
+
config: { amount: '500000' },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
builder.core.transfer('send-half', {
|
|
95
99
|
bind: {
|
|
96
|
-
amount:
|
|
100
|
+
amount: head,
|
|
97
101
|
recipient: builder.inputs.recipient,
|
|
98
102
|
},
|
|
99
|
-
config: {
|
|
103
|
+
config: {},
|
|
100
104
|
});
|
|
101
105
|
|
|
102
|
-
//
|
|
103
|
-
builder.lifi.swap('swap-
|
|
104
|
-
bind: { amountIn:
|
|
106
|
+
// Swap the rest.
|
|
107
|
+
builder.lifi.swap('swap-rest', {
|
|
108
|
+
bind: { amountIn: tail },
|
|
105
109
|
config: {
|
|
106
110
|
resourceOut: resources.native(1),
|
|
107
111
|
slippage: 0.03,
|
|
@@ -12,6 +12,10 @@ export interface CoreSplitConfig {
|
|
|
12
12
|
bps: Between010000;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export interface CoreSplitAtConfig {
|
|
16
|
+
amount: IntegerStringInput;
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* an array of at most 16 item(s)
|
|
17
21
|
*
|
|
@@ -179,6 +183,10 @@ export interface CorePartitionConfig {
|
|
|
179
183
|
* a positive number
|
|
180
184
|
*/
|
|
181
185
|
export type Positive = number;
|
|
186
|
+
/**
|
|
187
|
+
* a number between 0 and 1
|
|
188
|
+
*/
|
|
189
|
+
export type Between01 = number;
|
|
182
190
|
/**
|
|
183
191
|
* a string at most 64 character(s) long
|
|
184
192
|
*/
|
|
@@ -204,7 +212,7 @@ export interface LifiSwapConfig {
|
|
|
204
212
|
token: Address;
|
|
205
213
|
chainId: Positive;
|
|
206
214
|
};
|
|
207
|
-
slippage?:
|
|
215
|
+
slippage?: Between01;
|
|
208
216
|
timing?: {
|
|
209
217
|
swapStepTimingStrategies?: {
|
|
210
218
|
strategy: 'minWaitTime';
|
|
@@ -230,10 +238,6 @@ export interface LifiSwapConfig {
|
|
|
230
238
|
* a string starting with "0x"
|
|
231
239
|
*/
|
|
232
240
|
export type StartsWith0X = string;
|
|
233
|
-
/**
|
|
234
|
-
* a number between 0 and 1
|
|
235
|
-
*/
|
|
236
|
-
export type Between01 = number;
|
|
237
241
|
|
|
238
242
|
export interface LifiBridgeConfig {
|
|
239
243
|
resourceOut:
|
|
@@ -343,9 +347,7 @@ export interface CoreBalanceOfConfig {
|
|
|
343
347
|
owner?: Address;
|
|
344
348
|
}
|
|
345
349
|
|
|
346
|
-
export
|
|
347
|
-
amount?: IntegerStringInput;
|
|
348
|
-
}
|
|
350
|
+
export type CoreTransferConfig = Record<string, never>;
|
|
349
351
|
|
|
350
352
|
export interface CoreEmitEvent1Config {
|
|
351
353
|
signature: string;
|
|
@@ -1237,7 +1239,16 @@ export interface CorePeekConfig {
|
|
|
1237
1239
|
*/
|
|
1238
1240
|
target: Address;
|
|
1239
1241
|
functionSignature: string;
|
|
1240
|
-
args?:
|
|
1242
|
+
args?: (
|
|
1243
|
+
| MaxLength65536
|
|
1244
|
+
| (
|
|
1245
|
+
| MaxLength65536
|
|
1246
|
+
| (
|
|
1247
|
+
| MaxLength65536
|
|
1248
|
+
| (MaxLength65536 | (MaxLength65536 | MaxLength65536[])[])[]
|
|
1249
|
+
)[]
|
|
1250
|
+
)[]
|
|
1251
|
+
)[];
|
|
1241
1252
|
}
|
|
1242
1253
|
|
|
1243
1254
|
/**
|
|
@@ -40,6 +40,7 @@ import type {
|
|
|
40
40
|
CorePartitionConfig,
|
|
41
41
|
CorePeekConfig,
|
|
42
42
|
CoreRawCallConfig,
|
|
43
|
+
CoreSplitAtConfig,
|
|
43
44
|
CoreSplitConfig,
|
|
44
45
|
CoreStaticCallConfig,
|
|
45
46
|
CoreTransferConfig,
|
|
@@ -79,6 +80,15 @@ export interface CoreSplitArgs {
|
|
|
79
80
|
readonly guards?: readonly TypedGuard<'a' | 'b'>[];
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/** Split a resource at a fixed amount. Output `head` receives `min(source, amount)`; `tail` receives the rest, and is 0 (omitted when unspent) when the source is at or below `amount`. */
|
|
84
|
+
export interface CoreSplitAtArgs {
|
|
85
|
+
readonly bind: {
|
|
86
|
+
readonly source: Bindable<'resource'>;
|
|
87
|
+
};
|
|
88
|
+
readonly config: CoreSplitAtConfig;
|
|
89
|
+
readonly guards?: readonly TypedGuard<'head' | 'tail'>[];
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
/** Partition a resource into one output per basis-point share. `bps` lists 2 to 16 shares summing to 10000; output `parts.i` receives share i, rounded down, and the last part takes the remainder. */
|
|
83
93
|
export interface CorePartitionArgs<
|
|
84
94
|
TBps extends FamilySource<CorePartitionConfig['bps']> = FamilySource<
|
|
@@ -415,14 +425,14 @@ export interface CoreBalanceOfArgs {
|
|
|
415
425
|
readonly guards?: readonly TypedGuard<'balance'>[];
|
|
416
426
|
}
|
|
417
427
|
|
|
418
|
-
/** Transfer
|
|
428
|
+
/** Transfer the whole input resource to a recipient address. To send part of a resource, split it first with `core.split` or `core.splitAt`. */
|
|
419
429
|
export interface CoreTransferArgs {
|
|
420
430
|
readonly bind: {
|
|
421
431
|
readonly amount: Bindable<'resource'>;
|
|
422
432
|
readonly recipient: Bindable<'address'>;
|
|
423
433
|
};
|
|
424
434
|
readonly config: CoreTransferConfig;
|
|
425
|
-
readonly guards?: readonly TypedGuard<'transferred'
|
|
435
|
+
readonly guards?: readonly TypedGuard<'transferred'>[];
|
|
426
436
|
}
|
|
427
437
|
|
|
428
438
|
/** Emit a custom on-chain event carrying 1 32-byte payload value. The value becomes a non-indexed data word in a fixed VM log event; the signature is hashed into a discriminator word (it is NOT an indexed EVM topic). */
|
|
@@ -710,6 +720,11 @@ export interface CoreSplitOutputs {
|
|
|
710
720
|
readonly b: OutputHandle<'resource'>;
|
|
711
721
|
}
|
|
712
722
|
|
|
723
|
+
export interface CoreSplitAtOutputs {
|
|
724
|
+
readonly head: OutputHandle<'resource'>;
|
|
725
|
+
readonly tail: OutputHandle<'resource'>;
|
|
726
|
+
}
|
|
727
|
+
|
|
713
728
|
export interface CorePartitionOutputs<
|
|
714
729
|
TBps extends FamilySource<CorePartitionConfig['bps']> = FamilySource<
|
|
715
730
|
CorePartitionConfig['bps']
|
|
@@ -766,7 +781,6 @@ export interface CoreBalanceOfOutputs {
|
|
|
766
781
|
|
|
767
782
|
export interface CoreTransferOutputs {
|
|
768
783
|
readonly transferred: OutputHandle<'resource'>;
|
|
769
|
-
readonly remainder: OutputHandle<'resource'>;
|
|
770
784
|
}
|
|
771
785
|
|
|
772
786
|
export interface CoreRawCallOutputs {
|
|
@@ -889,6 +903,11 @@ export type GeneratedOps = {
|
|
|
889
903
|
readonly core: {
|
|
890
904
|
/** Split a resource into two outputs by basis-point ratio. Output `a` receives `bps` of the source, rounded up, and `b` takes the remainder. — original id: "core.split" */
|
|
891
905
|
readonly split: (nodeId: string, args: CoreSplitArgs) => CoreSplitOutputs;
|
|
906
|
+
/** Split a resource at a fixed amount. Output `head` receives `min(source, amount)`; `tail` receives the rest, and is 0 (omitted when unspent) when the source is at or below `amount`. — original id: "core.splitAt" */
|
|
907
|
+
readonly splitAt: (
|
|
908
|
+
nodeId: string,
|
|
909
|
+
args: CoreSplitAtArgs,
|
|
910
|
+
) => CoreSplitAtOutputs;
|
|
892
911
|
/** Partition a resource into one output per basis-point share. `bps` lists 2 to 16 shares summing to 10000; output `parts.i` receives share i, rounded down, and the last part takes the remainder. — original id: "core.partition" */
|
|
893
912
|
readonly partition: <
|
|
894
913
|
const TBps extends FamilySource<CorePartitionConfig['bps']>,
|
|
@@ -954,7 +973,7 @@ export type GeneratedOps = {
|
|
|
954
973
|
nodeId: string,
|
|
955
974
|
args: CoreBalanceOfArgs,
|
|
956
975
|
) => CoreBalanceOfOutputs;
|
|
957
|
-
/** Transfer
|
|
976
|
+
/** Transfer the whole input resource to a recipient address. To send part of a resource, split it first with `core.split` or `core.splitAt`. — original id: "core.transfer" */
|
|
958
977
|
readonly transfer: (
|
|
959
978
|
nodeId: string,
|
|
960
979
|
args: CoreTransferArgs,
|
|
@@ -1173,6 +1192,11 @@ export const bindGeneratedOps = (
|
|
|
1173
1192
|
a: 'resource',
|
|
1174
1193
|
b: 'resource',
|
|
1175
1194
|
} as const),
|
|
1195
|
+
splitAt: (nodeId: string, args: CoreSplitAtArgs) =>
|
|
1196
|
+
builder.call(nodeId, 'core.splitAt', args, {
|
|
1197
|
+
head: 'resource',
|
|
1198
|
+
tail: 'resource',
|
|
1199
|
+
} as const),
|
|
1176
1200
|
partition: <const TBps extends FamilySource<CorePartitionConfig['bps']>>(
|
|
1177
1201
|
nodeId: string,
|
|
1178
1202
|
args: CorePartitionArgs<TBps>,
|
|
@@ -1237,7 +1261,6 @@ export const bindGeneratedOps = (
|
|
|
1237
1261
|
transfer: (nodeId: string, args: CoreTransferArgs) =>
|
|
1238
1262
|
builder.call(nodeId, 'core.transfer', args, {
|
|
1239
1263
|
transferred: 'resource',
|
|
1240
|
-
remainder: 'resource',
|
|
1241
1264
|
} as const),
|
|
1242
1265
|
emitEvent1: (nodeId: string, args: CoreEmitEvent1Args) =>
|
|
1243
1266
|
builder.call(nodeId, 'core.emitEvent1', args, {}),
|
package/dist/discovery.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/discovery.ts"],"sourcesContent":["/**\n * Types for the Compose discovery API (`GET /compose/zap-packs`, `GET /chains`).\n *\n * These are SDK-facing presentation types — not part of the core compile\n * contract in compose-spec. The backend response is the source of truth;\n * the SDK provides typed access.\n *\n * The `type` field on edges is a plain `string` rather than a strict union\n * so the SDK remains forward-compatible when the backend introduces new\n * edge types. Known values at time of writing:\n * `\"enter-position\"`, `\"exit-position\"`, `\"wrap\"`, `\"unwrap\"`, `\"mint\"`, `\"burn\"`.\n */\n\n/**\n * A chain the Compose deployment supports.\n */\nexport interface ChainSummary {\n /** EVM chain ID. The stable identifier — key on this. */\n readonly chainId: number;\n /**\n * Human-readable label, suitable for display in a chain selector.\n *\n * Maintained by the deployment rather than derived from canonical chain\n * branding, so it can differ from a chain's marketed name and can change\n * without notice. Never treat it as an identifier, and never match on it.\n * A chain the deployment has no configured label for reports `Chain <id>`.\n */\n readonly name: string;\n}\n\n/**\n * A single routing edge representing a supported token-to-token path\n * through a DeFi protocol.\n */\nexport interface ZapPackEdge {\n /** Edge type (e.g. `\"enter-position\"`, `\"exit-position\"`, `\"wrap\"`). */\n readonly type: string;\n /** Input token. */\n readonly in: { readonly address: string; readonly chainId: number };\n /** Output token. */\n readonly out: { readonly address: string; readonly chainId: number };\n /** Minimum input amount accepted (stringified integer), if constrained. */\n readonly inAmountMin?: string;\n /** Maximum input amount accepted (stringified integer), if constrained. */\n readonly inAmountMax?: string;\n /**\n * Recipient binding obligation. `\"required\"` means the zap must bind its\n * `recipient` input. The output is externally owned, terminal, and unswept.\n * The loose string type preserves forward compatibility with new values.\n */\n readonly recipient?: string;\n /**\n * Output availability. `\"future\"` means the output becomes available only\n * after the initiating transaction settles; route via `lifi.zapAsync` with\n * a bound recipient. Absent means the output is available synchronously.\n * The loose string type preserves forward compatibility with new values.\n */\n readonly availability?: string;\n}\n\n/**\n * All routing edges for a single protocol.\n */\nexport interface ZapPackOverview {\n /** Protocol identifier (e.g. `\"aave\"`, `\"morpho\"`). */\n readonly protocol: string;\n /** Available routing edges for this protocol. */\n readonly edges: readonly ZapPackEdge[];\n}\n\n/**\n * Options for {@link ComposeClient.getZapPacks}.\n */\nexport interface GetZapPacksOptions {\n /**\n * Filter to specific protocols. Pass a single string or an array.\n * Only edges belonging to the listed protocols are returned.\n * Omit to fetch all available protocols.\n */\n readonly protocols?: string | readonly string[];\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/discovery.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|