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

Demo: break spot price API to operate on BigDec #6371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, poo
// Amount of quote token need to trade to get target spot price
// AmoutQuoteTokenNeedToTrade = AmoutQuoTokenNow * ((targetSpotPrice/spotPriceNow)^((weight_base/(weight_base + weight_quote))) -1 )

ratioPrice := targetSpotPrice.Quo(spotPriceNow)
ratioPrice := targetSpotPrice.Quo(spotPriceNow.Dec())
ratioWeight := (baseAsset.Weight.ToLegacyDec()).Quo(baseAsset.Weight.ToLegacyDec().Add(quoteAsset.Weight.ToLegacyDec()))

amountTrade = quoteAsset.Token.Amount.ToLegacyDec().Mul(osmomath.Pow(ratioPrice, ratioWeight).Sub(osmomath.OneDec()))
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (s *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []o

// SwapAndSetSpotPrice runs a swap to set Spot price of a pool using arbitrary values
// returns spot price after the arbitrary swap.
func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin, toAsset sdk.Coin) osmomath.Dec {
func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin, toAsset sdk.Coin) osmomath.BigDec {
// create a dummy account
acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v16/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(v16.DAIIBCDenom, concentratedTypePool.GetToken1())

// Validate that the spot price of the CL pool is what we expect
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice))
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice)

// Validate that link was created.
migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx)
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v17/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(assetPair.QuoteAsset, concentratedTypePool.GetToken1())

// Validate that the spot price of the CL pool is what we expect
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice))
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice)

// Validate that the link is correct.
migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx)
Expand Down Expand Up @@ -461,7 +461,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(quoteAsset, concentratedTypePool.GetToken1())

// Validate that the spot price of the CL pool is what we expect
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice))
osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice)

// Validate that the link is correct.
migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ func updateTWAPGenesis(appGenState map[string]json.RawMessage) func(twapGenState
Asset1Denom: denomPair.Denom0,
Height: 1,
Time: time.Date(2023, 0o2, 1, 0, 0, 0, 0, time.UTC), // some time in the past.
P0LastSpotPrice: sp0,
P1LastSpotPrice: sp1,
P0LastSpotPrice: sp0.Dec(),
P1LastSpotPrice: sp1.Dec(),
P0ArithmeticTwapAccumulator: osmomath.ZeroDec(),
P1ArithmeticTwapAccumulator: osmomath.ZeroDec(),
GeometricTwapAccumulator: osmomath.ZeroDec(),
Expand Down
229 changes: 76 additions & 153 deletions tests/mocks/cfmm_pool.go

Large diffs are not rendered by default.

50 changes: 12 additions & 38 deletions tests/mocks/cl_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 5 additions & 30 deletions tests/mocks/pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 84 additions & 8 deletions tests/mocks/pool_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading