Query editor
-- Per-NFT gauge fee attribution across multiple continuous epochs.---- Same logic as gauge_fees_by_position.sql but scans tables once for the-- full date range. The expensive swap×position join happens once, and-- results are bucketed by epoch week in the output.---- 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)-- ============================================================================-- 0. Pair info + epoch grid-- ============================================================================WITH pair_info AS (SELECTgauge, name, token0, token1,dec0 AS token0_decimals, dec1 AS token1_decimals,CASE WHEN name LIKE '%(v1)%'THEN 0x827922686190790b37229fd06084350E74485b72ELSE 0xa990C6a764b73BF43cee5Bb40339c3322FB9D55FEND AS nfpm_addressFROM dune.x_drome_analytics.result_aero_pairsWHERE pool = {{pool_address}}LIMIT 1),epochs AS (SELECT epoch_start, epoch_start + 604800 AS epoch_endFROM UNNEST(SEQUENCE(CAST({{range_start_ts}} AS BIGINT),CAST({{range_end_ts}} AS BIGINT) - 604800,604800)) AS t(epoch_start)),tx_fee_calls AS (SELECT call_tx_hash, output_0 AS fee_rate, call_block_number AS block_number,ROW_NUMBER() OVER (PARTITION BY call_tx_hash ORDER BY call_trace_address) AS call_seqFROM aerodrome_base.clfactory_call_getswapfeeWHERE pool = {{pool_address}} AND call_success = trueAND call_block_time >= from_unixtime({{range_start_ts}} - 604800)AND call_block_time < from_unixtime({{range_end_ts}})),-- ============================================================================-- 1. Deposit / Withdraw matching — full range-- ============================================================================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 (