Query editor
-- part of a query repo-- query name: WC Stablecoin Top Tokens by Region-- query link: https://dune.com/queries/6752950-- description: Which stablecoins WalletConnect users hold, segmented by world region.-- Shows top stablecoins by holder count and total USD per region.---- Parameters:-- {{min_balance}} : minimum total stablecoin balance per user in USD (default 100)-- {{region}} : multi-select world region filter (values from dim_country)-- {{country}} : multi-select country filter (values from dim_country)-- {{top_n}} : number of top tokens to show per region (default 15)WITH _regions AS (SELECT TRIM(v) AS v FROM UNNEST(SPLIT('{{region}}', ',')) AS t(v)),_countries AS (SELECT TRIM(v) AS v FROM UNNEST(SPLIT('{{country}}', ',')) AS t(v)),geo AS (SELECT country_id, name AS country, alpha_3, region, sub_regionFROM dune.walletconnect.dim_country),cex_addrs AS (SELECT DISTINCT LOWER(CONCAT('0x', TO_HEX(address))) AS address FROM cex.addresses),wc_balances AS (SELECTb.address,b.blockchain,b.token_symbol,b.balance_usd,wa.country_idFROM stablecoins_multichain.balances bINNER JOIN dune.walletconnect.address_countries wa ON b.address = wa.addressLEFT JOIN cex_addrs cx ON b.address = cx.addressWHERE b.day = (SELECT MAX(day) FROM stablecoins_multichain.balances)AND cx.address IS NULL),qualifying_users AS (SELECT addressFROM wc_balancesGROUP BY 1HAVING SUM(balance_usd) >= {{min_balance}}),_base AS (SELECTwb.address,wb.token_symbol,wb.balance_usd,g.regionFROM wc_balances wbINNER JOIN qualifying_users qu ON wb.address = qu.addressJOIN geo g ON wb.country_id = g.country_idWHERE (EXISTS(SELECT 1 FROM _regions WHERE v = 'All') OR g.region IN (SELECT v FROM _regions))