Query editor
-- LpUtilsV4_0xcb3d: 0xcb3d2a42022741b06f9b38459e3dd1ee9a64d129-- Chains: arbitrum, base, bnb, ethereum, polygon (unichain pending)-- Uses Uniswap V4 PositionManager for token0/token1 lookupWITH-- V4 PM: tokenId → currency0/currency1-- Deduplicate per (chain, tokenId) so any historical call to getPoolAndPositionInfo-- gives us the token pair — not just calls in the same tx as the Krystal event.position_info AS (SELECT chain, tokenId, token0, token1FROM (SELECTchain,tokenId,from_hex(JSON_EXTRACT_SCALAR(output_poolKey, '$.currency0')) AS token0,from_hex(JSON_EXTRACT_SCALAR(output_poolKey, '$.currency1')) AS token1,ROW_NUMBER() OVER (PARTITION BY chain, tokenId ORDER BY call_block_number) AS rnFROM uniswap_v4_multichain.positionmanager_call_getpoolandpositioninfoWHERE call_success = TRUE) tWHERE rn = 1),-- zap_in: new position minted with swapzap_in_data AS (SELECTz.evt_tx_hash AS tx_hash,z.evt_block_time AS time,p.token0,z.amount0,p.token1,z.amount1,z.chain,'zap_in' AS txn_type,lower(to_hex(z.posm)) AS nfpmFROM krystal_multichain.lputilsv4_0xcb3d_evt_swapandmint zINNER JOIN position_info p ON z.chain = p.chain AND z.tokenId = p.tokenId),-- zap_increase: add liquidity to existing positionzap_increase_data AS (SELECTz.evt_tx_hash AS tx_hash,z.evt_block_time AS time,p.token0,z.amount0,p.token1,z.amount1,z.chain,'zap_increase' AS txn_type,lower(to_hex(z.posm)) AS nfpmFROM krystal_multichain.lputilsv4_0xcb3d_evt_swapandincrease zINNER JOIN position_info p ON z.chain = p.chain AND z.tokenId = p.tokenId),-- rebalance: close old range, open new — token pair comes from the NEW positionrebalance_data AS (SELECTz.evt_tx_hash AS tx_hash,