Query editor
-- Aftermath Perps: taker markouts by gas bid (RGP toxicity filter)-- One row per FilledTakerOrder. drift_after_fill = side x (mark at t+h - mark at fill) / mark at fill: information, excluding the spread paid.-- Markout = side x (mark at t+h - fill price) / fill price, bps, notional-weighted.-- Gas buckets: at RGP; just above RGP (the priority taker fee applies to any bid strictly above RGP); 2x RGP or more.with params as (select 7 as days, 100 as rgp -- RGP was 100 MIST in every epoch of this window),ev as (select e.transaction_digest as tx, e.event_index, e.date, e.timestamp_ms as ts, e.event_json as jfrom sui.events ewhere e.date >= current_date - (select days from params) * interval '1' dayand e.event_type = '0x3ec740df8428aa9c93aaef7f8cc1542ac3194fd014826b51bfe245346d64efc7::events::FilledTakerOrder'),f as (selecttx, event_index, date, ts,json_extract_scalar(j, '$.ch_id') as ch_id,cast(json_extract_scalar(j, '$.base_asset_delta_bid') as double) / 1e18 as b_bid,cast(json_extract_scalar(j, '$.base_asset_delta_ask') as double) / 1e18 as b_ask,(cast(json_extract_scalar(j, '$.quote_asset_delta_bid') as double)+ cast(json_extract_scalar(j, '$.quote_asset_delta_ask') as double)) / 1e18 as notional,cast(json_extract_scalar(j, '$.taker_fees') as double) / 1e18 as fee_usd,cast(json_extract_scalar(j, '$.mark_price') as double) / 1e18 as markfrom ev),liq as (-- transactions that liquidated a position: excluded, since liquidator fills are not discretionary taker flowselect distinct transaction_digest as txfrom sui.eventswhere date >= current_date - (select days from params) * interval '1' dayand event_type = '0x3ec740df8428aa9c93aaef7f8cc1542ac3194fd014826b51bfe245346d64efc7::events::LiquidatedPosition'),fills as (select f.*, case when b_bid > 0 then 1 else -1 end as side, notional / (b_bid + b_ask) as px, ts / 1000 as secfrom f where b_bid + b_ask > 0and f.tx not in (select tx from liq)),-- last mark price per market per secondmarks as (select ch_id, sec, max_by(mark, ts) as mark from fills group by 1, 2),gas as (select t.transaction_digest as tx, t.gas_pricefrom sui.transactions tjoin (select distinct tx, date from fills) fxon fx.tx = t.transaction_digestand fx.date = t.datewhere t.date >= current_date - (select days from params) * interval '1' day),h as (selectx.tx, x.event_index, x.side, x.notional, x.px, x.mark, x.fee_usd,max_by(m.mark, m.sec) filter (where m.sec <= x.sec + 1) as m1,max_by(m.mark, m.sec) filter (where m.sec <= x.sec + 5) as m5,max_by(m.mark, m.sec) filter (where m.sec <= x.sec + 30) as m30,max_by(m.mark, m.sec) filter (where m.sec <= x.sec + 60) as m60from fills xjoin marks m on m.ch_id = x.ch_id and m.sec between x.sec and x.sec + 60group by 1, 2, 3, 4, 5, 6, 7)