Query editor
WITH swap_events AS (SELECTblock_time,block_number,tx_hash,bytearray_to_uint256(bytearray_substring(data, 1, 32)) as amount0In,bytearray_to_uint256(bytearray_substring(data, 33, 32)) as amount0Out,bytearray_substring(data, 65, 32) as tokenIn_address,CASEWHEN bytearray_to_uint256(bytearray_substring(data, 97, 32)) = 0 THEN falseELSE trueEND as is_stable,bytearray_substring(topic1, 13, 20) as sender,bytearray_substring(topic2, 13, 20) as recipientFROM avalanche_c.logsWHERE contract_address = 0xCaD684775d7879E63f5d319dAcC8086EeCC01B01AND topic0 = 0xe7857fba7d66e2e29213fda7a0394efbaa80d435dfc7b4c1f147d78c2f9caa62AND block_time >= NOW() - INTERVAL '7' day)SELECTDATE_TRUNC('hour', block_time) as hour,COUNT(*) as swap_count,COUNT(DISTINCT sender) as unique_swappers,SUM(amount0In / 1e18) as total_amount_in,SUM(amount0Out / 1e18) as total_amount_out,SUM((amount0In + amount0Out) / 1e18) as total_trading_volume,SUM(SUM((amount0In + amount0Out) / 1e18)) OVER (ORDER BY DATE_TRUNC('hour', block_time)) as cumulative_trading_volume,SUM(COUNT(*)) OVER (ORDER BY DATE_TRUNC('hour', block_time)) as cumulative_swap_count,AVG(amount0In / 1e18) as avg_amount_in,AVG(amount0Out / 1e18) as avg_amount_out,SUM(CASE WHEN is_stable THEN 1 ELSE 0 END) as stable_swaps,SUM(CASE WHEN NOT is_stable THEN 1 ELSE 0 END) as volatile_swapsFROM swap_eventsGROUP BY DATE_TRUNC('hour', block_time)ORDER BY hour DESC;