Query editor
WITH usdc_activity AS (SELECT "user" as user_addr, CAST(amount AS DOUBLE) / 1e6 as amount_usd, date_trunc('month', evt_block_time) as month FROM etherfi_scroll.topupdest_evt_topup WHERE token = 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4 UNION ALL SELECT "user" as user_addr, CAST(amount AS DOUBLE) / 1e6 as amount_usd, date_trunc('month', evt_block_time) as month FROM etherfi_scroll.debtmanagercore_evt_borrowed WHERE token = 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4), user_totals AS (SELECT user_addr, SUM(amount_usd) as total_vol FROM usdc_activity GROUP BY 1), top_users AS (SELECT user_addr FROM user_totals WHERE total_vol >= (SELECT APPROX_PERCENTILE(total_vol, 0.90) FROM user_totals)) SELECT a.month, COUNT(DISTINCT a.user_addr) as active_top_users, SUM(a.amount_usd) as total_vol, AVG(a.amount_usd) as avg_txn, COUNT(*) as num_txns, SUM(a.amount_usd) / COUNT(DISTINCT a.user_addr) as vol_per_user FROM usdc_activity a JOIN top_users t ON a.user_addr = t.user_addr GROUP BY 1 ORDER BY 1