Query editor
with bnb_staking as(select time, net_trend, sum(net_trend) over (order by time asc) as bnb_stakedfrom (select date_trunc('day', evt_block_time) as time, sum(amount/1e18) as net_trendfrom(select evt_block_time, (cast(amount as double)) as amountfrom ankr_bnb.BinancePool_R4_evt_Staked -- stake tablewhere evt_block_time >= date('2022-02-17') -- pool createdunion all -- combine data stake and unstake old poolselect evt_block_time, (cast(amount as double)) as amountfrom ankr_bnb.BinancePool_R10_evt_Staked -- staked tablewhere evt_block_time >= cast('2022-12-08 07:27:44' as timestamp) -- pool created Dec-08-2022 07:27:44union allselect evt_block_time, (-1)*(cast(amount as double)) as amountfrom ankr_bnb.BinancePool_R4_evt_UnstakePending -- unstake tablewhere evt_block_time <= date('2022-12-01') -- pool createdunion all -- combine data stake and unstake (new pool)select evt_block_time, (-1)*(cast(amount as double)) as amountfrom ankr_bnb.BinancePool_R10_evt_UnstakePending --unstake tablewhere evt_block_time >= cast('2022-12-08 07:27:44' as timestamp) -- pool created Dec-08-2022 07:27:44union allselect evt_block_time, (cast(amount as double)) as amountfrom ankr_bnb.BNBStakingPool_R1_evt_Stakedwhere evt_block_time >= date('2023-05-11') -- pool createdunion all -- combine data stake and unstake (parallel pool)select evt_block_time, (-1)*(cast(amount as double)) as amountfrom ankr_bnb.BNBStakingPool_R1_evt_Unstakedwhere evt_block_time >= date('2023-05-11') -- pool createdunion allselect time, nullfrom unnest(sequence(cast('2022-02-17' as timestamp), cast(now() as timestamp), interval '1' day)) as tbl(time)) xgroup by 1order by 1 desc) t),bnb_price as (select time, avg(price) as avg_pricefrom( select date_trunc('day', minute) as time, pricefrom prices.usd where blockchain = 'bnb' and symbol = 'WBNB') xgroup by 1order by 1 desc),tvl as (select time, net_trend, bnb_staked as total_staked, bnb_staked*avg_price as tvl