Skip to main content
Glama

sell_etf_token

Simulate selling ETF tokens for base currency on Paloma DEX across multiple EVM chains to preview transaction outcomes before execution.

Instructions

Sell ETF tokens back to base currency (simulation only - no actual transaction).

Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) etf_token_address: Address of the ETF token to sell etf_amount: Amount of ETF tokens to sell (in token units, e.g. '10.5') Returns: JSON string with transaction simulation details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYes
etf_token_addressYes
etf_amountYes

Implementation Reference

  • The handler function for the 'sell_etf_token' MCP tool. It validates inputs, checks balances, and returns a simulation of selling ETF tokens via the ETF connector contract without executing an actual transaction.
    async def sell_etf_token(ctx: Context, chain_id: str, etf_token_address: str, etf_amount: str) -> str: """Sell ETF tokens back to base currency (simulation only - no actual transaction). Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) etf_token_address: Address of the ETF token to sell etf_amount: Amount of ETF tokens to sell (in token units, e.g. '10.5') Returns: JSON string with transaction simulation details. """ 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 not config.etf_connector: return f"Error: ETF connector not configured for {config.name}" # Validate addresses if not Web3.is_address(etf_token_address): return f"Error: Invalid ETF token address format: {etf_token_address}" try: etf_amount_float = float(etf_amount) if etf_amount_float <= 0: raise ValueError("Amount must be positive") except ValueError: return f"Error: Invalid ETF amount: {etf_amount}" # Get ETF token information if chain_id not in paloma_ctx.web3_clients: return f"Error: Web3 client not available for {config.name}" web3 = paloma_ctx.web3_clients[chain_id] try: etf_contract = web3.eth.contract(address=etf_token_address, abi=ERC20_ABI) etf_symbol = etf_contract.functions.symbol().call() etf_decimals = etf_contract.functions.decimals().call() # Check current balance balance_wei = etf_contract.functions.balanceOf(paloma_ctx.address).call() balance = balance_wei / (10 ** etf_decimals) except Exception as e: return f"Error: Failed to read ETF token contract: {str(e)}" # Check if user has sufficient balance if etf_amount_float > balance: return f"Error: Insufficient balance. You have {balance} {etf_symbol}, trying to sell {etf_amount}" # Simulate transaction details (no actual execution) simulation_result = { "operation": "sell_etf_token", "chain": config.name, "chain_id": config.chain_id, "etf_connector": config.etf_connector, "etf_token": { "address": etf_token_address, "symbol": etf_symbol, "amount_to_sell": etf_amount, "current_balance": str(balance), "decimals": etf_decimals }, "recipient": paloma_ctx.address, "status": "simulation", "note": "This is a simulation. Actual trading requires approval and proper transaction execution.", "next_steps": [ "1. Approve ETF token spending to ETF connector", "2. Call ETF connector sell() function with deadline parameter", "3. Handle gas fees and transaction confirmation", "4. Receive proceeds in base currency" ] } return json.dumps(simulation_result, indent=2) except Exception as e: logger.error(f"Error in sell ETF token simulation: {e}") return f"Error in sell ETF token simulation: {str(e)}"
  • The ABI definition for the 'sell' function on the ETF connector contract, which is referenced in the sell_etf_token tool implementation.
    { "name": "sell", "type": "function", "inputs": [ {"name": "etf_token", "type": "address"}, {"name": "etf_amount", "type": "uint256"}, {"name": "deadline", "type": "uint256"}, {"name": "recipient", "type": "address"} ], "outputs": [], "stateMutability": "payable" }
  • The docstring of the sell_etf_token function defines the input parameters and return type, serving as the tool schema for MCP.
    Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) etf_token_address: Address of the ETF token to sell etf_amount: Amount of ETF tokens to sell (in token units, e.g. '10.5')

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