-
Notifications
You must be signed in to change notification settings - Fork 601
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 spotprice sigfig rounding for small spot prices #1699
Conversation
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.
Nice work!
osmomath/sigfig_round.go
Outdated
dkSigFig := dTimesK.MulInt(tenToSigFig) | ||
numerator := dkSigFig.RoundInt().ToDec() | ||
denominator := tenToSigFig | ||
if k != 0 { |
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.
if k == 0, then tenTok
is 1 so the conditional might be redundant
Please consider removing it. I found translating the comment above directly to code to be very helpful. At first, this check got me confused.
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.
Yeah I guess thats fair, don't need to optimize on two multiplications right now / there are better ways to do that.
|
||
var pointOne = sdk.OneDec().QuoInt64(10) | ||
|
||
func SigFigRound(d sdk.Dec, tenToSigFig sdk.Int) sdk.Dec { |
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.
Let's create an issue to add unit tests directly for this function
* Fix spotprice sigfig rounding for small spot prices * Changelog * Fix off by one in precision * Address PR comment (cherry picked from commit c211999) # Conflicts: # CHANGELOG.md
…1703) * Fix spotprice sigfig rounding for small spot prices (#1699) * Fix spotprice sigfig rounding for small spot prices * Changelog * Fix off by one in precision * Address PR comment (cherry picked from commit c211999) # Conflicts: # CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Dev Ojha <[email protected]>
What is the purpose of the change
Fixes query bug on mainnet, for pools with an asset with
10**18
precision. We passed all spot prices through 8 sig fig rounding, however our sig fig rounding was incorrect for inputs with value less than 1.This fixes a bug with spot price being called on values less than 1.
Brief Changelog
Testing and Verifying
This change added a new test for a large input from mainnet, that was returning 0.
I also checked that spot price is not called anywhere in the state machine, except in the cosmwasm bindings.
We will have to ensure that no contract gets uploaded with spot price calls in the v9.x release series, which was also the general plan since contracts should depend on TWAP not spot price.
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? yes