Skip to content

feat: Add pending exposure tracking, mm_ratio, and new risk engine commands#40

Merged
shanu516516 merged 2 commits into
mainfrom
bug-indentify
Feb 23, 2026
Merged

feat: Add pending exposure tracking, mm_ratio, and new risk engine commands#40
shanu516516 merged 2 commits into
mainfrom
bug-indentify

Conversation

@shanu516516
Copy link
Copy Markdown
Collaborator

Summary

  • Pending exposure tracking: Added total_pending_long_btc and total_pending_short_btc to the risk_engine_update table, Diesel schema, and MarketRiskStatsResponse. The archiver now persists pending exposure from RiskState on every risk engine event.
  • New risk engine commands: Handle AddPendingExposure, RemovePendingExposure, and RecalculateExposure variants from relayer-core. Each is archived with its position type and amount.
  • mm_ratio risk parameter: Added mm_ratio (maintenance margin ratio) to RiskParams, the risk_params_update table, and the archiver's param-update handler. Defaults to 0.4 via RISK_MM_RATIO env var and #[serde(default)].

Database Migrations

Migration Change
2026-02-21-000000_risk_engine_pending_exposure ALTER TABLE risk_engine_update ADD COLUMN total_pending_long_btc, total_pending_short_btc
2026-02-21-100000_add_mm_ratio_to_risk_params ALTER TABLE risk_params_update ADD COLUMN mm_ratio

Files Changed

  • src/archiver.rs — match arms for 3 new RiskEngineCommand variants; populate pending exposure and mm_ratio fields
  • src/database/models.rstotal_pending_long_btc, total_pending_short_btc on RiskEngineUpdateRow / NewRiskEngineUpdate; mm_ratio on RiskParamsUpdateRow / NewRiskParamsUpdate
  • src/database/schema.rs — Diesel schema updated for both tables
  • src/rpc/types.rsmm_ratio added to RiskParams with serde default; pending fields added to MarketRiskStatsResponse
  • src/rpc/util.rscompute_market_risk_stats now includes pending exposure in response
  • Cargo.toml — relayer-core dependency updated to bug-indentify branch

Test plan

  • cargo check passes — verified
  • Run pending migrations on dev database
  • Verify get_market_stats returns total_pending_long_btc and total_pending_short_btc fields
  • Send AddPendingExposure / RemovePendingExposure / RecalculateExposure events through archiver — rows inserted correctly
  • Verify mm_ratio is persisted in risk_params_update on a RiskParamsUpdate event

- Added new columns `total_pending_long_btc` and `total_pending_short_btc` to the `RiskEngineUpdateRow` and `NewRiskEngineUpdate` structs, as well as the corresponding database schema.
- Implemented new commands in the `DatabaseArchiver` for adding and removing pending exposures, improving risk management capabilities.
- Updated SQL migration files to reflect the addition of new columns for pending exposures in the `risk_engine_update` table.
- Introduced a new column `mm_ratio` in the `risk_params_update` table and corresponding structs in the Rust codebase.
- Updated SQL migration files to add and remove the `mm_ratio` column, ensuring proper database management.
- Implemented default value handling for `mm_ratio` in the `RiskParams` struct, enhancing risk management capabilities.
@shanu516516 shanu516516 merged commit a7b86ef into main Feb 23, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant