Query editor
-- Query 14: Destination Chain Volume by Ecosystem Category-- Section 4B (Why Stablecoins?) — what does the destination tell us about "why"?---- Approach:-- Map each destination chain to its primary ecosystem category, then aggregate-- stablecoin bridge volume by category. This connects "where are users bridging-- stablecoins to" with "why are they bridging."---- Ecosystem categorization (analyst judgment — documented for methodology):-- - Trading/Perps: Hyperliquid, Lighter (primarily derivatives/perps platforms)-- - DeFi Hub: Arbitrum, Optimism, Avalanche (broad DeFi ecosystems: lending, LPing, yield)-- - Consumer/Payments: Base, Polygon, BNB Chain (consumer apps, payments, low-cost txs)-- - General L1: Ethereum (settlement layer, high-value DeFi)-- - Emerging: Sui, Unichain, zkSync, Scroll, Linea, Mantle (newer chains building ecosystems)---- Categorization rationale:-- - Hyperliquid/Lighter are single-purpose trading venues, not general DeFi-- - Base is categorized as Consumer due to Coinbase's consumer focus + onchain social apps-- - Arbitrum/Optimism have deeper DeFi composability (Aave, GMX, Uniswap, Pendle)-- - Polygon has strong payments/gaming presence (Polygon Pay, gaming partnerships)-- - These are simplifications — most chains have multiple use cases. The dominant-- use case was chosen based on TVL composition and ecosystem narrative.---- Chart: Bar chart (volume by category), Table (chain detail within each category)-- 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.withdrawal_chain,b.amount_usd,b.deposit_block_dateFROM bridges_evms.flows bINNER JOIN stablecoin_tokens tON b.deposit_token_address = t.contract_addressAND b.deposit_chain = t.blockchainWHERE b.deposit_block_date >= CURRENT_DATE - INTERVAL '12' MONTHAND b.amount_usd > 0AND b.bridge_name != 'Agglayer'),categorized AS (SELECTwithdrawal_chain,amount_usd,CASEWHEN withdrawal_chain IN ('hyperliquid', 'lighter') THEN 'Trading / Perps'