Query editor
/* All streaming volumes, long format per day. Both for CFA and GDA (flow distributions). The process is the same for both */-- Events for CFA flowswith-- this creates a date-spine to merge the volume data on to. Source: https://dune.com/docs/migrations/PostgreSQL/#migrating-from-postgresqldate_spine as (SELECTcolumn_value AS dateFROM UNNEST(SEQUENCE(TRY_CAST('2021-03-05' AS DATE), CURRENT_DATE, INTERVAL '1' day)) AS t(column_value)),-- ======================-- === CFA calculations-- ======================cfa_flow_updated_events as (select * from query_3379909where flow_rate > 0),cfa_stream_periods_days as (select*,/* day_fraction is the fraction of the day that a given stream is active for. If the stream is active the whole day (i.e. not the start or end date of stream) the value is 1, else 1 > day_fraction > 0. */casewhen date > date(start_block_time) and date < date(end_block_time) then 1when date = date(start_block_time) and date = date(end_block_time) then (to_unixtime(end_block_time) - to_unixtime(start_block_time)) / 86400when date = date(start_block_time) then (to_unixtime(date_add('day', 1, date)) - to_unixtime(start_block_time)) / 86400when date = date(end_block_time) then (to_unixtime(end_block_time) - to_unixtime(date) + 1) / 86400 -- the +1 is a one second offset to account for the fact that the end_timestamp is one second before midnightelse null endas day_fractionfrom date_spinecross join cfa_flow_updated_eventswhere date >= date(start_block_time) and date <= date(end_block_time)),stream_periods_days_usd as (selectcfa.*,p.price as price_usd,-- 86400 is the number of seconds per day (flow_rate is per second)flow_rate * day_fraction * 86400 / pow(10, 18) * p.price as value_streamed_usdfrom cfa_stream_periods_days cfaleft join dune.superfluid_hq.result_daily_super_token_prices pon cfa.blockchain = p.blockchain and cfa.token = p.super_token and date = p.day),cfa_stream_volumes as (selectdate,blockchain as blockchain,sum(value_streamed_usd) as total_value_streamed_usdfrom stream_periods_days_usdgroup by date, blockchainorder by date asc),-- ======================-- === GDA calculations-- ======================gda_flow_distribution_updated_events as (select * from query_3380572where new_total_distribution_flow_rate > 0),gda_flow_distribution_periods_days as (select*,