Query editor
-- Sandwich pipeline, the transfer taxes each attacker paid for one UTC day (rules change 14, GitHub issue 2). A token that-- taxes or burns on transfer takes part of what the attacker buys or sells; the pool's swap amounts never see it, so the-- surplus they show counts that tax as tokens the attacker kept. The rolling view (recent_rolling.sql) subtracts it.-- Reads the day's enriched table and the ERC-20 Transfer events of the attacker's transactions in each Tier 1 and 2-- bracket: the front-run, its legs, the back-run and its unwinds. The attacker is every address that acts for it there:-- the signers, the entry contracts and the swap recipients of the front-run and the back-run, and inside an unwind leg's-- own transaction that leg's signer and entry contract, since the legs of a split back-run (rules change 15) share no-- actor with it. A tax is a transfer of either pool token to the zero address, the dead address or the token's own-- contract, sent by the attacker (a tax on its sell) or by the pool (a tax on its buy), unless that address is the pool-- itself, as for a token traded through its own contract. Builder payments and profit sweeps go elsewhere and are not-- taxes: gross profit stays before them. The attacker's net change in each token is kept for audit: transfers to its-- addresses minus transfers out of them.-- The transfer table's own transaction index is empty on BNB (checked 2026-10-02), so the member transactions are found by-- index in bnb.transactions first. A Uniswap V4 or Infinity pool has no address, so only the attacker's side is read there.-- Tokens: ENRICHED, DAY.WITH i AS (SELECT instance_id, block_number, from_hex(substr(token_lo, 3)) AS token_lo, from_hex(substr(token_hi, 3)) AS token_hi,CASE WHEN length(venue_key) = 42 THEN from_hex(substr(venue_key, 3)) END AS pool,array_distinct(concat(array[f_tx_index, b_tx_index], coalesce(leg_tx_indices, array[]), coalesce(unwind_tx_indices, array[]))) AS member_tx,coalesce(unwind_tx_indices, array[]) AS unwind_tx,transform(filter(array_distinct(array[f_from, f_to, f_taker, b_from, b_to, b_taker]), a -> a IS NOT NULL),a -> from_hex(substr(a, 3))) AS actorsFROM dune.blockspace_forensics_consortium.result_sw_day_20261130),m AS ( -- one row per bracket and member transactionSELECT i.instance_id, i.block_number, i.token_lo, i.token_hi, i.pool, i.actors, t.tx_index, contains(i.unwind_tx, t.tx_index) AS is_unwindFROM iCROSS JOIN UNNEST(i.member_tx) AS t(tx_index)),mt AS ( -- the member transactions' hashes, and in an unwind leg its own signer and entry contract among the attacker's addressesSELECT m.instance_id, m.block_number, m.token_lo, m.token_hi, m.pool,CASE WHEN m.is_unwind THEN concat(m.actors, filter(array[x."from", x.to], a -> a IS NOT NULL)) ELSE m.actors END AS actors,x.hash AS tx_hashFROM mJOIN bnb.transactions x ON x.block_date = date '2026-11-30' AND x.block_number = m.block_number AND x.index = m.tx_index),tr AS ( -- each transfer of either pool token in a member transaction that involves the attacker or is sent by the poolSELECT mt.instance_id, t.contract_address = mt.token_lo AS is_lo, cast(t.value AS double) AS amount,contains(mt.actors, t."from") AS from_attacker, contains(mt.actors, t."to") AS to_attacker,(t."to" IN (0x0000000000000000000000000000000000000000, 0x000000000000000000000000000000000000dead) OR t."to" = t.contract_address)AND (contains(mt.actors, t."from") OR t."from" = mt.pool) AND NOT coalesce(t."to" = mt.pool, false) AS is_taxFROM mtJOIN erc20_bnb.evt_Transfer tON t.evt_block_date = date '2026-11-30' AND t.evt_block_number = mt.block_number AND t.evt_tx_hash = mt.tx_hashAND (t.contract_address = mt.token_lo OR t.contract_address = mt.token_hi)WHERE contains(mt.actors, t."from") OR contains(mt.actors, t."to") OR t."from" = mt.pool)SELECT date '2026-11-30' AS day, i.instance_id,coalesce(sum(tr.amount) FILTER (WHERE tr.is_lo AND tr.is_tax), 0) AS tax_lo_raw,coalesce(sum(tr.amount) FILTER (WHERE NOT tr.is_lo AND tr.is_tax), 0) AS tax_hi_raw,coalesce(sum(CASE WHEN tr.to_attacker THEN tr.amount ELSE 0 END - CASE WHEN tr.from_attacker THEN tr.amount ELSE 0 END)FILTER (WHERE tr.is_lo), 0) AS net_lo_raw,coalesce(sum(CASE WHEN tr.to_attacker THEN tr.amount ELSE 0 END - CASE WHEN tr.from_attacker THEN tr.amount ELSE 0 END)FILTER (WHERE NOT tr.is_lo), 0) AS net_hi_raw,count(tr.instance_id) AS transfers,max(cardinality(i.member_tx)) AS member_transactionsFROM iLEFT JOIN tr ON tr.instance_id = i.instance_idGROUP BY 1, 2