Query editor
WITH flows AS (SELECTblockchain,block_date,tx_hash,ABS(amount_usd) AS volume_usd,CASEWHEN "to" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7 THEN "from"ELSE "to"END AS user_addressFROM tokens.transfersWHERE( "to" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7OR "from" = 0x1f8E735f424B7A49A885571A2fA104E8C13C26c7 )AND "from" NOT IN (0x3c2269811836af69497e5f486a85d7316753cf62,0xb6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7,0x66a71dcef29a0ffbdbe3c6a460a3b5bc225cd675,0x4200000000000000000000000000000000000006,0x0000000000000000000000000000000000000000,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x82af49447d8a07e3bd95bd0d56f35241523fbab1)AND "to" NOT IN (0x3c2269811836af69497e5f486a85d7316753cf62,0xb6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7,0x66a71dcef29a0ffbdbe3c6a460a3b5bc225cd675,0x4200000000000000000000000000000000000006,0x0000000000000000000000000000000000000000,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x82af49447d8a07e3bd95bd0d56f35241523fbab1)AND blockchain IN ('optimism','ethereum','bnb','base','avalanche_c','arbitrum')),-- one row = one "trade" per user per txuser_trades AS (SELECTuser_address,tx_hash,SUM(volume_usd) AS trade_volume_usdFROM flowsGROUP BY user_address, tx_hash),-- aggregate trades per user (across all chains)user_stats AS (SELECTuser_address,SUM(trade_volume_usd) AS total_volume_usd,COUNT(*) AS tx_count,AVG(trade_volume_usd) AS avg_trade_usd,approx_percentile(trade_volume_usd, 0.5) AS median_trade_usdFROM user_tradesGROUP BY user_address)SELECTuser_address,total_volume_usd,