get_price_across_dexes
Compare token prices across multiple decentralized exchanges on Base to identify arbitrage opportunities by analyzing price differences.
Instructions
Get current price of a token on all available DEXes on Base.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token_address | Yes | Token contract address on Base |
Implementation Reference
- src/index.ts:1043-1107 (handler)The implementation of the get_price_across_dexes MCP tool, which fetches token prices across multiple DEXes on Base and calculates the spread.
server.tool( "get_price_across_dexes", "Get current price of a token on all available DEXes on Base.", { token_address: z.string().describe("Token contract address on Base"), }, async ({ token_address }) => { try { const [symbol, decimals] = await Promise.all([ getSymbol(token_address), getDecimals(token_address), ]); const testAmount = ethers.parseEther("0.001"); // Small test amount const buyQuotes = await getAllBuyQuotes(token_address, testAmount); const prices = buyQuotes.map((q) => { // Price = ETH spent / tokens received const tokensOut = Number( ethers.formatUnits(q.amountOut, decimals) ); const ethIn = Number(ethers.formatEther(testAmount)); const priceInEth = tokensOut > 0 ? ethIn / tokensOut : 0; const tokensPerEth = tokensOut > 0 ? tokensOut : 0; return { dex: q.label, tokensPerEth: tokensPerEth.toFixed(4), pricePerTokenEth: priceInEth.toFixed(18), pricePerTokenUsd: (priceInEth * 2500).toFixed(6), // approximate }; }); // Calculate spread const priceValues = prices.map((p) => parseFloat(p.pricePerTokenEth)); const minPrice = Math.min(...priceValues); const maxPrice = Math.max(...priceValues); const spreadBps = minPrice > 0 ? Math.round(((maxPrice - minPrice) / minPrice) * 10000) : 0; return { content: [ { type: "text" as const, text: JSON.stringify( { token: token_address, symbol, decimals, testAmountEth: "0.001", dexCount: prices.length, spreadBps, prices, }, null, 2 ), }, ], }; } catch (e) { return { content: [