Query editor
WITH base_transfers AS (SELECTDATE_TRUNC('day', evt_block_time) AS time,"to" AS address,value AS amountFROM erc20_base.evt_TransferWHEREcontract_address = 0x0a14ef61AFB32e5CA672E021784f71705aC14908UNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS time,"from" AS address,-value AS amountFROM erc20_base.evt_TransferWHEREcontract_address = 0x0a14ef61AFB32e5CA672E021784f71705aC14908), unidx_transfers AS (SELECTtime,address,SUM(amount) AS amountFROM (SELECTtime,address,amountFROM base_transfers) AS all_transfersGROUP BY1,2), balances_with_gap_days AS (SELECTt.time,address,SUM(amount) OVER (PARTITION BY address ORDER BY t.time) AS balance,LEAD(time, 1, CURRENT_TIMESTAMP) OVER (PARTITION BY address ORDER BY t.time) AS next_dayFROM unidx_transfers AS t), days AS (SELECTtimeFROM UNNEST(SEQUENCE(TRY_CAST('2024-02-01 00:00:00' AS TIMESTAMP),CAST(TRY_CAST(CURRENT_TIMESTAMP AS TIMESTAMP) AS TIMESTAMP),INTERVAL '1' DAY) /* WARNING: Check out the docs for example of time series generation: https://dune.com/docs/query/syntax-differences/ */) AS date_table(time)), balance_all_days AS (SELECTd.time,address,SUM(balance) AS balanceFROM balances_with_gap_days AS bINNER JOIN days AS dON b.time <= d.time AND d.time < b.next_dayGROUP BY1,2ORDER BY1,2