Skip to main content
Glama

DeFi Trading Agent MCP Server

by edkdev

submit_gasless_swap

Execute token swaps without gas fees by signing approval and trade messages using quote data from get_gasless_quote.

Instructions

Submit a gasless swap by signing approval and trade messages (no gas fees required)

Input Schema

NameRequiredDescriptionDefault
chainIdNoBlockchain ID (optional if included in quoteData)
quoteDataYesQuote data from get_gasless_quote

Input Schema (JSON Schema)

{ "properties": { "chainId": { "description": "Blockchain ID (optional if included in quoteData)", "type": "integer" }, "quoteData": { "description": "Quote data from get_gasless_quote", "type": "object" } }, "required": [ "quoteData" ], "type": "object" }

Implementation Reference

  • Primary MCP tool handler for submit_gasless_swap: signs EIP-712 approval and trade messages using user's private key, then delegates submission to AgService.
    async submitGaslessSwap(params) { const { quoteData } = params; if (!quoteData) { throw new Error("Quote data from gasless quote is required"); } if (!this.userPrivateKey) { throw new Error( "User private key is required for gasless swap execution" ); } try { console.log("šŸš€ Processing gasless swap..."); // Prepare the submission data - extract chainId from trade domain const chainId = quoteData.trade?.eip712?.domain?.chainId || params.chainId; if (!chainId) { throw new Error("Chain ID not found in quote data or parameters"); } const submissionData = { chainId: chainId, }; // Sign approval if present if (quoteData.approval) { console.log("šŸ” Signing gasless approval..."); const signedApproval = await this.blockchain.signGaslessApproval( quoteData.approval ); submissionData.approval = signedApproval; console.log("āœ… Approval signed"); } // Sign trade (always required) if (!quoteData.trade) { throw new Error("Trade data is required in gasless quote"); } console.log("šŸ” Signing gasless trade..."); const signedTrade = await this.blockchain.signGaslessTrade( quoteData.trade ); submissionData.trade = signedTrade; console.log("āœ… Trade signed"); // Submit to Aggregator gasless API console.log("šŸ“¤ Submitting gasless swap to Agg..."); const result = await this.agg.submitGaslessSwap(submissionData); return { message: "Gasless swap submitted successfully", data: result, nextSteps: [ "1. Gasless swap has been submitted to relayer", "2. Monitor status using get_gasless_status tool", "3. No gas fees required - relayer handles execution", `4. Trade hash: ${result.tradeHash}`, ], gaslessInfo: { tradeHash: result.tradeHash, approvalSigned: !!submissionData.approval, tradeSigned: !!submissionData.trade, relayerHandled: true, }, }; } catch (error) { throw new Error(`Gasless swap submission failed: ${error.message}`); } }
  • Input schema and description for the submit_gasless_swap tool, registered in the ListTools response.
    name: TOOL_NAMES.SUBMIT_GASLESS_SWAP, description: "Submit a gasless swap by signing approval and trade messages (no gas fees required)", inputSchema: { type: "object", properties: { quoteData: { type: "object", description: "Quote data from get_gasless_quote", }, chainId: { type: "integer", description: "Blockchain ID (optional if included in quoteData)", }, }, required: ["quoteData"], },
  • src/index.js:1146-1148 (registration)
    Tool dispatcher in CallToolRequest handler that routes submit_gasless_swap calls to ToolService.submitGaslessSwap.
    case TOOL_NAMES.SUBMIT_GASLESS_SWAP: result = await toolService.submitGaslessSwap(args); break;
  • AgService helper that performs the HTTP POST to the aggregator API endpoint /api/swap/gasless/submit with signed data.
    async submitGaslessSwap(swapData) { try { const response = await fetch(`${this.baseUrl}/api/swap/gasless/submit`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(swapData) }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'Gasless swap submission failed'); } return data.data; } catch (error) { throw new Error(`Failed to submit gasless swap: ${error.message}`); } }
  • src/constants.js:13-13 (registration)
    Constant definition mapping SUBMIT_GASLESS_SWAP to the tool name string 'submit_gasless_swap'.
    SUBMIT_GASLESS_SWAP: "submit_gasless_swap",

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/edkdev/defi-trading-mcp'

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