@lifi/composer-sdk 0.4.1 → 0.5.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 +6 -3
- package/dist/authoring/FlowBuilderCore.cjs +1 -5
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
- package/dist/authoring/FlowBuilderCore.d.cts +9 -7
- package/dist/authoring/FlowBuilderCore.d.ts +9 -7
- package/dist/authoring/FlowBuilderCore.js +2 -6
- package/dist/authoring/FlowBuilderCore.js.map +1 -1
- package/dist/authoring/handles.cjs +5 -2
- package/dist/authoring/handles.cjs.map +1 -1
- package/dist/authoring/handles.d.cts +25 -6
- package/dist/authoring/handles.d.ts +25 -6
- package/dist/authoring/handles.js +3 -1
- package/dist/authoring/handles.js.map +1 -1
- package/dist/authoring/raw.cjs +3 -0
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.d.cts +33 -3
- package/dist/authoring/raw.d.ts +33 -3
- package/dist/authoring/raw.js +2 -0
- package/dist/authoring/raw.js.map +1 -1
- package/dist/authoring/signatureArgs.cjs.map +1 -1
- package/dist/authoring/signatureArgs.d.cts +16 -12
- package/dist/authoring/signatureArgs.d.ts +16 -12
- package/dist/authoring/signatureArgs.js.map +1 -1
- package/dist/client.cjs +112 -55
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +42 -5
- package/dist/client.d.ts +42 -5
- package/dist/client.js +116 -55
- package/dist/client.js.map +1 -1
- package/dist/discovery.cjs.map +1 -1
- package/dist/discovery.d.cts +18 -2
- package/dist/discovery.d.ts +18 -2
- package/dist/errors.cjs +42 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +67 -4
- package/dist/errors.d.ts +67 -4
- package/dist/errors.js +29 -2
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +21 -1
- package/dist/generated/config.generated.d.ts +21 -1
- package/dist/generated/operations.generated.cjs +6 -0
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +18 -2
- package/dist/generated/operations.generated.d.ts +18 -2
- package/dist/generated/operations.generated.js +6 -0
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/{raw-IxCF_bSS.d.ts → raw-BvRghN3r.d.ts} +3 -2
- package/dist/{raw-Dj_2rBSQ.d.cts → raw-s1rer8X3.d.cts} +3 -2
- package/dist/raw.cjs +2 -0
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.cts +1 -1
- package/dist/raw.d.ts +1 -1
- package/dist/raw.js +2 -1
- package/dist/raw.js.map +1 -1
- package/dist/responseSchemas.cjs +3 -0
- package/dist/responseSchemas.cjs.map +1 -1
- package/dist/responseSchemas.d.cts +3 -0
- package/dist/responseSchemas.d.ts +3 -0
- package/dist/responseSchemas.js +3 -0
- package/dist/responseSchemas.js.map +1 -1
- package/dist/run/inputs.cjs +14 -15
- package/dist/run/inputs.cjs.map +1 -1
- package/dist/run/inputs.d.cts +8 -0
- package/dist/run/inputs.d.ts +8 -0
- package/dist/run/inputs.js +14 -15
- package/dist/run/inputs.js.map +1 -1
- package/dist/run/simulate.cjs +5 -0
- package/dist/run/simulate.cjs.map +1 -1
- package/dist/run/simulate.d.cts +5 -2
- package/dist/run/simulate.d.ts +5 -2
- package/dist/run/simulate.js +5 -0
- package/dist/run/simulate.js.map +1 -1
- package/dist/sdk.cjs +2 -0
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +28 -1
- package/dist/sdk.d.ts +28 -1
- package/dist/sdk.js +2 -0
- package/dist/sdk.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +18 -2
- package/dist/types.d.ts +18 -2
- package/package.json +3 -10
- package/src/authoring/FlowBuilderCore.ts +13 -15
- package/src/authoring/handles.ts +41 -5
- package/src/authoring/raw.ts +36 -2
- package/src/authoring/signatureArgs.ts +17 -13
- package/src/client.ts +222 -62
- package/src/discovery.ts +18 -1
- package/src/errors.ts +116 -3
- package/src/examples/flySwap.ts +167 -0
- package/src/examples/run.ts +35 -13
- package/src/examples/supportedChains.ts +122 -0
- package/src/generated/config.generated.ts +24 -0
- package/src/generated/operations.generated.ts +26 -0
- package/src/index.ts +18 -2
- package/src/raw.ts +1 -1
- package/src/responseSchemas.ts +6 -0
- package/src/run/inputs.ts +30 -11
- package/src/run/simulate.ts +14 -2
- package/src/sdk.ts +30 -0
- package/src/types.ts +20 -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 {\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;
|
|
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 — 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 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":"AASA;AAAA,EACE;AAAA,OAIK;AACP,SAA6B,2BAA2B;AAExD;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gBAAsC;AAyKxC,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,qBAAqB,IAAI;AAAA,MACzB,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,oBAAoB,cAAc;AAAA,IAClC;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Ref } from '@lifi/compose-spec';\nimport {\n InputSpec,\n MaterialiserInput,\n Resource,\n SolType,\n} from '@lifi/compose-spec';\n\n/**\n * A string that represents a non-negative integer (e.g. \"1000000000\").\n * Uses a template literal type so that only numeric-looking strings\n * are assignable at compile time.\n */\nexport type IntegerString = `${bigint}`;\n\n/**\n * Accepted input for integer-string config fields.\n * Callers may pass either a numeric string (\"1000000000\") or a native bigint\n * (1000000000n). Bigint values are stringified automatically during JSON\n * serialization via the SDK's `bigintReplacer`.\n */\nexport type IntegerStringInput = IntegerString | bigint;\n\n/**\n * A `0x`-prefixed hex string representing an Ethereum address.\n * Template literal type catches obviously wrong values at compile time.\n */\nexport type Address = `0x${string}`;\n\n/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */\nexport type OutputKind = SolType | 'resource';\n\n/**\n * Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the\n * closest `OutputKind`. When the ABI type is one of the supported `SolType`\n * scalars, the mapping is exact; for all other Solidity types (e.g. tuples,\n * fixed-point decimals) it falls back to `SolType` — accepting any scalar\n * handle but not `'resource'` handles.\n *\n * The fallback excludes `'resource'` because every Solidity type is a scalar;\n * resource handles carry token-amount semantics that should only flow into\n * slots explicitly declared as resources.\n *\n * Extending `SolType` with new members automatically widens the exact-match\n * branch — no changes needed here.\n */\nexport type AbiTypeToOutputKind<T extends string> = T extends SolType\n ? T\n : SolType;\n\n/**\n * A typed `$ref` pointer carrying a phantom type parameter.\n * Extends `Ref` so it is accepted anywhere a plain `Ref` is.\n * The `__outputKind` field is never set at runtime — it exists only\n * for TypeScript's structural type checker to distinguish typed refs.\n */\nexport interface TypedRef<T extends OutputKind = OutputKind> extends Ref {\n readonly __outputKind?: T;\n}\n\n/**\n * An input declaration in a flow schema.\n * `Resource` values become resource inputs (token amounts);\n * `SolType` strings become handle inputs (scalars like addresses).\n */\nexport type InputDecl = Resource | SolType;\n\n/**\n * A record mapping input names to their declarations.\n * Used as the type parameter for generic flow builders and requests.\n */\nexport type InputSchema = Record<string, InputDecl>;\n\n/**\n * Maps an input declaration to the allowed runtime value type.\n * Resource inputs accept materialisers or literal amounts.\n * Handle inputs accept the scalar type matching their SolType.\n */\nexport type InputSpecOf<D> = D extends Resource\n ? MaterialiserInput | IntegerStringInput\n : D extends 'address'\n ? Address\n : D extends 'bool'\n ? boolean\n : D extends `${'u' | ''}int${string}`\n ? IntegerStringInput\n : D extends `bytes${string}`\n ? `0x${string}`\n : D extends 'string'\n ? string\n : InputSpec;\n\n/**\n * A guard applied to an operation, with the `port` field constrained\n * to a specific set of output port names.\n */\nexport interface TypedGuard<Port extends string = string> {\n readonly kind: string;\n readonly port: Port;\n readonly [key: string]: unknown;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { LiteralBinding, Ref } from '@lifi/compose-spec';\nimport {\n InputSpec,\n MaterialiserInput,\n Resource,\n SolType,\n} from '@lifi/compose-spec';\n\n/**\n * A string that represents a non-negative integer (e.g. \"1000000000\").\n * Uses a template literal type so that only numeric-looking strings\n * are assignable at compile time.\n */\nexport type IntegerString = `${bigint}`;\n\n/**\n * Accepted input for integer-string config fields.\n * Callers may pass either a numeric string (\"1000000000\") or a native bigint\n * (1000000000n). Bigint values are stringified automatically during JSON\n * serialization via the SDK's `bigintReplacer`.\n */\nexport type IntegerStringInput = IntegerString | bigint;\n\n/**\n * A `0x`-prefixed hex string representing an Ethereum address.\n * Template literal type catches obviously wrong values at compile time.\n */\nexport type Address = `0x${string}`;\n\n/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */\nexport type OutputKind = SolType | 'resource';\n\n/**\n * Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the\n * closest `OutputKind`. When the ABI type is one of the supported `SolType`\n * scalars, the mapping is exact; for all other Solidity types (e.g. tuples,\n * fixed-point decimals) it falls back to `SolType` — accepting any scalar\n * handle but not `'resource'` handles.\n *\n * The fallback excludes `'resource'` because every Solidity type is a scalar;\n * resource handles carry token-amount semantics that should only flow into\n * slots explicitly declared as resources.\n *\n * Extending `SolType` with new members automatically widens the exact-match\n * branch — no changes needed here.\n */\nexport type AbiTypeToOutputKind<T extends string> = T extends SolType\n ? T\n : SolType;\n\n/**\n * A typed `$ref` pointer carrying a phantom type parameter.\n * Extends `Ref` so it is accepted anywhere a plain `Ref` is.\n * The `__outputKind` field is never set at runtime — it exists only\n * for TypeScript's structural type checker to distinguish typed refs.\n */\nexport interface TypedRef<T extends OutputKind = OutputKind> extends Ref {\n readonly __outputKind?: T;\n}\n\n/**\n * A literal bind value carrying a phantom type parameter.\n *\n * The wire format accepts a constant in a bind slot as\n * `{ kind: <solType>, value: <string> }`, alongside `$ref` pointers. Use it\n * for a value that must be baked into the flow document rather than supplied\n * at run time — the destination of a flow the backend stores and re-runs\n * later (a `continuation.settle` node's `continuationFlow`) has no run to\n * take an input from.\n *\n * @typeParam T - The Solidity type of the literal (e.g. `'address'`).\n */\nexport interface TypedLiteral<\n T extends SolType = SolType,\n> extends LiteralBinding {\n readonly kind: T;\n readonly __outputKind?: T;\n}\n\n/**\n * An input declaration in a flow schema.\n * `Resource` values become resource inputs (token amounts);\n * `SolType` strings become handle inputs (scalars like addresses).\n */\nexport type InputDecl = Resource | SolType;\n\n/**\n * A record mapping input names to their declarations.\n * Used as the type parameter for generic flow builders and requests.\n */\nexport type InputSchema = Record<string, InputDecl>;\n\n/**\n * Maps an input declaration to the allowed runtime value type.\n * Resource inputs accept materialisers or literal amounts.\n * Handle inputs accept the scalar type matching their SolType.\n */\nexport type InputSpecOf<D> = D extends Resource\n ? MaterialiserInput | IntegerStringInput\n : D extends 'address'\n ? Address\n : D extends 'bool'\n ? boolean\n : D extends `${'u' | ''}int${string}`\n ? IntegerStringInput\n : D extends `bytes${string}`\n ? `0x${string}`\n : D extends 'string'\n ? string\n : InputSpec;\n\n/**\n * A guard applied to an operation, with the `port` field constrained\n * to a specific set of output port names.\n */\nexport interface TypedGuard<Port extends string = string> {\n readonly kind: string;\n readonly port: Port;\n readonly [key: string]: unknown;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SolType, Ref, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
1
|
+
import { SolType, Ref, LiteralBinding, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
@@ -44,6 +44,22 @@ type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
|
44
44
|
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
45
45
|
readonly __outputKind?: T;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* A literal bind value carrying a phantom type parameter.
|
|
49
|
+
*
|
|
50
|
+
* The wire format accepts a constant in a bind slot as
|
|
51
|
+
* `{ kind: <solType>, value: <string> }`, alongside `$ref` pointers. Use it
|
|
52
|
+
* for a value that must be baked into the flow document rather than supplied
|
|
53
|
+
* at run time — the destination of a flow the backend stores and re-runs
|
|
54
|
+
* later (a `continuation.settle` node's `continuationFlow`) has no run to
|
|
55
|
+
* take an input from.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
58
|
+
*/
|
|
59
|
+
interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
60
|
+
readonly kind: T;
|
|
61
|
+
readonly __outputKind?: T;
|
|
62
|
+
}
|
|
47
63
|
/**
|
|
48
64
|
* An input declaration in a flow schema.
|
|
49
65
|
* `Resource` values become resource inputs (token amounts);
|
|
@@ -71,4 +87,4 @@ interface TypedGuard<Port extends string = string> {
|
|
|
71
87
|
readonly [key: string]: unknown;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedRef };
|
|
90
|
+
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedLiteral, TypedRef };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SolType, Ref, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
1
|
+
import { SolType, Ref, LiteralBinding, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
@@ -44,6 +44,22 @@ type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
|
44
44
|
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
45
45
|
readonly __outputKind?: T;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* A literal bind value carrying a phantom type parameter.
|
|
49
|
+
*
|
|
50
|
+
* The wire format accepts a constant in a bind slot as
|
|
51
|
+
* `{ kind: <solType>, value: <string> }`, alongside `$ref` pointers. Use it
|
|
52
|
+
* for a value that must be baked into the flow document rather than supplied
|
|
53
|
+
* at run time — the destination of a flow the backend stores and re-runs
|
|
54
|
+
* later (a `continuation.settle` node's `continuationFlow`) has no run to
|
|
55
|
+
* take an input from.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
58
|
+
*/
|
|
59
|
+
interface TypedLiteral<T extends SolType = SolType> extends LiteralBinding {
|
|
60
|
+
readonly kind: T;
|
|
61
|
+
readonly __outputKind?: T;
|
|
62
|
+
}
|
|
47
63
|
/**
|
|
48
64
|
* An input declaration in a flow schema.
|
|
49
65
|
* `Resource` values become resource inputs (token amounts);
|
|
@@ -71,4 +87,4 @@ interface TypedGuard<Port extends string = string> {
|
|
|
71
87
|
readonly [key: string]: unknown;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedRef };
|
|
90
|
+
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedLiteral, TypedRef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/composer-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Public Composer SDK for building and submitting flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,9 +28,6 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"prettier": {
|
|
32
|
-
"singleQuote": true
|
|
33
|
-
},
|
|
34
31
|
"scripts": {
|
|
35
32
|
"build": "tsc --noEmit && tsup",
|
|
36
33
|
"clean": "rm -rf dist out",
|
|
@@ -40,18 +37,16 @@
|
|
|
40
37
|
"test": "vitest run --config vitest.config.ts",
|
|
41
38
|
"check:types": "tsc --noEmit",
|
|
42
39
|
"check:sdk-drift": "vitest run --config vitest.drift.config.ts",
|
|
43
|
-
"fix": "
|
|
40
|
+
"fix": "yarn fix:lint",
|
|
44
41
|
"fix:lint": "eslint src --fix",
|
|
45
|
-
"fix:prettier": "prettier \"src/**/*.ts\" \"scripts/**/*.ts\" --write",
|
|
46
42
|
"lint": "eslint src",
|
|
47
43
|
"test:lint": "eslint src",
|
|
48
|
-
"test:prettier": "prettier \"src/**/*.ts\" \"scripts/**/*.ts\" --list-different",
|
|
49
44
|
"verify:staged": "bash scripts/verify-staged.sh",
|
|
50
45
|
"example": "tsx src/examples/run.ts",
|
|
51
46
|
"example:staged": "tsx src/examples/run.ts --staged"
|
|
52
47
|
},
|
|
53
48
|
"peerDependencies": {
|
|
54
|
-
"@lifi/compose-spec": "0.
|
|
49
|
+
"@lifi/compose-spec": "0.5.1"
|
|
55
50
|
},
|
|
56
51
|
"dependencies": {
|
|
57
52
|
"abitype": "^1.2.3",
|
|
@@ -70,8 +65,6 @@
|
|
|
70
65
|
"eslint-plugin-import": "^2.22.0",
|
|
71
66
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
72
67
|
"json-schema-to-typescript": "^15.0.4",
|
|
73
|
-
"npm-run-all": "^4.1.5",
|
|
74
|
-
"prettier": "^3.9.4",
|
|
75
68
|
"tsup": "^8.5.1",
|
|
76
69
|
"tsx": "^4.20.4",
|
|
77
70
|
"typescript": "^6.0.3",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AppliedGuard,
|
|
3
|
+
BindValue,
|
|
3
4
|
Call,
|
|
4
5
|
Flow,
|
|
5
6
|
FlowInput,
|
|
6
|
-
Ref,
|
|
7
7
|
Resource,
|
|
8
8
|
SolType,
|
|
9
9
|
} from '@lifi/compose-spec';
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
InputSchema,
|
|
14
14
|
OutputKind,
|
|
15
15
|
TypedGuard,
|
|
16
|
+
TypedLiteral,
|
|
16
17
|
TypedRef,
|
|
17
18
|
} from '../types.js';
|
|
18
19
|
|
|
@@ -21,7 +22,7 @@ import type {
|
|
|
21
22
|
OutputHandle,
|
|
22
23
|
ResourceInputHandle,
|
|
23
24
|
} from './handles.js';
|
|
24
|
-
import {
|
|
25
|
+
import { toBindValue } from './handles.js';
|
|
25
26
|
import { ref } from './raw.js';
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -37,17 +38,14 @@ export interface CallArgs {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
* Any value that can be bound to an operation parameter: an input handle,
|
|
41
|
-
*
|
|
41
|
+
* Any value that can be bound to an operation parameter: an input handle, an
|
|
42
|
+
* output handle from a previous operation, a typed `$ref` pointer, or a typed
|
|
43
|
+
* literal.
|
|
42
44
|
*
|
|
43
|
-
* Use `raw.ref<T>()` to create a typed ref from a raw path string
|
|
45
|
+
* Use `raw.ref<T>()` to create a typed ref from a raw path string, and
|
|
46
|
+
* `raw.literal<T>()` to bake in a constant.
|
|
44
47
|
*/
|
|
45
|
-
export type AnyBindable = InputHandle | OutputHandle | TypedRef;
|
|
46
|
-
|
|
47
|
-
const toRef = (bindable: AnyBindable): Ref => {
|
|
48
|
-
if ('_tag' in bindable) return handleToRef(bindable);
|
|
49
|
-
return bindable;
|
|
50
|
-
};
|
|
48
|
+
export type AnyBindable = InputHandle | OutputHandle | TypedRef | TypedLiteral;
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
* Provides references to runtime context values available inside a flow.
|
|
@@ -127,7 +125,7 @@ export interface FlowBuilderCore<T extends InputSchema = InputSchema> {
|
|
|
127
125
|
id: string,
|
|
128
126
|
op: string,
|
|
129
127
|
args: {
|
|
130
|
-
readonly bind: Record<string,
|
|
128
|
+
readonly bind: Record<string, BindValue>;
|
|
131
129
|
readonly config: Record<string, unknown>;
|
|
132
130
|
readonly guards?: readonly AppliedGuard[];
|
|
133
131
|
},
|
|
@@ -196,9 +194,9 @@ export const createFlowBuilderCore = <T extends InputSchema>(
|
|
|
196
194
|
if (nodeIds.has(nodeId)) throw new Error(`Duplicate node id: "${nodeId}"`);
|
|
197
195
|
nodeIds.add(nodeId);
|
|
198
196
|
|
|
199
|
-
const bind: Record<string,
|
|
197
|
+
const bind: Record<string, BindValue> = {};
|
|
200
198
|
for (const [key, val] of Object.entries(args.bind)) {
|
|
201
|
-
bind[key] =
|
|
199
|
+
bind[key] = toBindValue(val);
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
const node: Call = {
|
|
@@ -230,7 +228,7 @@ export const createFlowBuilderCore = <T extends InputSchema>(
|
|
|
230
228
|
nodeId: string,
|
|
231
229
|
op: string,
|
|
232
230
|
args: {
|
|
233
|
-
readonly bind: Record<string,
|
|
231
|
+
readonly bind: Record<string, BindValue>;
|
|
234
232
|
readonly config: Record<string, unknown>;
|
|
235
233
|
readonly guards?: readonly AppliedGuard[];
|
|
236
234
|
},
|
package/src/authoring/handles.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BindValue,
|
|
3
|
+
Resource,
|
|
4
|
+
SolType,
|
|
5
|
+
StaticSolType,
|
|
6
|
+
} from '@lifi/compose-spec';
|
|
2
7
|
|
|
3
|
-
import type { OutputKind, TypedRef } from '../types.js';
|
|
8
|
+
import type { OutputKind, TypedLiteral, TypedRef } from '../types.js';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* A handle referencing a flow input declared in the flow's input schema.
|
|
@@ -75,16 +80,47 @@ type SlotAssignable<T extends OutputKind> = T extends 'bytes32'
|
|
|
75
80
|
: T;
|
|
76
81
|
|
|
77
82
|
/**
|
|
78
|
-
* The
|
|
83
|
+
* The values accepted by a typed slot that must resolve to a `$ref`:
|
|
79
84
|
* - `OutputHandle<T>` / `InputHandle<T>` (same type)
|
|
80
85
|
* - For `'uint256'` slots, also `'resource'`-tagged handles
|
|
81
86
|
* - For `'bytes32'` slots, any static-32-byte handle (and `'resource'`)
|
|
82
87
|
* - `TypedRef<T>` (typed context refs, subject to `SlotAssignable`)
|
|
83
88
|
*
|
|
84
|
-
* Plain `{ $ref: '...' }` objects are **not** accepted
|
|
89
|
+
* Plain `{ $ref: '...' }` objects are **not** accepted - use `raw.ref<T>()`
|
|
85
90
|
* to create a typed ref when you need to reference a raw path.
|
|
86
91
|
*/
|
|
87
|
-
export type
|
|
92
|
+
export type RefBindable<T extends OutputKind> =
|
|
88
93
|
| OutputHandle<SlotAssignable<T>>
|
|
89
94
|
| InputHandle<SlotAssignable<T>>
|
|
90
95
|
| TypedRef<SlotAssignable<T>>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Any ref-resolving bindable, with no per-slot type constraint.
|
|
99
|
+
*/
|
|
100
|
+
export type AnyRefBindable = InputHandle | OutputHandle | TypedRef;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The set of values accepted by a typed operation bind slot: everything
|
|
104
|
+
* {@link RefBindable} accepts, plus a {@link TypedLiteral} constant baked
|
|
105
|
+
* into the flow document. A `'resource'` slot rejects a literal: a token
|
|
106
|
+
* resource is not a scalar constant.
|
|
107
|
+
*
|
|
108
|
+
* Use `raw.literal<T>()` to create one.
|
|
109
|
+
*/
|
|
110
|
+
export type Bindable<T extends OutputKind> =
|
|
111
|
+
RefBindable<T> | LiteralBindable<SlotAssignable<T>>;
|
|
112
|
+
|
|
113
|
+
// Distributes over the slot's assignable kinds and keeps the scalar ones: a
|
|
114
|
+
// `'resource'` slot has no scalar arm, so its literal arm collapses to
|
|
115
|
+
// `never` and a literal is rejected outright.
|
|
116
|
+
type LiteralBindable<K extends OutputKind> = K extends SolType
|
|
117
|
+
? TypedLiteral<K>
|
|
118
|
+
: never;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Converts a bindable to the wire `bind` value it denotes: handles become
|
|
122
|
+
* `$ref` pointers, refs and literals pass through as-is.
|
|
123
|
+
*/
|
|
124
|
+
export const toBindValue = (
|
|
125
|
+
bindable: InputHandle | OutputHandle | TypedRef | TypedLiteral,
|
|
126
|
+
): BindValue => ('_tag' in bindable ? handleToRef(bindable) : bindable);
|
package/src/authoring/raw.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AppliedGuard } from '@lifi/compose-spec';
|
|
1
|
+
import type { AppliedGuard, SolType } from '@lifi/compose-spec';
|
|
2
2
|
|
|
3
|
-
import type { OutputKind, TypedRef } from '../types.js';
|
|
3
|
+
import type { OutputKind, TypedLiteral, TypedRef } from '../types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a typed `$ref` pointer for use in bind slots.
|
|
@@ -39,6 +39,40 @@ export const ref = <T extends OutputKind>(path: string): TypedRef<T> => ({
|
|
|
39
39
|
$ref: path,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Creates a typed literal for use in bind slots: a constant baked into the
|
|
44
|
+
* flow document rather than supplied at run time.
|
|
45
|
+
*
|
|
46
|
+
* Prefer a declared flow input and `builder.inputs.<name>` — a value the
|
|
47
|
+
* caller supplies per run stays out of the document. Use a literal when the
|
|
48
|
+
* flow has no run of its own to take the value from: the `continuationFlow`
|
|
49
|
+
* of a `continuation.settle` node is stored by the settlement backend and
|
|
50
|
+
* re-run later against the deferred proceeds, so its delivery address has to
|
|
51
|
+
* be part of the committed document.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
54
|
+
* @param kind - The literal's Solidity type.
|
|
55
|
+
* @param value - The literal value, as the wire format carries it: a string.
|
|
56
|
+
* @returns A {@link TypedLiteral} accepted by `Bindable<T>` slots matching `T`.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { raw } from '@lifi/composer-sdk';
|
|
61
|
+
*
|
|
62
|
+
* builder.core.transfer('deliver', {
|
|
63
|
+
* bind: {
|
|
64
|
+
* amount: zap.amountOut,
|
|
65
|
+
* recipient: raw.literal('address', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),
|
|
66
|
+
* },
|
|
67
|
+
* config: {},
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const literal = <T extends SolType>(
|
|
72
|
+
kind: T,
|
|
73
|
+
value: string,
|
|
74
|
+
): TypedLiteral<T> => ({ kind, value });
|
|
75
|
+
|
|
42
76
|
/**
|
|
43
77
|
* Creates a raw guard object for use in the `guards` array of an operation call.
|
|
44
78
|
*
|
|
@@ -3,32 +3,36 @@ import { type ParseAbiItem, parseAbiItem } from 'abitype';
|
|
|
3
3
|
|
|
4
4
|
import type { AbiTypeToOutputKind, TypedGuard } from '../types.js';
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
6
|
+
import type { CallArgs } from './FlowBuilderCore.js';
|
|
7
|
+
import type { AnyRefBindable, OutputHandle, RefBindable } from './handles.js';
|
|
8
8
|
import { handleToRef } from './handles.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Type-level extraction of named bind keys from a function signature string.
|
|
12
12
|
* When `TSig` is a string literal matching a Solidity function signature,
|
|
13
13
|
* resolves to a record whose keys are the parameter names and values are
|
|
14
|
-
* `
|
|
14
|
+
* `RefBindable<kind>` where the kind is derived from each parameter's Solidity
|
|
15
15
|
* type via `AbiTypeToOutputKind`. For recognised `SolType` parameters
|
|
16
16
|
* (e.g. `uint256`, `address`, `uint128`) the bind slot is precisely typed;
|
|
17
17
|
* for other Solidity types (e.g. tuples) the slot accepts any scalar handle.
|
|
18
|
-
* Falls back to `Record<string,
|
|
18
|
+
* Falls back to `Record<string, AnyRefBindable>` for non-literal strings.
|
|
19
|
+
*
|
|
20
|
+
* These slots are lowered into `config.args`, which is positional calldata
|
|
21
|
+
* rather than a node `bind` record, so a literal is not accepted here: only
|
|
22
|
+
* values that resolve to a `$ref`.
|
|
19
23
|
*/
|
|
20
24
|
export type SignatureBind<TSig extends string> = string extends TSig
|
|
21
|
-
? Record<string,
|
|
25
|
+
? Record<string, AnyRefBindable>
|
|
22
26
|
: ParseAbiItem<TSig> extends {
|
|
23
27
|
type: 'function';
|
|
24
28
|
inputs: infer I extends readonly { name: string; type: string }[];
|
|
25
29
|
}
|
|
26
30
|
? {
|
|
27
|
-
readonly [P in I[number] as P['name']]:
|
|
31
|
+
readonly [P in I[number] as P['name']]: RefBindable<
|
|
28
32
|
AbiTypeToOutputKind<P['type']>
|
|
29
33
|
>;
|
|
30
34
|
}
|
|
31
|
-
: Record<string,
|
|
35
|
+
: Record<string, AnyRefBindable>;
|
|
32
36
|
|
|
33
37
|
// ---------------------------------------------------------------------------
|
|
34
38
|
// Return-type inference from function signatures
|
|
@@ -126,18 +130,18 @@ export const parseFunctionParams = (functionSignature: string): string[] => {
|
|
|
126
130
|
};
|
|
127
131
|
|
|
128
132
|
/**
|
|
129
|
-
* Converts
|
|
133
|
+
* Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).
|
|
130
134
|
* Handles carry a `_tag` property and are converted via `handleToRef`;
|
|
131
135
|
* `Ref` objects pass through as-is.
|
|
132
136
|
*/
|
|
133
|
-
export const toBindRef = (bindable:
|
|
137
|
+
export const toBindRef = (bindable: AnyRefBindable): Ref => {
|
|
134
138
|
if ('_tag' in bindable) return handleToRef(bindable);
|
|
135
139
|
return bindable;
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
export interface BuildCallWireFormatInput {
|
|
139
|
-
readonly resource?:
|
|
140
|
-
readonly bind: Record<string,
|
|
143
|
+
readonly resource?: AnyRefBindable;
|
|
144
|
+
readonly bind: Record<string, AnyRefBindable>;
|
|
141
145
|
readonly config: Record<string, unknown>;
|
|
142
146
|
readonly guards?: readonly TypedGuard[];
|
|
143
147
|
}
|
|
@@ -155,7 +159,7 @@ export interface CallWireResult {
|
|
|
155
159
|
*/
|
|
156
160
|
const resolvePositionalArgs = (
|
|
157
161
|
label: string,
|
|
158
|
-
bind: Record<string,
|
|
162
|
+
bind: Record<string, AnyRefBindable>,
|
|
159
163
|
config: Record<string, unknown>,
|
|
160
164
|
): Ref[] => {
|
|
161
165
|
const functionSignature = config.functionSignature;
|
|
@@ -222,7 +226,7 @@ export const buildCallWireFormat = (
|
|
|
222
226
|
};
|
|
223
227
|
|
|
224
228
|
export interface BuildStaticCallWireFormatInput {
|
|
225
|
-
readonly bind: Record<string,
|
|
229
|
+
readonly bind: Record<string, AnyRefBindable>;
|
|
226
230
|
readonly config: Record<string, unknown>;
|
|
227
231
|
readonly guards?: readonly TypedGuard[];
|
|
228
232
|
}
|