Quoting prices
You have three ways to get a swap quote on Kumbaya, depending on whether you want to run the routing logic yourself or have Kumbaya do it for you.
QuoterV2 directly (RPC)
Single-pool quotes, you know the route
Fast, simple. No multi-hop optimization.
@kumbaya_xyz/smart-order-router
Multi-hop optimal routing, client-side
Heavier. Needs RPC + indexer access.
Exchange API /api/v1/quote
Most integrations - let us route
One HTTPS call. Cached. Returns calldata.
Option 1: QuoterV2 directly
For a single pool - fee tier and tokens known up front - the simplest path is calling QuoterV2.quoteExactInputSingle() via RPC.
import { createPublicClient, http, parseUnits } from 'viem'
const QUOTER_V2 = '0x1F1a8dC7E138C34b503Ca080962aC10B75384a27' // mainnet
const RPC = 'https://mainnet.megaeth.com/rpc'
const quoterAbi = [{
type: 'function',
name: 'quoteExactInputSingle',
stateMutability: 'nonpayable',
inputs: [{ type: 'tuple', name: 'params', components: [
{ type: 'address', name: 'tokenIn' },
{ type: 'address', name: 'tokenOut' },
{ type: 'uint256', name: 'amountIn' },
{ type: 'uint24', name: 'fee' },
{ type: 'uint160', name: 'sqrtPriceLimitX96' },
]}],
outputs: [
{ type: 'uint256', name: 'amountOut' },
{ type: 'uint160', name: 'sqrtPriceX96After' },
{ type: 'uint32', name: 'initializedTicksCrossed' },
{ type: 'uint256', name: 'gasEstimate' },
],
}] as const
const client = createPublicClient({ transport: http(RPC) })
const quote = await client.simulateContract({
address: QUOTER_V2,
abi: quoterAbi,
functionName: 'quoteExactInputSingle',
args: [{
tokenIn: '0x4200000000000000000000000000000000000006', // WETH
tokenOut: '0xYOUR_TOKEN',
amountIn: parseUnits('1', 18),
fee: 3000, // 0.3% - pick the right tier
sqrtPriceLimitX96: 0n,
}],
})
console.log('Out:', quote.result[0])
console.log('Gas estimate:', quote.result[3])Notes:
QuoterV2does a real on-chain simulation, so the result is exact (modulo the obvious caveat that price can move before your tx lands).It's a
nonpayablefunction despite being read-only - that's a Uniswap V3 quirk. UsesimulateContract(viem) orstaticCall(ethers) rather thanreadContract.For exact output, use
quoteExactOutputSingle(same shape, swapamountIn→amountOut).For multi-hop, use
quoteExactInput(bytes path, uint256 amountIn)with a packed path - but at that point you probably want option 2 or 3.
Option 2: Smart Order Router (client-side)
For multi-hop and split routes, use @kumbaya_xyz/smart-order-router. It enumerates pools, scores routes, and accounts for gas:
Smart Order Router is built on ethers v5 (
BaseProviderfrom@ethersproject/providers). It does not currently support ethers v6 or viem providers.
The returned methodParameters are ready to send to SwapRouter02 or UniversalRouter (configurable on the route call). See Executing swaps.
Option 3: Exchange API
If you don't want to run the SOR client-side, hit the hosted endpoint:
Response includes:
quoteandquoteGasAdjusted(human-readable decimal strings)gasUseEstimate,gasUseEstimateUSDmethodParameters: { to, value, calldata }- ready to submit as a transactionroute- the path the SOR picked
The GET endpoint takes
amountandtype(exactIn/exactOut); the POST partner endpoint takesfromAmountand uses a decimalslippageinstead. They're not interchangeable. See Quote endpoints.
See Executing swaps for what to do with the returned calldata.
Picking between them
Quick prototype, single pool:
QuoterV2direct.Production frontend or bot, full routing: Exchange API. Less to maintain, server-side caching.
Custom routing logic, alternative venues, or you want to inspect routes: Smart Order Router locally.
Last updated