tapp_swap_amm
Use this tool to execute token swaps on Automated Market Maker (AMM) pools on the Aptos blockchain. Specify pool address, swap direction, and token amounts to trade assets efficiently.
Instructions
Execute a swap on an AMM pool
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a2b | Yes | Direction of the swap; true for token A to B, false for B to A | |
| amount0 | Yes | Amount of token A | |
| amount1 | Yes | Amount of token B | |
| fixedAmountIn | No | Whether the input amount is fixed (defaults to true) | |
| poolId | Yes | The address of the pool in which the swap is performed |
Implementation Reference
- src/mcp/tapp/swap-tools.ts:56-68 (handler)The MCP tool handler function for 'tapp_swap_amm' that validates input, calls TappAgent.swapAMM, and returns the transaction result.handler: async (agent: TappAgent, input: Record<string, any>) => { const result = await agent.swapAMM({ poolId: input.poolId, a2b: input.a2b, fixedAmountIn: input.fixedAmountIn ?? true, amount0: input.amount0, amount1: input.amount1 }); return { status: "success", transaction: result }; },
- src/mcp/tapp/swap-tools.ts:49-55 (schema)Zod schema defining the input parameters for the tapp_swap_amm tool.schema: { poolId: z.string().describe("The address of the pool in which the swap is performed"), a2b: z.boolean().describe("Direction of the swap; true for token A to B, false for B to A"), fixedAmountIn: z.boolean().optional().describe("Whether the input amount is fixed (defaults to true)"), amount0: z.number().describe("Amount of token A"), amount1: z.number().describe("Amount of token B") },
- src/mcp/index.ts:33-33 (registration)Registration of the SwapAMMTool (tapp_swap_amm) in the central MCP tools export."SwapAMMTool": SwapAMMTool,
- src/agent/index.ts:252-271 (helper)TappAgent.swapAMM helper method that generates the swap transaction payload using the Tapp SDK and submits it via Aptos client.async swapAMM(params: SwapAMMParams): Promise<TransactionResponse> { try { const data = this.sdk.Swap.swapAMMTransactionPayload(params); const response = await this.aptos.transaction.submit.simple({ sender: this.account.accountAddress, data: data } as any); return { hash: response.hash, success: true }; } catch (error) { return { hash: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } }