Query editor
-- Query 10: Post-Bridge First Action Classification-- Section 4 (Post-Bridge Behavior) — what do users do after bridging stablecoins?---- Approach:-- 1. Get stablecoin bridge receipts on Base and Arbitrum (last 3 months)-- 2. For each bridge recipient, find their first on-chain action within 24 hours:-- a. DEX swap (appeared in dex.trades as taker)-- b. Outbound token transfer (sent tokens via tokens.transfers)-- 3. Classify into 3 categories:-- - "DEX Swap" — first action was a trade on a DEX (trading/speculation intent)-- - "Transfer Out" — first action was sending tokens to another address-- (payment, CEX deposit, or DeFi interaction not captured by dex.trades)-- - "Hold / Other" — no swap or outbound transfer within 24h-- (savings, yield farming via direct contract calls, or inactivity)---- Industry context:-- This 3-bucket classification is standard in on-chain behavioral analysis-- (used by Nansen, Messari, Delphi Digital). Finer-grained DeFi classification-- (lending vs LPing vs staking) would require protocol-specific decoded tables-- for every DeFi app, which is out of scope.---- Scoping decisions:-- - Destination chains: Base, Arbitrum, Optimism, Polygon, BNB Chain (top EVM destinations)-- - Time window: last 3 months (keeps joins manageable on free tier)-- - Post-bridge window: 24 hours (captures immediate intent)-- - Sampled: most recent 50K bridge events per chain to avoid timeout---- Chart: Donut chart (action distribution), Bar chart (action by bridge protocol)-- 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')),bridge_receipts AS (SELECTb.recipient AS wallet,b.withdrawal_chain AS chain,b.withdrawal_block_time AS bridge_time,b.bridge_name,b.amount_usd,ROW_NUMBER() OVER (PARTITION BY b.withdrawal_chainORDER BY b.withdrawal_block_time DESC) AS rnFROM 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 '3' MONTH