Query editor
WITH allocations AS (SELECTreceiver_1 AS owner,addr AS address,CASEWHEN addr = vesting_contract THEN initialallocationELSE 0END AS allocation,CASEWHEN addr = vesting_contract THEN vestedELSE 0END AS vested,"group" AS user_groupFROM dune.apeir99n.dataset_gearallocations202506,UNNEST(ARRAY[vesting_contract,receiver_1,CASE WHEN receiver_2 IS NOT NULL THEN receiver_2 ELSE NULL END]) AS t(addr)WHERE addr IS NOT NULL),transfers as (selecta.owner,a.user_group,a.allocation,a.vested,-value/1e18 as transfer_amount,evt_block_datefrom erc20_ethereum.evt_transfer t, allocations awhere t."from" = a.addressand contract_address = 0xba3335588d9403515223f109edc4eb7269a9ab5dand evt_block_date <= date_trunc('month', CURRENT_DATE)UNIONselecta.owner,a.user_group,a.allocation,a.vested,value/1e18 as transfer_amount,evt_block_datefrom erc20_ethereum.evt_transfer t, allocations awhere t."to" = a.addressand contract_address = 0xba3335588d9403515223f109edc4eb7269a9ab5dand evt_block_date <= date_trunc('month', CURRENT_DATE))selectt.owner,t.user_group,SUM(t.allocation) as total_allocation,SUM(t.vested) as total_vested,SUM(t.transfer_amount) as total_balance,SUM( t.allocation - t.transfer_amount) as differencefrom transfers tgroup by 1,2