Query editor
WITHtrades AS (SELECTblock_time,tx_hash,tx_from,project,version,project_contract_address,token_pair,amount_usd,CASEWHEN token_bought_address = 0x020bfc650a365f8bb26819deaabf3e21291018b4 THEN 'buy'WHEN token_sold_address = 0x020bfc650a365f8bb26819deaabf3e21291018b4 THEN 'sell'END AS directionFROM dex_evm.tradesWHERE blockchain = 'robinhood'AND block_month >= CAST(date_trunc('month', current_date - INTERVAL '30' DAY) AS date)AND block_time >= current_timestamp - INTERVAL '30' DAYAND (token_bought_address = 0x020bfc650a365f8bb26819deaabf3e21291018b4OR token_sold_address = 0x020bfc650a365f8bb26819deaabf3e21291018b4)),tx_direction AS (SELECTMAX(block_time) AS block_time,tx_hash,tx_from,direction,SUM(amount_usd) AS amount_usdFROM tradesGROUP BY tx_hash, tx_from, direction),sell_tx AS (SELECT *FROM tx_directionWHERE direction = 'sell'AND amount_usd IS NOT NULL),wallet_sides AS (SELECTtx_from,MAX(CASE WHEN direction = 'buy' THEN 1 ELSE 0 END) AS has_buy,MAX(CASE WHEN direction = 'sell' THEN 1 ELSE 0 END) AS has_sellFROM tx_directionGROUP BY 1),coverage AS (SELECTCOUNT_IF(has_buy = 1) AS buy_wallets,COUNT_IF(has_sell = 1) AS sell_wallets,COUNT_IF(has_buy = 1 AND has_sell = 1) AS wallets_with_both,100.0 * COUNT_IF(has_buy = 1 AND has_sell = 1)/ NULLIF(COUNT_IF(has_buy = 1), 0) AS buyers_with_sell_pctFROM wallet_sides),scenarios(label, scenario_usd) AS (VALUES('$100', DOUBLE '100'),