DEX_LIST
Retrieve a list of decentralized exchanges available on a specified blockchain network to identify trading platforms for token swaps.
Instructions
Get dex list
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | No | The blockchain network to execute the transaction on. uses fraxtal as default | fraxtal |
Implementation Reference
- src/tools/chain.ts:60-82 (handler)The main handler function for the DEX_LIST tool. It processes the chain input, resolves the chain, calls ChainService.dexList, handles errors, and returns JSON stringified response.export const dexList = async (args: z.infer<typeof chainParamsSchema>) => { try { const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); console.error(`[DEX_LIST] Using chain: ${chainObject.name}`); const service = new ChainService(); const dexList = await service.dexList(chainObject.id); if (dexList instanceof Error) { return `Error fetching dexList: ${dexList.message}`; } return JSON.stringify(dexList, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred while fetching dexList."; console.error(`[DEX_LIST] Error: ${message}`); throw new Error(`Failed to fetch dexList: ${message}`); } }
- src/types.ts:4-12 (schema)Zod schema defining the input parameters for DEX_LIST (and other chain-based tools), specifically the optional 'chain' string.export const chainParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal") });
- src/tools/index.ts:16-21 (registration)Tool object definition in tools/index.ts, specifying name, description, parameters schema, and execute handler reference.dexList: { name: "DEX_LIST", description: "Get dex list", parameters: chainParamsSchema, execute: chainExecute.dexList },
- src/index.ts:15-15 (registration)Addition of the DEX_LIST tool to the FastMCP server instance.server.addTool(tools.dexList);
- src/services/chain.ts:69-97 (helper)Supporting method in ChainService that performs the actual API fetch to OpenOcean endpoint for DEX list on given chainId.async dexList( chainId: number ) { try { const response = await fetch(`${OPENOCEAN_API_URL}/v3/${chainId}/dexList`, { method: "GET", headers: { "Content-Type": "application/json", } }); const data: any = await response.json(); if (!response.ok) { const errorData = data as ErrorResponse; throw new Error( `Failed to fetch dexList: ${errorData.detail} (Trace ID: ${errorData.traceId}, Error Code: ${errorData.errorCode})`, ); } return data; } catch (error) { console.error("Error fetching dexList:", error); throw new Error( `Fatally Failed to fetch dexList: ${(error as Error).message} with code ${ (error as { code?: string }).code || "unknown" }`, ); }