Quickstart
What we're building
Install
npm install @kumbaya_xyz/sdk-core @kumbaya_xyz/v3-sdk viemThe full script
import { createPublicClient, http, parseEther } from 'viem'
import { Token, ChainId } from '@kumbaya_xyz/sdk-core'
import { FeeAmount, Pool } from '@kumbaya_xyz/v3-sdk'
// 1. Network + RPC
const MEGAETH_MAINNET = {
id: 4326,
rpc: 'https://mainnet.megaeth.com/rpc',
}
// 2. Tokens (replace USDC with the real address from the token list / explorer)
// Note: `ChainId.MEGAETH` (= 4326). The mainnet enum is just `MEGAETH`.
const WETH = new Token(
ChainId.MEGAETH,
'0x4200000000000000000000000000000000000006',
18,
'WETH',
)
const USDC = new Token(
ChainId.MEGAETH,
'0xYOUR_USDC_ADDRESS_HERE', // get it from default-token-list
6,
'USDC',
)
// 3. Compute the pool address (Kumbaya's POOL_INIT_CODE_HASH is wired in already)
const poolAddress = Pool.getAddress(WETH, USDC, FeeAmount.MEDIUM) // 0.3%
// 4. Quote 1 WETH -> USDC via QuoterV2
const QUOTER_V2 = '0x1F1a8dC7E138C34b503Ca080962aC10B75384a27'
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(MEGAETH_MAINNET.rpc) })
const result = await client.simulateContract({
address: QUOTER_V2,
abi: quoterAbi,
functionName: 'quoteExactInputSingle',
args: [{
tokenIn: WETH.address as `0x${string}`,
tokenOut: USDC.address as `0x${string}`,
amountIn: parseEther('1'),
fee: FeeAmount.MEDIUM,
sqrtPriceLimitX96: 0n,
}],
})
console.log(`Pool address: ${poolAddress}`)
console.log(`1 WETH → ${result.result[0]} USDC (raw, 6 decimals)`)What just happened
Where to go from here
Don't do this
Last updated