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 channels as (selectblockchain as blockchain,block_time as blocktime,bytearray_substring(topic2, 13, 20) as owner,bytearray_substring(topic3, 13, 20) as channel,bytearray_substring(varbinary_substring(data, 1, 32), 13, 20) as pool,varbinary_to_int256(varbinary_substring(data, 33, 32)) as owner_share,varbinary_to_int256(varbinary_substring(data, 65, 32)) as subscription_feefrom (select'base' as blockchain,*from base.logswheretopic0 = 0x5494b1fc852316511252ddc42cf54d48c8df25db65a6979b2481d55c6fb241d4 andcontract_address = 0x30e0b740acfb45b6edb9eed40094134f24d8f159 --only last deployment)), flow_updated_events as (SELECTblockchain as blockchain,block_number as blocknumber,index as index,block_time as blocktime,varbinary_substring(topic1, 13) as token,varbinary_substring(topic2, 13) as sender,varbinary_substring(topic3, 13) as receiver,varbinary_to_int256(varbinary_substring(data, 1, 32)) as flowRateFROM (SELECT 'base' as blockchain, * FROM base.logs WHERE block_number >= 1000000 and topic0 = 0x57269d2ebcccecdcc0d9d2c0a0b80ead95f344e28ec20f50f709811f209d4e0e)),-- 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('2024-02-01' AS DATE), CURRENT_DATE, INTERVAL '1' day)) AS t(column_value)),stream_periods as (select*,blocktime as start_blocktime,/* to create the stream_periods from the flow updated events, simply find the end of the prion by using the next (LEAD()) event (ordered byblocknumber and index - in case there are multiple events in the same block) for each stream. */COALESCE(LEAD(blocktime) OVER (PARTITION BY blockchain, token, sender, receiver ORDER BY blocknumber, index), current_timestamp) AS end_blocktimefrom flow_updated_eventswhere receiver in (select channel from channels))--,-- we do not care about stream_periods where the flowrate is 0--stream_periods_final as (select*from stream_periodswhere flowrate > 0