Query editor
with vault_info as (select * from query_2208104-- manual address filter >>> name selectorwhere case when {{vault}} = 0x0000000000000000000000000000000000000000 then vaultName = '{{vaultName}}' else vault = {{vault}} end)-------------------------------------------------------------------------------------------- AUX TABLES ----------------------------------------------------------------------------------------------------------------------------------------------------------------------,pools as (select distinct m.contract_address as pool,v.vault,cast(p.fee as double) as fee,cast(p.tickSpacing as double)/5 as tick_spacing,case when p.token0 = v.token0 then true else false end as vault_order_flagfrom uniswap_v3_ethereum.Pair_evt_Mint as minner join vault_info as von v.deployBlock <= m.evt_block_number and v.vault = m.ownerinner join uniswap_v3_ethereum.Factory_evt_PoolCreated as pon v.deployBlock > p.evt_block_number and p.evt_block_number > 0 and m.contract_address = p.pool -- bound between Arrakis vault and UniV3 factory deploymentand p.pool = m.contract_address) --select * from pools-- use ethereum blocks table (12sec/entry) to generate a timeseries with a 1min interval,time_series as (select distinct date_trunc('day', b.time) as time_atfrom ethereum.blocks as binner join vault_info as von b.time >= v.deployedAt and b.time <= cast('{{end_time}}' as timestamp)) --select * from time_series order by 1 asc-------------------------------------------------------------------------------------------- GET POOL PRICE ------------------------------------------------------------------------------------------------------------------------------------------------------------------,prices as (select time_at,pool,ceil(log(1.0001, 0.5 * price)) as lower,floor(log(1.0001, 2 * price)) as upper,pricefrom (select date_trunc('day', s.evt_block_time) as time_at,s.contract_address as pool,avg(power(1.0001, s.tick)) as pricefrom uniswap_v3_ethereum.Pair_evt_Swap as sinner join vault_info as von v.deployBlock <= s.evt_block_number and s.evt_block_time < cast('{{end_time}}' as timestamp)inner join pools as pon p.pool = s.contract_addressgroup by 1, 2) as porder by pool, time_at desc) --select * from price,last_price as (select p.*from prices as pinner join (select pool, max(time_at) as time_at from prices group by 1) as last_swapon last_swap.time_at = p.time_at and last_swap.pool = p.pool) --select * from last_price