Query editor
-- Companion query for the cbETH/WETH LP dashboard (Dialectic MOU metrics).---- Returns everything needed to compute, locally: time-weighted staked TVL,-- in-range TVL, % of time in-range, and % of time with liquidity within-- ±0.03% (±3 ticks) of the active tick — per depositor per epoch.---- Position reconstruction matches gauge_fees_multi_epoch.sql (same-- deposit/withdraw seq matching), so positions line up with the fee CSVs.---- Output: unioned rows discriminated by `kind`:-- kind='pos': a=token_id, b=depositor, c=liquidity, d=tick_lower,-- e=tick_upper, f=deposit_ts, g=withdraw_ts (9999999999 if still staked)-- kind='swap': a=block_ts, d=tick (last swap in block; includes lookback-- day before range_start so the tick at range start is known)-- kind='price': a=hour_ts, b='t0'|'t1', c=usd_price---- Dune parameters:-- {{pool_address}} -- CLPool contract address (text, 0x-prefixed)-- {{range_start_ts}} -- first epoch start unix timestamp (number)-- {{range_end_ts}} -- last epoch end unix timestamp (number)WITH pair_info AS (SELECTgauge, name, token0, token1,CASE WHEN name LIKE '%(v1)%'THEN 0x827922686190790b37229fd06084350E74485b72ELSE 0xa990C6a764b73BF43cee5Bb40339c3322FB9D55FEND AS nfpm_addressFROM dune.x_drome_analytics.result_aero_pairsWHERE pool = {{pool_address}}LIMIT 1),range_token_ids AS (SELECT DISTINCT tokenId AS token_idFROM aerodrome_base.clgauge2_evt_withdrawWHERE contract_address = (SELECT gauge FROM pair_info)AND evt_block_time >= from_unixtime({{range_start_ts}})),all_deposits_seq AS (SELECT deposit_block, deposit_time, token_id, liquidity,evt_idx AS deposit_evt_index,ROW_NUMBER() OVER (PARTITION BY token_id ORDER BY deposit_block, evt_idx) AS seqFROM (SELECT evt_block_number AS deposit_block, evt_block_time AS deposit_time,tokenId AS token_id, liquidityToStake AS liquidity, evt_index AS evt_idxFROM aerodrome_base.clgauge2_evt_depositWHERE contract_address = (SELECT gauge FROM pair_info)AND tokenId IN (SELECT token_id FROM range_token_ids))),all_withdrawals_seq AS (SELECT withdraw_block, withdraw_time, depositor, token_id,ROW_NUMBER() OVER (PARTITION BY token_id ORDER BY withdraw_block, withdraw_evt_index) AS seqFROM (SELECT evt_block_number AS withdraw_block, evt_block_time AS withdraw_time,evt_index AS withdraw_evt_index,"user" AS depositor, tokenId AS token_id