Query editor
-- Uniswap V3 Mainnet LP, v2: same output as v6, rewritten to cut cost.-- Changes, none of which alter the result:-- * Each source table is read once. v6 re-read the call tables 3x and the mint table ~8x,-- because every reference to a WITH block re-runs it.-- * Event prices look up the event's own day and the day before (an equality join), instead-- of every minute of the token's price history for every event.-- * The current price reads the last day of prices; the current tick reads the last 30 days-- of swaps. The pool trades often, so both windows hold the latest value.WITH config AS (SELECTCOW_TOKEN_MAINNET,WETH_TOKEN_MAINNETFROM query_6231031),address_labels AS (SELECT * FROM (VALUES(LOWER('0x616dE58c011F8736fa20c7Ae5352F7f6FB9F0669'), 'kpk COW Treasury')) AS t(addr, label)),pool_addr AS (SELECT poolFROM (SELECTpc.pool,ROW_NUMBER() OVER (ORDER BY pc.evt_block_time DESC) AS rnFROM uniswap_v3_ethereum.factory_evt_PoolCreated pcJOIN config c ON TRUEWHERE pc.fee = 3000AND ((pc.token0 = c.COW_TOKEN_MAINNET AND pc.token1 = c.WETH_TOKEN_MAINNET)OR (pc.token0 = c.WETH_TOKEN_MAINNET AND pc.token1 = c.COW_TOKEN_MAINNET))) tWHERE rn = 1),pool_state AS (SELECTs.contract_address AS pool_address,CAST(max_by(s.tick, s.evt_block_time) AS INTEGER) AS current_tick,max_by(s.sqrtPriceX96, s.evt_block_time) AS current_sqrtPriceX96FROM uniswap_v3_ethereum.UniswapV3Pool_evt_Swap sWHERE s.contract_address IN (SELECT pool FROM pool_addr)AND s.evt_block_time >= NOW() - INTERVAL '30' DAYGROUP BY 1),mints AS (SELECTm.chain,m.call_block_time,m.call_tx_hash,m.call_trace_address,json_extract_scalar(m.params, '$.recipient') AS nft_owner,m.output_amount0,m.output_amount1,m.output_liquidity,