UNPKG

@iqai/mcp-bamm

Version:

MCP server for bamm (borrow automated market maker)

68 lines (64 loc) 2.47 kB
import dedent from "dedent"; import { z } from "zod"; import formatNumber from "../lib/format-number.js"; import { RepayService } from "../services/repay.js"; import { WalletService } from "../services/wallet.js"; const repayToolParams = z.object({ bammAddress: z .string() .regex(/^0x[a-fA-F0-9]{40}$/) .describe("The address of the BAMM contract"), amount: z.string().min(1).describe("The amount to repay"), borrowToken: z .string() .regex(/^0x[a-fA-F0-9]{40}$/) .optional() .describe("The address of the token to repay"), borrowTokenSymbol: z .string() .optional() .describe("The symbol of the token to repay (e.g., 'IQT')"), }); export const repayTool = { name: "REPAY", description: "Repay borrowed tokens to a BAMM position", parameters: repayToolParams, execute: async (params) => { try { if (!params.borrowToken && !params.borrowTokenSymbol) { return "Error: Either borrowToken address or borrowTokenSymbol is required"; } const privateKey = process.env.WALLET_PRIVATE_KEY; if (!privateKey) { return "Error: WALLET_PRIVATE_KEY environment variable is not set. Please set it with your wallet's private key (without 0x prefix)."; } const walletService = new WalletService(privateKey); const repayService = new RepayService(walletService); const result = await repayService.execute({ bammAddress: params.bammAddress, borrowToken: params.borrowToken, borrowTokenSymbol: params.borrowTokenSymbol, amount: params.amount, }); return dedent ` ✅ Repayment Successful 🌐 BAMM Address: ${params.bammAddress} 💸 Amount: ${formatNumber(Number(params.amount))} 🪙 Token: ${params.borrowTokenSymbol ?? params.borrowToken} 🔗 Transaction: ${result.txHash} Tokens have been repaid to your BAMM position. `; } catch (error) { if (error instanceof Error) { return dedent ` ❌ Repayment Failed Error: ${error.message} Please verify your inputs and try again. `; } return "An unknown error occurred while repaying tokens"; } }, }; //# sourceMappingURL=repay.js.map