@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
1 lines • 2.42 kB
Source Map (JSON)
{"version":3,"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BO,MAAM,QAAQ,CAAC,YAA+C;AAAA,EACnE,MAAM;AAAA,EACN;AACF;AA2BO,MAAM,MAAM,CAAC,eAAgD;AAAA,EAClE,MAAM;AAAA,EACN;AACF;","names":[]}