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?)| Account | Available operations |
|---|---|
WalletAccountEvm | Discovery, quote, status, and execution. |
WalletAccountEvmErc4337 | Discovery, quote, status, and execution through a smart account. |
WalletAccountReadOnlyEvm | Discovery, quote, and status. |
undefined | Chain 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
| Method | Description |
|---|---|
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:
| Option | Type | Description |
|---|---|---|
fromChain | string | number | Source chain name or LI.FI chain ID. |
toChain | string | number | Destination 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 status | Substatus | WDK status |
|---|---|---|
PENDING | Any | pending |
DONE | COMPLETED | completed |
DONE | PARTIAL | partial |
DONE | REFUNDED | refunded |
DONE | NOT_PROCESSABLE_REFUND_NEEDED | refund-pending |
FAILED | Any | failed |
| Any | Required actions present | action-required |
Fee Mapping
| LI.FI cost | WDK fee type | Legacy field |
|---|---|---|
gasCosts[].type === 'SEND' | network | fee |
feeCosts[] | protocol | bridgeFee |
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.
| Error | When thrown |
|---|---|
LifiConfigurationError | Required provider or configuration is missing or invalid. |
LifiQuoteError | LI.FI quote or token API request fails. |
LifiExecutionError | Execution cannot proceed, including fee-cap failures. |
LifiStatusError | Status lookup fails. Inspect lifiStatus: NOT_FOUND can mean indexing is pending, while INVALID is terminal. |
LifiReadOnlyAccountError | swidge() is called without a writable account. |
LifiUnsupportedChainError | An unknown chain name is passed. |
LifiTimeoutError | A LI.FI request exceeds the configured timeout. |
LifiNetworkError | Network failures persist after retries. |
LifiRateLimitError | LI.FI returns 429 after retries are exhausted. |
LifiSlippageError | LI.FI returns 409 for a stale quote. |
LifiValidationError | User input or API transaction data fails validation. |
LifiUntrustedContractError | trustedContracts rejects a target or approval address. |