Query editor
WITHstaking_unstaking as (SELECT -- depositsdate_trunc('day', call_block_time) as day,'deposits' as type_,SUM(stakeValue/1e18) as stakeFROMforta_network_polygon.FortaStaking_call_deposit fINNER JOINpolygon.transactions pON f.call_tx_hash = p.hashWHERE p.block_time >= CAST('2022-03-08' as timestamp)AND (p.to = 0xd2863157539b1D11F39ce23fC4834B62082F6874 OR p.to = 0xf22f690a41d22496496d4959acfff0f3bacc24f1)AND p.hash != 0x4132d43661e04b69641f2d526d5e0086c280dfe9a454f8386017b1e15b0efaf9AND (bytearray_substring(p.data,1,4) = 0x2cb31144 OR bytearray_substring(p.data, 1, 4) = 0xd9a34952)AND f.call_success = trueGROUP BY 1, 2UNION ALLSELECT -- withdrawalsdate_trunc('day', call_block_time) as day,'withdrawals' as type_,SUM(output_0/1e18) as stakeFROMforta_network_polygon.FortaStaking_call_withdraw fINNER JOINpolygon.transactions pON f.call_tx_hash = p.hashWHERE p.block_time >= CAST('2022-03-08' as timestamp)AND (p.to = 0xd2863157539b1D11F39ce23fC4834B62082F6874 OR p.to = 0xf22f690a41d22496496d4959acfff0f3bacc24f1)AND (bytearray_substring(p.data,1,4) = 0x3f489914 OR bytearray_substring(p.data, 1, 4) = 0xba087652)AND f.call_success = trueGROUP BY 1, 2),summary as (SELECTday,SUM(CASEWHEN type_ = 'withdrawals' THEN stakeELSE 0END) as withdrawals,SUM(CASEWHEN type_ = 'deposits' THEN stakeELSE 0END) as depositsFROMstaking_unstakingGROUP BY 1),summary_2 as (SELECTday,SUM(withdrawals) OVER (ORDER BY day ASC) as withdrawals_cum,SUM(deposits) OVER (ORDER BY day ASC) as deposits_cumFROMsummary