@lifi/composer-sdk 0.9.0 → 0.11.3
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 +37 -3
- package/dist/authoring/raw.cjs +12 -7
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.d.cts +12 -7
- package/dist/authoring/raw.d.ts +12 -7
- package/dist/authoring/raw.js +12 -7
- package/dist/authoring/raw.js.map +1 -1
- package/dist/client.cjs +11 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +11 -1
- package/dist/client.js.map +1 -1
- package/dist/errors.cjs +35 -13
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +19 -1
- package/dist/errors.d.ts +19 -1
- package/dist/errors.js +35 -14
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.d.cts +96 -1
- package/dist/generated/config.generated.d.ts +96 -1
- package/dist/generated/operations.generated.cjs +10 -0
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +56 -1
- package/dist/generated/operations.generated.d.ts +56 -1
- package/dist/generated/operations.generated.js +10 -0
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/outputs.cjs +3 -2
- package/dist/outputs.cjs.map +1 -1
- package/dist/outputs.d.cts +3 -2
- package/dist/outputs.d.ts +3 -2
- package/dist/outputs.js +3 -2
- package/dist/outputs.js.map +1 -1
- package/dist/responseSchemas.cjs.map +1 -1
- package/dist/responseSchemas.d.cts +2 -2
- package/dist/responseSchemas.d.ts +2 -2
- package/dist/responseSchemas.js.map +1 -1
- package/dist/run/inputs.cjs.map +1 -1
- package/dist/run/inputs.d.cts +3 -3
- package/dist/run/inputs.d.ts +3 -3
- package/dist/run/inputs.js.map +1 -1
- package/package.json +3 -3
- package/src/authoring/raw.ts +12 -7
- package/src/client.ts +24 -1
- package/src/errors.ts +48 -17
- package/src/examples/continuationBridgeSettle.ts +100 -0
- package/src/examples/continuationSettle.ts +113 -0
- package/src/examples/run.ts +8 -0
- package/src/generated/config.generated.ts +109 -1
- package/src/generated/operations.generated.ts +98 -0
- package/src/index.ts +5 -1
- package/src/outputs.ts +3 -2
- package/src/responseSchemas.ts +9 -5
- package/src/run/inputs.ts +3 -3
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["guardsMod","materialisersMod","preconditionsMod","resourcesMod","routeAmountMod","rawMod"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n TypedLiteral,\n} from './types.js';\n\nexport type {\n ChainSummary,\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type {\n Reachability,\n ReachabilityOptions,\n RoutablePair,\n TokenRef,\n} from './reachability.js';\nexport { buildReachability } from './reachability.js';\nexport type {\n ComposeError,\n ComposeErrorCode,\n ComposeSdkOutdated,\n ComposeServerOutdated,\n ComposePreparationOps,\n} from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeAction,\n ComposeFill,\n ComposeFee,\n ComposeUserProgramSimulation,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeErrorKind,\n ComposeRouteRequest,\n ComposeTransactionRequest,\n FailedPreparedOp,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n OutputAmount,\n Amount,\n ConsumedOutput,\n Delivery,\n Estimate,\n EstimateBasis,\n Minimum,\n MinimumBasis,\n Output,\n Outputs,\n TerminalOutput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n RouteAmount,\n RouteAmountAll,\n RouteAmountExact,\n SimulationPolicy,\n SimulationRevert,\n SolType,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["guardsMod","materialisersMod","preconditionsMod","resourcesMod","routeAmountMod","rawMod"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n TypedLiteral,\n} from './types.js';\n\nexport type {\n ChainSummary,\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type {\n Reachability,\n ReachabilityOptions,\n RoutablePair,\n TokenRef,\n} from './reachability.js';\nexport { buildReachability } from './reachability.js';\nexport type {\n ComposeError,\n ComposeErrorCode,\n ComposeSdkOutdated,\n ComposeServerOutdated,\n ComposePreparationOps,\n} from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeAction,\n ComposeFill,\n ComposeFee,\n ComposeUserProgramSimulation,\n ComposeWarning,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeErrorKind,\n ComposeRouteRequest,\n ComposeTransactionRequest,\n FailedPreparedOp,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n OutputAmount,\n Amount,\n ConsumedOutput,\n Delivery,\n Estimate,\n EstimateBasis,\n Minimum,\n MinimumBasis,\n Output,\n Outputs,\n TerminalOutput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n RouteAmount,\n RouteAmountAll,\n RouteAmountExact,\n SimulationPolicy,\n SimulationRevert,\n DeliveryErrorDetails,\n DeliveryErrorReason,\n SolType,\n ForwardTo,\n SimulateRequest,\n SimulateResult,\n SimulateOkResult,\n SimulateRevertResult,\n SimulateRevertDecodeResult,\n SimulateSetupErrorResult,\n SimulateBalanceEntry,\n TrackedBalance,\n SlotFinderRequirement,\n Erc20BalanceRequirement,\n NativeBalanceRequirement,\n Erc20AllowanceRequirement,\n ContinuationIntent,\n ContinuationOutcome,\n SettlementWire,\n SettlementEscrowWire,\n} from '@lifi/compose-spec';\nexport {\n SIMULATE_MAX_TRACKED_BALANCES,\n SIMULATE_MAX_REQUIREMENTS,\n} from '@lifi/compose-spec';\nexport {\n isComposeDeliveryError,\n isComposeError,\n isComposePreparationError,\n isComposeSdkOutdatedError,\n isComposeServerOutdatedError,\n} from './errors.js';\n\nexport type {\n Bindable,\n RefBindable,\n AnyRefBindable,\n InputHandle,\n ResourceInputHandle,\n OutputHandle,\n OutputFamilyHandles,\n FamilyCount,\n FamilySource,\n AnyHandle,\n} from './authoring/handles.js';\nexport { isInputHandle, isOutputHandle } from './authoring/handles.js';\nexport { ref } from './authoring/raw.js';\n\nexport type { AnyBindable } from './authoring/FlowBuilderCore.js';\nexport type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';\n\nexport type { ComposeRunInput } from './run/inputs.js';\nexport { materialiser } from './run/inputs.js';\n\nexport { buildSimulateRequest } from './run/simulate.js';\nexport type { BuildSimulateRequestInput } from './run/simulate.js';\n\nexport { terminalOutputs } from './outputs.js';\n\nexport { createComposeSdk } from './sdk.js';\nexport type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';\n\nimport * as guardsMod from './generated/guards.generated.js';\nimport * as materialisersMod from './generated/materialisers.generated.js';\nimport * as preconditionsMod from './generated/preconditions.generated.js';\nimport * as rawMod from './raw.js';\nimport * as resourcesMod from './resources.js';\nimport * as routeAmountMod from './routeAmount.js';\n\n/**\n * Guard factories for protecting operation outputs (e.g. slippage tolerance).\n * Pass guards to an operation's `guards` array.\n *\n * @example\n * ```ts\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.token },\n * config: { resourceOut: resources.native(1) },\n * guards: [guards.slippage({ port: 'amountOut', bps: 300 })],\n * });\n * ```\n */\nexport const guards: typeof guardsMod = guardsMod;\n/**\n * Materialiser factories that tell the runtime how to resolve token input\n * amounts on-chain (e.g. read a wallet balance, accept a direct deposit).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0x...',\n * });\n * ```\n */\nexport const materialisers: typeof materialisersMod = materialisersMod;\n/**\n * Precondition factories for asserting on-chain state before a flow executes\n * (e.g. minimum token balances, ERC-20 allowances).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * preconditions: [\n * preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),\n * ],\n * signer: '0x...',\n * });\n * ```\n */\nexport const preconditions: typeof preconditionsMod = preconditionsMod;\n/**\n * Resource declaration helpers for defining token inputs in a flow schema.\n * Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}\n * for the chain's native coin (ETH, MATIC, etc.).\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: {\n * usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),\n * eth: resources.native(1),\n * },\n * });\n * ```\n */\nexport const resources: typeof resourcesMod = resourcesMod;\n/**\n * Amount constructors for {@link ComposeSdk.route}. Use\n * {@link routeAmount.exact} to spend a fixed amount of the `fromToken`, and\n * {@link routeAmount.all} to spend the signer's whole balance.\n *\n * @example\n * ```ts\n * // USDC into the Aave v3 aEthUSDC position — one routing-catalog edge.\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n * toToken: '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c',\n * amount: routeAmount.exact(1_000_000n),\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport const routeAmount: typeof routeAmountMod = routeAmountMod;\nexport * from './generated/config.generated.js';\n\n/**\n * Low-level escape hatch for constructing flow nodes, guards, and materialiser\n * inputs without the typed builder API. Prefer the generated operation methods\n * on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces\n * for most use cases.\n */\nexport const raw: typeof rawMod = rawMod;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwKA,MAAa,SAA2BA;;;;;;;;;;;;;AAaxC,MAAa,gBAAyCC;;;;;;;;;;;;;;;;AAgBtD,MAAa,gBAAyCC;;;;;;;;;;;;;;;;AAgBtD,MAAa,YAAiCC;;;;;;;;;;;;;;;;;;AAkB9C,MAAa,cAAqCC;;;;;;;AASlD,MAAa,MAAqBC"}
|
package/dist/outputs.cjs
CHANGED
|
@@ -2,8 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
//#region src/outputs.ts
|
|
3
3
|
/**
|
|
4
4
|
* The entries of `outputs` the caller actually receives: every port no later
|
|
5
|
-
* node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
6
|
-
*
|
|
5
|
+
* node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource
|
|
6
|
+
* input no node spends, keyed `input.<name>`. Consumed ports (intermediate
|
|
7
|
+
* amounts a later op takes as input) are dropped.
|
|
7
8
|
*/
|
|
8
9
|
const terminalOutputs = (outputs) => Object.fromEntries(Object.entries(outputs).filter((entry) => entry[1].role === "terminal"));
|
|
9
10
|
//#endregion
|
package/dist/outputs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputs.cjs","names":[],"sources":["../src/outputs.ts"],"sourcesContent":["import type { Outputs, TerminalOutput } from '@lifi/compose-spec';\n\n/**\n * The entries of `outputs` the caller actually receives: every port no later\n * node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
1
|
+
{"version":3,"file":"outputs.cjs","names":[],"sources":["../src/outputs.ts"],"sourcesContent":["import type { Outputs, TerminalOutput } from '@lifi/compose-spec';\n\n/**\n * The entries of `outputs` the caller actually receives: every port no later\n * node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource\n * input no node spends, keyed `input.<name>`. Consumed ports (intermediate\n * amounts a later op takes as input) are dropped.\n */\nexport const terminalOutputs = (\n outputs: Outputs,\n): Record<string, TerminalOutput> =>\n Object.fromEntries(\n Object.entries(outputs).filter(\n (entry): entry is [string, TerminalOutput] =>\n entry[1].role === 'terminal',\n ),\n );\n"],"mappings":";;;;;;;;AAQA,MAAa,mBACX,YAEA,OAAO,YACL,OAAO,QAAQ,OAAO,CAAC,CAAC,QACrB,UACC,MAAM,EAAE,CAAC,SAAS,UACtB,CACF"}
|
package/dist/outputs.d.cts
CHANGED
|
@@ -2,8 +2,9 @@ import { Outputs, TerminalOutput } from "@lifi/compose-spec";
|
|
|
2
2
|
//#region src/outputs.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The entries of `outputs` the caller actually receives: every port no later
|
|
5
|
-
* node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
6
|
-
*
|
|
5
|
+
* node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource
|
|
6
|
+
* input no node spends, keyed `input.<name>`. Consumed ports (intermediate
|
|
7
|
+
* amounts a later op takes as input) are dropped.
|
|
7
8
|
*/
|
|
8
9
|
export declare const terminalOutputs: (outputs: Outputs) => Record<string, TerminalOutput>;
|
|
9
10
|
//#endregion
|
package/dist/outputs.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { Outputs, TerminalOutput } from "@lifi/compose-spec";
|
|
|
2
2
|
//#region src/outputs.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The entries of `outputs` the caller actually receives: every port no later
|
|
5
|
-
* node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
6
|
-
*
|
|
5
|
+
* node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource
|
|
6
|
+
* input no node spends, keyed `input.<name>`. Consumed ports (intermediate
|
|
7
|
+
* amounts a later op takes as input) are dropped.
|
|
7
8
|
*/
|
|
8
9
|
export declare const terminalOutputs: (outputs: Outputs) => Record<string, TerminalOutput>;
|
|
9
10
|
//#endregion
|
package/dist/outputs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
//#region src/outputs.ts
|
|
2
2
|
/**
|
|
3
3
|
* The entries of `outputs` the caller actually receives: every port no later
|
|
4
|
-
* node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
5
|
-
*
|
|
4
|
+
* node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource
|
|
5
|
+
* input no node spends, keyed `input.<name>`. Consumed ports (intermediate
|
|
6
|
+
* amounts a later op takes as input) are dropped.
|
|
6
7
|
*/
|
|
7
8
|
const terminalOutputs = (outputs) => Object.fromEntries(Object.entries(outputs).filter((entry) => entry[1].role === "terminal"));
|
|
8
9
|
//#endregion
|
package/dist/outputs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputs.js","names":[],"sources":["../src/outputs.ts"],"sourcesContent":["import type { Outputs, TerminalOutput } from '@lifi/compose-spec';\n\n/**\n * The entries of `outputs` the caller actually receives: every port no later\n * node spends, keyed `<nodeId>.<portName>` as on the wire
|
|
1
|
+
{"version":3,"file":"outputs.js","names":[],"sources":["../src/outputs.ts"],"sourcesContent":["import type { Outputs, TerminalOutput } from '@lifi/compose-spec';\n\n/**\n * The entries of `outputs` the caller actually receives: every port no later\n * node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource\n * input no node spends, keyed `input.<name>`. Consumed ports (intermediate\n * amounts a later op takes as input) are dropped.\n */\nexport const terminalOutputs = (\n outputs: Outputs,\n): Record<string, TerminalOutput> =>\n Object.fromEntries(\n Object.entries(outputs).filter(\n (entry): entry is [string, TerminalOutput] =>\n entry[1].role === 'terminal',\n ),\n );\n"],"mappings":";;;;;;;AAQA,MAAa,mBACX,YAEA,OAAO,YACL,OAAO,QAAQ,OAAO,CAAC,CAAC,QACrB,UACC,MAAM,EAAE,CAAC,SAAS,UACtB,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseSchemas.cjs","names":["z"],"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"responseSchemas.cjs","names":["z"],"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type {\n DeliveryErrorDetails,\n SimulateResult,\n SimulationRevert,\n} from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object at runtime but left `unknown` here — compose-spec\n * owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so\n * the caller narrows it in one step. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: unknown;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n readonly sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: string;\n readonly details?: SimulationRevert | DeliveryErrorDetails;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` or `DeliveryErrorDetails` schemas and forwards\n// the field verbatim onto `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them — which is\n// also why `port` and `fix`, set on every author-caused `validation_error`,\n// have to be declared here to reach the caller.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: z.string().optional(),\n details: z.custom<SimulationRevert | DeliveryErrorDetails>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SimulateResult, SimulationRevert } from "@lifi/compose-spec";
|
|
1
|
+
import { DeliveryErrorDetails, SimulateResult, SimulationRevert } from "@lifi/compose-spec";
|
|
2
2
|
//#region src/responseSchemas.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
@@ -46,7 +46,7 @@ export interface ServerErrorBody {
|
|
|
46
46
|
readonly sdkVersion?: string;
|
|
47
47
|
readonly serverVersion?: string;
|
|
48
48
|
readonly minimumSdkVersion?: string;
|
|
49
|
-
readonly details?: SimulationRevert;
|
|
49
|
+
readonly details?: SimulationRevert | DeliveryErrorDetails;
|
|
50
50
|
readonly failedOps?: readonly ServerFailedPreparedOp[];
|
|
51
51
|
readonly succeededOps?: readonly string[];
|
|
52
52
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SimulateResult, SimulationRevert } from "@lifi/compose-spec";
|
|
1
|
+
import { DeliveryErrorDetails, SimulateResult, SimulationRevert } from "@lifi/compose-spec";
|
|
2
2
|
//#region src/responseSchemas.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
@@ -46,7 +46,7 @@ export interface ServerErrorBody {
|
|
|
46
46
|
readonly sdkVersion?: string;
|
|
47
47
|
readonly serverVersion?: string;
|
|
48
48
|
readonly minimumSdkVersion?: string;
|
|
49
|
-
readonly details?: SimulationRevert;
|
|
49
|
+
readonly details?: SimulationRevert | DeliveryErrorDetails;
|
|
50
50
|
readonly failedOps?: readonly ServerFailedPreparedOp[];
|
|
51
51
|
readonly succeededOps?: readonly string[];
|
|
52
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseSchemas.js","names":[],"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"responseSchemas.js","names":[],"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type {\n DeliveryErrorDetails,\n SimulateResult,\n SimulationRevert,\n} from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object at runtime but left `unknown` here — compose-spec\n * owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so\n * the caller narrows it in one step. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: unknown;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n readonly sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: string;\n readonly details?: SimulationRevert | DeliveryErrorDetails;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` or `DeliveryErrorDetails` schemas and forwards\n// the field verbatim onto `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them — which is\n// also why `port` and `fix`, set on every author-caused `validation_error`,\n// have to be declared here to reach the caller.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: z.string().optional(),\n details: z.custom<SimulationRevert | DeliveryErrorDetails>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":"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"}
|
package/dist/run/inputs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.cjs","names":[],"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n
|
|
1
|
+
{"version":3,"file":"inputs.cjs","names":[],"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n ForwardTo,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: ForwardTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server also simulates the final user-facing transaction\n * after the structured simulation succeeds; reverts honour\n * `simulationPolicy`. On success the result is echoed back on the response as\n * `userProgramSimulation`. Defaults to `false`.\n */\n readonly simulateUserProgram?: boolean;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Drops the keys whose value is `undefined`, so optional fields are omitted\n * from the wire payload rather than serialized as `null`.\n *\n * A local copy of `pickDefined` from `@lifi/utils`: this package is published\n * to npm and `@lifi/utils` is a private workspace package, so it cannot be a\n * runtime dependency here.\n */\nconst pickDefined = <S extends Record<string, unknown>>(\n obj: S,\n): Partial<{ [K in keyof S]: Exclude<S[K], undefined> }> =>\n Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as Partial<{ [K in keyof S]: Exclude<S[K], undefined> }>;\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: ForwardTo;\n simulationPolicy?: SimulationPolicy;\n simulateUserProgram?: boolean;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n signer: run.signer,\n ...pickDefined({\n // An empty precondition list is the same as none, so drop it too.\n preconditions: run.preconditions?.length ? run.preconditions : undefined,\n assumptions: run.assumptions,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0FA,MAAa,gBACX,MACA,SAAkC,CAAC,OACZ;CACvB;CACA,GAAG;AACL;;;;;;;;;AAUA,MAAM,eACJ,QAEA,OAAO,YACL,OAAO,QAAQ,GAAG,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAC/D;;;;;;;AAQF,MAAa,YAAY,SAYN;CACjB,QAAQ,IAAI;CACZ,QAAQ,IAAI;CACZ,GAAG,YAAY;EAEb,eAAe,IAAI,eAAe,SAAS,IAAI,gBAAgB,KAAA;EAC/D,aAAa,IAAI;EACjB,UAAU,IAAI;EACd,kBAAkB,IAAI;EACtB,mBAAmB,IAAI;EACvB,SAAS,IAAI;EACb,kBAAkB,IAAI;EACtB,qBAAqB,IAAI;EACzB,wBAAwB,IAAI;CAC9B,CAAC;AACH"}
|
package/dist/run/inputs.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, InputSchema, InputSpecOf } from "../types.cjs";
|
|
2
|
-
import { ComposeRun, InputSpec, MaterialiserInput, Precondition, SimulationPolicy
|
|
2
|
+
import { ComposeRun, ForwardTo, InputSpec, MaterialiserInput, Precondition, SimulationPolicy } from "@lifi/compose-spec";
|
|
3
3
|
//#region src/run/inputs.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.
|
|
@@ -39,7 +39,7 @@ export interface ComposeRunInput<T extends InputSchema = InputSchema> {
|
|
|
39
39
|
* Pass a literal `0x`-prefixed address or `{ $ref: "context.sender" }` to
|
|
40
40
|
* send remaining tokens to the signer.
|
|
41
41
|
*/
|
|
42
|
-
readonly sweepTo?:
|
|
42
|
+
readonly sweepTo?: ForwardTo;
|
|
43
43
|
/**
|
|
44
44
|
* Controls behavior when simulation detects a revert.
|
|
45
45
|
* `'strict'` (default) returns an error; `'allow-revert'` returns a partial
|
|
@@ -94,7 +94,7 @@ export declare const buildRun: (run: {
|
|
|
94
94
|
referrer?: string;
|
|
95
95
|
integratorFeeBps?: number;
|
|
96
96
|
maxPriceImpactBps?: number;
|
|
97
|
-
sweepTo?:
|
|
97
|
+
sweepTo?: ForwardTo;
|
|
98
98
|
simulationPolicy?: SimulationPolicy;
|
|
99
99
|
simulateUserProgram?: boolean;
|
|
100
100
|
checkOnChainAllowances?: boolean;
|
package/dist/run/inputs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, InputSchema, InputSpecOf } from "../types.js";
|
|
2
|
-
import { ComposeRun, InputSpec, MaterialiserInput, Precondition, SimulationPolicy
|
|
2
|
+
import { ComposeRun, ForwardTo, InputSpec, MaterialiserInput, Precondition, SimulationPolicy } from "@lifi/compose-spec";
|
|
3
3
|
//#region src/run/inputs.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.
|
|
@@ -39,7 +39,7 @@ export interface ComposeRunInput<T extends InputSchema = InputSchema> {
|
|
|
39
39
|
* Pass a literal `0x`-prefixed address or `{ $ref: "context.sender" }` to
|
|
40
40
|
* send remaining tokens to the signer.
|
|
41
41
|
*/
|
|
42
|
-
readonly sweepTo?:
|
|
42
|
+
readonly sweepTo?: ForwardTo;
|
|
43
43
|
/**
|
|
44
44
|
* Controls behavior when simulation detects a revert.
|
|
45
45
|
* `'strict'` (default) returns an error; `'allow-revert'` returns a partial
|
|
@@ -94,7 +94,7 @@ export declare const buildRun: (run: {
|
|
|
94
94
|
referrer?: string;
|
|
95
95
|
integratorFeeBps?: number;
|
|
96
96
|
maxPriceImpactBps?: number;
|
|
97
|
-
sweepTo?:
|
|
97
|
+
sweepTo?: ForwardTo;
|
|
98
98
|
simulationPolicy?: SimulationPolicy;
|
|
99
99
|
simulateUserProgram?: boolean;
|
|
100
100
|
checkOnChainAllowances?: boolean;
|
package/dist/run/inputs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.js","names":[],"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n
|
|
1
|
+
{"version":3,"file":"inputs.js","names":[],"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n ForwardTo,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: ForwardTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server also simulates the final user-facing transaction\n * after the structured simulation succeeds; reverts honour\n * `simulationPolicy`. On success the result is echoed back on the response as\n * `userProgramSimulation`. Defaults to `false`.\n */\n readonly simulateUserProgram?: boolean;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Drops the keys whose value is `undefined`, so optional fields are omitted\n * from the wire payload rather than serialized as `null`.\n *\n * A local copy of `pickDefined` from `@lifi/utils`: this package is published\n * to npm and `@lifi/utils` is a private workspace package, so it cannot be a\n * runtime dependency here.\n */\nconst pickDefined = <S extends Record<string, unknown>>(\n obj: S,\n): Partial<{ [K in keyof S]: Exclude<S[K], undefined> }> =>\n Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as Partial<{ [K in keyof S]: Exclude<S[K], undefined> }>;\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: ForwardTo;\n simulationPolicy?: SimulationPolicy;\n simulateUserProgram?: boolean;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n signer: run.signer,\n ...pickDefined({\n // An empty precondition list is the same as none, so drop it too.\n preconditions: run.preconditions?.length ? run.preconditions : undefined,\n assumptions: run.assumptions,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0FA,MAAa,gBACX,MACA,SAAkC,CAAC,OACZ;CACvB;CACA,GAAG;AACL;;;;;;;;;AAUA,MAAM,eACJ,QAEA,OAAO,YACL,OAAO,QAAQ,GAAG,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAC/D;;;;;;;AAQF,MAAa,YAAY,SAYN;CACjB,QAAQ,IAAI;CACZ,QAAQ,IAAI;CACZ,GAAG,YAAY;EAEb,eAAe,IAAI,eAAe,SAAS,IAAI,gBAAgB,KAAA;EAC/D,aAAa,IAAI;EACjB,UAAU,IAAI;EACd,kBAAkB,IAAI;EACtB,mBAAmB,IAAI;EACvB,SAAS,IAAI;EACb,kBAAkB,IAAI;EACtB,qBAAqB,IAAI;EACzB,wBAAwB,IAAI;CAC9B,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/composer-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Public Composer SDK for building and submitting flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -47,12 +47,12 @@
|
|
|
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.11.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"abitype": "^1.2.3",
|
|
54
54
|
"effect": "^3.21.0",
|
|
55
|
-
"zod": "^4.6.
|
|
55
|
+
"zod": "^4.6.6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@eslint/compat": "^1.4.0",
|
package/src/authoring/raw.ts
CHANGED
|
@@ -45,11 +45,15 @@ export const ref = <T extends OutputKind>(path: string): TypedRef<T> =>
|
|
|
45
45
|
* flow document rather than supplied at run time.
|
|
46
46
|
*
|
|
47
47
|
* Prefer a declared flow input and `builder.inputs.<name>` — a value the
|
|
48
|
-
* caller supplies per run stays out of the document. Use a literal
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
48
|
+
* caller supplies per run stays out of the document. Use a literal for a
|
|
49
|
+
* constant that belongs to the document itself, such as a fixed treasury
|
|
50
|
+
* address.
|
|
51
|
+
*
|
|
52
|
+
* Never use a literal for the payee of a `continuation.settle` leg
|
|
53
|
+
* (`continuationFlow`). The leg produces its outcome into its own proxy
|
|
54
|
+
* (`leg.context.executionAddress`) and names no recipient; the composer
|
|
55
|
+
* appends a settlement epilogue at commit that forwards the outcome to the
|
|
56
|
+
* provider's recipient and the residual to `refund`.
|
|
53
57
|
*
|
|
54
58
|
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
55
59
|
* @param kind - The literal's Solidity type.
|
|
@@ -60,9 +64,10 @@ export const ref = <T extends OutputKind>(path: string): TypedRef<T> =>
|
|
|
60
64
|
* ```ts
|
|
61
65
|
* import { raw } from '@lifi/composer-sdk';
|
|
62
66
|
*
|
|
63
|
-
*
|
|
67
|
+
* // A fixed fee to a treasury baked into the flow document.
|
|
68
|
+
* builder.core.transfer('fee', {
|
|
64
69
|
* bind: {
|
|
65
|
-
* amount:
|
|
70
|
+
* amount: builder.inputs.fee,
|
|
66
71
|
* recipient: raw.literal('address', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),
|
|
67
72
|
* },
|
|
68
73
|
* config: {},
|
package/src/client.ts
CHANGED
|
@@ -218,6 +218,7 @@ const decodeAmount = (value: unknown, path: string, url: string): bigint => {
|
|
|
218
218
|
// every field before writing a decoded `bigint` back over the wire string.
|
|
219
219
|
interface WireAmountBody {
|
|
220
220
|
outputs?: unknown;
|
|
221
|
+
epilogue?: unknown;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
// One `Amount` as it arrives: each leaf is `unknown` until this seam has
|
|
@@ -280,14 +281,36 @@ const decodeOutputs = (data: WireAmountBody, url: string): void => {
|
|
|
280
281
|
}
|
|
281
282
|
};
|
|
282
283
|
|
|
284
|
+
// `epilogue` is optional (absent without an epilogue, and on every partial);
|
|
285
|
+
// when present, each named forward's `amount` is a decimal string on the wire.
|
|
286
|
+
const decodeEpilogue = (data: WireAmountBody, url: string): void => {
|
|
287
|
+
const epilogue = data.epilogue;
|
|
288
|
+
if (epilogue === undefined) return;
|
|
289
|
+
if (!isNonNullObject(epilogue) || !Array.isArray(epilogue.forwards)) {
|
|
290
|
+
throw malformed('epilogue', 'is not an object with forwards', url);
|
|
291
|
+
}
|
|
292
|
+
const forwards: readonly unknown[] = epilogue.forwards;
|
|
293
|
+
forwards.forEach((forward, index) => {
|
|
294
|
+
if (!isNonNullObject(forward)) {
|
|
295
|
+
throw malformed(`epilogue.forwards[${index}]`, 'is not an object', url);
|
|
296
|
+
}
|
|
297
|
+
forward.amount = decodeAmount(
|
|
298
|
+
forward.amount,
|
|
299
|
+
`epilogue.forwards[${index}].amount`,
|
|
300
|
+
url,
|
|
301
|
+
);
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
|
|
283
305
|
// THE decode seam for a compile-family response body: every amount the wire
|
|
284
306
|
// renders as a decimal string becomes the `bigint` its declared type promises.
|
|
285
|
-
// The amount
|
|
307
|
+
// The amount records are handled here so the body is narrowed once — a
|
|
286
308
|
// non-object body is not this function's error to raise, since the enveloping
|
|
287
309
|
// parse already rejected it.
|
|
288
310
|
const decodeWireAmounts = (data: unknown, url: string): void => {
|
|
289
311
|
if (!isNonNullObject(data)) return;
|
|
290
312
|
decodeOutputs(data, url);
|
|
313
|
+
decodeEpilogue(data, url);
|
|
291
314
|
};
|
|
292
315
|
|
|
293
316
|
const parseBody = async <T>(res: Response, url: string): Promise<T> => {
|
package/src/errors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ComposeErrorKind,
|
|
3
3
|
ComposeRouteErrorKind,
|
|
4
|
+
DeliveryErrorDetails,
|
|
4
5
|
FailedPreparedOp,
|
|
5
6
|
GenericComposeErrorKind,
|
|
6
7
|
SimulationRevert,
|
|
@@ -102,6 +103,12 @@ export class ComposeError extends Error {
|
|
|
102
103
|
* backend can parse the revert reason.
|
|
103
104
|
*/
|
|
104
105
|
readonly details?: SimulationRevert;
|
|
106
|
+
/**
|
|
107
|
+
* The delivery tranche's reason, first quote, and abandoned escrow,
|
|
108
|
+
* attached to `delivery_error` errors. Narrow with
|
|
109
|
+
* {@link isComposeDeliveryError}.
|
|
110
|
+
*/
|
|
111
|
+
readonly delivery?: DeliveryErrorDetails;
|
|
105
112
|
/**
|
|
106
113
|
* The prepared ops that failed, attached to `preparation_error` errors.
|
|
107
114
|
* Each entry carries the `callId` of the failing node so callers can drop
|
|
@@ -130,6 +137,7 @@ export class ComposeError extends Error {
|
|
|
130
137
|
port?: string;
|
|
131
138
|
fix?: string;
|
|
132
139
|
details?: SimulationRevert;
|
|
140
|
+
delivery?: DeliveryErrorDetails;
|
|
133
141
|
failedOps?: readonly FailedPreparedOp[];
|
|
134
142
|
succeededOps?: readonly string[];
|
|
135
143
|
sdkOutdated?: ComposeSdkOutdated;
|
|
@@ -145,6 +153,7 @@ export class ComposeError extends Error {
|
|
|
145
153
|
this.port = options?.port;
|
|
146
154
|
this.fix = options?.fix;
|
|
147
155
|
this.details = options?.details;
|
|
156
|
+
this.delivery = options?.delivery;
|
|
148
157
|
this.failedOps = options?.failedOps;
|
|
149
158
|
this.succeededOps = options?.succeededOps;
|
|
150
159
|
this.sdkOutdated = options?.sdkOutdated;
|
|
@@ -200,6 +209,19 @@ export const isComposePreparationError = (
|
|
|
200
209
|
Array.isArray(e.failedOps) &&
|
|
201
210
|
Array.isArray(e.succeededOps);
|
|
202
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Type guard for `delivery_error` failures (HTTP 422): a bridge delivering into
|
|
214
|
+
* a settle escrow no longer fits it. Narrows {@link ComposeError.delivery} to
|
|
215
|
+
* present. Recompile: each compile quotes and registers afresh.
|
|
216
|
+
*
|
|
217
|
+
* @param e - The value to check.
|
|
218
|
+
* @returns `true` if `e` is a `ComposeError` carrying delivery details.
|
|
219
|
+
*/
|
|
220
|
+
export const isComposeDeliveryError = (
|
|
221
|
+
e: unknown,
|
|
222
|
+
): e is ComposeError & { readonly delivery: DeliveryErrorDetails } =>
|
|
223
|
+
isComposeError(e) && e.kind === 'delivery_error' && e.delivery !== undefined;
|
|
224
|
+
|
|
203
225
|
// `isComposeError` accepts a structurally-similar error by name, so an error
|
|
204
226
|
// raised by a *second* copy of this package in the dependency tree reaches the
|
|
205
227
|
// guard below without its `sdkOutdated` field being type-guaranteed. Parse it.
|
|
@@ -287,21 +309,32 @@ const tryParseErrorBody = (body: string): ServerErrorBody | null => {
|
|
|
287
309
|
|
|
288
310
|
/**
|
|
289
311
|
* Extracts the version triple an `sdk_outdated` or `server_outdated` envelope
|
|
290
|
-
* carries
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* a half-populated object.
|
|
312
|
+
* carries, and routes the wire `details` by kind. The version slots reuse the
|
|
313
|
+
* same schemas the type guards narrow with. Zod strips keys the schema does
|
|
314
|
+
* not declare, so the parsed value is exactly the triple; a partial payload
|
|
315
|
+
* fails the parse and yields `undefined` rather than a half-populated object.
|
|
316
|
+
* A `delivery_error`'s `details` land in `delivery`; every other kind's are
|
|
317
|
+
* forwarded verbatim as `details`.
|
|
294
318
|
*/
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
319
|
+
const readKindSlots = (serverError: ServerErrorBody['error']) => {
|
|
320
|
+
const delivery = serverError?.kind === 'delivery_error';
|
|
321
|
+
return {
|
|
322
|
+
sdkOutdated:
|
|
323
|
+
serverError?.kind === 'sdk_outdated'
|
|
324
|
+
? sdkOutdatedSchema.safeParse(serverError).data
|
|
325
|
+
: undefined,
|
|
326
|
+
serverOutdated:
|
|
327
|
+
serverError?.kind === 'server_outdated'
|
|
328
|
+
? serverOutdatedSchema.safeParse(serverError).data
|
|
329
|
+
: undefined,
|
|
330
|
+
details: delivery
|
|
331
|
+
? undefined
|
|
332
|
+
: (serverError?.details as SimulationRevert | undefined),
|
|
333
|
+
delivery: delivery
|
|
334
|
+
? (serverError.details as DeliveryErrorDetails | undefined)
|
|
303
335
|
: undefined,
|
|
304
|
-
}
|
|
336
|
+
};
|
|
337
|
+
};
|
|
305
338
|
|
|
306
339
|
/**
|
|
307
340
|
* Constructs a {@link ComposeError} from an HTTP error response, extracting
|
|
@@ -319,7 +352,7 @@ export const errorFromHttpResponse = (
|
|
|
319
352
|
): ComposeError => {
|
|
320
353
|
const parsed = tryParseErrorBody(body);
|
|
321
354
|
const serverError = parsed?.error;
|
|
322
|
-
const
|
|
355
|
+
const slots = readKindSlots(serverError);
|
|
323
356
|
|
|
324
357
|
return new ComposeError(
|
|
325
358
|
STATUS_TO_CODE.get(status) ??
|
|
@@ -333,7 +366,7 @@ export const errorFromHttpResponse = (
|
|
|
333
366
|
path: serverError?.path,
|
|
334
367
|
port: serverError?.port,
|
|
335
368
|
fix: serverError?.fix,
|
|
336
|
-
|
|
369
|
+
...slots,
|
|
337
370
|
// The wire schema types `kind` as a bare string; the server only ever
|
|
338
371
|
// reports generic kinds for individual ops.
|
|
339
372
|
failedOps: serverError?.failedOps?.map((op) => ({
|
|
@@ -341,8 +374,6 @@ export const errorFromHttpResponse = (
|
|
|
341
374
|
kind: op.kind as GenericComposeErrorKind,
|
|
342
375
|
})),
|
|
343
376
|
succeededOps: serverError?.succeededOps,
|
|
344
|
-
sdkOutdated,
|
|
345
|
-
serverOutdated,
|
|
346
377
|
},
|
|
347
378
|
);
|
|
348
379
|
};
|