get_token_price
Retrieve current token prices from Base blockchain DEX pools including Uniswap V2/V3 and Aerodrome for accurate market valuation.
Instructions
Get current price of any Base token from on-chain DEX pools (Uniswap V2/V3, Aerodrome)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token_address | Yes | Token contract address on Base | |
| quote_currency | No | Quote currency: ETH/WETH or a token address | ETH |
Implementation Reference
- src/index.ts:422-470 (handler)The tool 'get_token_price' is registered here. The async function handles the logic: resolving decimals, finding pools, calculating prices across pools, and returning the best price in a JSON format.
server.tool( "get_token_price", "Get current price of any Base token from on-chain DEX pools (Uniswap V2/V3, Aerodrome)", { token_address: z.string().describe("Token contract address on Base"), quote_currency: z.string().default("ETH").describe("Quote currency: ETH/WETH or a token address"), }, async ({ token_address, quote_currency }) => { try { const quoteAddress = resolveQuote(quote_currency); const [tokenDecimals, quoteDecimals, tokenSymbol] = await Promise.all([ getTokenDecimals(token_address), getTokenDecimals(quoteAddress), getTokenSymbol(token_address), ]); const pools = await findAllPools(token_address, quoteAddress); if (pools.length === 0) { return { content: [{ type: "text" as const, text: `No DEX pools found for ${token_address} paired with ${quote_currency} on Base.` }] }; } const prices = pools.map((pool) => ({ dex: pool.dex, pool: pool.address, price: calculatePrice(pool, tokenDecimals, quoteDecimals), })); const bestPool = prices.reduce((best, p) => (p.price > best.price ? p : best), prices[0]); const result = { token: token_address, symbol: tokenSymbol, quote: quote_currency.toUpperCase(), bestPrice: formatEth(bestPool.price), bestDex: bestPool.dex, allPools: prices.map((p) => ({ dex: p.dex, pool: p.pool, price: formatEth(p.price), })), }; return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } catch (err: unknown) { const msg = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${msg}` }] }; } } );