Skip to content

Commit

Permalink
add option for market creation when another one is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
jgimeno committed Sep 7, 2023
1 parent 93f9c18 commit d2e631e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x/perp/v2/keeper/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions x/perp/v2/keeper/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit d2e631e

Please sign in to comment.