Query editor
withfromTX as (selectfrom_hex(CONCAT('0x',SUBSTRING(TRY_CAST(topic1 AS VARCHAR), 27, 40))) as user,sum(BYTEARRAY_TO_UINT256 (data)) as amountfrom{{chain}}.logsWHEREcontract_address = {{tokenAddress}}AND topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND to_unixtime(cast(block_time as TIMESTAMP (0))) <= IF({{timestamp}}=0, to_unixtime(cast(now() as TIMESTAMP (0))), {{timestamp}})GROUP by 1),toTX as (selectfrom_hex(CONCAT('0x',SUBSTRING(TRY_CAST(topic2 AS VARCHAR), 27, 40))) as user,sum(BYTEARRAY_TO_UINT256 (data)) as amountfrom{{chain}}.logsWHEREcontract_address = {{tokenAddress}}AND topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND to_unixtime(cast(block_time as TIMESTAMP (0))) <= IF({{timestamp}}=0, to_unixtime(cast(now() as TIMESTAMP (0))), {{timestamp}})GROUP by 1),allTx as (select a.user, IF(a.amount is null, 0, a.amount) as toAmount, IF(b.amount is null, 0, b.amount) as fromAmount from toTX a LEFT JOIN fromTX b on a.user=b.user)select count(user) as userCount from allTx where toAmount-fromAmount>0 and user != 0x0000000000000000000000000000000000000000-- select a.user, IF(a.amount is null, 0, a.amount) as fromAmount, IF(b.amount is null, 0, b.amount) as toAmount from fromTX a LEFT JOIN toTX b on a.user=b.user-- select a.user as fromUser, b.user as toUser, a.amount as fromAmount, b.amount as toAmount from fromTX a, toTX b where