Query editor
WITH router_data AS (SELECT * FROM query_4703164),combined_logs AS (SELECTblock_time, block_number,contract_address,topic0, topic1,topic2, topic3, data,'arbitrum' as chain_nameFROM arbitrum.logs lJOIN router_data rd ON rd.chain_name = 'arbitrum' AND l.block_number >= rd.start_blockUNION ALLSELECTblock_time, block_number,contract_address,topic0, topic1,topic2, topic3, data,'ethereum' as chain_nameFROM ethereum.logs lJOIN router_data rd ON rd.chain_name = 'ethereum' AND l.block_number >= rd.start_blockUNION ALLSELECTblock_time, block_number,contract_address,topic0, topic1,topic2, topic3, data,'bnb' as chain_nameFROM bnb.logs lJOIN router_data rd ON rd.chain_name = 'bnb' AND l.block_number >= rd.start_block-- Add other chains as needed (bnb, scroll, mantle) following the same pattern),all_events AS (SELECTblock_time,chain_name,contract_address,buyerTokenAmount as buy_token_amount,buyerToken as tokenIn,sellerTokenAmount as sell_token_amount,sellerToken as tokenOut,'RFQTrade' as event_typeFROMTABLE (decode_evm_event (abi => '{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"sellerToken","type":"address"},{"indexed":false,"internalType":"address","name":"buyerToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"sellerTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"buyerTokenAmount","type":"uint256"},{"indexed":false,"internalType":"bytes16","name":"quoteId","type":"bytes16"},{"indexed":false,"internalType":"address","name":"signer","type":"address"}],"name":"RFQTrade","type":"event"}',input => TABLE (SELECT *FROM combined_logsWHERE topic0 = 0xc82975a4eae9f14416813a0bd7312edf547928cd25ae9b8597ee4c92fa6862d2)))),volume_calculation AS (SELECTae.tokenIn as token_address,ABS(SUM(ae.buy_token_amount / POWER(10, IF(p.decimals IS NULL, pf.decimals, p.decimals)) *IF(p.price IS NULL, pf.price, p.price)