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.
const routes = await client.swap.getSwapRoutes({
fromTokenAddress,
toTokenAddress,
fromTokenDecimals,
toTokenDecimals,
amountIn: '100',
})| Parameter | Type | Description |
|---|---|---|
fromTokenAddress | string | Input token address |
toTokenAddress | string | Output token address |
fromTokenDecimals | number | Input token decimals |
toTokenDecimals | number | Output token decimals |
amountIn | string | number | Human-readable input amount |
providers | SwapProviderDescriptor[] | 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.
const preview = await client.swap.getSwapPreview({
fromTokenAddress,
toTokenAddress,
fromTokenDecimals,
toTokenDecimals,
amountIn: '100',
slippagePercent: 0.5,
swapProviderAddress,
})| Parameter | Type | Description |
|---|---|---|
fromTokenAddress | string | Input token address |
toTokenAddress | string | Output token address |
fromTokenDecimals | number | Input token decimals |
toTokenDecimals | number | Output token decimals |
amountIn | string | number | Human-readable input amount |
slippagePercent | number | Optional slippage tolerance. Defaults to 0.5 |
swapProviderAddress | string | Provider to route through |
path | string[] | 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.
const preview = client.swap.previewFromRoute(routes[0], 0.5)Executing
executeSwap
Build, sign, and submit a swap in one call.
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 }.