Query editor
WITH params AS (SELECT date_add('year', -7, current_date) AS window_start_date, -- rolling 7y (bounded width, self-maintaining)365 AS dormancy_days,100000 AS min_balance_usd,500 AS result_limit),stable AS ( -- real USD-stablecoin value per holderSELECT lower(address) AS wallet_v,from_hex(substr(address, 3)) AS wallet_b, -- varbinary for tx joinssum(balance_usd) AS balance_usd,max_by(token_symbol, balance_usd) AS asset_symbolFROM (SELECT address, token_symbol, balance_usd,ROW_NUMBER() OVER (PARTITION BY address, token_address, token_id ORDER BY day DESC) AS rnFROM stablecoins_multichain.balancesWHERE blockchain = 'ethereum' AND currency = 'USD'AND day >= date_add('day', -3, current_date) AND balance > 0) bWHERE rn = 1GROUP BY addressHAVING sum(balance_usd) >= (SELECT min_balance_usd FROM params)),last_outgoing AS ( -- dormancy/exposure for ONLY stablecoin holders (restricts the big tx scan)SELECT tx."from" AS address,min(tx.block_time) AS first_outgoing_tx_at,max(tx.block_time) AS last_outgoing_tx_at,count(*) AS signed_tx_countFROM ethereum.transactions txJOIN stable s ON s.wallet_b = tx."from"WHERE tx.success = trueAND tx.block_time >= CAST((SELECT window_start_date FROM params) AS timestamp)GROUP BY tx."from"),contracts AS (SELECT DISTINCT address FROM ethereum.creation_traces),entity_labels AS ( -- one row per address (labels.addresses has MANY labels/addr → fan-out fix); prefer identity labelsSELECT address,max_by(name, label_priority) AS entity_label,max_by(category, label_priority) AS entity_typeFROM (SELECT address, name, category,CASE categoryWHEN 'institution' THEN 4WHEN 'cex' THEN 3WHEN 'cex users' THEN 2ELSE 1END AS label_priorityFROM labels.addressesWHERE blockchain = 'ethereum')GROUP BY address),ranked AS (SELECT *,row_number() OVER (ORDER BY balance_usd DESC, wallet_v ASC) AS holder_rank,count(*) OVER () AS eligible_wallet_countFROM stable)SELECT