swap_quote
Calculate token exchange details including price impact, fees, and minimum output amount with slippage tolerance for informed trading decisions.
Instructions
Get swap quote for token exchange including price impact, fees, and minimum output amount with slippage.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount to swap (in token decimals) | |
| fromMint | Yes | Source token mint address | |
| poolAddress | Yes | Pool address for the swap | |
| slippage | No | Slippage tolerance (0-100, default 0.5) | |
| toMint | Yes | Destination token mint address |
Implementation Reference
- src/tools/swap-quote.js:5-55 (handler)The main handler function for the 'swap_quote' tool. Validates input parameters, calls poolService.getSwapQuote, formats a detailed quote response, and returns it as MCP content.async function swapQuoteTool(args, poolService) { const { poolAddress, fromMint, toMint, amount, slippage = 0.5 } = args; if (!poolAddress || !fromMint || !toMint || !amount) { throw new Error("poolAddress, fromMint, toMint, and amount are required"); } if (amount <= 0) { throw new Error("Amount must be greater than 0"); } if (slippage < 0 || slippage > 100) { throw new Error("Slippage must be between 0 and 100"); } try { const quote = await poolService.getSwapQuote( poolAddress, fromMint, toMint, amount, slippage ); const quoteText = `**Swap Quote**\n\n` + `**Input:**\n` + `- Pool: ${poolAddress}\n` + `- From: ${fromMint.slice(0, 8)}...\n` + `- To: ${toMint.slice(0, 8)}...\n` + `- Amount: ${amount}\n\n` + `**Output:**\n` + `- Expected Output: ${quote.outputAmount}\n` + `- Minimum Output (with slippage): ${quote.minimumOutputAmount}\n` + `- Price Impact: ${quote.priceImpact.toFixed(4)}%\n` + `- Fee: ${quote.fee}\n` + `- Slippage Tolerance: ${quote.slippage}%\n\n` + `**Rate:** 1 token = ${(quote.outputAmount / amount).toFixed(6)} tokens`; return { content: [ { type: "text", text: quoteText, }, ], }; } catch (error) { throw new Error(`Failed to get swap quote: ${error.message}`); } }
- src/index.js:115-146 (schema)Input schema definition for the 'swap_quote' tool, including properties, descriptions, defaults, and required fields, registered in the ListTools handler.{ name: "swap_quote", description: "Get swap quote for token exchange including price impact, fees, and minimum output amount with slippage.", inputSchema: { type: "object", properties: { poolAddress: { type: "string", description: "Pool address for the swap", }, fromMint: { type: "string", description: "Source token mint address", }, toMint: { type: "string", description: "Destination token mint address", }, amount: { type: "number", description: "Amount to swap (in token decimals)", }, slippage: { type: "number", description: "Slippage tolerance (0-100, default 0.5)", default: 0.5, }, }, required: ["poolAddress", "fromMint", "toMint", "amount"], }, },
- src/index.js:168-170 (registration)Registration in the tool dispatcher switch statement, mapping 'swap_quote' calls to the swapQuoteTool handler with poolService.case "swap_quote": return await swapQuoteTool(args, this.poolService);
- src/services/pool-service.js:37-48 (helper)Helper method in SarosPoolService that computes the swap quote details including output amount, min output, price impact, and fee.async getSwapQuote(poolAddress, fromMint, toMint, amount, slippage = 0.5) { const rate = 1.5; const outputAmount = amount * rate; return { inputAmount: amount, outputAmount, minimumOutputAmount: outputAmount * (1 - slippage / 100), priceImpact: 0.15, fee: amount * 0.0025, slippage, }; }
- src/index.js:20-20 (registration)Import of the swapQuoteTool handler function.const { swapQuoteTool } = require("./tools/swap-quote.js");