Skip to content

Commit

Permalink
misc formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Jun 14, 2024
1 parent 0766ef9 commit ae627fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion x/dex/migrations/v3/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
15 changes: 7 additions & 8 deletions x/dex/migrations/v3/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -152,22 +152,21 @@ func (suite *V3DexMigrationTestSuite) TestPriceUpdates() {
PriceTakerToMaker: math.ZeroPrecDec(),
PriceOppositeTakerToMaker: math.ZeroPrecDec(),
}

app.DexKeeper.SetPoolReserves(ctx, poolReserves)

// Run migration
suite.NoError(v3.MigrateStore(ctx, cdc, storeKey))

// 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")))
}

0 comments on commit ae627fe

Please sign in to comment.