Skip to main content
Glama

REMOVE_COLLATERAL

Remove collateral from a BAMM position by specifying the BAMM contract address, collateral token details, and the amount to withdraw on the Fraxtal blockchain.

Instructions

Remove collateral from your BAMM position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of collateral to remove
bammAddressYesThe address of the BAMM contract
collateralTokenNoThe address of the collateral token
collateralTokenSymbolNoThe symbol of the collateral token (e.g., 'IQT')

Implementation Reference

  • MCP tool handler execute function for REMOVE_COLLATERAL, orchestrating wallet setup, service execution, and formatted response.
    execute: async (params) => {
    	try {
    		if (!params.collateralToken && !params.collateralTokenSymbol) {
    			return "Error: Either collateralToken address or collateralTokenSymbol 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 removeCollateralService = new RemoveCollateralService(
    			walletService,
    		);
    
    		const result = await removeCollateralService.execute({
    			bammAddress: params.bammAddress as Address,
    			collateralToken: params.collateralToken as Address | undefined,
    			collateralTokenSymbol: params.collateralTokenSymbol,
    			amount: params.amount,
    		});
    
    		return dedent`
           ✅ Collateral Removal Successful
    
           🌐 BAMM Address: ${params.bammAddress}
           🔓 Amount: ${formatNumber(Number(params.amount))}
           💰 Token: ${params.collateralTokenSymbol ?? params.collateralToken}
           🔗 Transaction: ${result.txHash}
    
           Collateral has been removed from your BAMM position.
         `;
    	} catch (error) {
    		if (error instanceof Error) {
    			return dedent`
             ❌ Collateral Removal Failed
    
             Error: ${error.message}
    
             Please verify your inputs and try again.
           `;
    		}
    		return "An unknown error occurred while removing collateral";
    	}
    },
  • Zod input schema defining parameters for the REMOVE_COLLATERAL tool.
    const removeCollateralToolParams = 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 collateral to remove"),
    	collateralToken: z
    		.string()
    		.regex(/^0x[a-fA-F0-9]{40}$/)
    		.optional()
    		.describe("The address of the collateral token"),
    	collateralTokenSymbol: z
    		.string()
    		.optional()
    		.describe("The symbol of the collateral token (e.g., 'IQT')"),
    });
  • src/index.ts:24-24 (registration)
    Registration of the REMOVE_COLLATERAL tool in the FastMCP server.
    server.addTool(removeCollateralTool);
  • Core execution logic in RemoveCollateralService for performing the blockchain transaction to remove collateral.
    async execute(params: RemoveCollateralParams): Promise<{ txHash: string }> {
    	let { bammAddress, collateralToken, collateralTokenSymbol, amount } =
    		params;
    	if (!collateralToken && !collateralTokenSymbol) {
    		throw new Error(
    			"Either collateralToken or collateralTokenSymbol 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 removeAmountWei = -BigInt(Math.floor(Number(amount) * 1e18));
    
    	try {
    		if (collateralTokenSymbol) {
    			collateralToken = await getTokenAddressFromSymbol(
    				collateralTokenSymbol,
    			);
    		}
    
    		if (!collateralToken) {
    			throw new Error("Could not resolve collateral token address");
    		}
    
    		const tokenValidation = await validateTokenAgainstBAMM(
    			bammAddress,
    			collateralToken,
    			publicClient,
    		);
    		await checkTokenBalance(
    			collateralToken,
    			userAddress,
    			removeAmountWei,
    			publicClient,
    		);
    
    		const currentTime = Math.floor(Date.now() / 1000);
    		const deadline = BigInt(currentTime + 300);
    
    		const action = {
    			token0Amount: tokenValidation.isToken0 ? removeAmountWei : 0n,
    			token1Amount: tokenValidation.isToken1 ? removeAmountWei : 0n,
    			rent: 0n,
    			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 executing remove-collateral", error);
    		throw Error("Error executing remove-collateral");
    	}
    }
  • Type definition for parameters used in the RemoveCollateralService.
    export interface RemoveCollateralParams {
    	bammAddress: Address;
    	collateralToken?: Address;
    	collateralTokenSymbol?: string;
    	amount: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Remove') but doesn't clarify if this is a destructive operation, requires specific permissions, has side effects (e.g., impact on borrowing capacity), or involves transaction costs. This is a significant gap for a financial tool with potential risks.

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?

The description is a single, direct sentence with zero waste, efficiently conveying the core action. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly without unnecessary elaboration.

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?

Given the complexity of a financial operation with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits (e.g., safety, reversibility), expected outcomes, or error conditions, which are critical for an agent to use this tool correctly in a DeFi context.

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?

The input schema has 100% description coverage, providing clear details for all four parameters (amount, bammAddress, collateralToken, collateralTokenSymbol). The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline for adequate but not enhanced documentation.

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

Purpose4/5

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

The description clearly states the action ('Remove') and resource ('collateral from your BAMM position'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like ADD_COLLATERAL or REPAY, which would require more specific context about when removal versus other operations is appropriate.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like ADD_COLLATERAL, BORROW, REPAY, and GET_POSITIONS, there's no indication of prerequisites, timing, or exclusions, leaving the agent to guess based on the tool name alone.

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

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