Query editor
-- Token and Staking: GMX and esGMX Staking Events (research request F.24, staking / unstaking)-- Fork of 8921624 (Staking Data for GT Airdrop: Arb+Avax). Same logic, changes:-- 1. esGMX rows kept (8921624 ended with WHERE symbol <> 'esGMX')-- 2. joins to arbitrum.transactions / avalanche_c.transactions removed (only added the tx index); tx_index from logs instead-- 3. source column added; tracker withdrawals without a router event keep tx signer / target in tx_from / tx_to-- 4. NEW: from 2026-10-28 the RewardRouter emits RewardRouterStakeGmx / RewardRouterUnstakeGmx through the-- GMX v2 EventEmitter (account, token, amount) instead of its own StakeGmx / UnstakeGmx logs; these are added-- (source 'eventemitter'). 8921624 has no rows after 2026-10-28.-- Old RewardRouter contracts are not decoded on Dune, so their events are read from raw logs:-- v1 events StakeGmx(account, amount) / UnstakeGmx(account, amount) have no token: token = GMX or esGMX transferred-- to / from the staked GMX tracker in the same tx (default GMX)-- v2 events StakeGmx(account, token, amount) / UnstakeGmx(account, token, amount)-- arbitrum GMX withdrawals from the staked GMX tracker with no unstake event in the tx are added as 'unstake'-- Grain: one row per stake / unstake = (blockchain, tx_hash, log_index).WITH gmx_tokens AS (SELECT blockchain, symbol, contract_address, decimalsFROM gmx_v2.erc20WHERE symbol = 'GMX'UNION ALLSELECT blockchain, symbol, contract_address, decimalsFROM (VALUES('arbitrum','esGMX',0xf42Ae1D54fd613C9bb14810b0588FaAa09a426cA,18),('avalanche_c','esGMX',0xff1489227bbaac61a9209a08929e4c2a526ddd17,18)) AS gmx_contracts(blockchain, symbol, contract_address, decimals))-- ARBITRUM, gmx_evt_transfers_arb AS (SELECT'arbitrum' AS blockchain,tr.evt_block_time AS block_time,CAST(tr.evt_block_time AS DATE) AS block_date,tr.evt_block_number AS block_number,tr.evt_tx_index AS tx_index,tr.evt_index AS log_index,tr.evt_tx_hash AS tx_hash,tr.evt_tx_from AS tx_from,tr.evt_tx_to AS tx_to,tr.contract_address AS token_contract,tr."from" AS transfer_from,tr."to" AS transfer_to,tr."value"/POWER(10,18) AS token_value,CASEWHEN tr."from" = 0x908C4D94D34924765f1eDc22A1DD098397c59dD4 THEN 'withdrawal'WHEN tr."to" = 0x908C4D94D34924765f1eDc22A1DD098397c59dD4 THEN 'deposit'ELSE 'undefined'END AS transfer_typeFROM erc20_arbitrum.evt_transfer AS trWHERE tr.contract_address = (SELECT contract_address FROM gmx_tokens WHERE blockchain = 'arbitrum' AND symbol = 'GMX')AND (tr."from" = 0x908C4D94D34924765f1eDc22A1DD098397c59dD4OR tr."to" = 0x908C4D94D34924765f1eDc22A1DD098397c59dD4))