Skip to content

Swap ​

The swap service quotes routes across the supported providers (Aquarius and Soroswap) and executes standalone swaps. Swaps run through the market contract's batch operations as a single exact-input swap, so they settle atomically without touching your obligations or collateral.

Accessed via client.swap.

INFO

Unlike most signing methods in the SDK, executeSwap's debug option defaults to false.

Quoting ​

getSwapRoutes ​

Quote a pair against every known provider in parallel and return a ranked list, best expected output first. Pairs with no direct pool are also routed through bridge tokens, so a route can exist even when the two assets share no pool. Failed candidates are dropped silently.

typescript
const routes = await client.swap.getSwapRoutes({
  fromTokenAddress,
  toTokenAddress,
  fromTokenDecimals,
  toTokenDecimals,
  amountIn: '100',
})
ParameterTypeDescription
fromTokenAddressstringInput token address
toTokenAddressstringOutput token address
fromTokenDecimalsnumberInput token decimals
toTokenDecimalsnumberOutput token decimals
amountInstring | numberHuman-readable input amount
providersSwapProviderDescriptor[]Optional override of providers to query. Defaults to all known providers

Returns an array of SwapRoute, each with a stable key, providerName, providerAddress, path, hops, amountIn, expectedAmountOut, and spotPrice.


getSwapPreview ​

Quote a single route and apply slippage to produce a minAmountOut. Use this when you already know the provider and path.

typescript
const preview = await client.swap.getSwapPreview({
  fromTokenAddress,
  toTokenAddress,
  fromTokenDecimals,
  toTokenDecimals,
  amountIn: '100',
  slippagePercent: 0.5,
  swapProviderAddress,
})
ParameterTypeDescription
fromTokenAddressstringInput token address
toTokenAddressstringOutput token address
fromTokenDecimalsnumberInput token decimals
toTokenDecimalsnumberOutput token decimals
amountInstring | numberHuman-readable input amount
slippagePercentnumberOptional slippage tolerance. Defaults to 0.5
swapProviderAddressstringProvider to route through
pathstring[]Optional explicit path; defaults to the direct pair

Returns a SwapPreview with amountIn, expectedAmountOut, minAmountOut, spotPrice, and the resolved swapPath.


previewFromRoute ​

Turn a SwapRoute (from getSwapRoutes) into a full SwapPreview by applying slippage. This is a pure helper — no RPC call — so you can re-render a minimum-output figure instantly when the user changes their slippage or picks a different ranked route.

typescript
const preview = client.swap.previewFromRoute(routes[0], 0.5)

Executing ​

executeSwap ​

Build, sign, and submit a swap in one call.

typescript
await client.swap.executeSwap(
  {
    user,
    fromTokenAddress,
    toTokenAddress,
    fromTokenDecimals,
    toTokenDecimals,
    amountIn: '100',
    slippagePercent: 0.5,
    swapProviderAddress,
  },
  kit,
)

Takes all getSwapPreview parameters plus the user obligation. Build-only variant: buildSwapTx(params) returns { preview, tx }.