Query editor
WITH raw_swap AS (SELECT *FROM sei.logsWHERE contract_address = 0x23ff0b537def4a47ac3621bda923b2146f237bccAND topic0 = 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67AND block_time >= CURRENT_DATE - INTERVAL '7' DAY),swap_evt AS (SELECTrecipient, -- ← 這裡用 recipientCAST(amount0 AS DECIMAL(38,0)) AS amount0,CAST(amount1 AS DECIMAL(38,0)) AS amount1FROM TABLE (decode_evm_event(abi => '{ "anonymous":false, "inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"int256","name":"amount0","type":"int256"},{"indexed":false,"internalType":"int256","name":"amount1","type":"int256"},{"indexed":false,"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"int24","name":"tick","type":"int24"}],"name":"Swap","type":"event"}',input => TABLE(raw_swap)))),asset_swap AS (SELECTrecipient AS trader_bin,ABS(amount0) AS qtyFROM swap_evt),tot AS (SELECTCOALESCE(SUM(qty), 0) / POW(10, 6) AS pool_total,COALESCE(SUM(CASE WHEN trader_bin = 0x8d72Fa8b37F8A97CC0cE5Ee4077806e3b63dE9d0OR trader_bin = 0xE33793230aD4587EC74306D52D28e80E36C27B9DOR trader_bin = 0xDA437Bdb83Ba406Bc41185eBAeee6f2B2691d056OR trader_bin = 0x6497f51Fa685b5391BefF9FbA3aDaAaA3225bB95THEN qty END),0) / POW(10, 6) AS trex_totalFROM asset_swap)SELECT 'TREX' AS category, trex_total AS usd_total_volume FROM totUNION ALLSELECT 'Others' AS category, pool_total - trex_total FROM tot;