get_available_trading_tokens
Retrieve available trading tokens and their details for a specific blockchain network to facilitate cross-chain trading operations on Paloma DEX.
Instructions
Get available tokens for trading on a specific chain.
Args:
chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
Returns:
JSON string with available trading tokens and their information.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"chain_id": {
"title": "Chain Id",
"type": "string"
}
},
"required": [
"chain_id"
],
"type": "object"
}
Implementation Reference
- padex.py:1277-1349 (handler)Handler function for the 'get_available_trading_tokens' tool. Decorated with @mcp.tool() which registers it with the FastMCP server. Fetches available trading tokens for a given chain using PalomaDEXAPI or fallback list, returns JSON.@mcp.tool() async def get_available_trading_tokens(ctx: Context, chain_id: str) -> str: """Get available tokens for trading on a specific chain. Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) Returns: JSON string with available trading tokens and their information. """ 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] chain_name = get_chain_name_for_api(chain_id) if not chain_name: return f"Error: Chain name mapping not found for chain ID {chain_id}" # Use our Paloma-based API implementation try: tokens_data = await paloma_ctx.palomadex_api.get_tokens(chain_id) result = { "chain": config.name, "chain_id": config.chain_id, "trader_contract": TRADER_ADDRESSES.get(chain_id, "Not configured"), "total_tokens": len(tokens_data), "tradeable_tokens": len([t for t in tokens_data if t.get('is_pair_exist', False)]), "tokens": tokens_data, "data_source": "paloma_dex_api" } return json.dumps(result, indent=2) except Exception as api_error: logger.warning(f"Paloma API failed: {api_error}, using fallback") # Fallback: Return common tokens that are likely available for trading common_tokens = [] if chain_id == ChainID.ETHEREUM_MAIN: common_tokens = [ {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Wrapped Ether", "erc20_symbol": "WETH", "erc20_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "erc20_decimals": 18, "is_pair_exist": True} ] elif chain_id == ChainID.ARBITRUM_MAIN: common_tokens = [ {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", "erc20_decimals": 6, "is_pair_exist": True} ] # Add more chains as needed result = { "chain": config.name, "chain_id": config.chain_id, "trader_contract": TRADER_ADDRESSES.get(chain_id, "Not configured"), "note": "Using fallback token list - Paloma API unavailable", "total_tokens": len(common_tokens), "tradeable_tokens": len(common_tokens), "tokens": common_tokens, "data_source": "fallback" } return json.dumps(result, indent=2) except Exception as e: logger.error(f"Error getting available tokens: {e}") return f"Error getting available tokens: {str(e)}"
- padex.py:421-438 (helper)Supporting method in PalomaDEXAPI class that provides the list of available tokens per chain. Called by the main handler via paloma_ctx.palomadex_api.get_tokens(chain_id). Currently a mock with common tokens.async def get_tokens(self, chain_id: str) -> List[Dict]: """Get available tokens for a chain (mock implementation).""" # In real implementation, this would query the factory contract # For now, return common tokens per chain common_tokens = { "1": [ # Ethereum {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Wrapped Ether", "erc20_symbol": "WETH", "erc20_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "erc20_decimals": 18, "is_pair_exist": True} ], "42161": [ # Arbitrum {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", "erc20_decimals": 6, "is_pair_exist": True} ] } return common_tokens.get(chain_id, [])
- padex.py:416-438 (helper)PalomaDEXAPI class containing the get_tokens method used by the tool handler."""PalomaDEX API implementation using Paloma queries.""" def __init__(self, paloma_client: PalomaClient): self.client = paloma_client async def get_tokens(self, chain_id: str) -> List[Dict]: """Get available tokens for a chain (mock implementation).""" # In real implementation, this would query the factory contract # For now, return common tokens per chain common_tokens = { "1": [ # Ethereum {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Wrapped Ether", "erc20_symbol": "WETH", "erc20_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "erc20_decimals": 18, "is_pair_exist": True} ], "42161": [ # Arbitrum {"erc20_name": "USD Coin", "erc20_symbol": "USDC", "erc20_address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", "erc20_decimals": 6, "is_pair_exist": True}, {"erc20_name": "Tether USD", "erc20_symbol": "USDT", "erc20_address": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", "erc20_decimals": 6, "is_pair_exist": True} ] } return common_tokens.get(chain_id, [])