Query editor
-- Contract-wide concurrent-fill exposure on a Bebop-style settlement contract.---- For fills with amount_usd <= cap_usd in [start_date, end_date), computes:-- * rolling fill count in any window of `window_seconds` seconds (peak / p95 / p99)-- * rolling USD volume in the same window (p50 / p95 / p99 / peak)-- Plus per-fill size percentiles (p50 / p95 / p99) within the cap.---- Window semantics: per-fill rolling SUM/COUNT over [block_time - S, block_time],-- so the percentile is over fill-arrival moments (not time).---- Parameters:-- cap_usd : per-fill USD ceiling (only fills <= cap counted)-- window_seconds : rolling-window size, e.g. "5" or "10"-- start_date / end_date : block_date range (inclusive / exclusive)-- project_contract_address : settlement contract literal, e.g. 0xbbbb...---- See docs/MAKER-SIZING-METHODOLOGY.md for the framework that uses this.WITH filtered AS (SELECT block_time, amount_usdFROM bebop_base.tradesWHERE block_date >= DATE '{{start_date}}'AND block_date < DATE '{{end_date}}'AND project_contract_address = {{project_contract_address}}AND amount_usd > 0AND amount_usd <= {{cap_usd}}),rolled AS (SELECTamount_usd,COUNT(*) OVER (ORDER BY block_timeRANGE BETWEEN INTERVAL '{{window_seconds}}' SECOND PRECEDING AND CURRENT ROW) AS cnt_w,SUM(amount_usd) OVER (ORDER BY block_timeRANGE BETWEEN INTERVAL '{{window_seconds}}' SECOND PRECEDING AND CURRENT ROW) AS usd_wFROM filtered)SELECTCOUNT(*) AS fills,SUM(amount_usd) AS usd_total,approx_percentile(amount_usd, 0.50) AS fill_p50,approx_percentile(amount_usd, 0.95) AS fill_p95,approx_percentile(amount_usd, 0.99) AS fill_p99,MAX(cnt_w) AS peak_cnt,approx_percentile(cnt_w, 0.95) AS cnt_p95,approx_percentile(cnt_w, 0.99) AS cnt_p99,approx_percentile(usd_w, 0.50) AS usd_p50,approx_percentile(usd_w, 0.95) AS usd_p95,approx_percentile(usd_w, 0.99) AS usd_p99,MAX(usd_w) AS usd_peakFROM rolled