Skip to main content
Glama
lordbasilaiassistant-sudo

base-price-oracle-mcp

get_price_impact

Estimate price impact for trades on Base DEX pools using the constant product formula to calculate how trade size affects token prices.

Instructions

Estimate price impact for a given trade size using constant product formula

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token_addressYesToken contract address on Base
trade_size_ethYesTrade size in ETH (e.g. '0.1')

Implementation Reference

  • The "get_price_impact" tool handler, which calculates the estimated price impact of a trade based on pool reserves (V2/Aerodrome) or liquidity (V3).
    server.tool(
      "get_price_impact",
      "Estimate price impact for a given trade size using constant product formula",
      {
        token_address: z.string().describe("Token contract address on Base"),
        trade_size_eth: z.string().describe("Trade size in ETH (e.g. '0.1')"),
      },
      async ({ token_address, trade_size_eth }) => {
        try {
          const quoteAddress = WETH;
          const tradeEth = parseFloat(trade_size_eth);
          if (isNaN(tradeEth) || tradeEth <= 0) {
            return { content: [{ type: "text" as const, text: "Invalid trade size. Must be a positive number." }] };
          }
    
          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} on Base.` }] };
          }
    
          const impacts = pools.map((pool) => {
            const spotPrice = calculatePrice(pool, tokenDecimals, quoteDecimals);
    
            if (pool.sqrtPriceX96 !== undefined) {
              // V3 — rough estimate using liquidity
              const liq = Number(pool.liquidity ?? 0n);
              if (liq === 0) {
                return { dex: pool.dex, pool: pool.address, spotPrice: formatEth(spotPrice), impact: "N/A (no liquidity)" };
              }
              // Approximate: impact ~ tradeSize / (2 * liquidity_in_eth_terms)
              // This is a rough estimate for V3
              const roughImpact = (tradeEth / (liq / 1e18)) * 100;
              return {
                dex: pool.dex,
                pool: pool.address,
                spotPrice: formatEth(spotPrice),
                estimatedImpact: Math.min(roughImpact, 100).toFixed(4) + "%",
                note: "V3 impact is approximate (depends on tick range)",
              };
            }
    
            // V2/Aerodrome — constant product formula
            // Buy: tokensOut = reserveToken - k / (reserveETH + tradeETH)
            const ethReserve = pool.tokenIsToken0
              ? Number(ethers.formatUnits(pool.reserve1, quoteDecimals))
              : Number(ethers.formatUnits(pool.reserve0, quoteDecimals));
            const tokenReserve = pool.tokenIsToken0
              ? Number(ethers.formatUnits(pool.reserve0, tokenDecimals))
              : Number(ethers.formatUnits(pool.reserve1, tokenDecimals));
    
            if (ethReserve <= 0 || tokenReserve <= 0) {
              return { dex: pool.dex, pool: pool.address, spotPrice: formatEth(spotPrice), impact: "N/A (empty pool)" };
            }
    
            const k = ethReserve * tokenReserve;
            const newEthReserve = ethReserve + tradeEth;
            const newTokenReserve = k / newEthReserve;
            const tokensOut = tokenReserve - newTokenReserve;
            const effectivePrice = tradeEth / tokensOut;
            const priceImpact = ((effectivePrice - spotPrice) / spotPrice) * 100;
    
            return {
              dex: pool.dex,
              pool: pool.address,
              spotPrice: formatEth(spotPrice),
              effectivePrice: formatEth(effectivePrice),
              tokensReceived: tokensOut.toFixed(4),
              priceImpact: priceImpact.toFixed(4) + "%",
              ethReserve: formatEth(ethReserve),
            };
          });
    
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify({
                token: token_address,
                symbol: tokenSymbol,
                tradeSizeETH: trade_size_eth,
                pools: impacts,
              }, null, 2),
            }],
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool 'estimates' price impact, implying a read-only, non-destructive operation, but does not address potential limitations like accuracy, assumptions (e.g., constant product model), rate limits, or error handling. For a tool with zero annotation coverage, this is insufficient to inform the agent adequately about its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It is front-loaded with the core purpose and uses specific terminology ('constant product formula'), making it highly concise and well-structured for quick comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of price impact estimation and the lack of annotations and output schema, the description is incomplete. It does not explain what the output represents (e.g., percentage impact, slippage), potential errors, or dependencies on external factors like liquidity pools. For a tool with no structured behavioral or output information, more detail is needed to ensure the agent can use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with clear parameter descriptions: 'token_address' as a contract address on Base and 'trade_size_eth' in ETH format. The description adds minimal value beyond this, mentioning 'trade size' and 'constant product formula' but not elaborating on parameter interactions or constraints. Given the high schema coverage, a baseline score of 3 is appropriate as the description does not significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Estimate price impact for a given trade size using constant product formula.' It specifies the verb ('estimate'), resource ('price impact'), and method ('constant product formula'), making it easy to understand. However, it does not explicitly differentiate from sibling tools like 'get_liquidity_depth' or 'compare_prices', which might also relate to pricing or liquidity analysis, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools such as 'get_liquidity_depth' or 'get_token_price', nor does it specify contexts or exclusions for its use. This lack of comparative information leaves the agent without clear direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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-price-oracle-mcp'

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