Query editor
WITH deposits AS (SELECTvarbinary_ltrim(topic3) AS user,varbinary_to_uint256(bytearray_substring(data, 1, 32))/1e18 AS Staked_TREEFROM ethereum.logsWHEREtopic0 = 0xd3757d6844bcd1c0edad1353d5cb68603837ce8e724a82f88e9391358c91ed63AND contract_address = 0x636b40FEbF37Fd9F059b68F5BAE3A26285314551),withdrawals AS (SELECTvarbinary_ltrim(topic2) AS user,varbinary_to_uint256(bytearray_substring(data, 1, 32))/1e18 AS Staked_TREEFROM ethereum.logsWHEREtopic0 = 0x5052059932c9d87385ad34a74db8e657d43cbd3f8e1b08ddacd2a0adfa9789dfAND contract_address = 0x636b40FEbF37Fd9F059b68F5BAE3A26285314551)SELECTCOALESCE(deposits.user, withdrawals.user) AS user, -- Combine users from deposits and withdrawalsCOALESCE(SUM(deposits.Staked_TREE), 0) AS total_deposits, -- Sum of depositsCOALESCE(SUM(withdrawals.Staked_TREE), 0) AS total_withdrawals, -- Sum of withdrawalsCOALESCE(SUM(deposits.Staked_TREE), 0) - COALESCE(SUM(withdrawals.Staked_TREE), 0) AS net_balance -- Net balanceFROMdepositsFULL OUTER JOINwithdrawalsONdeposits.user = withdrawals.user -- Match users across deposits and withdrawalsGROUP BY1ORDER BY4 DESC