Query editor
/* ===================================================STAGE 2a (v7): LIFETIME WALLET-COUNTRY LINKS, ALL COUNTRIES IN ONE PASSSave as dune.boc.result_wallet_country_links_v7.v7 = v5 plus the block-fee-recipient exclusion (Stage 0 check C).Identification uses tokens_ethereum.transfers only. Deposit addresses arefound by our own 5-sweep rule; whether that rule holds is checkedafterwards with stage2a_summary_v7.sql.One row per (wallet, country) over 2021-01-01 to 2025-12-31: how the wallettransacted with that country's anchor exchanges. A wallet can link toseveral countries (one row each). Only two kinds of row are kept:- link_class = 'deposit_candidate': the wallet sent to the exchange andreceived nothing from it except possible gas top-ups (native ETH under$25), with 5 or more transfers to the exchange. Most are the exchange'sper-customer deposit addresses: one sweep per customer deposit, so adeposit address with fewer than 5 sweeps belongs to a customer with fewerthan 5 deposits (exception: exchanges that batch several deposits into onesweep; checked in Stage 2b). Gas-like receipts are ignored because someexchanges top up gas from the hot wallet itself.- link_class = 'direct_user': the wallet received a non-gas transfer fromthe exchange at least once and has 5 or more anchor transfers in total.This group also contains any unlabelled withdrawal (payout) wallets theexchange uses as a second hop; Stage 2b flags those by their fan-out.Other wallets (1-4 transfers, at least one non-gas withdrawal) are dropped.If they also deposited through a deposit address, Stage 2c recovers themand counts direct and via-deposit transfers together toward the 5.Which transfers count (decision 7):- native ETH of any size above zero, and any token transfer with a USDprice (amount_usd not null) above zero;- not counted: zero-value transfers and unpriced tokens, which is howaddress-poisoning and fake-transfer spam show an exchange address assender without any customer relationship.Anchors: anchor_list_v2 (anchor_list_v1 plus Iran). Labels from Dune'scex.addresses (blockchain = 'ethereum') minus Kaia-chain labels, gas suppliers, the exchange'sdeposit addresses at other exchanges, and deployer/staking/treasury labels.Efficiency:- One scan of tokens_ethereum.transfers for every country; the anchor list(~1,100 addresses) is broadcast; one join per direction with UNION ALL.- Constant block_month range for partition pruning.- If one run times out: run each year separately into the same columns,drop the HAVING clause in the yearly runs, combine with SUM / MIN / MAX /array_union by (wallet, country), then apply the HAVING rule once.=================================================== */WITH anchor_exchanges (cex_name, country, tier) AS (VALUES('Coinsquare', 'Canada', 'domestic'),('Shakepay', 'Canada', 'domestic'),('Newton', 'Canada', 'domestic'),('Netcoins', 'Canada', 'domestic'),('NDAX', 'Canada', 'domestic'),('Wealthsimple', 'Canada', 'domestic'),('Bitbuy', 'Canada', 'domestic'),('CoinField', 'Canada', 'regional'),('Bitcoin Suisse', 'Switzerland', 'domestic'),('Bity', 'Switzerland', 'regional'),('GMO Coin', 'Japan', 'domestic'),