Query editor
-- Per-pool CASHCAT swap activity across ALL discovered pools (primary + siblings).-- Exposes the coverage gap: how much CASHCAT DEX activity happens outside the-- primary pool the rest of the dashboard is scoped to.---- Trino fix: the previous version had a correlated subquery in the SELECT list-- to look up fee_tier per pool. Trino rejects that ("correlated subquery is-- not supported"). Pulled fee_tier up into the per_swap CTE via the existing-- JOIN to cashcat_pools and added it to the outer GROUP BY. Same semantics.WITH cashcat_pools AS (SELECTbytearray_substring(data, 45, 20) AS pool_addr,bytearray_substring(topic1, 13, 20) AS token0_addr,bytearray_substring(topic2, 13, 20) AS token1_addr,CAST(bytearray_to_uint256(topic3) AS INTEGER) AS fee_tier,(bytearray_substring(topic1, 13, 20) = 0x020bfC650A365f8BB26819deAAbF3E21291018b4) AS is_token0FROM robinhood.logsWHERE contract_address = {{factory_address}}AND topic0 = 0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118AND (topic1 = 0x000000000000000000000000020bfc650a365f8bb26819deaabf3e21291018b4OR topic2 = 0x000000000000000000000000020bfc650a365f8bb26819deaabf3e21291018b4)),swaps AS (SELECTcontract_address AS pool_addr,block_time,bytearray_to_int256(bytearray_substring(data, 1, 32)) AS amount0,bytearray_to_int256(bytearray_substring(data, 33, 32)) AS amount1FROM robinhood.logsWHERE contract_address IN (SELECT pool_addr FROM cashcat_pools)AND topic0 = 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67),per_swap AS (SELECTs.pool_addr,p.fee_tier,s.block_time,CAST(CASE WHEN p.is_token0 THEN abs(s.amount0) ELSE abs(s.amount1) END AS DECIMAL(38,0)) AS cashcat_rawFROM swaps sJOIN cashcat_pools p ON s.pool_addr = p.pool_addr)SELECTCASE WHEN pool_addr = {{pool_address}} THEN 'PRIMARY' ELSE 'sibling' END AS role,concat('0x', to_hex(pool_addr)) AS pool,fee_tier,COUNT(*) AS total_swaps,COUNT_IF(block_time > now() - interval '24' hour) AS swaps_24h,COUNT_IF(block_time > now() - interval '7' day) AS swaps_7d,SUM(cashcat_raw) / 1e18 AS total_cashcat_volume,SUM(CASE WHEN block_time > now() - interval '24' hour THEN cashcat_raw ELSE 0 END) / 1e18AS cashcat_volume_24hFROM per_swapGROUP BY pool_addr, fee_tierORDER BY CASE WHEN role = 'PRIMARY' THEN 0 ELSE 1 END, total_swaps DESC;