QUOTE
Get real-time price quotes for token swaps on decentralized exchanges. Input token addresses and amounts to calculate exchange rates across multiple blockchain networks.
Instructions
Quote the price of a specific trading pair
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | No | The blockchain network to execute the transaction on. uses fraxtal as default | fraxtal |
| inTokenAddress | Yes | The token to swap from (address). | |
| outTokenAddress | Yes | The token to swap to (address). | |
| amount | Yes | Token amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6). | |
| slippage | No | Define the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1. | 1 |
Implementation Reference
- src/tools/swap.ts:7-41 (handler)The main execution handler for the QUOTE tool. Processes arguments, retrieves chain and gas price data, calls SwapService.quote, and returns the formatted quote response.export const quote = async (args: z.infer<typeof getQuoteParamsSchema>) => { try { const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); console.error(`[QUOTE] Using chain: ${chainObject.name}`, args); const chainService = new ChainService(); const gasRes: any = await chainService.gasPrice(chainObject.id); const gasPrice = gasRes.data.fast; const swapService = new SwapService(); const quote = await swapService.quote( args.inTokenAddress, args.outTokenAddress, chainObject.id, args.amount, args.slippage ? Number(args.slippage) * 100 : 100, gasPrice, ); if (quote instanceof Error) { return `Error fetching quote: ${quote.message}`; } // return JSON.stringify(quote); return JSON.stringify(quote, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred while fetching quote."; console.error(`[QUOTE] Error: ${message}`); throw new Error(`Failed to fetch quote: ${message}`); } };
- src/tools/index.ts:34-39 (registration)Registers the QUOTE tool in the tools object, defining its name, description, input parameters schema, and the execute handler.quote: { name: "QUOTE", description: "Quote the price of a specific trading pair", parameters: getQuoteParamsSchema, execute: swapExecute.quote },
- src/types.ts:28-53 (schema)Zod schema defining the input parameters for the QUOTE tool, including chain, token addresses, amount, and optional slippage.export const getQuoteParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal"), inTokenAddress: z .string() .refine(isAddress, { message: "Invalid inToken address" }) .describe("The token to swap from (address)."), outTokenAddress: z .string() .refine(isAddress, { message: "Invalid outToken address" }) .describe("The token to swap to (address)."), amount: z .string() .regex(/^\d+$/, { message: "Amount must be a string in wei (no decimals)" }) .describe("Token amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6). "), slippage: z .string() .optional() .describe("Define the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1.") .default('1'), });
- src/types.ts:94-100 (schema)TypeScript interface for the expected output/response structure of the QUOTE tool.export interface QuoteResponse { inToken: token; outToken: token; inAmount: number; outAmount: number; estimatedGas: number; }