diff --git a/x/perp/v2/keeper/admin.go b/x/perp/v2/keeper/admin.go index 85f50346f..6e43d9f57 100644 --- a/x/perp/v2/keeper/admin.go +++ b/x/perp/v2/keeper/admin.go @@ -104,7 +104,8 @@ func (k admin) CreateMarket( return err } - lastVersion := k.MarketLastVersion.GetOr(ctx, pair, types.MarketLastVersion{Version: 1}) + lastVersion := k.MarketLastVersion.GetOr(ctx, pair, types.MarketLastVersion{Version: 0}) + lastVersion.Version += 1 market.Version = lastVersion.Version k.Markets.Insert(ctx, collections.Join(pair, lastVersion.Version), market) diff --git a/x/perp/v2/keeper/admin_test.go b/x/perp/v2/keeper/admin_test.go index 15d28e1ab..ec1ebd64f 100644 --- a/x/perp/v2/keeper/admin_test.go +++ b/x/perp/v2/keeper/admin_test.go @@ -152,4 +152,19 @@ func TestCreateMarketFail(t *testing.T) { SqrtDepth: amm.SqrtDepth, }) require.ErrorContains(t, err, "already exists") + + // Disable the market to test that we can create it again but with an increased version + err = app.PerpKeeperV2.ChangeMarketEnabledParameter(ctx, pair, false) + require.NoError(t, err) + + err = app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + Pair: pair, + PriceMultiplier: amm.PriceMultiplier, + SqrtDepth: amm.SqrtDepth, + }) + require.NoError(t, err) + + lastVersion, err = app.PerpKeeperV2.MarketLastVersion.Get(ctx, pair) + require.NoError(t, err) + require.Equal(t, uint64(2), lastVersion.Version) }