Query editor
-- As long as you retain this notice you can do whatever you want with this stuff.-- If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.-- // YT eETH Apr 2024 — Arbitrumwith transfers as (selectMONTH,address,token_address,sum(amount) as amountfrom (selectDATE_TRUNC('month', evt_block_time) as MONTH,"to" as address,tr.contract_address as token_address,CAST(value as decimal) as amountfrom erc20_arbitrum.evt_Transfer as trwherecontract_address = 0xf28db483773e3616da91fdfa7b5d4090ac40cc59union ALLselectDATE_TRUNC('month', evt_block_time) as MONTH,"from" as address,tr.contract_address as token_address,-CAST(value as decimal) as amountfrom erc20_arbitrum.evt_Transfer as trwherecontract_address = 0xf28db483773e3616da91fdfa7b5d4090ac40cc59) as tgroup by1,2,3), balances_with_gap_days as (selectt.MONTH,address,SUM(amount) OVER (PARTITION BY address ORDER BY t.MONTH) as balance,LEAD(MONTH, 1, CURRENT_TIMESTAMP) OVER (PARTITION BY address ORDER BY t.MONTH) as next_monthFROM transfers as t), months as (selectMONTHfrom UNNEST(SEQUENCE(TRY_CAST('2020-01-01' AS TIMESTAMP),CAST(TRY_CAST(TRY_CAST(TRY_CAST(DATE_TRUNC('month', CURRENT_TIMESTAMP) AS TIMESTAMP) AS TIMESTAMP) AS TIMESTAMP) AS TIMESTAMP),INTERVAL '1' month) /* WARNING: Check out the docs for example of time series generation: https://dune.com/docs/query/syntax-differences/ */) AS _u(MONTH)), balance_all_months as (selectd.MONTH,address,SUM(balance / TRY_CAST(POWER(10, 0) as DOUBLE)) as balanceFROM balances_with_gap_days as bINNER JOIN months as dON b.MONTH <= d.MONTH and d.MONTH < b.next_monthGROUP BY1,2