Query editor
-- Goal of this query is to find the first 100 buyers of a token and those still holding.-- 1. Pull all transfer events from the token after launchWITH transferEvents AS (SELECTcontract_address,evt_block_number,evt_block_time,evt_index,evt_tx_hash,"from","to",valueFROM erc20_base.evt_transferWHERE evt_block_number >= {{initial_block_number}}AND contract_address = {{token_address}}),-- 2. Determine when each address first received tokensfirstTransfers AS (SELECT"to" AS address,MIN(evt_block_time) AS first_transfer_timeFROM transferEventsGROUP BY "to"),-- 3. Get initial balances for each address at their first transfer timeinitialBalances AS (SELECTt."to" AS address,SUM(CAST(t.value AS INT256)) AS initial_balance,f.first_transfer_time AS initial_buy_timeFROM transferEvents tJOIN firstTransfers f ON t."to" = f.address AND t.evt_block_time = f.first_transfer_timeGROUP BY t."to", f.first_transfer_time),-- 4. Limit to first 100 buyersrankedBuyers AS (SELECT *,ROW_NUMBER() OVER (ORDER BY initial_buy_time ASC) AS row_numFROM initialBalances),top100Buyers AS (SELECT * FROM rankedBuyers WHERE row_num <= 100),-- 5. Calculate current balances from all transferscurrentTransfers AS (SELECT "to" AS address, SUM(CAST(value AS INT256)) AS balanceFROM transferEventsGROUP BY "to"UNION ALLSELECT "from" AS address, -SUM(CAST(value AS INT256)) AS balanceFROM transferEventsWHERE "from" != 0x0000000000000000000000000000000000000000GROUP BY "from"),