Query editor
-- pmm_by_pair-- Per-pair fill and USD volume breakdown with maker_bucket dimension.-- Restricted to top 20 pairs globally (by total usd_volume).WITH base AS (SELECTamount_usd,token_pair,CASE LOWER(to_hex(maker))WHEN '51c72848c68a965f66fa7a88855f9f7784502a7f' THEN 'top1_51c7'WHEN '4446adc0b8136ffc55ddb7a488ba5509ace2a5ef' THEN 'top2_4446'WHEN 'b7131fc8cdc43060a6210257f537dba5fcae6aed' THEN 'top3_b713'WHEN '6047b384d58dc7f8f6fef85d75754e6928f06484' THEN 'top4_6047'WHEN LOWER(REGEXP_REPLACE(COALESCE('{{our_maker_address}}', ''), '^0x', ''))THEN 'ours'ELSE 'other'END AS maker_bucketFROM bebop_base.tradesWHERE project_contract_address = 0xbbbbbbb520d69a9775e85b458c58c648259fad5fAND block_date >= DATE '{{start_date}}'AND block_date < DATE '{{end_date}}'AND amount_usd > 0AND ('{{pair_filter}}' = ''OR token_pair IN (SELECT TRIM(x) FROM UNNEST(SPLIT('{{pair_filter}}', ',')) AS t(x)))),top_pairs AS (SELECT token_pairFROM baseGROUP BY token_pairORDER BY SUM(amount_usd) DESCLIMIT 20),scoped AS (SELECT * FROM base WHERE token_pair IN (SELECT token_pair FROM top_pairs)),agg AS (SELECTCOALESCE(maker_bucket, 'ALL') AS maker_bucket,token_pair AS pair,COUNT(*) AS fills,SUM(amount_usd) AS usd_volumeFROM scopedGROUP BY GROUPING SETS ((maker_bucket, token_pair), (token_pair)))SELECTmaker_bucket,pair,fills,usd_volume,100.0 * fills / SUM(fills) OVER (PARTITION BY maker_bucket) AS share_fills_pct,100.0 * usd_volume / NULLIF(SUM(usd_volume) OVER (PARTITION BY maker_bucket), 0)AS share_usd_pctFROM aggORDER BYCASE maker_bucketWHEN 'ALL' THEN 0