Query editor
-- Stabletide A2: 7-day CEX stablecoin flows (USDT+USDC, Ethereum)-- Source: cex.flows (spellbook). net = Inflow - Outflow; only deposits/withdrawals-- that cross a CEX custody boundary with a non-CEX counterparty are counted.withbase as (selectcasewhen token_address = 0xdac17f958d2ee523a2206206994597c13d831ec7then 'USDT'else 'USDC'end as token,flow_type,amount_usdfrom cex.flowswhereblockchain = 'ethereum'and block_month >= date_trunc('month', current_date - interval '7' day)and block_time >= current_date - interval '7' dayand token_address in (0xdac17f958d2ee523a2206206994597c13d831ec7,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)and flow_type in ('Inflow', 'Outflow')),per_token as (selecttoken,sum(case when flow_type = 'Inflow' then amount_usd else 0 end)as inflow_usd,sum(case when flow_type = 'Outflow' then amount_usd else 0 end)as outflow_usdfrom basegroup by token),labeled as (select'USDT+USDC Total' as token,sum(inflow_usd) as inflow_usd,sum(outflow_usd) as outflow_usd,1 as sort_orderfrom per_tokenunion allselect token, inflow_usd, outflow_usd, 2 as sort_orderfrom per_token)selecttoken,inflow_usd,outflow_usd,inflow_usd - outflow_usd as net_usd,sort_orderfrom labeledorder by sort_order, token