Query editor
-- 参数(右侧面板可直接改,不用碰 SQL):-- hours 统计窗口(小时)-- xrouter/xrouter_multi/xrouter_basket 当前生产路由合约地址-- collector 利润收款地址(收 WBNB 的地址,不是 tx 发送方——194 个节点各自用不同钱包发交易,-- profit 统一转给这一个 collector,所以按 to=router + WBNB Transfer(topic2=collector) 归因,-- 不能按 from=collector 查,那样查不到任何 XRouter 交易)---- nodeid 编码:gas_limit % 1,000,000(源码核实过,不是按记忆里的旧公式)。-- 0gwei tx 走公共广播,不带这个偏移,nodeid 恒为 null,单独一行统计,不拆节点。with router_txs as (selectt.hash,t.success,t.gas_price,t.gas_used,case when t.gas_price = 0 then 'zero-gwei' else 'non-zero-gwei' end as bucket,casewhen t.gas_price = 0 then nullwhen t.gas_limit >= 1000000 and t.gas_limit % 1000000 < 100 then cast(t.gas_limit % 1000000 as varchar)else 'other/unknown'end as nodeidfrom bnb.transactions twhere t."to" in ({{xrouter}}, {{xrouter_multi}}, {{xrouter_basket}})and t.block_time >= now() - interval '{{hours}}' hourand t.block_date >= date(now() - interval '{{hours}}' hour) - interval '1' day),tx_profit as (selectrt.hash,rt.bucket,rt.nodeid,rt.success,rt.gas_used,rt.gas_price,coalesce(sum(varbinary_to_uint256(l.data)), 0) as profit_weifrom router_txs rtleft join bnb.logs lon l.tx_hash = rt.hashand l.contract_address = 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c -- WBNBand l.topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef -- Transfer(address,address,uint256)and bytearray_substring(l.topic2, 13, 20) = {{collector}}and l.block_time >= now() - interval '{{hours}}' hourand l.block_date >= date(now() - interval '{{hours}}' hour) - interval '1' daygroup by rt.hash, rt.bucket, rt.nodeid, rt.success, rt.gas_used, rt.gas_price)-- ① 0gwei:不区分 nodeid(公共广播路径无节点偏移),只按 success 拆select'zero-gwei' as bucket,cast(null as varchar) as nodeid,success,count(*) as tx_count,sum(profit_wei) / 1e18 as profit_wbnb,sum(gas_used * gas_price) / 1e18 as gas_fee_bnbfrom tx_profitwhere bucket = 'zero-gwei'group by success