Query editor
with flow_updated_events as (select * from query_3379909),flow_distribution_updated_events as (select * from query_3380572),pool_connection_updated_events as (select * from query_3435154),-- 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)),-- flow_distribution_periods as (-- select-- *,-- block_time as start_block_time,-- /* to create the stream_periods from the flow updated events, simply find the end of the prion by using the next (LEAD()) event (ordered by-- blocknumber and index - in case there are multiple events in the same block) for each stream. */-- COALESCE(LEAD(block_time) OVER (PARTITION BY blockchain, token, distributor, pool ORDER BY blocknumber, index), current_timestamp) AS end_block_time-- from flow_distribution_updated_events-- ),flow_distribution_periods_days as (select*from date_spinecross join flow_distribution_updated_eventswhere date >= date(start_block_time) and date <= date(end_block_time)),--find the maximum flow rate per day per pool. If it is >0 it can be merged onto pool_connection_periods_days in order to classify a connected wallet as activeflow_distribution_periods_days_max as (selectdate,blockchain,token,pool,max(new_total_distribution_flow_rate) as max_flow_ratefrom flow_distribution_periods_daysgroup by date, blockchain, token, pool),-- pool_connection_periods as (-- select-- *,-- block_time as start_block_time,-- /* to create the stream_periods from the flow updated events, simply find the end of the prion by using the next (LEAD()) event (ordered by-- blocknumber and index - in case there are multiple events in the same block) for each stream. */-- COALESCE(LEAD(block_time) OVER (PARTITION BY blockchain, token, pool, account ORDER BY blocknumber, index), current_timestamp) AS end_block_time-- from pool_connection_updated_events-- ),pool_connection_periods_final as (select*from pool_connection_updated_eventswhere connected = true),pool_connection_periods_days as (select*,