Query editor
with deposits as(select *,substr(data, 13,20) deposit_from,substr(data, 33+12,20) deposit_to,substr(data, 33+12+20) deposit_amount,bytearray_to_uint256(substr(data, 33+12+20)) / 1e18 matic_deposit_amountfrom polygon.logswhere contract_address = 0xcd97405fb58e94954e825e46db192b916a45d412and topic0 = 0x5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f62 -- Deposit (address from, address to, uint256 amount)Viewand block_number >= 45259065 -- to speed up the query),deposits_agg as(select date_trunc('day', block_time) block_date,sum(matic_deposit_amount) total_matic_deposited,count(1) num_depositsfrom depositsgroup by 1 ),deposits_agg_w_cum as(select block_date,total_matic_deposited,sum(total_matic_deposited) over (order by block_date) cumulative_matic_deposited,num_deposits,sum(num_deposits) over (order by block_date) cumulative_num_deposits,total_matic_deposited*price total_usd_deposited,sum(total_matic_deposited*price) over (order by block_date) cumulative_usd_depositedfrom deposits_aggleft join (select distinct * from prices.usd_latest p where p.symbol = 'MATIC' and p.blockchain is null) p on 1=1)select *,cumulative_matic_deposited / cumulative_num_deposits running_avg_deposit_size_matic,cumulative_usd_deposited / cumulative_num_deposits running_avg_deposit_size_usdfrom deposits_agg_w_cumorder by block_date desc