feat: Add pending exposure tracking, mm_ratio, and new risk engine commands#40
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
total_pending_long_btcandtotal_pending_short_btcto therisk_engine_updatetable, Diesel schema, andMarketRiskStatsResponse. The archiver now persists pending exposure fromRiskStateon every risk engine event.AddPendingExposure,RemovePendingExposure, andRecalculateExposurevariants from relayer-core. Each is archived with its position type and amount.mm_ratiorisk parameter: Addedmm_ratio(maintenance margin ratio) toRiskParams, therisk_params_updatetable, and the archiver's param-update handler. Defaults to0.4viaRISK_MM_RATIOenv var and#[serde(default)].Database Migrations
2026-02-21-000000_risk_engine_pending_exposureALTER TABLE risk_engine_update ADD COLUMN total_pending_long_btc,total_pending_short_btc2026-02-21-100000_add_mm_ratio_to_risk_paramsALTER TABLE risk_params_update ADD COLUMN mm_ratioFiles Changed
src/archiver.rs— match arms for 3 newRiskEngineCommandvariants; populate pending exposure andmm_ratiofieldssrc/database/models.rs—total_pending_long_btc,total_pending_short_btconRiskEngineUpdateRow/NewRiskEngineUpdate;mm_ratioonRiskParamsUpdateRow/NewRiskParamsUpdatesrc/database/schema.rs— Diesel schema updated for both tablessrc/rpc/types.rs—mm_ratioadded toRiskParamswith serde default; pending fields added toMarketRiskStatsResponsesrc/rpc/util.rs—compute_market_risk_statsnow includes pending exposure in responseCargo.toml— relayer-core dependency updated tobug-indentifybranchTest plan
cargo checkpasses — verifiedget_market_statsreturnstotal_pending_long_btcandtotal_pending_short_btcfieldsAddPendingExposure/RemovePendingExposure/RecalculateExposureevents through archiver — rows inserted correctlymm_ratiois persisted inrisk_params_updateon aRiskParamsUpdateevent