Query editor
--Goal is to find the wallets still holding tokens which are part of the initial first 100 buyersWITH transferEvents AS ( --this is the first table to calculate transfer eventsSELECTcontract_address,evt_block_number,evt_block_time, --to find when the token launchedevt_index,evt_tx_hash,"from","to","value"FROM erc20_{{blockchain}}.evt_transfer --parameter to switch to any blockchain of my choice. Parameters are flexibleWHERE --First condition: find the initial block number where token was launchedevt_block_number >= {{initial_block_number}} --using greater or equal to makes the query not to start counting from any transaction that happened before that block number taking more time.--Because we are looking for a specific token, we will start counting from the block number that this query was created.AND --next conditioncontract_address = {{token_address}}--first CTE completed. Only the first CTE carries a WITH others can be named as I please.),firstTransfer AS (--this next CTE is to find the first transfers that occurred in our query ie the first time that each wallet received a token or bought oneSELECT"to" AS address,MIN(evt_block_time) AS first_transfer_timeFROM transferEventsGROUP BY "to" --to ensure that no two columns repeat itself. We didn't use address because the address has not been ran yet. It is not yet recognised.),initialBalances AS (SELECTt."to" AS address,SUM(CAST(t.value AS INT256)) AS initial_balance,f.first_transfer_time AS initial_buy_timeFROMtransferEvents t JOIN firstTransfer f ON t."to"=f.address AND t.evt_block_time = f.first_transfer_timeGROUP BY t."to", f.first_transfer_time),currentTransfers AS ( --union all of how much entered and how much is left gives the net transfer that is the current balance of the wallet(SELECT ---this is for whenever the wallet receives ie, there is positive changes in the wallet balance where "to" is the token received"to" AS address,SUM(CAST(value AS INT256)) AS balanceFROM transferEventsGROUP BY "to")UNION ALL(SELECT ---this is for whenever the wallet gives ie, there is negative change in the wallet balance.--The aim is to find the negative change in the balance of the wallet excluding the token mint address"from" AS address,- SUM(CAST(value AS INT256)) AS balanceFROM transferEventsWHERE "from" != 0x0000000000000000000000000000000000000000GROUP BY "from")),currentBalances AS (SELECTaddress,SUM(balance)/{{decimal}} AS balance