Skip to main content
Glama

LEND

Deposit Fraxswap LP tokens into a BAMM contract to enable borrowing and liquidity management on the Fraxtal blockchain.

Instructions

Lend Fraxswap LP tokens to a BAMM contract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of LP tokens to lend
bammAddressYesThe address of the BAMM contract

Implementation Reference

  • The main handler for the 'LEND' tool, defining the tool name, description, parameters schema, and the execute function that orchestrates wallet setup and calls the LendService.
    export const lendTool: Tool<undefined, typeof lendToolParams> = {
    	name: "LEND",
    	description: "Lend Fraxswap LP tokens to a BAMM contract",
    	parameters: lendToolParams,
    	execute: async (params) => {
    		try {
    			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 lendService = new LendService(walletService);
    
    			const result = await lendService.execute({
    				bammAddress: params.bammAddress as Address,
    				amount: params.amount,
    			});
    
    			return dedent`
            βœ… Lending Successful
    
            🌐 BAMM Address: ${params.bammAddress}
            πŸ’° Amount: ${formatNumber(Number(params.amount))} LP tokens
            πŸ”— Transaction: ${result.txHash}
    
            LP tokens have been deposited to the BAMM contract.
          `;
    		} catch (error) {
    			if (error instanceof Error) {
    				return dedent`
              ❌ Lending Failed
    
              Error: ${error.message}
    
              Please verify your inputs and try again.
            `;
    			}
    			return "An unknown error occurred while lending LP tokens";
    		}
    	},
    };
  • Zod schema definition for the LEND tool parameters (bammAddress and amount), including TypeScript type export.
    const lendToolParams = 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 of LP tokens to lend"),
    });
    
    export type LendToolParams = z.infer<typeof lendToolParams>;
  • src/index.ts:22-22 (registration)
    Registration of the LEND tool on the FastMCP server instance.
    server.addTool(lendTool);
  • The LendService class containing the core logic for lending: reading LP token from BAMM.pair(), balance checks, approvals, and minting BAMM tokens.
    export class LendService {
    	constructor(private walletService: WalletService) {}
    
    	/**
    	 * Lend Fraxswap LP tokens to the BAMM contract.
    	 * Reads the LP token address from bamm.pair(), approves the BAMM to spend them if needed,
    	 * and calls bamm.mint() to deposit.
    	 */
    	async execute(params: LendParams): Promise<{ txHash: string }> {
    		const { bammAddress, amount } = params;
    		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 lpAmountWei = BigInt(Math.floor(Number(amount) * 1e18));
    		try {
    			// 1. Read the Fraxswap LP token address from the BAMM contract
    			const lpTokenAddress: Address = await publicClient.readContract({
    				address: bammAddress,
    				abi: BAMM_ABI,
    				functionName: "pair",
    				args: [],
    			});
    
    			// 2. Check user's LP token balance
    			await checkTokenBalance(
    				lpTokenAddress,
    				userAddress,
    				lpAmountWei,
    				publicClient,
    			);
    
    			// 3. Approve the BAMM contract to spend LP tokens
    			await ensureTokenApproval(
    				lpTokenAddress,
    				bammAddress,
    				lpAmountWei,
    				publicClient,
    				walletClient,
    			);
    			// 4. Call bamm.mint(to, lpIn) to deposit LP and receive BAMM tokens
    			const { request: mintRequest } = await publicClient.simulateContract({
    				address: bammAddress,
    				abi: BAMM_ABI,
    				functionName: "mint",
    				args: [userAddress, lpAmountWei],
    				account: walletClient.account,
    			});
    			const txHash = await walletClient.writeContract(mintRequest);
    			await publicClient.waitForTransactionReceipt({ hash: txHash });
    
    			return { txHash };
    		} catch (error) {
    			console.error("Error in lend service", error);
    			throw error;
    		}
    	}
    }
Install Server

Other Tools

Related 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