fix(marginfi-client-v2): cap PythLegacy confidence interval at MAX_CONFIDENCE_INTERVAL_RATIO - #1140
Open
latent-9 wants to merge 1 commit into
Open
fix(marginfi-client-v2): cap PythLegacy confidence interval at MAX_CONFIDENCE_INTERVAL_RATIO#1140latent-9 wants to merge 1 commit into
latent-9 wants to merge 1 commit into
Conversation
…NFIDENCE_INTERVAL_RATIO
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.
What
For
OracleSetup.PythLegacybanks the price confidence interval is effectively not capped.parseOraclePriceDatapassesPYTH_PRICE_CONF_INTERVALS(2.12) as the cap ratio tocapConfidenceInterval, instead of theMAX_CONFIDENCE_INTERVAL_RATIO(0.05) that every other oracle path uses.Why
capConfidenceInterval(price, confidence, maxConfidence)returnsmin(confidence, price * maxConfidence), so the third argument is the fraction of price the confidence is capped at. The PythLegacy branch passesPYTH_PRICE_CONF_INTERVALS:PYTH_PRICE_CONF_INTERVALSis the standard deviation multiplier already applied to the raw confidence a few lines above; it is not a cap ratio. Using it as the cap makes the ceilingprice * 2.12(212 percent of price), which the confidence never reaches, so the interval is uncapped for legacy Pyth banks. Every other branch in this function (PythPushOracle, SwitchboardV2, SwitchboardPull) passesMAX_CONFIDENCE_INTERVAL_RATIO(0.05).The effect is a wider low and high price band than intended. Example at price 100 with a published confidence of 8, so the scaled confidence is
8 * 2.12 = 16.96:min(16.96, 100 * 2.12) = 16.96, lowest price 83.04min(16.96, 100 * 0.05) = 5, lowest price 95.00So the SDK values PythLegacy collateral about 12 percent below what the 5 percent cap gives, and over weights liabilities symmetrically.
Change
Pass
MAX_CONFIDENCE_INTERVAL_RATIOas the cap in both PythLegacycapConfidenceIntervalcalls, matching the other oracle paths. ThePYTH_PRICE_CONF_INTERVALSmultiplier on the raw confidence is unchanged.