Query editor
WITH btc_prices AS (SELECT DATE_TRUNC('minute', minute) as minute, priceFROM prices.usdWHERE blockchain = 'ethereum' AND symbol = 'WBTC'ORDER BY minute DESC),lombard_cumulative_net_flows AS (SELECT"date",chain,token,cumulative_lbtc_flow AS cumulative_net_lbtc_flowFROM query_6088885-- WHERE token in ('BTCK')WHERE token IN ('BTCK', 'BTC.b')ORDER BY 1 DESC),adjusted_chain_flows AS (SELECTf."date",f.chain,SUM(CASEWHEN f.token = 'BTC.b'AND f."date" < DATE '2025-10-28'THEN 0ELSE f.cumulative_net_lbtc_flowEND) AS cumulative_net_lbtc_flowFROM lombard_cumulative_net_flows fGROUP BY 1, 2),dune_chain_values AS (SELECTl."date",l.chain,l.cumulative_net_lbtc_flow,l.cumulative_net_lbtc_flow * p.price as tvl,p.price as btc_priceFROM adjusted_chain_flows lLEFT JOIN btc_prices p ON l."date" = p.minuteWHERE l."date" >= date '2024-08-28')SELECT"date",chain,cumulative_net_lbtc_flow,tvl,btc_price,SUM(cumulative_net_lbtc_flow) OVER (PARTITION BY date) as total_tvl_all_chains_btc,SUM(tvl) OVER (PARTITION BY date) as total_tvl_all_chains_usd,SUM(tvl) OVER (PARTITION BY date)/1e6 as total_tvl_all_chains_usd_in_mlnFROM dune_chain_valuesORDER BY 1 DESC, 2