Skip to main content
Glama

ADD_COLLATERAL

Add collateral to a BAMM position to increase borrowing capacity. Specify the BAMM contract address and the amount of collateral to add.

Instructions

Add collateral to your BAMM position

Input Schema

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

Implementation Reference

  • The main handler/execute function for the ADD_COLLATERAL tool. It validates inputs, creates a WalletService and AddCollateralService, calls the service's execute method, and returns a formatted success/error message.
    export const addCollateralTool: Tool<
    	FastMCPSessionAuth,
    	typeof addCollateralToolParams
    > = {
    	name: "ADD_COLLATERAL",
    	description: "Add collateral to your BAMM position",
    	parameters: addCollateralToolParams,
    	execute: async (params, _context) => {
    		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 addCollateralService = new AddCollateralService(walletService);
    
    			const result = await addCollateralService.execute({
    				bammAddress: params.bammAddress as Address,
    				collateralToken: params.collateralToken as Address | undefined,
    				collateralTokenSymbol: params.collateralTokenSymbol,
    				amount: params.amount,
    			});
    
    			return dedent`
            ✅ Collateral Addition Successful
    
            🌐 BAMM Address: ${params.bammAddress}
            🔒 Amount: ${formatNumber(Number(params.amount))}
            💰 Token: ${params.collateralTokenSymbol ?? params.collateralToken}
            🔗 Transaction: ${result.txHash}
    
            Collateral has been added to your BAMM position.
          `;
    		} catch (error) {
    			if (error instanceof Error) {
    				return dedent`
              ❌ Collateral Addition Failed
    
              Error: ${error.message}
    
              Please verify your inputs and try again.
            `;
    			}
    			return "An unknown error occurred while adding collateral";
    		}
    	},
    };
  • Zod schema for ADD_COLLATERAL tool parameters: bammAddress (regex 0x address), amount (string), collateralToken (optional regex 0x address), collateralTokenSymbol (optional string).
    const addCollateralToolParams = 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 add"),
    	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:19-19 (registration)
    Registration of the addCollateralTool on the FastMCP server instance via server.addTool(addCollateralTool).
    server.addTool(addCollateralTool);
  • The AddCollateralService class which contains the core business logic: resolves token address from symbol, validates token against BAMM, checks balance, ensures token approval, then calls executeActions on the BAMM contract.
    import type { Address } from "viem";
    import { BAMM_ABI } from "../lib/bamm.abi.js";
    import { getTokenAddressFromSymbol } from "../lib/symbol-to-address.js";
    import { checkTokenBalance, ensureTokenApproval } from "../lib/token-utils.js";
    import { validateTokenAgainstBAMM } from "../lib/token-validator.js";
    import type { WalletService } from "./wallet.js";
    
    export interface AddCollateralParams {
    	bammAddress: Address;
    	collateralToken?: Address;
    	collateralTokenSymbol?: string;
    	amount: string;
    }
    
    export class AddCollateralService {
    	constructor(private walletService: WalletService) {}
    
    	async execute(params: AddCollateralParams): 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 amountInWei = BigInt(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,
    				amountInWei,
    				publicClient,
    			);
    			await ensureTokenApproval(
    				collateralToken,
    				bammAddress,
    				amountInWei,
    				publicClient,
    				walletClient,
    			);
    
    			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: 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 in add collateral service:", error);
    			throw Error("Error in add collateral service");
    		}
    	}
    }
  • The ADD_COLLATERAL_TEMPLATE, a prompt template used for AI extraction of collateral addition parameters from user messages.
    export const ADD_COLLATERAL_TEMPLATE = TOKEN_OPERATION_TEMPLATE.replace(
    	/{{operation}}/g,
    	"collateral addition",
    ).replace(/{{tokenType}}/g, "collateralToken");
    
    export const REMOVE_COLLATERAL_TEMPLATE = TOKEN_OPERATION_TEMPLATE.replace(
    	/{{operation}}/g,
    	"collateral withdrawal",
    ).replace(/{{tokenType}}/g, "collateralToken");
Behavior2/5

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

With no annotations, the description bears full burden for behavioral disclosure. It merely states 'add collateral' without explaining if it's a write operation, requires prior approvals, or has irreversible effects. Critical safety information is missing.

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

Conciseness4/5

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

The description is a single, non-redundant sentence. It is concise but lacks structure; front-loading is effective, but it omits necessary detail.

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 the tool (4 parameters, two optional, no output schema) and absence of annotations, the description is insufficient. It does not cover prerequisites, return values, or typical usage 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?

Schema coverage is 100%, so the schema itself documents each parameter. The tool description adds no additional meaning beyond the schema's descriptions. Baseline 3 is appropriate.

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 (add) and the resource (collateral to BAMM position), distinguishing it from siblings like REMOVE_COLLATERAL. However, it assumes familiarity with the term 'BAMM position', which may be unclear to new users.

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 is provided on when to use this tool versus alternatives (e.g., LEND or REPAY). There are no prerequisites, use cases, or exclusions mentioned.

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