Query editor
-- part of a query repo-- query name: WC Stablecoin Balance Tiers by Region-- query link: https://dune.com/queries/6752949-- description: Distribution of WalletConnect stablecoin holders across balance tiers,-- segmented by world region and sub-region.---- Parameters:-- {{min_balance}} : minimum total stablecoin balance per user in USD (default 0)-- {{region}} : multi-select world region filter (values from dim_country)-- {{country}} : multi-select country filter (values from dim_country)-- {{t1}} - {{t5}} : tier boundaries in USD (defaults: 10, 100, 1000, 10000, 100000)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.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),user_totals AS (SELECTaddress,SUM(balance_usd) AS total_stablecoin_usdFROM wc_balancesGROUP BY 1HAVING SUM(balance_usd) >= {{min_balance}}),_base AS (SELECTut.address,ut.total_stablecoin_usd,CASEWHEN ut.total_stablecoin_usd >= {{t5}} THEN 'e_$' || CAST(CAST({{t5}} AS BIGINT) AS VARCHAR) || '+'WHEN ut.total_stablecoin_usd >= {{t4}} THEN 'd_$' || CAST(CAST({{t4}} AS BIGINT) AS VARCHAR) || '-$' || CAST(CAST({{t5}} AS BIGINT) AS VARCHAR)WHEN ut.total_stablecoin_usd >= {{t3}} THEN 'c_$' || CAST(CAST({{t3}} AS BIGINT) AS VARCHAR) || '-$' || CAST(CAST({{t4}} AS BIGINT) AS VARCHAR)WHEN ut.total_stablecoin_usd >= {{t2}} THEN 'b_$' || CAST(CAST({{t2}} AS BIGINT) AS VARCHAR) || '-$' || CAST(CAST({{t3}} AS BIGINT) AS VARCHAR)WHEN ut.total_stablecoin_usd >= {{t1}} THEN 'a_$' || CAST(CAST({{t1}} AS BIGINT) AS VARCHAR) || '-$' || CAST(CAST({{t2}} AS BIGINT) AS VARCHAR)