Query editor
/* ===================================================STAGE 1c: PAYOUT WALLETSSave as dune.boc.result_payout_wallets.Some exchanges pay customers out through an unlabelled wallet: hot wallet-> payout wallet -> customer. In Stage 1a these show up as direct users.This query measures, for the direct users that could be one, where theirmoney comes from and where it goes, and flags payout wallets:- 90%+ of incoming USD comes from that country's exchanges,- they send to 50+ distinct wallets,- money passes through (outgoing USD at least 80% of incoming).All inputs are kept, so the thresholds can be changed without a rescan.Candidates: direct users that received at least $50,000 or 50 transfersfrom the exchanges (a payout wallet handles many customers' withdrawals;this keeps the scan small).Same transfer rule as Stage 1a: native ETH and priced tokens above zero.=================================================== */WITH candidates AS (SELECT wallet, country, n_withdraw, withdraw_usdFROM dune.boc.result_wallet_country_linksWHERE link_class = 'direct_user'AND (withdraw_usd >= 50000 OR n_withdraw >= 50)),candidate_wallets AS (SELECT DISTINCT wallet FROM candidates),xfers AS (SELECT "from" AS src, "to" AS dst, amount_usdFROM tokens_ethereum.transfersWHERE block_month >= DATE '2021-01-01'AND block_month < DATE '2026-01-01'AND amount > 0AND (token_standard = 'native' OR amount_usd IS NOT NULL)),flows AS (-- outgoingSELECT x.src AS wallet, 'out' AS direction, x.dst AS counterparty, x.amount_usdFROM xfers xINNER JOIN candidate_wallets c ON x.src = c.walletUNION ALL-- incomingSELECT x.dst, 'in', x.src, x.amount_usdFROM xfers xINNER JOIN candidate_wallets c ON x.dst = c.wallet),wallet_flows AS (SELECTwallet,SUM(CASE WHEN direction = 'in' THEN amount_usd END) AS in_usd,SUM(CASE WHEN direction = 'out' THEN amount_usd END) AS out_usd,COUNT_IF(direction = 'out') AS n_out,COUNT(DISTINCT CASE WHEN direction = 'out' THEN counterparty END) AS n_recipients,COUNT(DISTINCT CASE WHEN direction = 'in' THEN counterparty END) AS n_senders