Skip to content

Commit

Permalink
refactor: break PoolI.SpotPrice API to return BigDec (backport #6372) (
Browse files Browse the repository at this point in the history
…#6407)

* updates

* fix conflicts in tests

* lint

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Sep 20, 2023
1 parent 01f0117 commit 3c734c9
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 271 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* maxDecBitLen has changed by one bit so overflow panic can be triggerred sooner.
* [#6368](https://github.com/osmosis-labs/osmosis/pull/6368) Convert priceLimit API in CL swaps to BigDec

* [#6371](https://github.com/osmosis-labs/osmosis/pull/6371) Change PoolI.SpotPrice API from Dec (18 decimals) to BigDec (36 decimals), maintain state-compatibility.

## v19.0.0

Expand Down
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
21 changes: 11 additions & 10 deletions tests/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,17 @@ func updateTWAPGenesis(appGenState map[string]json.RawMessage) func(twapGenState
}

twapRecord := twaptypes.TwapRecord{
PoolId: balancerPool.Id,
Asset0Denom: denomPair.Denom0,
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,
P0ArithmeticTwapAccumulator: osmomath.ZeroDec(),
P1ArithmeticTwapAccumulator: osmomath.ZeroDec(),
GeometricTwapAccumulator: osmomath.ZeroDec(),
PoolId: balancerPool.Id,
Asset0Denom: denomPair.Denom0,
Asset1Denom: denomPair.Denom0,
Height: 1,
Time: time.Date(2023, 0o2, 1, 0, 0, 0, 0, time.UTC), // some time in the past.
// Note: truncation is acceptable as x/twap is guaranteed to work only on pools with spot prices > 10^-18.
P0LastSpotPrice: sp0.Dec(),
P1LastSpotPrice: sp1.Dec(),
P0ArithmeticTwapAccumulator: sdk.ZeroDec(),
P1ArithmeticTwapAccumulator: sdk.ZeroDec(),
GeometricTwapAccumulator: sdk.ZeroDec(),
LastErrorTime: time.Time{}, // no previous error
}
twapGenState.Twaps = append(twapGenState.Twaps, twapRecord)
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

0 comments on commit 3c734c9

Please sign in to comment.