Feature/volatility circuit breaker#331
Open
dominiccreates wants to merge 4 commits into
Open
Conversation
…o-pause on large price deviation
…tion' into feature/ed25519-signature-validation and implement volatility-based asset circuit breaker
|
@dominiccreates 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.
this pr closes #296 Volatility-Based Circuit Breaker and Compilation Fixes
Description
Extreme flash crashes can drain consumer lending pools before administrators can manually step in to halt operations. This PR adds an automated circuit breaker that temporarily pauses an asset's data feed if a new price submission exceeds a 15% variance threshold.
Additionally, this PR fixes a critical pre-existing compilation error where 19 error variants (e.g., AdminNotSet, InvalidNormalizedPrice, InvalidPriceBounds) were used across the contract source files (lib.rs, auth.rs, math.rs, slashing.rs) but were never defined in the Error enum.
Key Changes
Automated Volatility Circuit Breaker:
Integrated a 15% variance threshold check (CIRCUIT_BREAKER_BPS) in the update_price price submission flow.
Triggers asset-level pausing via _set_asset_paused on deviation > 15%, returning Error::CircuitBreakerTriggered.
Placed this check before the standard max deviation limit check so severe price spikes are correctly caught and trigger a pause instead of a simple validation rejection.
Getter Restrictions:
Modified get_price, get_price_with_status, get_price_safe, and batch getters to fail with Error::AssetPaused (or return None for safe/batch getters) when the target asset feed is paused by the circuit breaker.
Admin Unpause Capabilities:
Added the administrative function unpause_asset allowing authorized admins to lift the circuit breaker pause for a given asset.
Compilation Fixes:
Added all 19 missing/undefined error variants to the contract's Error enum in lib.rs.
Testing:
Added a comprehensive unit test test_asset_circuit_breaker covering positive price submissions, circuit breaker trigger conditions, getter access denials, and administrative unpause actions.