-
Notifications
You must be signed in to change notification settings - Fork 613
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
refactor: break PoolI.SpotPrice API to return BigDec #6372
Conversation
Important Notice This PR includes modifications to the
Please let us know if you need any help. |
// The reason why we convert the result to Dec and then back to BigDec is to temporarily | ||
// maintain backwards compatibility with the original implementation. | ||
// TODO: remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete | ||
if baseAssetDenom == p.Token0 { | ||
return p.CurrentSqrtPrice.PowerInteger(2).Dec(), nil | ||
return osmomath.BigDecFromDec(p.CurrentSqrtPrice.PowerInteger(2).Dec()), nil | ||
} |
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: tracked in #5726
// TODO: truncation is acceptable temporary | ||
// remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete | ||
s.Require().True(spotPriceFromMethod.Dec().Sub(tc.expectedSpotPrice).Abs().LT(elipson)) |
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: tracked here: #5726
// TODO: remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete. | ||
// Acceptable for backwards compatibility with v19.x. | ||
return price.Dec(), nil |
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: tracked here: #5726
return osmomath.MustNewDecFromStr(response.SpotPrice), nil | ||
return osmomath.MustNewBigDecFromStr(response.SpotPrice), nil |
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.
Reviewer, please pay closer attention to this. I think it is acceptable to convert this to BigDec from string directly instead of string -> Dec -> BigDec but would like some more eyes.
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.
This seems fine to me
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.
This seems okay conceptually but would be great to have tests for it to be sure
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.
Thanks.
On another look, will make an issue to error as opposed to panic in the conversion. Will try to see if I can test this without having to modify the transmuter contract as well
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, question on one of your assumption though. You said twap will continue to only support 18 dec precision to be compatible with pools with smaller spot price. Did you mean that this is the behavior due to this PR or is this the desired end state? If the former, cant we support the full precision in the twap records? If the latter, then disregard.
return osmomath.MustNewDecFromStr(response.SpotPrice), nil | ||
return osmomath.MustNewBigDecFromStr(response.SpotPrice), nil |
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.
This seems fine to me
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, seems in alignment with offline discussions. Had one light request for tests on the CW pool conversion but I think it's okay to do that in a separate PR to not block this one.
return osmomath.MustNewDecFromStr(response.SpotPrice), nil | ||
return osmomath.MustNewBigDecFromStr(response.SpotPrice), nil |
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.
This seems okay conceptually but would be great to have tests for it to be sure
This is the end state. We can but this is outside of scope of this work. This can be done in the future if there is a need for it |
Issue made: #6406 |
(cherry picked from commit 39341fa) # Conflicts: # app/apptesting/gamm.go # tests/e2e/initialization/config.go # x/concentrated-liquidity/model/pool.go # x/concentrated-liquidity/model/pool_test.go # x/concentrated-liquidity/pool.go # x/concentrated-liquidity/swaps_test.go # x/cosmwasmpool/model/pool.go # x/cosmwasmpool/model/pool_test.go # x/cosmwasmpool/model/store_model.go # x/gamm/keeper/pool_service_test.go # x/gamm/pool-models/balancer/pool.go # x/gamm/pool-models/stableswap/pool.go # x/poolmanager/types/pool.go # x/superfluid/keeper/migrate_test.go
…#6407) * updates * fix conflicts in tests * lint * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: roman <[email protected]>
Progress towards: #6064
What is the purpose of the change
This PR is an incremental step towards implementing a 36 decimal spot price query.
The proposal and demo of what the end result would roughly look like can be seen here: #6371
The goal is to incrementally break APIs in a state-compatible manner while backporting them to
v19.x
The assumptions made:
Testing and Verifying
Documentation and Release Note
Unreleased
section ofCHANGELOG.md
?Where is the change documented?
x/{module}/README.md
)