Query editor
WITH params AS (SELECT 365 AS dormant_days, 100000 AS min_transfer_usd, 500 AS result_limit),stablecoin_large_receivers AS (SELECT"to" AS wallet_address,CONCAT(SUBSTRING(CAST("to" AS VARCHAR), 1, 6), '…',SUBSTRING(CAST("to" AS VARCHAR), LENGTH(CAST("to" AS VARCHAR)) - 3, 4)) AS entity_label,ARRAY_JOIN(ARRAY_AGG(DISTINCT symbol), ', ') AS token_symbols,SUM(amount_usd) AS received_usd_proxy,MAX(block_time) AS last_large_inbound_at,-- COVERAGE (additive): window functions evaluate over every grouped-- (wallet-deduplicated) row BEFORE this block's ORDER BY/LIMIT apply,-- so eligible_wallet_count is the complete pre-LIMIT eligible cohort-- size and cohort_rank is each wallet's deterministic admission rank.COUNT(*) OVER () AS eligible_wallet_count,ROW_NUMBER() OVER (ORDER BY SUM(amount_usd) DESC, "to" ASC) AS cohort_rankFROM tokens.transfersWHERE blockchain = 'ethereum'AND block_time >= CURRENT_TIMESTAMP - INTERVAL '180' DAYAND symbol IN ('USDC', 'USDT', 'DAI')AND amount_usd >= (SELECT min_transfer_usd FROM params)AND "to" IS NOT NULLGROUP BY "to"ORDER BY received_usd_proxy DESC, wallet_address ASCLIMIT 500 -- must equal params.result_limit above (Trino LIMIT cannot read a subquery)),current_balance AS (SELECT bb.wallet_address, SUM(bb.balance_usd) AS balance_usdFROM (SELECT from_hex(substr(address, 3)) AS wallet_address, 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) bbJOIN stablecoin_large_receivers r ON r.wallet_address = bb.wallet_addressWHERE bb.rn = 1GROUP BY bb.wallet_address),outgoing_activity AS (SELECT tx."from" AS wallet_address,MIN(tx.block_time) AS first_outgoing_tx_at,MAX(tx.block_time) AS last_outgoing_tx_at,COUNT(*) AS outgoing_tx_countFROM ethereum.transactions txINNER JOIN stablecoin_large_receivers r ON tx."from" = r.wallet_addressWHERE tx.success = trueGROUP BY tx."from"),classified AS (SELECTr.wallet_address,r.entity_label,COALESCE(cb.balance_usd, r.received_usd_proxy) AS balance_usd_proxy,r.token_symbols,