check_token_allowance
Verify token spending permissions on Paloma DEX by checking approved allowances between owners and spenders across supported EVM chains.
Instructions
Check token allowance for a specific owner and spender.
Args:
chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
token_address: Address of the token
owner_address: Address of the token owner
spender_address: Address of the spender (typically Trader contract)
Returns:
JSON string with allowance information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain_id | Yes | ||
| token_address | Yes | ||
| owner_address | Yes | ||
| spender_address | Yes |
Implementation Reference
- padex.py:1816-1894 (handler)The handler function decorated with @mcp.tool() that implements the core logic for checking ERC20 token allowances on specified EVM chains using Web3.py contract calls.async def check_token_allowance(ctx: Context, chain_id: str, token_address: str, owner_address: str, spender_address: str) -> str: """Check token allowance for a specific owner and spender. Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) token_address: Address of the token owner_address: Address of the token owner spender_address: Address of the spender (typically Trader contract) Returns: JSON string with allowance 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] if chain_id not in paloma_ctx.web3_clients: return f"Error: Web3 client not available for {config.name}" # Validate addresses if not Web3.is_address(token_address): return f"Error: Invalid token address: {token_address}" if not Web3.is_address(owner_address): return f"Error: Invalid owner address: {owner_address}" if not Web3.is_address(spender_address): return f"Error: Invalid spender address: {spender_address}" web3 = paloma_ctx.web3_clients[chain_id] token_contract = web3.eth.contract(address=token_address, abi=ERC20_ABI) # Get allowance and token info allowance = token_contract.functions.allowance(owner_address, spender_address).call() try: token_symbol = token_contract.functions.symbol().call() token_decimals = token_contract.functions.decimals().call() balance = token_contract.functions.balanceOf(owner_address).call() except: token_symbol = "Unknown" token_decimals = 18 balance = 0 allowance_display = float(allowance) / (10 ** token_decimals) balance_display = float(balance) / (10 ** token_decimals) result = { "chain": config.name, "chain_id": config.chain_id, "token": { "address": token_address, "symbol": token_symbol, "decimals": token_decimals }, "owner_address": owner_address, "spender_address": spender_address, "allowance": { "wei": str(allowance), "display": str(allowance_display), "is_unlimited": allowance == MAX_AMOUNT }, "owner_balance": { "wei": str(balance), "display": str(balance_display) }, "needs_approval": allowance == 0, "sufficient_allowance": allowance >= balance if balance > 0 else True } return json.dumps(result, indent=2) except Exception as e: logger.error(f"Error checking token allowance: {e}") return f"Error checking token allowance: {str(e)}"
- padex.py:198-239 (helper)Minimal ERC20 ABI including the allowance(), balanceOf(), decimals(), and symbol() functions used by the check_token_allowance handler to query contract state.ERC20_ABI = [ { "constant": True, "inputs": [{"name": "_owner", "type": "address"}], "name": "balanceOf", "outputs": [{"name": "balance", "type": "uint256"}], "type": "function" }, { "constant": True, "inputs": [], "name": "decimals", "outputs": [{"name": "", "type": "uint8"}], "type": "function" }, { "constant": True, "inputs": [], "name": "symbol", "outputs": [{"name": "", "type": "string"}], "type": "function" }, { "constant": False, "inputs": [ {"name": "spender", "type": "address"}, {"name": "amount", "type": "uint256"} ], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "type": "function" }, { "constant": True, "inputs": [ {"name": "owner", "type": "address"}, {"name": "spender", "type": "address"} ], "name": "allowance", "outputs": [{"name": "", "type": "uint256"}], "type": "function" }