@lifi/composer-sdk 0.0.1-alpha
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/LICENSE +201 -0
- package/README.md +220 -0
- package/dist/authoring/FlowBuilderCore.cjs +115 -0
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -0
- package/dist/authoring/FlowBuilderCore.d.cts +114 -0
- package/dist/authoring/FlowBuilderCore.d.ts +114 -0
- package/dist/authoring/FlowBuilderCore.js +91 -0
- package/dist/authoring/FlowBuilderCore.js.map +1 -0
- package/dist/authoring/handles.cjs +43 -0
- package/dist/authoring/handles.cjs.map +1 -0
- package/dist/authoring/handles.d.cts +61 -0
- package/dist/authoring/handles.d.ts +61 -0
- package/dist/authoring/handles.js +17 -0
- package/dist/authoring/handles.js.map +1 -0
- package/dist/authoring/raw.cjs +41 -0
- package/dist/authoring/raw.cjs.map +1 -0
- package/dist/authoring/raw.d.cts +47 -0
- package/dist/authoring/raw.d.ts +47 -0
- package/dist/authoring/raw.js +16 -0
- package/dist/authoring/raw.js.map +1 -0
- package/dist/authoring/signatureArgs.cjs +114 -0
- package/dist/authoring/signatureArgs.cjs.map +1 -0
- package/dist/authoring/signatureArgs.d.cts +146 -0
- package/dist/authoring/signatureArgs.d.ts +146 -0
- package/dist/authoring/signatureArgs.js +87 -0
- package/dist/authoring/signatureArgs.js.map +1 -0
- package/dist/client.cjs +140 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +67 -0
- package/dist/client.d.ts +67 -0
- package/dist/client.js +116 -0
- package/dist/client.js.map +1 -0
- package/dist/discovery.cjs +17 -0
- package/dist/discovery.cjs.map +1 -0
- package/dist/discovery.d.cts +56 -0
- package/dist/discovery.d.ts +56 -0
- package/dist/discovery.js +1 -0
- package/dist/discovery.js.map +1 -0
- package/dist/errors.cjs +91 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +77 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/config.generated.cjs +17 -0
- package/dist/generated/config.generated.cjs.map +1 -0
- package/dist/generated/config.generated.d.cts +144 -0
- package/dist/generated/config.generated.d.ts +144 -0
- package/dist/generated/config.generated.js +1 -0
- package/dist/generated/config.generated.js.map +1 -0
- package/dist/generated/guards.generated.cjs +32 -0
- package/dist/generated/guards.generated.cjs.map +1 -0
- package/dist/generated/guards.generated.d.cts +4 -0
- package/dist/generated/guards.generated.d.ts +4 -0
- package/dist/generated/guards.generated.js +8 -0
- package/dist/generated/guards.generated.js.map +1 -0
- package/dist/generated/materialisers.generated.cjs +44 -0
- package/dist/generated/materialisers.generated.cjs.map +1 -0
- package/dist/generated/materialisers.generated.d.cts +4 -0
- package/dist/generated/materialisers.generated.d.ts +4 -0
- package/dist/generated/materialisers.generated.js +18 -0
- package/dist/generated/materialisers.generated.js.map +1 -0
- package/dist/generated/operations.generated.cjs +110 -0
- package/dist/generated/operations.generated.cjs.map +1 -0
- package/dist/generated/operations.generated.d.cts +337 -0
- package/dist/generated/operations.generated.d.ts +337 -0
- package/dist/generated/operations.generated.js +89 -0
- package/dist/generated/operations.generated.js.map +1 -0
- package/dist/generated/preconditions.generated.cjs +44 -0
- package/dist/generated/preconditions.generated.cjs.map +1 -0
- package/dist/generated/preconditions.generated.d.cts +4 -0
- package/dist/generated/preconditions.generated.d.ts +4 -0
- package/dist/generated/preconditions.generated.js +18 -0
- package/dist/generated/preconditions.generated.js.map +1 -0
- package/dist/guards.generated-DKKDKREA.d.ts +14 -0
- package/dist/guards.generated-hrQ1KPNv.d.cts +14 -0
- package/dist/index.cjs +76 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +99 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/materialisers.generated-BsA1uDW8.d.ts +24 -0
- package/dist/materialisers.generated-nMxTAaVi.d.cts +24 -0
- package/dist/preconditions.generated-DblS13Wq.d.cts +24 -0
- package/dist/preconditions.generated-U7YpVh30.d.ts +24 -0
- package/dist/raw-Dj_2rBSQ.d.cts +19 -0
- package/dist/raw-IxCF_bSS.d.ts +19 -0
- package/dist/raw.cjs +34 -0
- package/dist/raw.cjs.map +1 -0
- package/dist/raw.d.cts +4 -0
- package/dist/raw.d.ts +4 -0
- package/dist/raw.js +8 -0
- package/dist/raw.js.map +1 -0
- package/dist/resources-BKlFxjo8.d.cts +56 -0
- package/dist/resources-CYis1_DS.d.ts +56 -0
- package/dist/resources.cjs +39 -0
- package/dist/resources.cjs.map +1 -0
- package/dist/resources.d.cts +3 -0
- package/dist/resources.d.ts +3 -0
- package/dist/resources.js +14 -0
- package/dist/resources.js.map +1 -0
- package/dist/run/inputs.cjs +51 -0
- package/dist/run/inputs.cjs.map +1 -0
- package/dist/run/inputs.d.cts +91 -0
- package/dist/run/inputs.d.ts +91 -0
- package/dist/run/inputs.js +26 -0
- package/dist/run/inputs.js.map +1 -0
- package/dist/sdk.cjs +60 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +112 -0
- package/dist/sdk.d.ts +112 -0
- package/dist/sdk.js +40 -0
- package/dist/sdk.js.map +1 -0
- package/dist/types.cjs +17 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +74 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
- package/src/authoring/FlowBuilderCore.ts +270 -0
- package/src/authoring/handles.ts +81 -0
- package/src/authoring/raw.ts +60 -0
- package/src/authoring/signatureArgs.ts +249 -0
- package/src/client.ts +230 -0
- package/src/discovery.ts +51 -0
- package/src/errors.ts +150 -0
- package/src/examples/approveAndDeposit.ts +84 -0
- package/src/examples/callContract.ts +199 -0
- package/src/examples/config.ts +9 -0
- package/src/examples/consolidateToEth.ts +94 -0
- package/src/examples/consolidateToUsdc.ts +95 -0
- package/src/examples/depositFromProxy.ts +87 -0
- package/src/examples/dustSweep.ts +66 -0
- package/src/examples/lifiSwap.ts +56 -0
- package/src/examples/lifiZap.ts +60 -0
- package/src/examples/rawCallWithArithmetic.ts +78 -0
- package/src/examples/readContractState.ts +77 -0
- package/src/examples/run.ts +168 -0
- package/src/examples/splitAndZap.ts +73 -0
- package/src/examples/splitWithArithmetic.ts +93 -0
- package/src/examples/swapAndZap.ts +72 -0
- package/src/examples/swapToRecipient.ts +109 -0
- package/src/examples/swapWithAllowRevert.ts +119 -0
- package/src/examples/swapWithBalanceCheck.ts +73 -0
- package/src/examples/swapWithOutputValidation.ts +125 -0
- package/src/examples/transferTokens.ts +123 -0
- package/src/examples/untypedOpWithTypedRef.ts +77 -0
- package/src/generated/config.generated.ts +174 -0
- package/src/generated/guards.generated.ts +14 -0
- package/src/generated/materialisers.generated.ts +44 -0
- package/src/generated/operations.generated.ts +568 -0
- package/src/generated/preconditions.generated.ts +43 -0
- package/src/index.ts +149 -0
- package/src/raw.ts +10 -0
- package/src/resources.ts +61 -0
- package/src/run/inputs.ts +117 -0
- package/src/sdk.ts +173 -0
- package/src/types.ts +101 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n SweepTo,\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 /** 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?: SweepTo;\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 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 * 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 maxPriceImpactBps?: number;\n sweepTo?: SweepTo;\n simulationPolicy?: SimulationPolicy;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n ...(run.preconditions?.length && { preconditions: run.preconditions }),\n signer: run.signer,\n ...(run.assumptions && { assumptions: run.assumptions }),\n ...(run.referrer != null && { referrer: run.referrer }),\n ...(run.maxPriceImpactBps != null && {\n maxPriceImpactBps: run.maxPriceImpactBps,\n }),\n ...(run.sweepTo != null && { sweepTo: run.sweepTo }),\n ...(run.simulationPolicy != null && {\n simulationPolicy: run.simulationPolicy,\n }),\n ...(run.checkOnChainAllowances != null && {\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n});\n"],"mappings":"AA4EO,MAAM,eAAe,CAC1B,MACA,SAAkC,CAAC,OACZ;AAAA,EACvB;AAAA,EACA,GAAG;AACL;AAQO,MAAM,WAAW,CAAC,SAUN;AAAA,EACjB,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,UAAU,EAAE,eAAe,IAAI,cAAc;AAAA,EACpE,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,EAAE,aAAa,IAAI,YAAY;AAAA,EACtD,GAAI,IAAI,YAAY,QAAQ,EAAE,UAAU,IAAI,SAAS;AAAA,EACrD,GAAI,IAAI,qBAAqB,QAAQ;AAAA,IACnC,mBAAmB,IAAI;AAAA,EACzB;AAAA,EACA,GAAI,IAAI,WAAW,QAAQ,EAAE,SAAS,IAAI,QAAQ;AAAA,EAClD,GAAI,IAAI,oBAAoB,QAAQ;AAAA,IAClC,kBAAkB,IAAI;AAAA,EACxB;AAAA,EACA,GAAI,IAAI,0BAA0B,QAAQ;AAAA,IACxC,wBAAwB,IAAI;AAAA,EAC9B;AACF;","names":[]}
|
package/dist/sdk.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sdk_exports = {};
|
|
20
|
+
__export(sdk_exports, {
|
|
21
|
+
createComposeSdk: () => createComposeSdk
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sdk_exports);
|
|
24
|
+
var import_FlowBuilderCore = require("./authoring/FlowBuilderCore.js");
|
|
25
|
+
var import_client = require("./client.js");
|
|
26
|
+
var import_operations_generated = require("./generated/operations.generated.js");
|
|
27
|
+
var import_inputs = require("./run/inputs.js");
|
|
28
|
+
const createComposeSdk = (options) => {
|
|
29
|
+
const composeClient = (0, import_client.createComposeClient)(options);
|
|
30
|
+
const request = (flowDoc, run) => ({
|
|
31
|
+
flow: flowDoc,
|
|
32
|
+
run: (0, import_inputs.buildRun)({
|
|
33
|
+
inputs: run.inputs,
|
|
34
|
+
preconditions: run.preconditions,
|
|
35
|
+
signer: run.signer,
|
|
36
|
+
assumptions: run.assumptions,
|
|
37
|
+
referrer: run.referrer,
|
|
38
|
+
maxPriceImpactBps: run.maxPriceImpactBps,
|
|
39
|
+
sweepTo: run.sweepTo,
|
|
40
|
+
simulationPolicy: run.simulationPolicy,
|
|
41
|
+
checkOnChainAllowances: run.checkOnChainAllowances
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
const flow = (chainId, opts) => {
|
|
45
|
+
const core = (0, import_FlowBuilderCore.createFlowBuilderCore)(chainId, opts);
|
|
46
|
+
const builder = Object.assign(core, (0, import_operations_generated.bindGeneratedOps)(core));
|
|
47
|
+
const compile = async (run) => {
|
|
48
|
+
const flowDoc = builder.build();
|
|
49
|
+
const req = request(flowDoc, run);
|
|
50
|
+
return composeClient.compile(req);
|
|
51
|
+
};
|
|
52
|
+
return Object.assign(builder, { compile });
|
|
53
|
+
};
|
|
54
|
+
return { client: composeClient, flow, request };
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
createComposeSdk
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=sdk.cjs.map
|
package/dist/sdk.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\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 /** Optional LI.FI API key for authenticated access. Sent as the `x-lifi-api-key` header on every request. */\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' });\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\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });\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 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 { client: composeClient, flow, request };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,6BAKO;AACP,oBAAwD;AACxD,kCAGO;AACP,oBAA+C;AAmHxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO,EAAE,QAAQ,eAAe,MAAM,QAAQ;AAChD;","names":[]}
|
package/dist/sdk.d.cts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ComposeCompileResult, ComposeCompileRequest } from '@lifi/compose-spec';
|
|
2
|
+
import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.cjs';
|
|
3
|
+
import { ComposeClient } from './client.cjs';
|
|
4
|
+
import { GeneratedOps } from './generated/operations.generated.cjs';
|
|
5
|
+
import { ComposeRunInput } from './run/inputs.cjs';
|
|
6
|
+
import { InputSchema } from './types.cjs';
|
|
7
|
+
import './authoring/handles.cjs';
|
|
8
|
+
import './discovery.cjs';
|
|
9
|
+
import './authoring/signatureArgs.cjs';
|
|
10
|
+
import 'abitype';
|
|
11
|
+
import './generated/config.generated.cjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A flow builder augmented with generated operation methods and a `compile` method
|
|
15
|
+
* that submits the flow to the Compose backend for compilation.
|
|
16
|
+
*
|
|
17
|
+
* Created via {@link ComposeSdk.flow}.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - The input schema describing the flow's required inputs.
|
|
20
|
+
*/
|
|
21
|
+
type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
|
|
22
|
+
/**
|
|
23
|
+
* Builds the flow document from the current builder state and submits it
|
|
24
|
+
* to the Compose API for compilation.
|
|
25
|
+
*
|
|
26
|
+
* @param run - Runtime inputs, preconditions, and signer address.
|
|
27
|
+
* @returns The compiled transaction calldata and metadata.
|
|
28
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const result = await builder.compile({
|
|
33
|
+
* inputs: { token: materialisers.balanceOf({}) },
|
|
34
|
+
* signer: '0xYourAddress...',
|
|
35
|
+
* });
|
|
36
|
+
* console.log(result.calldata);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for creating a Compose SDK instance.
|
|
43
|
+
*/
|
|
44
|
+
interface ComposeSdkOptions {
|
|
45
|
+
/** Base URL of the Compose API (e.g. `"https://li.quest"`). */
|
|
46
|
+
readonly baseUrl: string;
|
|
47
|
+
/** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
|
|
48
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
49
|
+
/** Optional LI.FI API key for authenticated access. Sent as the `x-lifi-api-key` header on every request. */
|
|
50
|
+
readonly apiKey?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The top-level Compose SDK interface.
|
|
54
|
+
*
|
|
55
|
+
* Provides methods to build flows, compile them into executable calldata, and
|
|
56
|
+
* interact with the Compose API directly.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';
|
|
61
|
+
*
|
|
62
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
63
|
+
*
|
|
64
|
+
* const builder = sdk.flow(1, {
|
|
65
|
+
* inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* builder.lifi.swap('swap1', {
|
|
69
|
+
* bind: { amountIn: builder.inputs.usdc },
|
|
70
|
+
* config: { resourceOut: resources.native(1) },
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const result = await builder.compile({
|
|
74
|
+
* inputs: { usdc: materialisers.balanceOf({}) },
|
|
75
|
+
* signer: '0xYourAddress...',
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
interface ComposeSdk {
|
|
80
|
+
/** Low-level HTTP client for the Compose API. */
|
|
81
|
+
readonly client: ComposeClient;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new flow builder targeting the given chain.
|
|
84
|
+
* @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
|
|
85
|
+
* @param options - Flow configuration including input declarations.
|
|
86
|
+
* @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
|
|
87
|
+
* @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
|
|
88
|
+
*/
|
|
89
|
+
readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Builds a raw compile request without sending it. Useful for inspecting the
|
|
92
|
+
* request payload or submitting it through a custom transport.
|
|
93
|
+
* @param flow - A built flow document (from `builder.build()`).
|
|
94
|
+
* @param run - Runtime inputs, preconditions, and signer address.
|
|
95
|
+
* @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
|
|
96
|
+
*/
|
|
97
|
+
readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new Compose SDK instance.
|
|
101
|
+
*
|
|
102
|
+
* @param options - SDK configuration including the API base URL and optional fetch implementation.
|
|
103
|
+
* @returns A {@link ComposeSdk} instance.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
|
|
111
|
+
|
|
112
|
+
export { ComposeRunInput, type ComposeSdk, type ComposeSdkOptions, type FlowBuilder, createComposeSdk };
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ComposeCompileResult, ComposeCompileRequest } from '@lifi/compose-spec';
|
|
2
|
+
import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.js';
|
|
3
|
+
import { ComposeClient } from './client.js';
|
|
4
|
+
import { GeneratedOps } from './generated/operations.generated.js';
|
|
5
|
+
import { ComposeRunInput } from './run/inputs.js';
|
|
6
|
+
import { InputSchema } from './types.js';
|
|
7
|
+
import './authoring/handles.js';
|
|
8
|
+
import './discovery.js';
|
|
9
|
+
import './authoring/signatureArgs.js';
|
|
10
|
+
import 'abitype';
|
|
11
|
+
import './generated/config.generated.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A flow builder augmented with generated operation methods and a `compile` method
|
|
15
|
+
* that submits the flow to the Compose backend for compilation.
|
|
16
|
+
*
|
|
17
|
+
* Created via {@link ComposeSdk.flow}.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - The input schema describing the flow's required inputs.
|
|
20
|
+
*/
|
|
21
|
+
type FlowBuilder<T extends InputSchema = InputSchema> = FlowBuilderCore<T> & GeneratedOps & {
|
|
22
|
+
/**
|
|
23
|
+
* Builds the flow document from the current builder state and submits it
|
|
24
|
+
* to the Compose API for compilation.
|
|
25
|
+
*
|
|
26
|
+
* @param run - Runtime inputs, preconditions, and signer address.
|
|
27
|
+
* @returns The compiled transaction calldata and metadata.
|
|
28
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const result = await builder.compile({
|
|
33
|
+
* inputs: { token: materialisers.balanceOf({}) },
|
|
34
|
+
* signer: '0xYourAddress...',
|
|
35
|
+
* });
|
|
36
|
+
* console.log(result.calldata);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
readonly compile: (run: ComposeRunInput<T>) => Promise<ComposeCompileResult>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for creating a Compose SDK instance.
|
|
43
|
+
*/
|
|
44
|
+
interface ComposeSdkOptions {
|
|
45
|
+
/** Base URL of the Compose API (e.g. `"https://li.quest"`). */
|
|
46
|
+
readonly baseUrl: string;
|
|
47
|
+
/** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
|
|
48
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
49
|
+
/** Optional LI.FI API key for authenticated access. Sent as the `x-lifi-api-key` header on every request. */
|
|
50
|
+
readonly apiKey?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The top-level Compose SDK interface.
|
|
54
|
+
*
|
|
55
|
+
* Provides methods to build flows, compile them into executable calldata, and
|
|
56
|
+
* interact with the Compose API directly.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';
|
|
61
|
+
*
|
|
62
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
63
|
+
*
|
|
64
|
+
* const builder = sdk.flow(1, {
|
|
65
|
+
* inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* builder.lifi.swap('swap1', {
|
|
69
|
+
* bind: { amountIn: builder.inputs.usdc },
|
|
70
|
+
* config: { resourceOut: resources.native(1) },
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const result = await builder.compile({
|
|
74
|
+
* inputs: { usdc: materialisers.balanceOf({}) },
|
|
75
|
+
* signer: '0xYourAddress...',
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
interface ComposeSdk {
|
|
80
|
+
/** Low-level HTTP client for the Compose API. */
|
|
81
|
+
readonly client: ComposeClient;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new flow builder targeting the given chain.
|
|
84
|
+
* @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).
|
|
85
|
+
* @param options - Flow configuration including input declarations.
|
|
86
|
+
* @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.
|
|
87
|
+
* @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
|
|
88
|
+
*/
|
|
89
|
+
readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Builds a raw compile request without sending it. Useful for inspecting the
|
|
92
|
+
* request payload or submitting it through a custom transport.
|
|
93
|
+
* @param flow - A built flow document (from `builder.build()`).
|
|
94
|
+
* @param run - Runtime inputs, preconditions, and signer address.
|
|
95
|
+
* @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
|
|
96
|
+
*/
|
|
97
|
+
readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new Compose SDK instance.
|
|
101
|
+
*
|
|
102
|
+
* @param options - SDK configuration including the API base URL and optional fetch implementation.
|
|
103
|
+
* @returns A {@link ComposeSdk} instance.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
|
|
111
|
+
|
|
112
|
+
export { ComposeRunInput, type ComposeSdk, type ComposeSdkOptions, type FlowBuilder, createComposeSdk };
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFlowBuilderCore
|
|
3
|
+
} from "./authoring/FlowBuilderCore.js";
|
|
4
|
+
import { createComposeClient } from "./client.js";
|
|
5
|
+
import {
|
|
6
|
+
bindGeneratedOps
|
|
7
|
+
} from "./generated/operations.generated.js";
|
|
8
|
+
import { buildRun } from "./run/inputs.js";
|
|
9
|
+
const createComposeSdk = (options) => {
|
|
10
|
+
const composeClient = createComposeClient(options);
|
|
11
|
+
const request = (flowDoc, run) => ({
|
|
12
|
+
flow: flowDoc,
|
|
13
|
+
run: buildRun({
|
|
14
|
+
inputs: run.inputs,
|
|
15
|
+
preconditions: run.preconditions,
|
|
16
|
+
signer: run.signer,
|
|
17
|
+
assumptions: run.assumptions,
|
|
18
|
+
referrer: run.referrer,
|
|
19
|
+
maxPriceImpactBps: run.maxPriceImpactBps,
|
|
20
|
+
sweepTo: run.sweepTo,
|
|
21
|
+
simulationPolicy: run.simulationPolicy,
|
|
22
|
+
checkOnChainAllowances: run.checkOnChainAllowances
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
const flow = (chainId, opts) => {
|
|
26
|
+
const core = createFlowBuilderCore(chainId, opts);
|
|
27
|
+
const builder = Object.assign(core, bindGeneratedOps(core));
|
|
28
|
+
const compile = async (run) => {
|
|
29
|
+
const flowDoc = builder.build();
|
|
30
|
+
const req = request(flowDoc, run);
|
|
31
|
+
return composeClient.compile(req);
|
|
32
|
+
};
|
|
33
|
+
return Object.assign(builder, { compile });
|
|
34
|
+
};
|
|
35
|
+
return { client: composeClient, flow, request };
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
createComposeSdk
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\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 /** Optional LI.FI API key for authenticated access. Sent as the `x-lifi-api-key` header on every request. */\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' });\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\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });\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 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 { client: composeClient, flow, request };\n};\n"],"mappings":"AAMA;AAAA,EACE;AAAA,OAIK;AACP,SAA6B,2BAA2B;AACxD;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gBAAsC;AAmHxC,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,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,OAAO,sBAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,MAAM,iBAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO,EAAE,QAAQ,eAAe,MAAM,QAAQ;AAChD;","names":[]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +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":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SolType, Ref, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
5
|
+
* Uses a template literal type so that only numeric-looking strings
|
|
6
|
+
* are assignable at compile time.
|
|
7
|
+
*/
|
|
8
|
+
type IntegerString = `${bigint}`;
|
|
9
|
+
/**
|
|
10
|
+
* Accepted input for integer-string config fields.
|
|
11
|
+
* Callers may pass either a numeric string ("1000000000") or a native bigint
|
|
12
|
+
* (1000000000n). Bigint values are stringified automatically during JSON
|
|
13
|
+
* serialization via the SDK's `bigintReplacer`.
|
|
14
|
+
*/
|
|
15
|
+
type IntegerStringInput = IntegerString | bigint;
|
|
16
|
+
/**
|
|
17
|
+
* A `0x`-prefixed hex string representing an Ethereum address.
|
|
18
|
+
* Template literal type catches obviously wrong values at compile time.
|
|
19
|
+
*/
|
|
20
|
+
type Address = `0x${string}`;
|
|
21
|
+
/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */
|
|
22
|
+
type OutputKind = SolType | 'resource';
|
|
23
|
+
/**
|
|
24
|
+
* Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the
|
|
25
|
+
* closest `OutputKind`. When the ABI type is one of the supported `SolType`
|
|
26
|
+
* scalars, the mapping is exact; for all other Solidity types (e.g. tuples,
|
|
27
|
+
* fixed-point decimals) it falls back to `SolType` — accepting any scalar
|
|
28
|
+
* handle but not `'resource'` handles.
|
|
29
|
+
*
|
|
30
|
+
* The fallback excludes `'resource'` because every Solidity type is a scalar;
|
|
31
|
+
* resource handles carry token-amount semantics that should only flow into
|
|
32
|
+
* slots explicitly declared as resources.
|
|
33
|
+
*
|
|
34
|
+
* Extending `SolType` with new members automatically widens the exact-match
|
|
35
|
+
* branch — no changes needed here.
|
|
36
|
+
*/
|
|
37
|
+
type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
38
|
+
/**
|
|
39
|
+
* A typed `$ref` pointer carrying a phantom type parameter.
|
|
40
|
+
* Extends `Ref` so it is accepted anywhere a plain `Ref` is.
|
|
41
|
+
* The `__outputKind` field is never set at runtime — it exists only
|
|
42
|
+
* for TypeScript's structural type checker to distinguish typed refs.
|
|
43
|
+
*/
|
|
44
|
+
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
45
|
+
readonly __outputKind?: T;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An input declaration in a flow schema.
|
|
49
|
+
* `Resource` values become resource inputs (token amounts);
|
|
50
|
+
* `SolType` strings become handle inputs (scalars like addresses).
|
|
51
|
+
*/
|
|
52
|
+
type InputDecl = Resource | SolType;
|
|
53
|
+
/**
|
|
54
|
+
* A record mapping input names to their declarations.
|
|
55
|
+
* Used as the type parameter for generic flow builders and requests.
|
|
56
|
+
*/
|
|
57
|
+
type InputSchema = Record<string, InputDecl>;
|
|
58
|
+
/**
|
|
59
|
+
* Maps an input declaration to the allowed runtime value type.
|
|
60
|
+
* Resource inputs accept materialisers or literal amounts.
|
|
61
|
+
* Handle inputs accept the scalar type matching their SolType.
|
|
62
|
+
*/
|
|
63
|
+
type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends 'address' ? Address : D extends 'bool' ? boolean : D extends `${'u' | ''}int${string}` ? IntegerStringInput : D extends `bytes${string}` ? `0x${string}` : D extends 'string' ? string : InputSpec;
|
|
64
|
+
/**
|
|
65
|
+
* A guard applied to an operation, with the `port` field constrained
|
|
66
|
+
* to a specific set of output port names.
|
|
67
|
+
*/
|
|
68
|
+
interface TypedGuard<Port extends string = string> {
|
|
69
|
+
readonly kind: string;
|
|
70
|
+
readonly port: Port;
|
|
71
|
+
readonly [key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedRef };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SolType, Ref, Resource, MaterialiserInput, InputSpec } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A string that represents a non-negative integer (e.g. "1000000000").
|
|
5
|
+
* Uses a template literal type so that only numeric-looking strings
|
|
6
|
+
* are assignable at compile time.
|
|
7
|
+
*/
|
|
8
|
+
type IntegerString = `${bigint}`;
|
|
9
|
+
/**
|
|
10
|
+
* Accepted input for integer-string config fields.
|
|
11
|
+
* Callers may pass either a numeric string ("1000000000") or a native bigint
|
|
12
|
+
* (1000000000n). Bigint values are stringified automatically during JSON
|
|
13
|
+
* serialization via the SDK's `bigintReplacer`.
|
|
14
|
+
*/
|
|
15
|
+
type IntegerStringInput = IntegerString | bigint;
|
|
16
|
+
/**
|
|
17
|
+
* A `0x`-prefixed hex string representing an Ethereum address.
|
|
18
|
+
* Template literal type catches obviously wrong values at compile time.
|
|
19
|
+
*/
|
|
20
|
+
type Address = `0x${string}`;
|
|
21
|
+
/** The universe of output port kinds: Solidity scalar types plus `'resource'`. */
|
|
22
|
+
type OutputKind = SolType | 'resource';
|
|
23
|
+
/**
|
|
24
|
+
* Maps an ABI parameter type string (from abitype's `ParseAbiItem`) to the
|
|
25
|
+
* closest `OutputKind`. When the ABI type is one of the supported `SolType`
|
|
26
|
+
* scalars, the mapping is exact; for all other Solidity types (e.g. tuples,
|
|
27
|
+
* fixed-point decimals) it falls back to `SolType` — accepting any scalar
|
|
28
|
+
* handle but not `'resource'` handles.
|
|
29
|
+
*
|
|
30
|
+
* The fallback excludes `'resource'` because every Solidity type is a scalar;
|
|
31
|
+
* resource handles carry token-amount semantics that should only flow into
|
|
32
|
+
* slots explicitly declared as resources.
|
|
33
|
+
*
|
|
34
|
+
* Extending `SolType` with new members automatically widens the exact-match
|
|
35
|
+
* branch — no changes needed here.
|
|
36
|
+
*/
|
|
37
|
+
type AbiTypeToOutputKind<T extends string> = T extends SolType ? T : SolType;
|
|
38
|
+
/**
|
|
39
|
+
* A typed `$ref` pointer carrying a phantom type parameter.
|
|
40
|
+
* Extends `Ref` so it is accepted anywhere a plain `Ref` is.
|
|
41
|
+
* The `__outputKind` field is never set at runtime — it exists only
|
|
42
|
+
* for TypeScript's structural type checker to distinguish typed refs.
|
|
43
|
+
*/
|
|
44
|
+
interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
|
|
45
|
+
readonly __outputKind?: T;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An input declaration in a flow schema.
|
|
49
|
+
* `Resource` values become resource inputs (token amounts);
|
|
50
|
+
* `SolType` strings become handle inputs (scalars like addresses).
|
|
51
|
+
*/
|
|
52
|
+
type InputDecl = Resource | SolType;
|
|
53
|
+
/**
|
|
54
|
+
* A record mapping input names to their declarations.
|
|
55
|
+
* Used as the type parameter for generic flow builders and requests.
|
|
56
|
+
*/
|
|
57
|
+
type InputSchema = Record<string, InputDecl>;
|
|
58
|
+
/**
|
|
59
|
+
* Maps an input declaration to the allowed runtime value type.
|
|
60
|
+
* Resource inputs accept materialisers or literal amounts.
|
|
61
|
+
* Handle inputs accept the scalar type matching their SolType.
|
|
62
|
+
*/
|
|
63
|
+
type InputSpecOf<D> = D extends Resource ? MaterialiserInput | IntegerStringInput : D extends 'address' ? Address : D extends 'bool' ? boolean : D extends `${'u' | ''}int${string}` ? IntegerStringInput : D extends `bytes${string}` ? `0x${string}` : D extends 'string' ? string : InputSpec;
|
|
64
|
+
/**
|
|
65
|
+
* A guard applied to an operation, with the `port` field constrained
|
|
66
|
+
* to a specific set of output port names.
|
|
67
|
+
*/
|
|
68
|
+
interface TypedGuard<Port extends string = string> {
|
|
69
|
+
readonly kind: string;
|
|
70
|
+
readonly port: Port;
|
|
71
|
+
readonly [key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedRef };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lifi/composer-sdk",
|
|
3
|
+
"version": "0.0.1-alpha",
|
|
4
|
+
"description": "Public Composer SDK for building and submitting flows",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"prettier": {
|
|
27
|
+
"singleQuote": true
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc --noEmit && tsup",
|
|
31
|
+
"clean": "rm -rf dist out",
|
|
32
|
+
"pack:local": "yarn build && mkdir -p out && yarn pack --out 'out/%s-%v.tgz'",
|
|
33
|
+
"generate": "tsx scripts/generate-sdk.ts",
|
|
34
|
+
"test": "vitest run --config vitest.config.ts",
|
|
35
|
+
"check:types": "tsc --noEmit",
|
|
36
|
+
"check:sdk-drift": "vitest run --config vitest.drift.config.ts",
|
|
37
|
+
"fix": "run-s fix:lint fix:prettier",
|
|
38
|
+
"fix:lint": "eslint src --fix",
|
|
39
|
+
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
|
40
|
+
"lint": "eslint src",
|
|
41
|
+
"test:lint": "eslint src",
|
|
42
|
+
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
|
43
|
+
"example": "tsx src/examples/run.ts"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@lifi/compose-spec": "0.0.1-alpha"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"abitype": "^1.2.3",
|
|
50
|
+
"effect": "^3.21.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/compat": "^1.4.0",
|
|
54
|
+
"@lifi/compose-spec": "workspace:^",
|
|
55
|
+
"@types/node": "^25.6.0",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^8.44.1",
|
|
57
|
+
"@typescript-eslint/parser": "^8.44.1",
|
|
58
|
+
"eslint": "^9.36.0",
|
|
59
|
+
"eslint-config-prettier": "^9.0.0",
|
|
60
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
61
|
+
"eslint-plugin-import": "^2.22.0",
|
|
62
|
+
"eslint-plugin-require-extensions": "^0.1.3",
|
|
63
|
+
"json-schema-to-typescript": "^15.0.4",
|
|
64
|
+
"npm-run-all": "^4.1.5",
|
|
65
|
+
"prettier": "^3.0.0",
|
|
66
|
+
"tsup": "^8.5.1",
|
|
67
|
+
"tsx": "^4.20.4",
|
|
68
|
+
"typescript": "^5.9.2",
|
|
69
|
+
"vitest": "^3.2.4"
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"dist/**",
|
|
73
|
+
"!dist/**/*.tsbuildinfo",
|
|
74
|
+
"src/**/*.ts",
|
|
75
|
+
"!src/**/*.spec.ts",
|
|
76
|
+
"!src/**/*.test.ts",
|
|
77
|
+
"!src/**/*.mock.ts",
|
|
78
|
+
"!src/**/*.typecheck.ts",
|
|
79
|
+
"!dist/**/*.typecheck.*"
|
|
80
|
+
]
|
|
81
|
+
}
|