Query editor
-- P&L of an arb executor on Base between {{start_block}} and {{end_block}} (inclusive).-- fee_eth = fees paid by callers; profit_weth / profit_usdc = the executor's net token balance-- change in successful trading calls, before gas. Token amounts, no USD pricing.-- state-loader pnl-report runs this file.---- {{address}} must be the executor contract. Fee: every tx sent to it, reverts included.-- Set {{start_block}} and {{end_block}} as numeric Dune parameters.-- Discover trading selectors from successful calls with >= 2 swap events in the window. Count-- all successful calls to those selectors, including routes with an undecoded hop. No executor-- address or trading selector is hardcoded (e.g. 0x00000000, 0x33333333, or awesome()). Raw swap-- events cover undecoded venues; dex.trades adds other decoded venues, deduplicated by log index.-- Withdraw/funding calls and single-swap fuel calls have no qualifying selector and are excluded.-- This is a heuristic for arb executors, not a general arb classifier: ordinary multi-hop swaps-- also qualify. A selector needs at least one recognized multi-swap call within the window;-- maintenance calls sharing a trading selector cannot be distinguished by this query.-- profit_weth = WETH Transfers in - out + Deposit - Withdrawal: V4 native-ETH hops-- wrap/unwrap inside the tx, and Base WETH's deposit/withdraw emit Deposit/Withdrawal, not-- Transfer, so Transfers alone read as a big WETH loss. Self-transfers net to zero. Only WETH-- and USDC retained by this address are reported; other tokens, native ETH and payouts to other-- addresses are not included in these profit columns.---- first_block / last_block are the first / last matching tx, not Dune's indexed chain head.WITH txs AS (SELECThash AS tx_hash,block_number,block_time,success,bytearray_substring(data, 1, 4) AS selector,CAST(gas_used AS DECIMAL(38,0)) * CAST(gas_price AS DECIMAL(38,0))+ CAST(COALESCE(l1_fee, 0) AS DECIMAL(38,0)) AS fee_weiFROM base.transactionsWHERE block_number BETWEEN {{start_block}} AND {{end_block}}AND "to" = {{address}}),swap_events AS (SELECT l.tx_hash, l.index AS evt_indexFROM base.logs lJOIN txs x ON x.tx_hash = l.tx_hash AND x.successWHERE l.block_number BETWEEN {{start_block}} AND {{end_block}}AND l.topic0 IN (0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822, -- Uniswap V2 / forks0xb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b, -- Aerodrome V20xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67, -- Uniswap V3 / Slipstream0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83, -- Pancake V30x40e9cecb9f5f1f1c5b9c97dec2917b7ee92e57ba5563708daca94dd84ad7112f, -- Uniswap V40x121cb44ee54098b1a04743c487e7460d8dd429b27f88b1f4d4767396e1a59f79, -- Algebra0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140, -- Curve TokenExchange0x9734819749a91fc3be03ea83205f924ee08479bd3f0da48efc91d94d050cac1e, -- Metric OMM0xfcfa612587d1091cc6d8ce39878a7e6e8742c856865fc9d64db3e1a2f1ab52ef, -- ALTBC0x56441808e0dc590c63862fb3c0c914bff286fc67b3983cd294eb33e21cca326e -- Tessera)UNION -- A decoded trade and its raw Swap log count as one event.SELECT d.tx_hash, d.evt_indexFROM dex.trades dJOIN txs x ON x.tx_hash = d.tx_hash AND x.successWHERE d.blockchain = 'base'AND d.block_number BETWEEN {{start_block}} AND {{end_block}}AND d.block_time BETWEEN (SELECT MIN(block_time) FROM txs) AND (SELECT MAX(block_time) FROM txs)