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

fix(gamm): SpotPrice keeper function #3715

Merged
merged 13 commits into from
Dec 16, 2022
Merged

fix(gamm): SpotPrice keeper function #3715

merged 13 commits into from
Dec 16, 2022

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Dec 14, 2022

Closes: #XXX

What is the purpose of the change

This PR fixes the SpotPrice keeper function.

It fixes the underlying balancer pool bug and stableswap pool hack. Then, it switches parameter order on the keeper layer so that TWAP does not require migrations.

The parameter order is switched for the following functions:

It refactors tests that utilize these functions. As an outcome of this change, v1.SpotPrice querier switches the arguments in the wrong order to make the result correct.

Testing and Verifying

  • Pre-existing twap tests pass
  • GAMM tests pass with base / quote switched
  • Pool model tests pass with base / quote switched

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? yes
  • How is the feature or change documented? not applicable

@github-actions github-actions bot added C:app-wiring Changes to the app folder C:x/gamm Changes, features and bugs related to the gamm module. C:x/swaprouter C:x/twap Changes to the twap module C:x/txfees labels Dec 14, 2022
x/gamm/keeper/grpc_query.go Outdated Show resolved Hide resolved
quoteAssetDenom string,
baseAssetDenom string,
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: the order is changed to avoid twap migrations

@@ -40,7 +40,7 @@ func (k Keeper) CalculateSpotPrice(
}
}()

spotPrice, err = pool.SpotPrice(ctx, baseAssetDenom, quoteAssetDenom)
spotPrice, err = pool.SpotPrice(ctx, quoteAssetDenom, baseAssetDenom)
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: technically, pools could keep the existing parameter order and just get fixed on the implementation level. However, I think it is useful to keep the order consistent with the keeper. As a result, I changed the denom order for pools as well

x/gamm/pool-models/balancer/pool.go Outdated Show resolved Hide resolved
@p0mvn p0mvn added the V:state/breaking State machine breaking PR label Dec 14, 2022
@p0mvn p0mvn marked this pull request as ready for review December 14, 2022 18:47
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.

Changes LGTM

//
// Case 1: base = uosmo, quote = uatom -> for one uosmo, get 2 uatom = 4 / 2 = 2
//
// Case 2: base = uatom, quote = uosmo -> for one uatom, get 0.5 uosmo = 2 / 4 = 0.5
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same thing, but I find it easier to read "it costs 0.5 uosmo to get one uatom" and "it costs "2 uatom to get 1 osmo".

I think this is because the word "quote" implies to me that it is the price/cost of the base asset denominated in quote asset. So, what you're "getting" is the base asset.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, I added your interpretation in comments as well

sp0, err0 := k.CalculateSpotPrice(ctx, poolId, denom0, denom1)
// sp1 = denom0 base, denom1 quote.
Copy link
Contributor

Choose a reason for hiding this comment

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

useful to have these comments here!

@p0mvn
Copy link
Member Author

p0mvn commented Dec 16, 2022

Merging once CI passes since have 2 approvals

@p0mvn p0mvn merged commit 4f887b9 into main Dec 16, 2022
@p0mvn p0mvn deleted the roman/spot-price-fix branch December 16, 2022 23:56
@github-actions github-actions bot mentioned this pull request Feb 15, 2024
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:x/gamm Changes, features and bugs related to the gamm module. C:x/swaprouter C:x/twap Changes to the twap module C:x/txfees V:state/breaking State machine breaking PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants