Query editor
WITHtransferEvents AS(SELECTcontract_address,evt_block_number,evt_block_time,evt_index,evt_tx_hash,"from","to","value"FROM erc20_unichain.evt_transferWHEREevt_block_number >= 8112360ANDcontract_address = 0x81908BBaad3f6fC74093540Ab2E9B749BB62aA0d),firstTransfers AS (SELECT"to" AS address,MIN(evt_block_time) AS first_transfer_timeFROMtransferEventsGROUP BY "to"),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 firstTransfers f ON t."to"=f.address AND t.evt_block_time =f.first_transfer_timeGROUP BY t."to", f.first_transfer_time),currentTransfers AS ((SELECT"to" AS address,SUM(CAST(value AS INT256)) AS balanceFROM transferEventsGROUP BY "to")UNION ALL(SELECT"from" AS address,- SUM(CAST(value AS INT256)) AS balanceFROM transferEventsWHERE "from" != 0x000000000000000000000000000000000000000000GROUP BY "from")),currentBalances AS (SELECTaddress,SUM(balance)/1e18 AS balanceFROM currentTransfersGROUP BY address