Skip to content
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

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Sep 11, 2023

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:

  • x/twap will continue to support only 18 decimal prices and not function correctly for pools with smaller spot price
  • x/gamm pools will continue to support 18 decimal spot price only. Fixing/changing them is outside of scope.

Testing and Verifying

  • Covered by existing tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@p0mvn p0mvn added the V:state/compatible/backport State machine compatible PR, should be backported label Sep 11, 2023
@github-actions github-actions bot added C:x/gamm Changes, features and bugs related to the gamm module. C:x/superfluid C:app-wiring Changes to the app folder C:x/concentrated-liquidity C:x/poolmanager labels Sep 11, 2023
@p0mvn p0mvn removed C:x/gamm Changes, features and bugs related to the gamm module. C:x/superfluid labels Sep 11, 2023
@github-actions
Copy link
Contributor

Important Notice

This PR includes modifications to the tests/e2e/initialization module.
Please follow the instructions below:

  1. Backport these changes to the previous Osmosis version's branch.
  2. Run the script inside a Docker container to update genesis and configs for pre-upgrade Osmosis.
  3. Merge the backported changes.
  4. The image will be built and uploaded to Docker Hub here.
  5. Grab the latest image and update it in the PR to the main branch replacing the previousVersionInitTag in the osmosis/tests/e2e/containers/config.go

Please let us know if you need any help.

@p0mvn p0mvn added A:backport/v19.x backport patches to v19.x branch and removed C:app-wiring Changes to the app folder C:x/concentrated-liquidity C:x/poolmanager labels Sep 11, 2023
Comment on lines +121 to 126
// 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
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: tracked in #5726

Comment on lines +219 to +221
// 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))
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: tracked here: #5726

Comment on lines +174 to +176
// TODO: remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete.
// Acceptable for backwards compatibility with v19.x.
return price.Dec(), nil
Copy link
Member Author

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
Copy link
Member Author

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.

Copy link
Member

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

Copy link
Contributor

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

Copy link
Member Author

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

@p0mvn p0mvn marked this pull request as ready for review September 11, 2023 21:44
Copy link
Member

@czarcas7ic czarcas7ic left a 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
Copy link
Member

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

Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu left a 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
Copy link
Contributor

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

@p0mvn
Copy link
Member Author

p0mvn commented Sep 14, 2023

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.

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

@p0mvn
Copy link
Member Author

p0mvn commented Sep 14, 2023

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.

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

@p0mvn p0mvn merged commit 39341fa into main Sep 14, 2023
@p0mvn p0mvn deleted the roman/spot-price-pooli-bigdec branch September 14, 2023 10:35
mergify bot pushed a commit that referenced this pull request Sep 14, 2023
(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
p0mvn added a commit that referenced this pull request Sep 20, 2023
…#6407)

* updates

* fix conflicts in tests

* lint

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: roman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v19.x backport patches to v19.x branch V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants