Query editor
with swap AS (SELECTdate_trunc('hour', sw."evt_block_time") AS hour,("amount0In" + "amount0Out")/1e9 AS a0_amt,("amount1In" + "amount1Out")/1e18 AS a1_amtFROM sushi."Pair_evt_Swap" swWHERE CASE WHEN evt_block_time >= '2021-12-18' THEN contract_address = '\x055475920a8c93cffb64d039a8205f7acc7722d3' ELSE contract_address = '\x34d7d7Aaf50AD4944B70B320aCB24C95fa2def7c' END -- liq pair address I am searching the price for --> previously OHMv1-DAI now OHMv2-DAI),a1_prcs AS (SELECT avg(price) a1_prc, date_trunc('hour', minute) AS hourFROM prices.usdWHERE minute >= '2021-03-22'and contract_address ='\x6b175474e89094c44da98b954eedeac495271d0f'group by 2),migration as (select evt_block_time, epoch, rebase/1e9 as rebase, index/1e9 as index, contract_address, evt_tx_hashfrom olympus."sOlympus_evt_LogRebase"where contract_address = '\x04f2694c8fcee23e8fd0dfea1d4f5bb8c352111f' and epoch < 770union allselect evt_block_time, epoch, rebase/1e9 as rebase, index/1e9 as index, contract_address, evt_tx_hashfrom olympus."sOlympus_evt_LogRebase"where contract_address = '\x04906695d6d12cf5459975d7c3c03356e4ccd460' and epoch >= 770),index as (select * from migration order by evt_block_time desc),price as ( SELECTa1_prcs."hour" AS hour,AVG((a1_amt/a0_amt)*a1_prc) AS price, indexFROM swapJOIN a1_prcs ON swap."hour" = a1_prcs."hour"left join index on date_trunc('hour', evt_block_time) = swap."hour"GROUP BY 1,3ORDER BY "hour" DESC),filled_index as (select *,MAX(CASE WHEN index IS NOT NULL THEN index END) OVER(ORDER BY hour ROWS UNBOUNDED PRECEDING) AS new_indexfrom pricewhere "hour" > '2021-03-23 01:00')select "hour", price, new_index as index, price * new_index as index_adj_pricefrom filled_indexwhere "hour" > '2021-06-16'order by 1 desc