Skip to content

Feature/volatility circuit breaker#331

Open
dominiccreates wants to merge 4 commits into
StellarFlow-Network:mainfrom
dominiccreates:feature/volatility-circuit-breaker
Open

Feature/volatility circuit breaker#331
dominiccreates wants to merge 4 commits into
StellarFlow-Network:mainfrom
dominiccreates:feature/volatility-circuit-breaker

Conversation

@dominiccreates
Copy link
Copy Markdown

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.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@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! 🚀

Learn more about application limits

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.

📊 Contracts | Volatility-Based Circuit Breaker Trigger

1 participant