simulate_rebalance
Simulate liquidity pool rebalancing when impermanent loss exceeds your threshold. Get position adjustment recommendations to optimize your DeFi portfolio on Solana.
Instructions
Simulate rebalancing LP positions based on impermanent loss threshold. Provides recommendations for position adjustments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| threshold | Yes | IL threshold percentage (e.g., 5 for 5%) | |
| wallet | Yes | Solana wallet address |
Implementation Reference
- src/tools/simulate-rebalance.js:5-67 (handler)The main handler function that executes the simulate_rebalance tool. Validates wallet and threshold, fetches LP positions, generates rebalance recommendations, and returns formatted 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}`); } }
- src/index.js:68-83 (schema)Defines the input schema for the simulate_rebalance tool in the listTools response, specifying wallet (string) and threshold (number 0-100).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)Registers and dispatches the simulate_rebalance tool call to the imported handler, injecting poolService and analyticsService.case "simulate_rebalance": return await simulateRebalanceTool(args, this.poolService, this.analyticsService);
- src/index.js:65-84 (registration)Tool metadata registration in listTools handler, including name, description, and 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"], }, },