Skip to main content
Glama
lordbasilaiassistant-sudo

base-price-oracle-mcp

get_volatility

Calculate price volatility from recent swap data on Base to assess token price stability and market risk.

Instructions

Calculate price volatility (standard deviation of returns) from recent swaps

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token_addressYesToken contract address on Base
lookback_hoursNoHours to look back for swap data

Implementation Reference

  • The handler for the get_volatility MCP tool, which calculates price volatility based on swap history.
    async ({ token_address, lookback_hours }) => {
      try {
        const quoteAddress = WETH;
        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 bestPool = pools[0];
        // Base: ~2s blocks, so lookback_hours * 3600 / 2
        const lookbackBlocks = Math.min(Math.floor((lookback_hours * 3600) / 2), 50000);
        const swaps = await getSwapHistory(bestPool, tokenDecimals, quoteDecimals, lookbackBlocks);
    
        if (swaps.length < 3) {
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify({
                token: token_address,
                symbol: tokenSymbol,
                message: `Insufficient swap data (${swaps.length} swaps). Need at least 3 for volatility calculation.`,
              }, null, 2),
            }],
          };
        }
    
        const prices = swaps.map((s) => s.price);
        const returns = calculateReturns(prices);
        const vol = stddev(returns);
        const annualized = vol * Math.sqrt(365 * 24); // hourly returns annualized
  • src/index.ts:572-578 (registration)
    The registration of the get_volatility tool within the MCP server.
    server.tool(
      "get_volatility",
      "Calculate price volatility (standard deviation of returns) from recent swaps",
      {
        token_address: z.string().describe("Token contract address on Base"),
        lookback_hours: z.number().default(24).describe("Hours to look back for swap data"),
      },

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