Query editor
/* ============================================================================Q2 · Calamari — swap fees, protocol revenue and LP fees, daily, by pool class----------------------------------------------------------------------------Every swap on Calamari's PoolManager (0x6E4723A6..9560) emits Swap(id,sender, amount0, amount1, sqrtPriceX96, liquidity, tick, fee). `fee` is theTOTAL rate in pips (LP fee + v4 protocol fee). The protocol fee is aper-pool, per-direction rate set by ProtocolFeeUpdated(id, protocolFee):12 bits for zeroForOne, 12 bits for oneForZero. The InkProtocolFeeController(0xE7297c70..8994) stamps pools with 1000|1000 pips (0.1% each way); as of2026-11-09 all 688 pools are stamped, including the direct pools. A swapbefore its pool's stamp pays no protocol fee, so the rate is replayed perswap from that history (ordered by block, log index).protocol fee (REVENUE) = input amount x protocol pips / 1e6, in the inputcurrency; held in the PoolManager until thecontroller sweeps it to its feeRecipient, theTsunami treasury Safe 0x686c..1d42 (never sweptas of 2026-11-09).LP fee (NOT revenue) = input x (fee - protocol pips) / 1e6. Zero onTsunami-graduated pools (lpFee 0); nonzero ondirect / third-party-hook pools.Tsunami's own 1% hook fee on graduated pools is NOT in `fee`. It is a hookdelta, booked to Tsunami in Q1, so graduated-pool swaps are never doublecounted.USD: each swap is valued off whichever leg is a recognised quote asset(native ETH, WETH, or any currency the Tsunami factories enabled viaCurrencyAdded), using prices.hour. Fees charged in a launch token are valuedat that swap's own rate. ETH columns = fees actually charged in ETH/WETH.========================================================================== */WITH pools AS (SELECT pool_id, pool_class, currency0, currency1 FROM query_9105572),quote_assets AS ( -- assets we trust a price forSELECT 0x0000000000000000000000000000000000000000 AS assetUNION SELECT 0x4200000000000000000000000000000000000006UNION SELECT DISTINCT bytearray_substring(data, 13, 20) -- CurrencyAdded(address currency, uint256 maxRaise)FROM ink.logsWHERE contract_address IN (0x5934a5c377309453746ee8aa5194f671930c09fa, 0x1fc16511f5fa4b4c1591ffeb8c38affc367076f1)AND topic0 = 0x851abf613adb21a333f609020a896197a65dd7e078e2786cea53b08b3ccf3f8c),pf_hist AS ( -- ProtocolFeeUpdated(bytes32 indexed id, uint24 protocolFee)SELECT topic1 AS pool_id,block_number * 100000 + index AS pos,coalesce(lead(block_number * 100000 + index) OVER (PARTITION BY topic1 ORDER BY block_number, index),9223372036854775807) AS next_pos,cast(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS bigint) AS packed_feeFROM ink.logsWHERE contract_address = 0x6e4723a612831afb9f5b2a5ae22723c37aab9560AND topic0 = 0xe9c42593e71f84403b84352cd168d693e2c9fcd1fdbcc3feb21d92b43e6696f9AND block_number >= 54652108),swaps AS (SELECT l.block_time, l.block_number * 100000 + l.index AS pos, l.tx_from, l.topic1 AS pool_id,cast(bytearray_to_int256(bytearray_substring(l.data, 1, 32)) AS double) AS amount0,cast(bytearray_to_int256(bytearray_substring(l.data, 33, 32)) AS double) AS amount1,cast(bytearray_to_uint256(bytearray_substring(l.data, 161, 32)) AS bigint) AS fee_pipsFROM ink.logs lWHERE l.contract_address = 0x6e4723a612831afb9f5b2a5ae22723c37aab9560AND l.topic0 = 0x40e9cecb9f5f1f1c5b9c97dec2917b7ee92e57ba5563708daca94dd84ad7112f