Query editor
WITHlatest_balances AS (-- Calculate current balances by summing all transfersSELECTaddress,SUM(amount) / 1e18 AS balanceFROM(-- Combine all transfers with normalized directionsSELECT"to" AS address,value AS amountFROMdegen_base.degenlocktoken_evt_transferUNION ALLSELECT"from" AS address,- value AS amountFROMdegen_base.degenlocktoken_evt_transfer) transfersGROUP BYaddressHAVINGSUM(amount) > 0),deposit_balances AS (-- Calculate staked balancesSELECTd.account AS address,SUM(CASEWHEN d.amount IS NOT NULLAND w.amount IS NULL THEN d.amount / 1e18WHEN d.amount IS NOT NULLAND w.amount IS NOT NULL THEN (d.amount - w.amount) / 1e18ELSE 0END) AS staked_balanceFROM(SELECTaccount,depositTimestamp,SUM(amount) AS amountFROMdegen_base.degenlocktoken_evt_depositGROUP BYaccount,depositTimestamp) dLEFT JOIN (SELECTaccount,depositTimestamp,SUM(amount) AS amountFROMdegen_base.degenlocktoken_evt_withdrawGROUP BYaccount,