Query editor
--[Ethereum ETF] Historical Netflow Trendwith time_series as (select timefrom (unnest(sequence(date(try_cast('2024-07-23' as timestamp)), date(current_timestamp), interval '1' day)) as s(time))),etf_entity as (select address, issuer, distinct_name, etf_ticker, track_inflow, track_outflow, inverse_valuesfrom dune.balancercap.result_ethereum_etf_addresses),non_outflow_addresses as (select 0x8ebda19ddee719dab78def3e22c3d37970e35217 as address, 'Coinbase Staking Contract' as descriptionunion allselect 0x00000000219ab540356cbb839cbe05303d7705fa as address, 'Beacon Deposit Contract' as description),flow_data as (-- inflowsselect date_trunc('day', t.block_time) as time, a.issuer, a.etf_ticker,case when a.inverse_values = true then -t.amount else t.amount end as flowfrom tokens_ethereum.transfers as tinner join etf_entity as a on a.address = t.to and a.track_inflow = truewhere t.token_standard = 'native' and t.block_time >= try_cast('2024-07-23' as timestamp)union all-- outflows (exclude tx to staking contract)select date_trunc('day', t.block_time) as time, a.issuer, a.etf_ticker,case when a.inverse_values = true then t.amount else -t.amount end as flowfrom tokens_ethereum.transfers as tinner join etf_entity as a on a.address = t."from" and a.track_outflow = trueleft join non_outflow_addresses as noa on t.to = noa.addresswhere t.token_standard = 'native' and t.block_time >= try_cast('2024-07-23' as timestamp)and noa.address is null -- exclude tx to staking contract),expanded_flows as (select ts.time, i.issuer, coalesce(sum(f.flow), 0) as flowfrom time_series as tscross join (select distinct issuer from etf_entity) as ileft join flow_data as f on ts.time = f.time and i.issuer = f.issuergroup by 1, 2),cumulative_data as (select try_cast(f.time as timestamp) as time, f.issuer, f.flow as net_flow, pu.price * f.flow as net_flow_usd,sum(f.flow) over (partition by issuer order by time) as net_tvl,pu.price * sum(f.flow) over (partition by issuer order by time) as net_tvl_usdfrom expanded_flows as fleft join prices.usd_forward_fill as pu on pu.blockchain is null and pu.symbol = 'ETH' and pu.minute = f.time)select time, issuer, net_flow, net_flow_usd, net_tvl, net_tvl_usdfrom cumulative_dataorder by time desc