feat(contract): Reflector oracle cross-asset sanity checks (D12)#186
Open
cybermax4200 wants to merge 1 commit into
Open
feat(contract): Reflector oracle cross-asset sanity checks (D12)#186cybermax4200 wants to merge 1 commit into
cybermax4200 wants to merge 1 commit into
Conversation
- oracle.rs: OracleClient (shared interface for Blend + Reflector), assert_price_aligned(), normalise_to_7(), oracle/diverge event - storage.rs: Config gains reflector: Option<Address> and oracle_threshold: i128 (bps) - lib.rs: declare oracle mod, parse args[8]/[9] in constructor (optional, default threshold 200 bps), call assert_price_aligned at start of deposit() and rebalance() - Tests: normalise_to_7 unit tests, aligned/diverging/at-threshold/ downtime/stale coverage in oracle::tests Closes Dgetsylver#53
|
@cybermax4200 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! 🚀 |
Owner
|
Thanks — this is valuable (oracle divergence guard). It isn't on |
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
Adds a Reflector oracle divergence guard to the blend_leverage strategy. Before executing a deposit or rebalance, the contract fetches prices from both Blend's internal oracle and Reflector and refuses if they diverge beyond a configurable threshold.
Changes
oracle.rs (new)
OracleClient— single contractclient trait covering both Blend's oracle and Reflector (same interface)assert_price_aligned(e, config)— fetches both prices, normalises to 1e7, computes divergence in bps, emitsoracle/divergeevent and returnsExternalErroron failurenormalise_to_7(price, decimals)— converts any decimal precision to Blend's 1e7 scalestorage.rs
Configgainsreflector: Option<Address>andoracle_threshold: i128Nonereflector disables the guard (backward compatible)lib.rs
args[8](reflector, optional) andargs[9](threshold bps, default 200)deposit()callsoracle::assert_price_alignedbefore any pool interactionrebalance()callsoracle::assert_price_alignedafter the debt checkTests (oracle::tests)
test_no_oracle_configured_passes— guard disabled when reflector is Nonetest_aligned_divergence_zero— 0 bps divergence passestest_diverging_prices_exceed_threshold— 500 bps > 200 bps threshold refusedtest_divergence_at_threshold_passes— exactly at threshold passes (not strictly greater)test_oracle_downtime_returns_none— None response refusedtest_stale_price_detected— price older than 300s refusedtest_normalise_*— 14→7, 7→7, 4→7 decimal conversionsCloses #53