Trading

How to execute and estimate LiquidCore swaps. Use the router for automatic pool discovery; direct pool calls are also supported.

Swap Function

Recommended: Execute swaps via the LiquidCore Router (0x625aC1D165c776121A52ff158e76e3544B4a0b8B). Approve the router for tokenIn, then call swap(tokenIn, tokenOut, amountIn, minAmountOut). The router discovers the correct pool automatically, so integrators don't need to update code when new pools are added. See Integration Guide.

Option: direct pool. You can call swap on a pool contract directly if you already know the pool address (see Overview). Approve the pool for tokenIn, then call:

function swap(
    address tokenIn,
    address tokenOut, 
    uint256 amountIn,
    uint256 minAmountOut
) external returns (uint256 amountOut)

Parameters

Parameter
Type
Description

tokenIn

address

Address of token being sold

tokenOut

address

Address of token being bought

amountIn

uint256

Amount of tokenIn to swap

minAmountOut

uint256

Minimum amount of tokenOut expected (slippage protection)

Returns: Actual amount of tokenOut received

Supported Trading Pairs

See the Overview for pool addresses and token details.

Swap Estimation

Preview Swaps (On-Chain)

Before executing, estimate swap outcomes:

Quote API (Off-Chain)

Use GET /liquidcore/quote for swap quotes (single or comma-separated amountIn). Full request/response and execution steps: API Endpoints.

Error Handling

When calling a pool directly, common errors include:

When using the router, see API Reference for NoPoolForPair and TransferFailed.

Error Resolution

  • InvalidToken: Ensure using correct token addresses for the specific pool

  • ZeroAmount: Check amount input is greater than zero

  • SlippageExceeded: Increase slippage tolerance or reduce trade size

  • InsufficientReserve: Pool lacks liquidity, try smaller amount

  • PriceDeviationTooLarge: Spot price differs from oracle price

Last updated