-
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
feat(x/twap): use exp2 in twapPow; add overflow test #3809
Conversation
if exponent.IsNegative() { | ||
return osmomath.OneDec().Quo(exp2).SDKDec() | ||
} |
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.
Note: this is possible if sp0 is < 1
Currently, there is a micro-optimization possible to avoid taking 1 / result
twice. This happens when:
arithmeticMeanOfLogPrices.IsNegative() && quoteAsset == startRecord.Asset1Denom
I'm planning to revisit this in the future
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.
tracked in: #3541
amazing the TWAP testing time spent in pow has 10x decreased, great sign for our Exp2 fn :) |
x/twap/strategy_test.go
Outdated
RoundingDir: osmomath.RoundDown, | ||
} | ||
|
||
oneYear := OneSec.MulInt64(60 * 60 * 24 * 365) |
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.
Can we test w/ 100 years 👀
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.
Do we also need to test min spot price, since this can get underflow? (or is that a future PR?)
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.
(not blocking merge, as long as we track in an issue otherwise)
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.
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.
Tested with 100 years - will address underflow in #3815
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.
LGTM aside from my overflow & underflow comment!
Co-authored-by: Dev Ojha <[email protected]>
Closes: #3540
What is the purpose of the change
This PR switches to use the new
Exp2
function (#3708) in x/twap for computing geometric twap.It also adds a test at max spot price, showing that there is no overflow.
Testing and Verifying
This change added overflow test and refactored twap math function tests to be simpler.
Note that adding more hand-calculated tests is tracked in: #3541
On top of this PR, I made a PR with query tests that currently pass: #3802
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? no