Query editor
with avax_price as(select date_trunc('day',minute) as date, avg(price) as avax_price from prices.usdwhere symbol = 'AVAX' and minute >= cast('2022-09-05 00:00' as timestamp)group by date_trunc('day',minute)),net_flows as(select date_trunc('day',a.date) as date, sum(amount_x/1e18) as amount_x, sum(amount_y/1e18) as amount_y from(select evt_block_time as date, cast(amount0 as double) as amount_x, cast(amount1 as double) as amount_y from pharaoh_avalanche_c.clpool_evt_mintwhere contract_address = 0xd3648b87e26661826f11b21C817D9e89657d49BCunionselect evt_block_time, -cast(amount0 as double) as amount_x, -cast(amount1 as double) as amount_y from pharaoh_avalanche_c.clpool_evt_burnwhere contract_address = 0xd3648b87e26661826f11b21C817D9e89657d49BC) as agroup by date_trunc('day',a.date)),prices as(select date, avax_price, first_value(cai_price) over (partition by cai_count order by a.date asc) as cai_price from(select a.date , avax_price, cai_price,count(cai_price) over (order by a.date asc) as cai_count from(select a.date, avax_price, cai_price from(select * from avax_price) as aleft join(select date_trunc('day',hour) as date, avg(median_price) as cai_price from dex.priceswhere contract_address = 0x48f88A3fE843ccb0b5003e70B4192c1d7448bEf0 and blockchain = 'avalanche_c'group by date_trunc('day',hour)) as b on a.date = b.date) as a) as aorder by a.date desc),traderjoe_v1 as( SELECTDATE_TRUNC('day', evt_block_time) AS date,avg(cast(reserve0 as double)/1e18) as reserve0,avg(cast(reserve1 as double)/1e18) as reserve1FROMtrader_joe_avalanche_c.JoePair_evt_SyncWHEREcontract_address = 0xe5e9d67e93ad363a50cabcb9e931279251bbefd0group by date_trunc('day',evt_block_time))selecta.date,first_value(reserve0) over (partition by tj_count_0 order by date asc) * cai_price + first_value(reserve1) over (partition by tj_count_1 order by date asc) * avax_price as tj_v1_liquidity,first_value(amount_x) over (partition by pharaoh_count_x order by date asc) * cai_price + first_value(amount_y) over (partition by pharaoh_count_y order by date asc) * avax_price as pharaoh_liquidityfrom(select *,count(amount_x) over (order by a.date asc) as pharaoh_count_x,count(amount_y) over (order by a.date asc) as pharaoh_count_yfrom(select a.date,reserve0,reserve1,cai_price,avax_price,count(reserve0) over (order by a.date asc) tj_count_0,count(reserve1) over (order by a.date asc) as tj_count_1,sum(amount_x) over (order by a.date asc) as amount_x,sum(amount_y) over (order by a.date asc) as amount_yfrom(select date, cai_price, avax_price from prices) as aleft join(select * from traderjoe_v1) as b on a.date = b.dateleft join