Query editor
-- Query 3: Bridge Protocol Market Share for Stablecoin Transfers-- Section 1 (Macro Picture) — who dominates stablecoin bridging?---- Calculates each protocol's share of total stablecoin bridge volume.-- Charts:-- 1. Pie/donut chart: market share by volume (Group by: bridge_name, Value: pct_volume)-- 2. Bar chart: protocol ranking by volume-- 3. Counter: number of active bridge protocols-- FIX: tokens.erc20 contains duplicate rows per token (same contract_address + blockchain-- with slightly different metadata). Joining bridges_evms.flows directly against tokens.erc20-- causes a fan-out join, multiplying each bridge row by the number of duplicates and inflating-- COUNT(*), SUM(amount_usd), AVG(), and APPROX_PERCENTILE(). Deduplicating into a CTE first-- ensures a 1:1 join so each bridge transaction is counted exactly once.WITH stablecoin_tokens AS (SELECT DISTINCT contract_address, blockchainFROM tokens.erc20WHERE symbol IN ('USDC', 'USDC.e', 'USDbC', 'USDT', 'USDT0','DAI', 'BUSD', 'TUSD', 'FRAX', 'LUSD','USDP', 'PYUSD', 'GHO', 'USDe', 'USDS', 'crvUSD')),stablecoin_bridges AS (SELECTb.bridge_name,b.amount_usd,b.senderFROM bridges_evms.flows bINNER JOIN stablecoin_tokens tON b.deposit_token_address = t.contract_addressAND b.deposit_chain = t.blockchainWHERE b.deposit_block_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '12' MONTH)AND b.amount_usd > 0AND b.bridge_name != 'Agglayer'),protocol_stats AS (SELECTbridge_name,COUNT(*) AS tx_count,SUM(amount_usd) AS total_volume_usd,COUNT(DISTINCT sender) AS unique_walletsFROM stablecoin_bridgesGROUP BY 1)SELECTbridge_name,tx_count,total_volume_usd,unique_wallets,ROUND(total_volume_usd * 100.0 / SUM(total_volume_usd) OVER (), 2) AS pct_volume,ROUND(tx_count * 100.0 / SUM(tx_count) OVER (), 2) AS pct_txsFROM protocol_statsORDER BY total_volume_usd DESC