Skip to main content
Glama

simulate_rebalance

Simulate liquidity pool rebalancing based on impermanent loss thresholds to optimize DeFi positions. Provides adjustment recommendations for Solana wallets.

Instructions

Simulate rebalancing LP positions based on impermanent loss threshold. Provides recommendations for position adjustments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletYesSolana wallet address
thresholdYesIL threshold percentage (e.g., 5 for 5%)

Implementation Reference

  • The main handler function for the 'simulate_rebalance' tool. It validates inputs, retrieves LP positions, generates rebalance recommendations using the analytics service, and returns formatted simulation results.
    async function simulateRebalanceTool(args, poolService, analyticsService) { const { wallet, threshold } = args; if (!wallet || threshold === undefined) { throw new Error("Wallet address and threshold are required"); } if (threshold < 0 || threshold > 100) { throw new Error("Threshold must be between 0 and 100"); } try { // Get current positions const positions = await poolService.getLPPositions(wallet); if (positions.length === 0) { return { content: [ { type: "text", text: `No LP positions found for wallet: ${wallet}. Cannot simulate rebalance.`, }, ], }; } // Generate recommendations const recommendations = analyticsService.generateRebalanceRecommendations( positions, threshold ); // Format simulation results let resultText = `**Rebalance Simulation for ${wallet}**\n\n`; resultText += `IL Threshold: ${threshold}%\n`; resultText += `Positions Analyzed: ${positions.length}\n`; resultText += `Recommendations: ${recommendations.length}\n\n`; if (recommendations.length === 0) { resultText += `✅ All positions are within acceptable IL range (< ${threshold}%). No rebalancing needed.`; } else { resultText += `**Recommendations:**\n`; recommendations.forEach((rec, idx) => { resultText += `\n${idx + 1}. Pool: ${rec.poolAddress}\n` + ` - Current IL: ${rec.currentIL.toFixed(2)}%\n` + ` - Severity: ${rec.severity}\n` + ` - Action: ${rec.recommendation}\n`; }); } return { content: [ { type: "text", text: resultText, }, ], }; } catch (error) { throw new Error(`Failed to simulate rebalance: ${error.message}`); } }
  • Input schema validation for the 'simulate_rebalance' tool, specifying wallet address and IL threshold parameters.
    inputSchema: { type: "object", properties: { wallet: { type: "string", description: "Solana wallet address", }, threshold: { type: "number", description: "IL threshold percentage (e.g., 5 for 5%)", minimum: 0, maximum: 100, }, }, required: ["wallet", "threshold"], },
  • src/index.js:64-84 (registration)
    Tool registration in the listTools handler, including name, description, and input schema.
    { name: "simulate_rebalance", description: "Simulate rebalancing LP positions based on impermanent loss threshold. Provides recommendations for position adjustments.", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "Solana wallet address", }, threshold: { type: "number", description: "IL threshold percentage (e.g., 5 for 5%)", minimum: 0, maximum: 100, }, }, required: ["wallet", "threshold"], }, },
  • src/index.js:159-160 (registration)
    Tool dispatch in the CallToolRequestSchema handler, routing 'simulate_rebalance' calls to the simulateRebalanceTool function.
    case "simulate_rebalance": return await simulateRebalanceTool(args, this.poolService, this.analyticsService);
  • src/index.js:17-17 (registration)
    Import of the simulateRebalanceTool from its implementation file.
    const { simulateRebalanceTool } = require("./tools/simulate-rebalance.js");

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/Pavilion-devs/saros-mcp-server'

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