portfolio_analytics
Analyze DeFi portfolio performance on Solana by providing total value, impermanent loss metrics, yield data, and position breakdowns for any wallet address.
Instructions
Get comprehensive portfolio analytics including total value, IL metrics, yield performance, and position breakdown.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wallet | Yes | Solana wallet address |
Implementation Reference
- src/tools/portfolio-analytics.js:5-67 (handler)The handler function that executes the portfolio_analytics tool. Fetches LP positions for the wallet, analyzes the portfolio using analyticsService, formats metrics like total value, average impermanent loss (IL), position details, and provides a risk assessment. Returns formatted text content in MCP response format.async function portfolioAnalyticsTool(args, poolService, analyticsService) { const { wallet } = args; if (!wallet) { throw new Error("Wallet address is required"); } try { // Get all positions const positions = await poolService.getLPPositions(wallet); if (positions.length === 0) { return { content: [ { type: "text", text: `No positions found for wallet: ${wallet}`, }, ], }; } // Analyze portfolio const analytics = await analyticsService.analyzePortfolio(positions); // Format analytics output let analyticsText = `**Portfolio Analytics for ${wallet}**\n\n`; analyticsText += `**Overview:**\n`; analyticsText += `- Total Positions: ${analytics.positionCount}\n`; analyticsText += `- Estimated Total Value: $${analytics.totalValue.toFixed(2)}\n`; analyticsText += `- Average IL: ${analytics.averageIL.toFixed(2)}%\n\n`; analyticsText += `**Position Breakdown:**\n`; analytics.positions.forEach((pos, idx) => { analyticsText += `\n${idx + 1}. Pool: ${pos.poolAddress.slice(0, 8)}...\n` + ` - LP Balance: ${pos.lpBalance}\n` + ` - Estimated Value: $${pos.estimatedValue.toFixed(2)}\n` + ` - IL: ${pos.impermanentLoss.toFixed(2)}%\n`; }); analyticsText += `\n**Risk Assessment:**\n`; const avgIL = Math.abs(analytics.averageIL); if (avgIL < 2) { analyticsText += `✅ Low Risk - Portfolio is performing well`; } else if (avgIL < 5) { analyticsText += `⚠️ Medium Risk - Monitor positions closely`; } else { analyticsText += `🔴 High Risk - Consider rebalancing`; } return { content: [ { type: "text", text: analyticsText, }, ], }; } catch (error) { throw new Error(`Failed to get portfolio analytics: ${error.message}`); } }
- src/index.js:89-98 (schema)Input schema for the portfolio_analytics tool, defining the required 'wallet' string parameter.inputSchema: { type: "object", properties: { wallet: { type: "string", description: "Solana wallet address", }, }, required: ["wallet"], },
- src/index.js:85-99 (registration)Registration of the portfolio_analytics tool in the ListToolsRequestSchema handler, including name, description, and input schema.{ name: "portfolio_analytics", description: "Get comprehensive portfolio analytics including total value, IL metrics, yield performance, and position breakdown.", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "Solana wallet address", }, }, required: ["wallet"], }, },
- src/index.js:162-163 (registration)Tool dispatch/registration in the CallToolRequestSchema switch statement, invoking the portfolioAnalyticsTool handler with services.case "portfolio_analytics": return await portfolioAnalyticsTool(args, this.poolService, this.analyticsService);
- src/index.js:18-18 (registration)Import of the portfolioAnalyticsTool from its implementation file.const { portfolioAnalyticsTool } = require("./tools/portfolio-analytics.js");