Query editor
-- Blackhole — individual IncreaseLiquidity deposit events for one pool/window.---- Parameters:-- {{pool_address}} varbinary pool address-- {{lookback_hours}} number---- Python filters these events to the wallets included in the PNL report and-- then computes avg/median/high/low per individual deposit event.WITH params AS (SELECT{{pool_address}} AS pool,CAST({{lookback_hours}} AS integer) AS lookback_hours,date_add('hour', -CAST({{lookback_hours}} AS integer), current_timestamp) AS start_time),pool_meta AS (SELECT pool, token0, token1FROM dune.blackhole_foundation.result_bh_pool_metadataWHERE pool = (SELECT pool FROM params)),prices_hour AS (SELECTcontract_address AS token,date_trunc('hour', timestamp) AS ts,AVG(price) AS price,AVG(decimals) AS decimalsFROM prices.hourWHERE blockchain = 'avalanche_c'AND timestamp >= (SELECT start_time FROM params)GROUP BY 1, 2),prices_day AS (SELECTcontract_address AS token,date(timestamp) AS dt,AVG(price) AS price,AVG(decimals) AS decimalsFROM prices.dayWHERE blockchain = 'avalanche_c'AND timestamp >= date_add('day', -7, (SELECT start_time FROM params))GROUP BY 1, 2),-- tokenId is only unique WITHIN an NFPM deployment; after the redeploy the-- unique position key is (contract_address, tokenId). Match the contract so a-- duplicate tokenId from another deployment isn't attributed to this wallet.pool_token_owners AS (SELECT DISTINCTi.contract_address,i.tokenId AS tokenid,t."to" AS walletFROM blackhole_avalanche_c.nonfungiblepositionmanager_evt_increaseliquidity iJOIN blackhole_avalanche_c.nonfungiblepositionmanager_evt_transfer tON i.tokenId = t.tokenIdAND i.contract_address = t.contract_addressWHERE i.pool = (SELECT pool FROM params)AND t."from" = 0x0000000000000000000000000000000000000000)SELECTpto.wallet,i.tokenId AS tokenid,