swap_transaction
Execute cryptocurrency swap transactions by processing swap requests and returning transaction responses, enabling trading operations within crypto ecosystems.
Instructions
Execute a swap transaction.
Expects a SwapTransactionRequestContainer, returns a list of SwapTransactionResponse.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| swap_transaction_requests | Yes |
Implementation Reference
- armor_crypto_mcp/armor_mcp.py:160-173 (handler)MCP tool handler and registration for 'swap_transaction'. Thin wrapper that checks authentication and delegates to ArmorWalletAPIClient.swap_transaction.@mcp.tool() async def swap_transaction(swap_transaction_requests: SwapTransactionRequestContainer) -> List[SwapTransactionResponse]: """ Execute a swap transaction. Expects a SwapTransactionRequestContainer, returns a list of SwapTransactionResponse. """ if not armor_client: return [{"error": "Not logged in"}] try: result: List[SwapTransactionResponse] = await armor_client.swap_transaction(swap_transaction_requests) return result except Exception as e: return [{"error": str(e)}]
- Pydantic model for a single SwapTransactionRequest, containing the transaction_id from a prior swap quote.class SwapTransactionRequest(BaseModel): transaction_id: str = Field(description="unique id of the generated swap quote")
- Container model for the input to swap_transaction tool, holding a list of SwapTransactionRequest.class SwapTransactionRequestContainer(BaseModel): swap_transaction_requests: List[SwapTransactionRequest]
- Pydantic model for SwapTransactionResponse, defining the output structure of the tool.class SwapTransactionResponse(BaseModel): id: str = Field(description="unique id of the swap transaction") transaction_error: Optional[str] = Field(description="error message if the transaction fails") transaction_url: str = Field(description="public url of the transaction") input_amount: float = Field(description="input amount in input token") output_amount: float = Field(description="output amount in output token") status: str = Field(description="status of the transaction")
- Core implementation in ArmorWalletAPIClient that sends POST request to '/transactions/swap/' API endpoint with list of transaction_ids to execute the swaps.async def swap_transaction(self, data: SwapTransactionRequestContainer) -> List[SwapTransactionResponse]: """Execute the swap transactions.""" # payload = [v.model_dump() for v in data.swap_transaction_requests] payload = data.model_dump(exclude_none=True)['swap_transaction_requests'] return await self._api_call("POST", "transactions/swap/", payload)