Query editor
-- mark-out ledger + cumulative PnL for an arbitrary N-minute horizon-- add {{markout_minutes}} as a Number parameter in DuneWITH trades AS ( -- raw fills on the poolSELECTt.block_time,t.tx_hash,t.evt_index,/* taker-signed WETH size (+ buy, – sell) */CASEWHEN t.token_bought_symbol = 'WETH' THEN t.token_bought_amountWHEN t.token_sold_symbol = 'WETH' THEN -t.token_sold_amountEND AS weth_signed_qty_taker,/* execution price (USDC per WETH) */CASEWHEN t.token_bought_symbol = 'WETH'THEN t.token_sold_amount / NULLIF(t.token_bought_amount, 0)WHEN t.token_sold_symbol = 'WETH'THEN t.token_bought_amount / NULLIF(t.token_sold_amount, 0)END AS exec_price_usdcFROM dex.trades tWHERE t.blockchain = 'ethereum'AND t.project_contract_address = 0x836951eb21f3df98273517b7249dceff270d34bf),eth_prices AS ( -- minute ETH-USD midpointSELECT"timestamp" AS ts_minute,priceFROM prices.minuteWHERE blockchain = 'ethereum'AND contract_address = 0x0000000000000000000000000000000000000000),annotated AS ( -- spot price at T + N minutesSELECTtr.*,p_fut.price AS price_markoutFROM trades trLEFT JOIN eth_prices p_futON p_fut.ts_minute =date_trunc('minute',tr.block_time + interval '{{markout_minutes}}' minute)),markouts AS ( -- pool-side PnL in USDCSELECTblock_time,tx_hash,evt_index,-weth_signed_qty_taker AS weth_signed_qty_pool,exec_price_usdc,price_markout,(price_markout - exec_price_usdc)* -weth_signed_qty_taker AS pnl_usdcFROM annotated