Query editor
-- Query to replicate Subsquid's snapshot logic in Dune SQL-- Target Snapshot Time: 2026-07-12 15:59:00 UTC-- This query reconstructs the current open positions as of the exact timestamp-- by computing the latest size from increase/decrease events and accumulating PnL/fees.WITH target_time AS (SELECT TIMESTAMP '2026-07-12 16:00:00' AS snapshot_time), participants AS (SELECT*,-- Participant Score Windowsfrom_unixtime(CAST(p.score_from AS BIGINT)) AS participant_score_from_time,from_unixtime(CAST(p.score_to AS BIGINT)) AS participant_score_to_timeFROM dune."gmx-io".dataset_gmx_masters_participants AS p)-- SELECT *-- FROM participants-- 1. Combine all increases and decreases up to the target time, position_events AS (SELECTblockchain, block_time, block_number, tx_hash, index,account, market, collateral_token, is_long, position_key,size_in_usd, size_in_tokens, collateral_amount,size_delta_usd,0 AS base_pnl_usd, 'increase' AS event_typeFROM gmx_v2.position_increaseWHERE block_time <= (SELECT snapshot_time FROM target_time)AND blockchain = 'arbitrum'AND account IN (SELECT wallet_address FROM participants)UNION ALLSELECTblockchain, block_time, block_number, tx_hash, index,account, market, collateral_token, is_long, position_key,size_in_usd, size_in_tokens, collateral_amount,size_delta_usd,base_pnl_usd, -- Accumulated on decreases'decrease' AS event_typeFROM gmx_v2.position_decreaseWHERE block_time <= (SELECT snapshot_time FROM target_time)AND blockchain = 'arbitrum'AND account IN (SELECT wallet_address FROM participants))-- SELECT-- *-- , COUNT(DISTINCT account) OVER () AS total_traders-- FROM position_events-- 2. Determine Position Lifecycles-- Since position_keys are reused, a position is considered a "new" lifecycle-- if the previous size was 0 (or null) and the current size goes > 0., ranked_events AS (SELECT*