Skip to main content
Glama

generate_bridge_code

Generate TypeScript code for bridging assets between Arbitrum layers (L1/L2/L3) using the Arbitrum SDK, supporting ETH and ERC20 token transfers.

Instructions

Generate TypeScript code for Arbitrum asset bridging using the Arbitrum SDK. Supports ETH/ERC20 bridging L1<->L2 and L1->L3.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bridge_typeYesType of bridging operation to generate code for
amountNoAmount to bridge (in ETH or token units)0.1
token_addressNoL1 token address (required for erc20 operations)
destination_addressNoDestination address (for deposit_to operations)

Implementation Reference

  • The 'execute' method of GenerateBridgeCodeTool handles the tool logic, selecting and formatting the appropriate template based on 'bridge_type'.
    def execute(self, **kwargs) -> dict[str, Any]:
        """Generate bridging code based on the specified type."""
        bridge_type = kwargs.get("bridge_type")
        amount = kwargs.get("amount", "0.1")
        token_address = kwargs.get("token_address", "0x...")
        destination = kwargs.get("destination_address", "0x...")
        _include_status = kwargs.get("include_status_check", True)
    
        # Validate inputs
        if not bridge_type:
            return {"error": "bridge_type is required"}
    
        if bridge_type.startswith("erc20") and not token_address:
            return {"error": "token_address is required for ERC20 operations"}
    
        # Select template
        templates = {
            "eth_deposit": ETH_DEPOSIT_TEMPLATE,
            "eth_deposit_to": ETH_DEPOSIT_TO_TEMPLATE,
            "eth_withdraw": ETH_WITHDRAW_TEMPLATE,
            "erc20_deposit": ERC20_DEPOSIT_TEMPLATE,
            "erc20_withdraw": ERC20_WITHDRAW_TEMPLATE,
            "eth_l1_l3": ETH_L1_L3_TEMPLATE,
            "erc20_l1_l3": ERC20_L1_L3_TEMPLATE,
            "eth_l3_l2": ETH_L3_L2_TEMPLATE,
            "erc20_l3_l2": ERC20_L3_L2_TEMPLATE,
        }
    
        template = templates.get(bridge_type)
        if not template:
            return {"error": f"Unknown bridge_type: {bridge_type}"}
    
        # Format template using replace to avoid curly brace issues
        code = template.replace("{amount}", amount)
        code = code.replace("{token_address}", token_address)
        code = code.replace("{destination}", destination)
    
        # Build response
        result = {
            "code": code,
            "bridge_type": bridge_type,
            "dependencies": {
                "ethers": "^5.7.0",
                "@arbitrum/sdk": "^4.0.0",
            },
            "env_vars": [
                "L1_RPC_URL",
                "L2_RPC_URL",
                "PRIVATE_KEY",
            ],
            "notes": self._get_notes(bridge_type),
            "disclaimer": TEMPLATE_DISCLAIMER,
        }
    
        if bridge_type in ["eth_l1_l3", "erc20_l1_l3", "eth_l3_l2", "erc20_l3_l2"]:
            result["env_vars"].append("L3_RPC_URL")
    
        return result
  • The input_schema defines the parameters for the 'generate_bridge_code' tool, including bridge_type, amount, and token_address.
    input_schema = {
        "type": "object",
        "properties": {
            "bridge_type": {
                "type": "string",
                "enum": ["eth_deposit", "eth_deposit_to", "eth_withdraw",
                         "erc20_deposit", "erc20_withdraw",
                         "eth_l1_l3", "erc20_l1_l3",
                         "eth_l3_l2", "erc20_l3_l2"],
                "description": "Type of bridging operation to generate code for",
            },
            "amount": {
                "type": "string",
                "description": "Amount to bridge (in ETH for eth operations, or token units)",
                "default": "0.1",
            },
            "token_address": {
                "type": "string",
                "description": "L1 token address (required for erc20 operations)",
            },
            "destination_address": {
                "type": "string",
                "description": "Destination address (for deposit_to operations)",
            },
            "include_status_check": {
                "type": "boolean",
                "description": "Include code for checking bridge status",
                "default": True,
            },
        },
        "required": ["bridge_type"],
    }
  • The tool name is registered as 'generate_bridge_code' inside the GenerateBridgeCodeTool class definition.
    name = "generate_bridge_code"

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/Quantum3-Labs/ARBuilder'

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