Skip to main content
Glama

validate_trade_quote

Check if a trade quote meets spread and liquidity requirements before execution on Paloma DEX across multiple EVM chains.

Instructions

Validate a trade against max spread and liquidity requirements.

Args:
    chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
    input_token_address: Address of token to trade from
    output_token_address: Address of token to trade to  
    input_amount: Amount of input token in wei format

Returns:
    JSON string with trade validation results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYes
input_token_addressYes
output_token_addressYes
input_amountYes

Implementation Reference

  • The primary handler for the 'validate_trade_quote' MCP tool. Validates trades by checking if the trading pair exists, has liquidity, and if the requested amount does not exceed the maximum spread limit (40% of available liquidity). Returns JSON with validation results.
    async def validate_trade_quote(ctx: Context, chain_id: str, input_token_address: str, output_token_address: str, input_amount: str) -> str:
        """Validate a trade against max spread and liquidity requirements.
        
        Args:
            chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
            input_token_address: Address of token to trade from
            output_token_address: Address of token to trade to  
            input_amount: Amount of input token in wei format
        
        Returns:
            JSON string with trade validation results.
        """
        try:
            paloma_ctx = ctx.request_context.lifespan_context
            
            if chain_id not in CHAIN_CONFIGS:
                return f"Error: Unsupported chain ID {chain_id}"
            
            config = CHAIN_CONFIGS[chain_id]
            
            # Validate addresses
            if not Web3.is_address(input_token_address):
                return f"Error: Invalid input token address: {input_token_address}"
            
            if not Web3.is_address(output_token_address):
                return f"Error: Invalid output token address: {output_token_address}"
            
            try:
                input_amount_int = int(input_amount)
                if input_amount_int <= 0:
                    raise ValueError("Amount must be positive")
            except ValueError:
                return f"Error: Invalid input amount: {input_amount}"
            
            # Use our Paloma-based quote validation
            try:
                quote_data = await paloma_ctx.palomadex_api.get_quote(
                    input_token_address, output_token_address, chain_id
                )
                
                if not quote_data.get('exist', False):
                    return json.dumps({
                        "valid": False,
                        "reason": "Trading pair does not exist",
                        "chain": config.name,
                        "chain_id": config.chain_id
                    }, indent=2)
                
                if quote_data.get('empty', True):
                    return json.dumps({
                        "valid": False,
                        "reason": "Pool has no liquidity",
                        "chain": config.name,
                        "chain_id": config.chain_id
                    }, indent=2)
                
                # Check against max spread (40% limit)
                available_liquidity = int(quote_data.get('amount0', '0'))
                max_trade_amount = int(available_liquidity * MAX_SPREAD) if available_liquidity > 0 else 0
                
                if input_amount_int > max_trade_amount:
                    return json.dumps({
                        "valid": False,
                        "reason": f"Amount exceeds max spread limit ({MAX_SPREAD*100}%)",
                        "max_amount": str(max_trade_amount),
                        "requested_amount": input_amount,
                        "chain": config.name,
                        "chain_id": config.chain_id
                    }, indent=2)
                
                # Trade is valid
                return json.dumps({
                    "valid": True,
                    "available_liquidity": str(available_liquidity),
                    "max_trade_amount": str(max_trade_amount),
                    "requested_amount": input_amount,
                    "spread_check": "passed",
                    "chain": config.name,
                    "chain_id": config.chain_id,
                    "trader_contract": TRADER_ADDRESSES.get(chain_id, "Not configured")
                }, indent=2)
                
            except Exception as api_error:
                logger.error(f"Quote validation failed: {api_error}")
                return json.dumps({
                    "valid": False,
                    "reason": f"Quote validation failed: {str(api_error)}",
                    "chain": config.name,
                    "chain_id": config.chain_id
                }, indent=2)
            
        except Exception as e:
            logger.error(f"Error validating trade quote: {e}")
            return f"Error validating trade quote: {str(e)}"
  • Helper method in PalomaDEXAPI class called by validate_trade_quote to retrieve liquidity quote data (amount0, exist, empty flags). Currently uses mock data.
    async def get_quote(self, token0: str, token1: str, chain_id: str) -> Dict:
        """Get quote for trade validation."""
        try:
            # Mock liquidity check
            return {
                "amount0": "1000000000000000000000000",  # 1M tokens
                "exist": True,
                "empty": False
            }
        except Exception as e:
            logger.error(f"Error in quote: {e}")
            return {"exist": False, "empty": True}
  • padex.py:1720-1720 (registration)
    MCP tool registration decorator @mcp.tool() applied to the validate_trade_quote handler function.
    async def validate_trade_quote(ctx: Context, chain_id: str, input_token_address: str, output_token_address: str, input_amount: str) -> str:
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions validation criteria (max spread, liquidity) but doesn't explain what happens during validation (e.g., whether it's a simulation, if it modifies state, rate limits, or error conditions). For a tool with 4 parameters and no annotation coverage, this leaves significant behavioral gaps.

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 well-structured with clear sections (purpose, args, returns) and uses minimal sentences that each add value. It could be slightly more concise by integrating the args list more seamlessly, but overall it's efficiently written without wasted words.

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

Completeness3/5

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

Given 4 parameters, no annotations, and no output schema, the description does a good job with parameters but has gaps in behavioral context and output details. It mentions returns a 'JSON string with trade validation results' but doesn't describe what those results contain. For a validation tool with moderate complexity, this is adequate but incomplete.

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

Parameters5/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It provides specific details for chain_id (listing valid values: 1, 10, 56, 100, 137, 8453, 42161), clarifies input_amount format ('in wei format'), and explains what each token address represents. This fully compensates for the schema's lack of documentation.

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 clearly states the specific action ('validate a trade') and the criteria ('against max spread and liquidity requirements'), distinguishing it from sibling tools like execute_token_swap or get_token_price_estimate which perform different functions. It uses precise terminology that conveys the tool's unique purpose.

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. It doesn't mention prerequisites (e.g., needing a quote first), exclusions, or how it relates to sibling tools like execute_token_swap or get_token_price_estimate. Usage context is implied but not explicitly stated.

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/VolumeFi/mcpPADEX'

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