Query editor
with tab1 as (SELECTblock_time,index as index_1,tx_hash,concat('0x', to_hex(contract_address)) AS address,concat('0x', to_hex(topic0)) AS topic0,topic1,topic2,concat('0x', to_hex(bytearray_substring(topic1, 13, 20))) AS from_address,concat('0x', to_hex(bytearray_substring(topic2, 13, 20))) AS to_address,try(varbinary_to_uint256(bytearray_substring(data, 1, 32))) / power(10, 18) AS amtFROM hyperevm.logswhere contract_address = from_hex('fD739d4e423301CE9385c1fb8850539D657C296D')), tab2 as (SELECTblock_time,index as index_2,tx_hash,concat('0x', to_hex(contract_address)) AS address,concat('0x', to_hex(topic0)) AS topic0,topic1,topic2,concat('0x', to_hex(bytearray_substring(topic1, 13, 20))) AS from_address,concat('0x', to_hex(bytearray_substring(topic2, 13, 20))) AS to_address,try(varbinary_to_uint256(bytearray_substring(data, 1, 32))) / power(10, 18) AS amt1FROM hyperevm.logswhere contract_address = from_hex('0x2222222222222222222222222222222222222222')and tx_hash in (select tx_hash from tab1 where from_address = '0x0000000000000000000000000000000000000000')--and concat('0x', to_hex(bytearray_substring(topic2, 13, 20))) = '0x393D0B87ED38fC779FD9611144AE649BA6082109'), tab3 as (select --tab2.*, tab1.amt, tab2.amt1/tab1.amt as test, index_1date_trunc('day', tab2.block_time) as day,avg(tab2.amt1/tab1.amt) as kHYPE_price_HYPEfrom tab2left outer join tab1on tab2.tx_hash = tab1.tx_hashwhere tab2.from_address = '0x393D0B87ED38FC779FD9611144AE649BA6082109'and index_1 = 0 and index_2 = 1group by 1)select*,LAG(kHYPE_price_HYPE, 30) OVER (ORDER BY day) as price_30d_ago,-- APY calculation: ((current_price / price_30d_ago)^(365/30) - 1) * 100CASEWHEN LAG(kHYPE_price_HYPE, 30) OVER (ORDER BY day) IS NOT NULLAND LAG(kHYPE_price_HYPE, 30) OVER (ORDER BY day) > 0THEN (POWER(kHYPE_price_HYPE / LAG(kHYPE_price_HYPE, 30) OVER (ORDER BY day), 365.0/30) - 1) * 100ELSE NULLEND as apy_30d_annualizedfrom tab3order by day desc