Query editor
/* ============================================================================Calamari — daily volume, swaps and users----------------------------------------------------------------------------Calamari runs its own Uniswap v4 deployment on Ink (PoolManager0x6E4723A6..9560). It is NOT the canonical v4 deployment and Dune'suniswap_v4_ink decoding does not cover it, so everything here is decodedfrom raw ink.logs.Swap topic 0x40e9cecb.. data: amount0(int128) amount1(int128)sqrtPriceX96(uint160) liquidity(uint128) tick(int24) fee(uint24)Init topic 0xdd466e67.. topics: poolId, currency0, currency1data: fee, tickSpacing, hooks, sqrtPriceX96, tickVolume follows the DefiLlama convention: the priceable leg of each swap(ETH or a stablecoin), never both, so a swap is never double counted."Users" are transaction senders, not the Swap event's `sender`, which is arouter or hook contract rather than a person.========================================================================== */WITH pools AS (SELECT topic1 AS pool_id,bytearray_substring(topic2, 13, 20) AS currency0,bytearray_substring(topic3, 13, 20) AS currency1,bytearray_substring(bytearray_substring(data, 65, 32), 13, 20) AS hooksFROM ink.logsWHERE contract_address = 0x6e4723a612831afb9f5b2a5ae22723c37aab9560AND topic0 = 0xdd466e674ea557f56295e2d0218a125ea4b4f0f6f3307b95f85e6110838d6438),swaps AS (SELECT l.block_time, l.tx_hash, l.topic1 AS pool_id,bytearray_to_uint256(bytearray_substring(l.data, 17, 16)) AS a0u,bytearray_to_uint256(bytearray_substring(l.data, 49, 16)) AS a1u,cast(bytearray_to_uint256(bytearray_substring(l.data, 161, 32)) AS double) / 1e6 AS fee_rateFROM ink.logs lWHERE l.contract_address = 0x6e4723a612831afb9f5b2a5ae22723c37aab9560AND l.topic0 = 0x40e9cecb9f5f1f1c5b9c97dec2917b7ee92e57ba5563708daca94dd84ad7112fAND l.block_time >= now() - INTERVAL '90' day),signed AS (SELECT s.*,abs(CASE WHEN a0u >= cast('170141183460469231731687303715884105728' AS uint256)THEN -cast(cast('340282366920938463463374607431768211456' AS uint256) - a0u AS double)ELSE cast(a0u AS double) END) AS amt0,abs(CASE WHEN a1u >= cast('170141183460469231731687303715884105728' AS uint256)THEN -cast(cast('340282366920938463463374607431768211456' AS uint256) - a1u AS double)ELSE cast(a1u AS double) END) AS amt1FROM swaps s),/* hourly quote prices: native ETH is address zero in v4, priced off WETH */eth_px AS (SELECT timestamp AS hr, price AS pxFROM prices.hourWHERE blockchain = 'ink' AND contract_address = 0x4200000000000000000000000000000000000006AND timestamp >= now() - INTERVAL '90' day),priced AS (SELECT s.block_time, s.tx_hash, s.fee_rate,CASEWHEN p.currency0 = 0x0000000000000000000000000000000000000000 THEN s.amt0 / 1e18 * e.pxWHEN p.currency0 IN (0x0200c29006150606b650577bbe7b6248f58470c1,0x2d270e6886d130d724215a266106e6832161eaed) THEN s.amt0 / 1e6