Query editor
with params as (selectfrom_hex('0xD09cf0982A32DD6856e12d6BF2F08A822eA5D91D') as fey20,from_hex('0x72f5565Ab147105614ca4Eb83ecF15f751Fd8C50') as vault20,from_hex('0x4200000000000000000000000000000000000006') as weth20,from_hex('ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') as transfer_topic,concat(from_hex('000000000000000000000000'), from_hex('0x72f5565Ab147105614ca4Eb83ecF15f751Fd8C50')) as vault32,concat(from_hex('000000000000000000000000'), from_hex('0xD09cf0982A32DD6856e12d6BF2F08A822eA5D91D')) as fey32),-- 4-hour buckets helperbucketed as (selectl.*,date_add('hour', - (hour(date_trunc('hour', l.block_time)) % 4), date_trunc('hour', l.block_time)) as ts_4hfrom base.logs l),-- Total FEY staked over time (running balance of vault)fey_stakes as (selectdate_trunc('day', b.block_time) as day,sum(casewhen b.topic2 = p.vault32 then cast(bytearray_to_uint256(b.data) as double) -- to vault (stake)when b.topic1 = p.vault32 then -1 * cast(bytearray_to_uint256(b.data) as double) -- from vault (unstake)else 0end) as net_stake_change_weifrom base.logs bcross join params pwhere b.contract_address = p.fey20and b.topic0 = p.transfer_topicand (b.topic1 = p.vault32 or b.topic2 = p.vault32)and b.topic1 != b.topic2and length(b.data) = 32group by 1),-- Running total of staked FEY by daystaked_supply as (selectday,sum(net_stake_change_wei) over (order by day) / 1e18 as total_staked_feyfrom fey_stakes),-- FEY rewards distributed to stakers (FeesClaimed with token=FEY)fey_rewards as (selectdate_trunc('day', b.block_time) as day,sum(bytearray_to_uint256(substr(b.data, 1, 32))) / 1e18 as fey_rewards_distributedfrom bucketed bcross join params pwhere b.contract_address = p.vault20and b.topic0 = from_hex('8a9c37f1c6ed380089808b6c2a4dfa1c09658478f02de4b3a67b8f2a8e4e85f7') -- FeesClaimedand b.topic2 = p.fey32and length(b.data) = 32group by 1),-- Buyback events: BuybackExecuted(router, amountIn(WETH), amountOut(FEY))