Query editor
-- Query 2: Top Chain Pairs for Stablecoin Bridging-- Section 1 (Macro Picture) — which routes carry the most stablecoin volume?---- Shows source → destination chain pairs ranked by volume.-- Useful for: heatmap, Sankey diagram, or ranked bar chart on dashboard.---- Charts:-- 1. Bar chart: top chain pairs by volume (X: chain_pair, Y: total_volume_usd)-- 2. Table: full breakdown with tx count and avg size-- 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.deposit_chain,b.withdrawal_chain,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')SELECTdeposit_chain || ' → ' || withdrawal_chain AS chain_pair,deposit_chain,withdrawal_chain,COUNT(*) AS tx_count,SUM(amount_usd) AS total_volume_usd,SUM(amount_usd) / COUNT(*) AS avg_tx_size_usd,COUNT(DISTINCT sender) AS unique_sendersFROM stablecoin_bridgesGROUP BY 1, 2, 3ORDER BY 5 DESCLIMIT 25