Trading

Swap Function

Basic Swap

Execute swaps between supported token pairs with slippage protection:

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.

Price Discovery

LiquidCore uses Hyperliquid's HyperEVM read precompiles for price discovery. See Overview for details on this architecture.

Getting Current Prices

Returns:

  • forwardPrice: token0/token1 price from pool

  • inversePrice: token1/token0 price from pool

Dynamic Fee System

Fees adjust dynamically to optimize pool balance. Check getPoolFees() for current rates. See Fee System for distribution and claiming details.

Swap Estimation

Preview Swaps (On-Chain)

Before executing, estimate swap outcomes:

Quote API (Off-Chain)

REST API for getting quotes with multiple amounts in a single request.

Endpoint: GET https://api.liqd.ag/liquidcore/quote

Parameters:

  • tokenIn (address): Input token address

  • tokenOut (address): Output token address

  • amountIn (string): Comma-separated amounts in token units

Example:

Returns quotes for all specified amounts in human-readable format. See Integration Guide for complete usage and workflows.

Error Handling

Common Errors

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