feat: add oracle price deviation bound to resolution path#575
Merged
greatest0fallt1me merged 2 commits intoMay 29, 2026
Merged
Conversation
- Add max_deviation_bps: Option<u32> to GlobalOracleValidationConfig and EventOracleValidationConfig in types.rs (None = disabled, backward-compat) - validate_oracle_data in OracleValidationConfigManager now checks the fetched price against the last accepted reference price stored per market; deviation > max_deviation_bps returns Err(OracleNoConsensus) and emits an oracle_validation_failed event with reason 'price_deviation_exceeded' - First reading (no reference stored) is always accepted and stored - add get_reference_price helper for test inspection - validate_config_values rejects deviation = 0 or > 10_000 bps - Wire set_oracle_val_cfg_global / set_oracle_val_cfg_event entrypoints through to OracleValidationConfigManager (removes 'temporarily disabled') - get_oracle_val_cfg_effective now returns live config instead of hardcoded defaults - Update all existing struct construction sites and tests with new field - 6 new deviation tests: first-reading, within-bound, exactly-at-bound, spike-beyond-bound, disabled-when-none, per-event-override
|
@Vvictor-commits Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #554
Summary
Adds a configurable price deviation guard to the oracle validation path. A Reflector (or any oracle) price that moves beyond a configured percentage from the last accepted reading is rejected before it can influence market resolution — closing a key oracle manipulation vector.
Changes
types.rsmax_deviation_bps: Option<u32>toGlobalOracleValidationConfigandEventOracleValidationConfigNonedisables the check (fully backward-compatible)oracles.rs—OracleValidationConfigManagervalidate_oracle_datanow runs a deviation check after staleness/confidence:("ORC_REF", market_id))deviation_bps = abs(price - ref) * 10_000 / ref; if> max_deviation_bps→Err(OracleNoConsensus)+oracle_validation_failedevent with reasonprice_deviation_exceededget_reference_pricehelper (used by tests)validate_config_valuesrejectsmax_deviation_bps = 0or> 10_000set_global_config/set_event_configlib.rsset_oracle_val_cfg_globalandset_oracle_val_cfg_eventaccept newmax_deviation_bps: Option<u32>param and call through toOracleValidationConfigManagerget_oracle_val_cfg_effectivereturns live config instead of hardcoded defaultsTests (6 new, inline in
oracles.rs)test_deviation_first_reading_accepted_and_storedtest_deviation_within_bound_acceptedtest_deviation_exactly_at_bound_acceptedtest_deviation_spike_beyond_bound_rejectedOracleNoConsensus+ eventtest_deviation_disabled_when_nonemax_deviation_bps: None→ 50% move passestest_deviation_per_event_overrideRun tests