Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/with pool_info as (select concat(format('USDC/ETH (%.2f', cast(fee as double)/10000),'%)') as poolName,pool,token0,token1,case when token0 = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 then 6else 18 end as decimals0,case when token1 = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 then 6else 18 end as decimals1from uniswap_v3_ethereum.Factory_evt_PoolCreated where pool in (0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640, 0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8)) --select * from pool_info,last_price as (select t0.pool, price0, price1 from (select pool, minute, price as price0 from prices.usd as pinner join pool_info as i on p.contract_address = i.token0where blockchain = 'ethereum' and minute >= date_trunc('day', now())order by minute desc limit 2) as t0inner join (select pool, minute, price as price1 from prices.usd as pinner join pool_info as i on p.contract_address = i.token1where blockchain = 'ethereum' and minute >= date_trunc('day', now())order by minute desc limit 2) as t1 on t0.pool = t1.pool) --select * from last_price-------------------------------------------------------------------------------------------- PREPROCESS DATA -----------------------------------------------------------------------------------------------------------------------------------------------------------------,lp_data as (select q.*, -tx_fee_usd as tx_fee_usdfrom query_2023391 as qinner join gas.fees as gon q.tx_hash = g.tx_hashwhere q.pool = {{pool}} and g.blockchain = 'ethereum'),id_to_lp as (select distinct position_id, lpfrom lp_datawhere position_id != 0),collect as (select distinct i.pool,c.evt_tx_hash,case when c.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 then id.lpelse c.owner end as lp,greatest((cast(c.amount0 as double) - coalesce(cast(b.amount0 as double), 0)) / pow(10, i.decimals0), 0) as amount0,greatest((cast(c.amount1 as double) - coalesce(cast(b.amount1 as double), 0)) / pow(10, i.decimals1), 0) as amount1from uniswap_v3_ethereum.Pair_evt_Collect as cinner join pool_info as ion i.pool = c.contract_addressleft join uniswap_v3_ethereum.Pair_evt_Burn as bon c.owner = b.owner and c.evt_tx_hash = b.evt_tx_hashleft join uniswap_v3_ethereum.NonfungibleTokenPositionManager_evt_Collect as pmon c.owner = pm.contract_address and c.evt_tx_hash = pm.evt_tx_hash