Query editor
/* -------------------------------------------------------------------------1. Any event that can change a strategy’s debt ratio• StrategyDebtRatioSet → real _debtRatio• StrategyRetired → _debtRatio := 0------------------------------------------------------------------------- */WITH ratio_events AS (SELECT_strategy,_debtRatio AS debt_ratio, -- basis‑points (0‑10 000)evt_block_timeFROM goatfi_arbitrum.ycusdt_evt_strategydebtratiosetUNION ALLSELECT_strategy,0 AS debt_ratio, -- retirement freezes it at 0evt_block_timeFROM goatfi_arbitrum.ycusdt_evt_strategyretired),/* -------------------------------------------------------------------------2. Keep only the single *latest* row per strategy------------------------------------------------------------------------- */latest AS (SELECT_strategy,debt_ratioFROM (SELECT_strategy,debt_ratio,ROW_NUMBER() OVER (PARTITION BY _strategyORDER BY evt_block_time DESC) AS rnFROM ratio_events) tWHERE rn = 1),/* -------------------------------------------------------------------------3 Relies on debt ratios summing to 10 000 bp------------------------------------------------------------------------- */simple AS (SELECT_strategy,ROUND(debt_ratio / 100.0, 2) AS pct_allocation -- 4250 bp → 42.50 %FROM latestWHERE debt_ratio > 0 -- drop retired (0 %) if desired)/* -------------------------------------------------------------------------4. Pick one of the two final SELECTs below------------------------------------------------------------------------- */SELECT * FROM simple ORDER BY pct_allocation DESC;