diff --git a/x/dex/migrations/v3/store.go b/x/dex/migrations/v3/store.go index c9404d239..1f3079a46 100644 --- a/x/dex/migrations/v3/store.go +++ b/x/dex/migrations/v3/store.go @@ -106,6 +106,7 @@ func migrateLimitOrderExpirations(ctx sdk.Context, cdc codec.BinaryCodec, storeK } func migrateTickLiquidityPrices(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + // Due to change in precision of PrecDec between v2 and v3 we need to recompute all PrecDecs in the kvstore ctx.Logger().Info("Migrating TickLiquidity Prices...") // Iterate through all tickLiquidity @@ -146,6 +147,7 @@ func migrateTickLiquidityPrices(ctx sdk.Context, cdc codec.BinaryCodec, storeKey } func migrateInactiveTranchePrices(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + // Due to change in precision of PrecDec between v2 and v3 we need to recompute all PrecDecs in the kvstore ctx.Logger().Info("Migrating InactiveLimitOrderTranche Prices...") // Iterate through all tickLiquidity @@ -169,7 +171,7 @@ func migrateInactiveTranchePrices(ctx sdk.Context, cdc codec.BinaryCodec, storeK return err } - ctx.Logger().Info("Finished Migrating InactiveLimitOrderTranche Prices...") + ctx.Logger().Info("Finished migrating InactiveLimitOrderTranche Prices...") return nil } diff --git a/x/dex/migrations/v3/store_test.go b/x/dex/migrations/v3/store_test.go index 8e4c3caf1..5f9e4a7ba 100644 --- a/x/dex/migrations/v3/store_test.go +++ b/x/dex/migrations/v3/store_test.go @@ -136,12 +136,12 @@ func (suite *V3DexMigrationTestSuite) TestPriceUpdates() { Key: trancheKey, PriceTakerToMaker: math.ZeroPrecDec(), } - // create active tranche app.DexKeeper.SetLimitOrderTranche(ctx, tranche) - // create inactive tranche + + // also create inactive tranche app.DexKeeper.SetInactiveLimitOrderTranche(ctx, tranche) - // Write poolReserves with old precision + // Write poolReserves with incorrect prices poolKey := &types.PoolReservesKey{ TradePairId: types.MustNewTradePairID("TokenA", "TokenB"), TickIndexTakerToMaker: 60000, @@ -152,7 +152,6 @@ func (suite *V3DexMigrationTestSuite) TestPriceUpdates() { PriceTakerToMaker: math.ZeroPrecDec(), PriceOppositeTakerToMaker: math.ZeroPrecDec(), } - app.DexKeeper.SetPoolReserves(ctx, poolReserves) // Run migration @@ -160,14 +159,14 @@ func (suite *V3DexMigrationTestSuite) TestPriceUpdates() { // Check LimitOrderTranche has correct price newTranche := app.DexKeeper.GetLimitOrderTranche(ctx, trancheKey) - suite.True(newTranche.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("1.005012269623051203500693815")), "was : %v", newTranche.PriceTakerToMaker) + suite.True(newTranche.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("1.005012269623051203500693815"))) // check InactiveLimitOrderTranche has correct price inactiveTranche, _ := app.DexKeeper.GetInactiveLimitOrderTranche(ctx, trancheKey) - suite.True(inactiveTranche.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("1.005012269623051203500693815")), "was : %v", newTranche.PriceTakerToMaker) + suite.True(inactiveTranche.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("1.005012269623051203500693815"))) // Check PoolReserves has the correct prices newPool, _ := app.DexKeeper.GetPoolReserves(ctx, poolKey) - suite.True(newPool.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("0.002479495864288162666675923")), "was : %v", newPool.PriceTakerToMaker) - suite.True(newPool.PriceOppositeTakerToMaker.Equal(math.MustNewPrecDecFromStr("403.227141612124702272520931931")), "was : %v", newPool.PriceOppositeTakerToMaker) + suite.True(newPool.PriceTakerToMaker.Equal(math.MustNewPrecDecFromStr("0.002479495864288162666675923"))) + suite.True(newPool.PriceOppositeTakerToMaker.Equal(math.MustNewPrecDecFromStr("403.227141612124702272520931931"))) }