Skip to main content
Glama

REPAY

Repay borrowed tokens to a BAMM position on Fraxtal. Provide BAMM address and amount to reduce debt.

Instructions

Repay borrowed tokens to a BAMM position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bammAddressYesThe address of the BAMM contract
amountYesThe amount to repay
borrowTokenNoThe address of the token to repay
borrowTokenSymbolNoThe symbol of the token to repay (e.g., 'IQT')

Implementation Reference

  • The tool handler definition for 'REPAY'. Contains the name, description, Zod schema parameters, and execute function that delegates to RepayService.
    export const repayTool: Tool<FastMCPSessionAuth, typeof repayToolParams> = {
    	name: "REPAY",
    	description: "Repay borrowed tokens to a BAMM position",
    	parameters: repayToolParams,
    	execute: async (params, _context) => {
    		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 as Address,
    				borrowToken: params.borrowToken as Address | undefined,
    				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";
    		}
    	},
    };
  • Zod input schema for REPAY tool: requires bammAddress (Ethereum address), amount (string), and optionally borrowToken (address) or borrowTokenSymbol (e.g., 'IQT').
    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')"),
    });
  • TypeScript interface for RepayParams used by RepayService.execute().
    export interface RepayParams {
    	bammAddress: Address;
    	borrowToken?: Address;
    	borrowTokenSymbol?: string;
    	amount: string;
    }
  • RepayService class containing the core repayment logic: resolves token address, validates against BAMM, checks balance, ensures approval, reads rentedMultiplier, calculates effectiveRent (negative), and calls executeActions on the BAMM contract.
    export class RepayService {
    	constructor(private walletService: WalletService) {}
    
    	async execute(params: RepayParams): Promise<{ txHash: string }> {
    		let { bammAddress, borrowToken, borrowTokenSymbol, amount } = params;
    		if (!params.borrowToken && !params.borrowTokenSymbol) {
    			throw new Error("Either borrowToken or borrowTokenSymbol is required");
    		}
    		const publicClient = this.walletService.getPublicClient();
    		const walletClient = this.walletService.getWalletClient();
    
    		if (!walletClient || !walletClient.account) {
    			throw new Error("Wallet client is not initialized");
    		}
    
    		const userAddress = walletClient.account.address;
    		const amountInWei = BigInt(Math.floor(Number(amount) * 1e18));
    
    		try {
    			if (borrowTokenSymbol) {
    				borrowToken = await getTokenAddressFromSymbol(borrowTokenSymbol);
    			}
    
    			if (!borrowToken) {
    				throw new Error("Could not resolve borrow token address");
    			}
    
    			const tokenValidation = await validateTokenAgainstBAMM(
    				bammAddress,
    				borrowToken,
    				publicClient,
    			);
    			await checkTokenBalance(
    				borrowToken,
    				userAddress,
    				amountInWei,
    				publicClient,
    			);
    			await ensureTokenApproval(
    				borrowToken,
    				bammAddress,
    				amountInWei,
    				publicClient,
    				walletClient,
    			);
    
    			const rentedMultiplier: bigint = await publicClient.readContract({
    				address: bammAddress,
    				abi: BAMM_ABI,
    				functionName: "rentedMultiplier",
    				args: [],
    			});
    
    			// Calculate effective rent for repayment (negative rent for repayment)
    			const effectiveRent =
    				-(amountInWei * 1_000_000_000_000_000_000n) / rentedMultiplier;
    
    			const currentTime = Math.floor(Date.now() / 1000);
    			const deadline = BigInt(currentTime + 300);
    
    			const action = {
    				token0Amount: tokenValidation.isToken0 ? amountInWei : 0n,
    				token1Amount: tokenValidation.isToken1 ? amountInWei : 0n,
    				rent: effectiveRent,
    				to: userAddress,
    				token0AmountMin: 0n,
    				token1AmountMin: 0n,
    				closePosition: false,
    				approveMax: false,
    				v: 0,
    				r: "0x0000000000000000000000000000000000000000000000000000000000000000" as `0x${string}`,
    				s: "0x0000000000000000000000000000000000000000000000000000000000000000" as `0x${string}`,
    				deadline,
    			};
    
    			const { request: executeRequest } = await publicClient.simulateContract({
    				address: bammAddress,
    				abi: BAMM_ABI,
    				functionName: "executeActions",
    				args: [action],
    				account: walletClient.account,
    			});
    			const txHash = await walletClient.writeContract(executeRequest);
    			await publicClient.waitForTransactionReceipt({ hash: txHash });
    			return { txHash };
    		} catch (error) {
    			console.error("Error repaying:", error);
    			throw error;
    		}
    	}
    }
  • src/index.ts:9-25 (registration)
    Registration: imports repayTool from './tools/repay.js' (line 9) and registers it on the MCP server via server.addTool(repayTool) (line 25).
    import { repayTool } from "./tools/repay.js";
    
    async function main() {
    	console.log("🚀 Initializing BAMM MCP Server...");
    
    	const server = new FastMCP({
    		name: "BAMM MCP Server",
    		version: "0.0.1",
    	});
    
    	server.addTool(addCollateralTool);
    	server.addTool(borrowTool);
    	server.addTool(getPositionsTool);
    	server.addTool(lendTool);
    	server.addTool(poolStatsTool);
    	server.addTool(removeCollateralTool);
    	server.addTool(repayTool);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits. It only implies mutation via 'Repay' but does not specify effects on position, required tokens, authorization needs, or return values. Minimal transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Definition is a single, front-loaded sentence with no redundant information. Every word serves a purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema and no annotations, the description is too sparse. For a financial tool with 4 parameters, it should explain side effects (e.g., reduction of debt), return values, and auth requirements. Both conciseness and completeness are insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and descriptions exist for all parameters. However, most descriptions are tautological (e.g., 'The amount to repay') and add little beyond parameter names. The borrowTokenSymbol description provides an example, adding slight value. Baseline 3 is appropriate, but no significant enrichment.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Repay borrowed tokens to a BAMM position' uses a specific verb (repay) and resource (borrowed tokens to a BAMM position). It clearly distinguishes from sibling tools like BORROW and REMOVE_COLLATERAL, indicating its unique action.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives, no prerequisites (e.g., must have an active borrow), and no when-not-to-use conditions. The description provides no context for appropriate invocation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/IQAIcom/mcp-bamm'

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