@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
150 lines (140 loc) • 4.17 kB
text/typescript
/**
* `@lifi/composer-sdk` — TypeScript SDK for building and compiling
* Compose flows into executable EVM calldata.
*
* Start by creating an SDK instance with {@link createComposeSdk}, then use
* {@link ComposeSdk.flow} to build flows and compile them.
*
* @packageDocumentation
*/
export type {
AbiTypeToOutputKind,
Address,
InputDecl,
InputSchema,
InputSpecOf,
IntegerString,
IntegerStringInput,
OutputKind,
TypedGuard,
TypedRef,
} from './types.js';
export type {
GetZapPacksOptions,
ZapPackEdge,
ZapPackOverview,
} from './discovery.js';
export type { ComposeError, ComposeErrorCode } from './errors.js';
export type {
AppliedGuard,
ApprovalEntry,
Call,
ComposeCompilePartialData,
ComposeCompileRequest,
ComposeCompileResult,
ComposeCompileSuccessData,
ComposeContinuation,
ComposeErrorKind,
ComposeTransactionRequest,
Flow,
InputSpec,
MaterialiserConfigOf,
MaterialiserInput,
Precondition,
PreconditionConfigOf,
PriceImpact,
Ref,
Resource,
SimulationPolicy,
SimulationRevert,
SolType,
SweepTo,
} from '@lifi/compose-spec';
export { isComposeError } from './errors.js';
export type {
Bindable,
InputHandle,
ResourceInputHandle,
OutputHandle,
AnyHandle,
} from './authoring/handles.js';
export { isInputHandle, isOutputHandle } from './authoring/handles.js';
export { ref } from './authoring/raw.js';
export type { AnyBindable } from './authoring/FlowBuilderCore.js';
export type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';
export type { ComposeRunInput } from './run/inputs.js';
export { materialiser } from './run/inputs.js';
export { createComposeSdk } from './sdk.js';
export type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';
import * as guardsMod from './generated/guards.generated.js';
import * as materialisersMod from './generated/materialisers.generated.js';
import * as preconditionsMod from './generated/preconditions.generated.js';
import * as rawMod from './raw.js';
import * as resourcesMod from './resources.js';
/**
* Guard factories for protecting operation outputs (e.g. slippage tolerance).
* Pass guards to an operation's `guards` array.
*
* @example
* ```ts
* builder.lifi.swap('swap1', {
* bind: { amountIn: builder.inputs.token },
* config: { resourceOut: resources.native(1) },
* guards: [guards.slippage({ port: 'amountOut', bps: 300 })],
* });
* ```
*/
export const guards: typeof guardsMod = guardsMod;
/**
* Materialiser factories that tell the runtime how to resolve token input
* amounts on-chain (e.g. read a wallet balance, accept a direct deposit).
*
* @example
* ```ts
* await builder.compile({
* inputs: { token: materialisers.balanceOf({}) },
* signer: '0x...',
* });
* ```
*/
export const materialisers: typeof materialisersMod = materialisersMod;
/**
* Precondition factories for asserting on-chain state before a flow executes
* (e.g. minimum token balances, ERC-20 allowances).
*
* @example
* ```ts
* await builder.compile({
* inputs: { token: materialisers.balanceOf({}) },
* preconditions: [
* preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),
* ],
* signer: '0x...',
* });
* ```
*/
export const preconditions: typeof preconditionsMod = preconditionsMod;
/**
* Resource declaration helpers for defining token inputs in a flow schema.
* Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}
* for the chain's native coin (ETH, MATIC, etc.).
*
* @example
* ```ts
* const builder = sdk.flow(1, {
* inputs: {
* usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),
* eth: resources.native(1),
* },
* });
* ```
*/
export const resources: typeof resourcesMod = resourcesMod;
export * from './generated/config.generated.js';
/**
* Low-level escape hatch for constructing flow nodes, guards, and materialiser
* inputs without the typed builder API. Prefer the generated operation methods
* on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces
* for most use cases.
*/
export const raw: typeof rawMod = rawMod;