Skip to content

FLO-19 Update Price Deviation to Use DEX Price as Base#206

Open
holyfuchs wants to merge 5 commits intomainfrom
holyfuchs/FLO-19-dexOraclePriceDeviationInRange
Open

FLO-19 Update Price Deviation to Use DEX Price as Base#206
holyfuchs wants to merge 5 commits intomainfrom
holyfuchs/FLO-19-dexOraclePriceDeviationInRange

Conversation

@holyfuchs
Copy link
Member

@holyfuchs holyfuchs commented Mar 5, 2026

Closes: #228

What Changed
Updated the deviation denominator from min(dexPrice, oraclePrice) to a fixed dexPrice.

Why
Since we are swapping at the DEX price, it represents our actual execution value. We use it as the "ground truth" so that the deviation check is always relative to the price we are actually paying or receiving.

The Math
By using the execution price as the base, the 1000 bps (10%) threshold creates a consistent safety buffer:

$$\text{Deviation} = \frac{|dexPrice - oraclePrice|}{dexPrice}$$

Example (1000 bps / 10% Threshold):

  • If DEX Price is 100:
  • |100 - 90| / 100 = 0.10 (1000 bps) -> Pass
  • |100 - 110| / 100 = 0.10 (1000 bps) -> Pass
  • Result: Symmetric +/- 10 range (90–110).

@holyfuchs holyfuchs requested a review from a team as a code owner March 5, 2026 15:48
Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Quantstamp audit mentions this as well (FLO-19), but suggests the opposite resolution (use the oracle price as the denominator in all cases).

My 2c is that there is no unambiguously "right" answer to this problem. I still have a slight preference for the way it is now, because it is the most conservative way to compute the deviation (you will reject more pairs of oraclePrice, dexPrice values), but don't have a super strong opinion.

@holyfuchs holyfuchs changed the title Update Price Deviation to Use DEX Price as Base FLO-19 Update Price Deviation to Use DEX Price as Base Mar 6, 2026
@holyfuchs holyfuchs force-pushed the holyfuchs/FLO-19-dexOraclePriceDeviationInRange branch from 52e73ee to c1b5edb Compare March 6, 2026 10:16
@holyfuchs
Copy link
Member Author

Should we even care if the DEX gives a better price than the oracle?

Thinking about it again, the oracle is an aggregate that already includes DEX data and also checks deviation between the 2 prices. It makes more sense to use it as the "ground truth" and only allow a specific deviation from that value.

If the Oracle is $1,000 and we allow 1% slippage: DEX is allowed to return 990$

@holyfuchs holyfuchs force-pushed the holyfuchs/FLO-19-dexOraclePriceDeviationInRange branch from c1b5edb to a6a798a Compare March 6, 2026 11:53
@holyfuchs holyfuchs force-pushed the holyfuchs/FLO-19-dexOraclePriceDeviationInRange branch from a6a798a to 044198d Compare March 6, 2026 11:54
@holyfuchs holyfuchs requested a review from a team March 13, 2026 09:20
/// Checks that the DEX price does not deviate from the oracle price by more than the given threshold.
/// The deviation is computed as the absolute difference divided by the smaller price, expressed in basis points.
/// Checks if the DEX price deviates from the oracle price by more than the allowed threshold (in basis points).
/// The deviation is measured relative to the oracle price, which is treated as the reference price.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new implementation, because it's simple, easier to remember (does what the function name says) and reason about since it removes an if-check.

If we need the behavior of existing implementation, which has a slight bias, then I would change the function to take two DeviationBps, (instead of one) one for the case when dexPrice < oraclePrice, the other for the opposite case. But I'm not sure if that complexity is always better. I'm still prefer simplicity.

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.

FLO-19: dexOraclePriceDeviationInRange() Enforces Asymmetric Price Bounds

3 participants