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

[CL]: Increase min tick past canonical tick range #5551

Merged
merged 15 commits into from
Jun 21, 2023

Conversation

AlpinYukseloglu
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu commented Jun 16, 2023

Closes: #5550

What is the purpose of the change

This PR moves the min tick & min spot price for CL up to past the point where canonical ticks start to matter.

Due to a majority of test vectors relating to min tick or full range being hard coded and/or manually computed, this change broke many more tests than we originally expected. Most of them have been amended and modularized to not break for future changes, and the remaining ones were recomputed with the math documented in comments

Testing and Verifying

All relevant tests were amended to refer to the new min tick/min price. Where applicable, types.MinTick was used in place of hard coded values to make future changes break fewer 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

@github-actions github-actions bot added C:x/gamm Changes, features and bugs related to the gamm module. C:x/superfluid labels Jun 21, 2023
defaultErrorTolerance := osmomath.ErrTolerance{
AdditiveTolerance: sdk.NewDec(100),
AdditiveTolerance: sdk.NewDec(100000),
Copy link
Contributor Author

@AlpinYukseloglu AlpinYukseloglu Jun 21, 2023

Choose a reason for hiding this comment

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

Note to reviewer: sorry for the large comment here, but wanted to make sure our tolerances aren't arbitrary.

A good sanity check for this change is that increasing min price by 10^6 increases min sqrt price by 10^3, so it follows that liquidity calculations (most of which are done in sqrt price domain should shift by 10^3

@@ -162,7 +162,7 @@ func (s *KeeperTestSuite) TestUpdateHighestLiquidityPools() {
},
expectedBaseDenomPools: map[string]map[string]keeper.LiquidityPoolStruct{
"epochTwo": {
"uosmo": {Liquidity: sdk.Int(sdk.NewUintFromString("999999999000000001000000000000000000")), PoolId: 49},
"uosmo": {Liquidity: sdk.Int(sdk.NewUintFromString("999999000000000001000000000000000000")), PoolId: 49},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewer: this number seemed right based on the migration calculations (above) and superfluid calculations (below), but admittedly I did slightly eyeball this as the underlying test components are quite obscure

(there's 0 documentation on where this number comes from, although I can infer it's the asset1 amount for a set of full range positions)

@AlpinYukseloglu AlpinYukseloglu marked this pull request as ready for review June 21, 2023 17:35
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +833 to +835
// Note that these numbers were calculated using `GetLiquidityFromAmounts` and `TickToSqrtPrice` and thus assume correctness of those functions.
// https://www.wolframalpha.com/input?i=212041526.154556192317664016+*+%2870.728769315114743566+-+0.000001000000000000%29
amount1Expected: sdk.NewInt(14997435977),
Copy link
Member

Choose a reason for hiding this comment

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

Note that these numbers were calculated using GetLiquidityFromAmounts and TickToSqrtPrice and thus assume correctness of those functions.

Are you explaining being off by one compared to the Wolfram calculation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes sorry – the expected output is bankers rounded instead of truncated due to GetLiquidityFromAmounts being bankers rounded. This does not pose any security risks as the balance is still deducted from the caller.

@@ -1405,89 +1405,3 @@ func (s *KeeperTestSuite) TestValidateTickRangeIsValid() {
})
}
}

func (s *KeeperTestSuite) TestRoundTickToCanonicalPriceTick() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this removed? Is there a replacement for these test vectors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The notion of canonical price ticks no longer exist, so these vectors no longer make sense. All the test vectors added relating to the behavior in ticks surrounding the new MinTick ensure the appropriate properties hold.

x/concentrated-liquidity/lp_test.go Outdated Show resolved Hide resolved
Comment on lines 544 to 547
"smallest + min price * increment 10^12": {
price: sdk.MustNewDecFromStr("1.000000000000000000"),
tickExpected: 0,
},
Copy link
Member

Choose a reason for hiding this comment

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

Does this title reflect this test case? I think the previous one might have been incorrect as well right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for flagging this, fixed

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

This LGTM

@AlpinYukseloglu
Copy link
Contributor Author

Addressed all comments, will merge once CI passes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:no-changelog C:x/concentrated-liquidity C:x/gamm Changes, features and bugs related to the gamm module. C:x/superfluid V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CL]: Remove notion of canonical ticks by increasing min tick/spot price
4 participants