Skip to main content
Glama

ODOS_SWAP

Facilitates token swaps on decentralized exchanges via the MCP-ODOS server by specifying blockchain, tokens, and amount, ensuring efficient cross-token transactions.

Instructions

Execute a swap transaction

Input Schema

NameRequiredDescriptionDefault
amountYesThe amount of tokens to swap, in wei.
chainNoThe blockchain network to execute the transaction on. uses fraxtal as defaultfraxtal
fromTokenYesThe token to swap from (address).
prettyFormatNoWhether to pretty format the quote.
toTokenYesThe token to swap to (address).

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "amount": { "description": "The amount of tokens to swap, in wei.", "pattern": "^\\d+$", "type": "string" }, "chain": { "default": "fraxtal", "description": "The blockchain network to execute the transaction on. uses fraxtal as default", "type": "string" }, "fromToken": { "description": "The token to swap from (address).", "type": "string" }, "prettyFormat": { "default": true, "description": "Whether to pretty format the quote.", "type": "boolean" }, "toToken": { "description": "The token to swap to (address).", "type": "string" } }, "required": [ "fromToken", "toToken", "amount" ], "type": "object" }

Implementation Reference

  • The main execute function that implements the ODOS_SWAP tool logic: initializes wallet, fetches quote via GetQuoteActionService, assembles transaction via AssembleService, checks/sets allowance, and executes the swap via ExecuteSwapService.
    execute: async (args: z.infer<typeof swapParamsSchema>) => { try { const walletPrivateKey = process.env.WALLET_PRIVATE_KEY; if (!walletPrivateKey) { throw new Error( "WALLET_PRIVATE_KEY is not set in the environment. This is required to execute trades.", ); } console.log("[ODOS_SWAP] Called..."); const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); const walletService = new WalletService( walletPrivateKey, chainObject ?? fraxtal, ); console.log( `[ODOS_SWAP] Using chain: ${chainObject} (${chainObject.id})`, ); console.log( walletService.getWalletClient()?.account?.address ?? "No wallet address found", ); const getQuoteService = new GetQuoteActionService(walletService); const quote = await getQuoteService.execute( args.fromToken, args.toToken, chainObject.id, args.amount, ); if (quote instanceof Error || !quote.pathId) { return `Error fetching quote: ${quote instanceof Error ? quote.message : String(quote)}`; } const assembleService = new AssembleService(walletService); const txn = await assembleService.execute(quote.pathId); if (!txn) { return `Error assembling transaction: ${txn}`; } const executeSwapService = new ExecuteSwapService(walletService); try { await executeSwapService.checkAndSetAllowance( quote.inTokens[0], BigInt(quote.inAmounts[0]), txn.to, ); const hash = await executeSwapService.execute(txn); return args.prettyFormat ? await executeSwapService.formatWithConfirmation(txn, hash) : JSON.stringify({ hash, txn }, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred during the execution."; throw new Error(`Error executing swap: ${message}`); } } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred during the fetch."; console.error(`[ODOS_SWAP] Error: ${message}`); throw new Error(`Failed in swap process: ${message}`); } },
  • Zod schema defining the input parameters for ODOS_SWAP: chain (default fraxtal), fromToken, toToken addresses, amount in wei, optional prettyFormat.
    const swapParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal"), fromToken: z .string() .refine(isAddress, { message: "Invalid fromToken address" }) .describe("The token to swap from (address)."), toToken: z .string() .refine(isAddress, { message: "Invalid toToken address" }) .describe("The token to swap to (address)."), amount: z .string() .regex(/^\d+$/, { message: "Amount must be a string in wei (no decimals)" }) .describe("The amount of tokens to swap, in wei."), prettyFormat: z .boolean() .optional() .describe("Whether to pretty format the quote.") .default(true), });
  • src/index.ts:15-15 (registration)
    Registers the swapTool (ODOS_SWAP) with the FastMCP server.
    server.addTool(swapTool);

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/IQAIcom/mcp-odos'

If you have feedback or need assistance with the MCP directory API, please join our Discord server