-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Add maximum for intent price deviation #468
Conversation
/// @param price The oracle price to compare | ||
/// @return The price deviation of the guarantee from the oracle price | ||
function priceDeviation(Guarantee memory self, Fixed6 price) internal pure returns (UFixed6) { | ||
if (takerTotal(self).isZero()) return UFixed6Lib.ZERO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use taker(self)
here to correspond with the below div
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
takerTotal
is more correct for measuring whether the guarantee is empty, since you can have an aggregated guarantee net to zero, but we need to use taker
in the math below for the sign.
if (takerTotal(self).isZero()) return UFixed6Lib.ZERO; | ||
|
||
Fixed6 guarenteePrice = self.notional.div(taker(self)); | ||
return guarenteePrice.sub(price).div(guarenteePrice.min(price)).abs(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to assume that price
and guaranteePrice
will not be 0 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be possible for price
to be zero due to the latest oracle override.
The guaranteePrice
could be zero, but this would correctly revert due to being infinitely out of range.
Any reverts here would only block a fresh update, it wouldn't brick the settlement flywheel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment stating that, to avoid audit reports on the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments inline.
if (takerTotal(self).isZero()) return UFixed6Lib.ZERO; | ||
|
||
Fixed6 guarenteePrice = self.notional.div(taker(self)); | ||
return guarenteePrice.sub(price).div(guarenteePrice.min(price)).abs(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment stating that, to avoid audit reports on the same.
@@ -49,7 +52,8 @@ using MarketParameterStorageLib for MarketParameterStorage global; | |||
/// uint24 riskFee; // <= 1677% | |||
/// uint16 maxPendingGlobal; // <= 65k | |||
/// uint16 maxPendingLocal; // <= 65k | |||
/// uint48 __unallocated__; // <= 281m | |||
/// uint24 maxPriceDeviation; // <= 16.77x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: // <= 1677%
seems more consistent and appropriate here
function priceDeviation(Guarantee memory self, Fixed6 price) internal pure returns (UFixed6) { | ||
if (takerTotal(self).isZero()) return UFixed6Lib.ZERO; | ||
|
||
Fixed6 guarenteePrice = self.notional.div(taker(self)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spelling guaranteePrice
[Periphery] Unit Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
[Core] Integration Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👨🍳👌
[Periphery] Integration Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
[Periphery] Combined Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
[Core] Unit Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
[Core] Combined Test Coverage ReportCoverage after merging britz-add-price-override-bound into v2.3-fix-review will be
Coverage Report
|
Adds a new market parameter:
maxPriceDeviation
which caps the geometric distance that the quoted intent price can be from the underlying oracle price.Suggested change from: sherlock-audit/2024-08-perennial-v2-update-3-judging#42.