Skip to main content
Glama
lordbasilaiassistant-sudo

base-flash-arb-mcp

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
NameRequiredDescriptionDefault
token_addressYesToken contract address on Base

Implementation Reference

  • 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: [

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lordbasilaiassistant-sudo/base-flash-arb-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server