buyInFailMarket
Purchase tokens in the fail market for a specific proposal, enabling users to trade based on proposal outcomes within the Futarchy protocol on Solana.
Instructions
Buy tokens in the fail market for a proposal
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| proposalId | Yes | The ID of the proposal to trade in | |
| amount | Yes | Amount to buy | |
| user | Yes | User's public key |
Implementation Reference
- src/mcp/server/index.ts:420-464 (registration)Full registration of the 'buyInFailMarket' MCP tool, including name, description, Zod input schema (proposalId: string, amount: number, user: string), and handler function that calls apiClient.buyInFailMarket and returns formatted response or error.server.tool( "buyInFailMarket", "Buy tokens in the fail market for a proposal", { proposalId: z.string().describe("The ID of the proposal to trade in"), amount: z.number().describe("Amount to buy"), user: z.string().describe("User's public key"), }, async ({ proposalId, amount, user }) => { try { const response = await apiClient.buyInFailMarket(proposalId, amount, user); if (!response.success) { return { content: [ { type: "text" as const, text: response.error || 'Unknown error', }, ], isError: true, }; } return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: "text" as const, text: `Error buying in fail market: ${error.message || 'Unknown error'}`, }, ], isError: true, }; } } );
- src/mcp/server/index.ts:423-427 (schema)Zod schema for tool inputs: proposalId (string), amount (number), user (public key string).{ proposalId: z.string().describe("The ID of the proposal to trade in"), amount: z.number().describe("Amount to buy"), user: z.string().describe("User's public key"), },
- src/mcp/server/index.ts:428-463 (handler)Handler function that executes the tool: calls apiClient.buyInFailMarket, checks success, returns JSON text response or error message.async ({ proposalId, amount, user }) => { try { const response = await apiClient.buyInFailMarket(proposalId, amount, user); if (!response.success) { return { content: [ { type: "text" as const, text: response.error || 'Unknown error', }, ], isError: true, }; } return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: "text" as const, text: `Error buying in fail market: ${error.message || 'Unknown error'}`, }, ], isError: true, }; } }
- src/mcp/common/api.ts:224-252 (helper)FutarchyApiClient helper method that proxies the buyInFailMarket action via HTTP POST to backend /proposals/{proposalId}/buy-fail endpoint.async buyInFailMarket(proposalId: string, amount: number, userPublicKey: string): Promise<Response> { try { const response = await fetch(`${this.baseUrl}/proposals/${proposalId}/buy-fail`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ amount, user: userPublicKey }) }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); return { success: true, data: data }; } catch (error: any) { return { success: false, error: error.message || 'Failed to buy in fail market' }; } }