UNPKG

@lifi/composer-sdk

Version:

Public Composer SDK for building and submitting flows

1 lines 2.14 kB
{"version":3,"sources":["../src/resources.ts"],"sourcesContent":["import type { Address } from './types.js';\n\n// These resource types are SDK-local declarations that mirror the shape of\n// `Resource` from `@lifi/compose-spec`. They exist so the SDK can be used\n// without directly depending on `@lifi/compose-spec` at the call site.\n// The types are structurally compatible, so they are assignable to each other.\n\n/** A resource declaration representing the chain's native token (e.g. ETH, MATIC). */\nexport interface NativeResource {\n readonly kind: 'native';\n readonly chainId: number;\n}\n\n/** A resource declaration representing an ERC-20 token at a specific address. */\nexport interface Erc20Resource {\n readonly kind: 'erc20';\n readonly token: Address;\n readonly chainId: number;\n}\n\n/** A token resource — either the chain's native token or an ERC-20. */\nexport type Resource = NativeResource | Erc20Resource;\n\n/**\n * Creates a native token resource declaration.\n *\n * @param chainId - The EVM chain ID the native token belongs to.\n * @returns A {@link NativeResource} for use in flow input schemas.\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: { eth: native(1) },\n * });\n * ```\n */\nexport const native = (chainId: number): NativeResource => ({\n kind: 'native',\n chainId,\n});\n\n/**\n * Creates an ERC-20 token resource declaration.\n *\n * @param token - The `0x`-prefixed contract address of the ERC-20 token.\n * @param chainId - The EVM chain ID the token is deployed on.\n * @returns An {@link Erc20Resource} for use in flow input schemas.\n *\n * @example\n * ```ts\n * const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';\n * const builder = sdk.flow(1, {\n * inputs: { usdc: erc20(USDC, 1) },\n * });\n * ```\n */\nexport const erc20 = (token: Address, chainId: number): Erc20Resource => ({\n kind: 'erc20',\n token,\n chainId,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,MAAM,SAAS,CAAC,aAAqC;AAAA,EAC1D,MAAM;AAAA,EACN;AACF;AAiBO,MAAM,QAAQ,CAAC,OAAgB,aAAoC;AAAA,EACxE,MAAM;AAAA,EACN;AAAA,EACA;AACF;","names":[]}