WDK logoWDK documentation

LI.FI Swidge API Reference

API reference for @lifi/wdk-protocol-swidge-lifi.

Community modules are developed and maintained independently by third-party contributors.

Tether and the WDK Team do not endorse or assume responsibility for their code, security, or maintenance. Use your own judgment and proceed at your own risk.

LifiSwidgeProtocol

LifiSwidgeProtocol extends SwidgeProtocol from @tetherto/wdk-wallet/protocols and implements the shared WDK swidge methods.

import {
  LifiSwidgeProtocol
} from '@lifi/wdk-protocol-swidge-lifi'

const swidge = new LifiSwidgeProtocol(account, config)

Constructor

new LifiSwidgeProtocol(account?, config?)
AccountAvailable operations
WalletAccountEvmDiscovery, quote, status, and execution.
WalletAccountEvmErc4337Discovery, quote, status, and execution through a smart account.
WalletAccountReadOnlyEvmDiscovery, quote, and status.
undefinedChain and token discovery without a provider; quote when config.provider is supplied.

Use WalletAccountReadOnlyEvm for quote-only flows that should include the account address or support status lookups. In no-account mode, quoteSwidge() resolves the source chain through config.provider and omits fromAddress from the LI.FI request.

Methods

MethodDescription
quoteSwidge(options)Returns a non-binding LI.FI route quote.
swidge(options, config?)Executes a swap, bridge, or combined route.
getSwidgeStatus(id, options?)Maps LI.FI status to WDK SwidgeStatus.
getSupportedChains()Returns chains supported by LI.FI.
getSupportedTokens(options?)Returns tokens supported by LI.FI, optionally filtered by chain context.

quoteSwidge(options)

quoteSwidge(options: SwidgeOptions): Promise<SwidgeQuote>

Use this before execution to estimate output amounts, minimum output, and fees.

swidge(options, config?)

swidge(
  options: SwidgeOptions,
  config?: LifiSwidgeProtocolConfig
): Promise<SwidgeResult>

Executes through the bound writable account. The module sends required approval transactions before the route transaction where needed.

For quote-first flows, pass the minAmountOut field in options: set it to the toTokenAmountMin from a previously displayed quoteSwidge() result, and swidge() throws before any approval or transaction is sent if the fresh execution quote's minimum output falls below it. minAmountOut is not forwarded to LI.FI, and quoteSwidge() ignores it.

Throws before execution when validation fails, a fee cap is exceeded, the quote falls below minAmountOut, allowNativeValue: false and the quote requires native value, or trustedContracts rejects the quote target or approval address.

getSwidgeStatus(id, options?)

getSwidgeStatus(
  id: string,
  options?: SwidgeStatusOptions
): Promise<SwidgeStatusResult>

Chain hints are optional:

OptionTypeDescription
fromChainstring | numberSource chain name or LI.FI chain ID.
toChainstring | numberDestination chain name or LI.FI chain ID.

Config Type

type LifiRouteOrder = 'RECOMMENDED' | 'FASTEST' | 'CHEAPEST'

type LifiSwidgeProtocolConfig = {
  maxNetworkFeeBps?: number | bigint
  maxProtocolFeeBps?: number | bigint
  provider?: string | Eip1193Provider
  integrator?: string
  apiKey?: string
  order?: LifiRouteOrder
  allowBridges?: string[]
  denyBridges?: string[]
  allowDestinationCall?: boolean
  allowNativeValue?: boolean
  timeout?: number
  retries?: number
  retryDelay?: number
  trustedContracts?: true | Record<number, string | string[]>
}

Status Mapping

LI.FI statusSubstatusWDK status
PENDINGAnypending
DONECOMPLETEDcompleted
DONEPARTIALpartial
DONEREFUNDEDrefunded
DONENOT_PROCESSABLE_REFUND_NEEDEDrefund-pending
FAILEDAnyfailed
AnyRequired actions presentaction-required

Fee Mapping

LI.FI costWDK fee typeLegacy field
gasCosts[].type === 'SEND'networkfee
feeCosts[]protocolbridgeFee

When LI.FI supplies cost-token metadata, fee.chain identifies that token's chain and may differ from the source or execution chain. The field is omitted when LI.FI does not supply a chain.

Error Types

All LI.FI module errors extend LifiProtocolError.

ErrorWhen thrown
LifiConfigurationErrorRequired provider or configuration is missing or invalid.
LifiQuoteErrorLI.FI quote or token API request fails.
LifiExecutionErrorExecution cannot proceed, including fee-cap failures.
LifiStatusErrorStatus lookup fails. Inspect lifiStatus: NOT_FOUND can mean indexing is pending, while INVALID is terminal.
LifiReadOnlyAccountErrorswidge() is called without a writable account.
LifiUnsupportedChainErrorAn unknown chain name is passed.
LifiTimeoutErrorA LI.FI request exceeds the configured timeout.
LifiNetworkErrorNetwork failures persist after retries.
LifiRateLimitErrorLI.FI returns 429 after retries are exhausted.
LifiSlippageErrorLI.FI returns 409 for a stale quote.
LifiValidationErrorUser input or API transaction data fails validation.
LifiUntrustedContractErrortrustedContracts rejects a target or approval address.

On this page