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

feat: make PoolModuleI CalculateSpotPrice API return BigDec #6487

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Sep 21, 2023

Progress towards: #6064

What is the purpose of the change

This PR aims to continue the progress toward introducing a BigDec spot price query.

It should be state-compatible. The current clients are not expected to be broken because we truncate the spot price to 18 decimals before returning.

In the subsequent PR, a new spot price query is to be introduced that returns a 36-decimal spot price.

Testing and Verifying

  • Covered by existing tests
  • To be backported to v19.x and tested on a node

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

@github-actions github-actions bot added C:CLI C:x/gamm Changes, features and bugs related to the gamm module. C:x/txfees C:app-wiring Changes to the app folder C:x/twap Changes to the twap module C:x/concentrated-liquidity C:x/poolmanager labels Sep 21, 2023
@p0mvn p0mvn added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v19.x backport patches to v19.x branch labels Sep 21, 2023
Comment on lines +282 to +284
// TODO: remove Dec truncation before https://github.com/osmosis-labs/osmosis/issues/5726 is complete
// Currently exists for state-compatibility with v19.x
s.Require().Equal(spotPriceBaseETH.Dec(), DefaultCurrSqrtPrice.PowerInteger(2).Dec())
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 #6064

Comment on lines +289 to +291
// TODO: remove Dec truncation before https://github.com/osmosis-labs/osmosis/issues/5726 is complete
// Currently exists for state-compatibility with v19.x
s.Require().Equal(spotPriceBaseUSDC.Dec(), osmomath.OneBigDec().Quo(DefaultCurrSqrtPrice.PowerInteger(2)).Dec())
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 #6064

Comment on lines +48 to +50
// TODO: this is done to maintain state-compatibility with v19.x
// Remove after https://github.com/osmosis-labs/osmosis/issues/6064 is complete.
spotPrice.ChopPrecisionMut(osmomath.PrecisionDec)
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: #6064

Comment on lines +54 to +55
// TODO: remove truncation before https://github.com/osmosis-labs/osmosis/issues/6064 is fully complete.
return &types.QueryDenomSpotPriceResponse{PoolID: feeToken.PoolID, SpotPrice: spotPrice.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 #6064

Comment on lines +35 to +38
// Note: spotPrice truncation is done here for maintaining state-compatibility with v19.x
// It should be changed to support full spot price precision before
// https://github.com/osmosis-labs/osmosis/issues/6064 is complete
return sdk.NewCoin(baseDenom, spotPrice.Dec().MulInt(inputFee.Amount).RoundInt()), 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 #6064

@p0mvn p0mvn marked this pull request as ready for review September 21, 2023 20:23
@p0mvn
Copy link
Member Author

p0mvn commented Sep 22, 2023

Merging with one approval since this is a low-risk change that will be backported to v19.x and tested for state-compat

@p0mvn p0mvn merged commit a171707 into main Sep 22, 2023
1 check passed
@p0mvn p0mvn deleted the roman/spot-price-big-dec branch September 22, 2023 12:10
mergify bot pushed a commit that referenced this pull request Sep 22, 2023
* feat: make PoolModuleI CalculateSpotPrice API  return BigDec

* updates

* clean up

* updates

* updates

(cherry picked from commit a171707)

# Conflicts:
#	CHANGELOG.md
#	app/upgrades/v16/upgrades_test.go
#	app/upgrades/v17/upgrades_test.go
#	x/poolmanager/router.go
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 C:app-wiring Changes to the app folder C:CLI C:x/concentrated-liquidity C:x/gamm Changes, features and bugs related to the gamm module. C:x/poolmanager C:x/twap Changes to the twap module C:x/txfees V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants