Query editor
WITH getAllDelegated as (select evt_block_time,contract_address,"from",to,value,ROW_NUMBER() OVER (PARTITION BY evt_tx_hash,to ORDER BY evt_index DESC) as rnfrom erc20_ethereum.evt_transferwhere contract_address = 0x608917f8392634428ec71c6766f3ec3f5cc8f421and "from" != 0x0000000000000000000000000000000000000000and to != 0x0000000000000000000000000000000000000000),getBurnOrUnDelegate as (select a.evt_block_time,a."from",a.to,a.contract_address,a.value,a.evt_tx_hash,data from erc20_ethereum.evt_transfer aINNER JOIN getAllDelegated bON (a.contract_address = b.contract_address ANDa."from" = b.to ANDa.value = b.value ANDa.evt_block_time > b.evt_block_time)LEFT JOIN ethereum.transactionsON (a.evt_tx_hash = hash)WHERE bytearray_substring(data,1,4) != 0xb2383e55)SELECT end_date,SUM(value/1e18) as daily_change,SUM(SUM(value/1e18)) OVER (ORDER BY end_date) as cumulative_delegatedFROM (select evt_block_time,CAST(value AS DOUBLE) as value FROM getAllDelegatedUNION ALLselect evt_block_time,-CAST(value AS DOUBLE) FROM getBurnOrUnDelegateUNION ALLSELECT period,0 FROM UNNEST(sequence(CAST('2022-08-18' AS TIMESTAMP),CAST(NOW() as TIMESTAMP),interval '1' day)) as tbl(period)) x LEFT JOIN query_1255018 ON evt_block_time >= date_start and evt_block_time < end_dateGROUP BY 1ORDER BY 1 DESC