diff --git a/CHANGELOG.md b/CHANGELOG.md index faa124ba5..aa4f492fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1630](https://github.com/NibiruChain/nibiru/pull/1630) - refactor(wasm): clean up wasmbinding/ folder structure * [#1631](https://github.com/NibiruChain/nibiru/pull/1631) - fix(.goreleaser.yml): Load version for wasmvm dynamically. * [#1638](https://github.com/NibiruChain/nibiru/pull/1638) - test(tokenfactory): integration test core logic with a real smart contract using `nibiru-std` +* [#1639](https://github.com/NibiruChain/nibiru/pull/1639) - fix(perp): by default, disable new markets until they are toggled on. ### Dependencies - Bump `github.com/prometheus/client_golang` from 1.16.0 to 1.17.0 ([#1605](https://github.com/NibiruChain/nibiru/pull/1605)) diff --git a/wasmbinding/exec_perp.go b/wasmbinding/exec_perp.go index a8b458e50..e3abaf869 100644 --- a/wasmbinding/exec_perp.go +++ b/wasmbinding/exec_perp.go @@ -182,7 +182,7 @@ func (exec *ExecutorPerp) InsuranceFundWithdraw( return err } - return exec.PerpV2.Admin().WithdrawFromInsuranceFund( + return exec.PerpV2.Admin.WithdrawFromInsuranceFund( ctx, cwMsg.Amount, to, @@ -202,7 +202,7 @@ func (exec *ExecutorPerp) SetMarketEnabled( return err } - return exec.PerpV2.CloseMarket(ctx, pair) + return exec.PerpV2.Admin.CloseMarket(ctx, pair) } func (exec *ExecutorPerp) CreateMarket( @@ -239,7 +239,7 @@ func (exec *ExecutorPerp) CreateMarket( } } - return exec.PerpV2.Admin().CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{ + return exec.PerpV2.Admin.CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: cwMsg.PegMult, SqrtDepth: cwMsg.SqrtDepth, diff --git a/wasmbinding/exec_test.go b/wasmbinding/exec_test.go index 20d6d60b8..7c3912b1e 100644 --- a/wasmbinding/exec_test.go +++ b/wasmbinding/exec_test.go @@ -550,7 +550,7 @@ func (s *TestSuiteExecutor) TestCreateMarket() { market, err := s.nibiru.PerpKeeperV2.GetMarket(s.ctx, pair) s.NoError(err) s.NoError(market.Validate()) - s.True(market.Enabled) + s.False(market.Enabled, "by default, we create a market in a disabled state") s.EqualValues(pair, market.Pair) s.T().Log("Executing without permission should fail") diff --git a/x/common/testutil/action/testcase.go b/x/common/testutil/action/testcase.go index 633888ce6..cf094d57e 100644 --- a/x/common/testutil/action/testcase.go +++ b/x/common/testutil/action/testcase.go @@ -48,67 +48,73 @@ func TC(name string) TestCase { return TestCase{Name: name} } -func (t TestCase) Given(action ...Action) TestCase { - t.given = append(t.given, action...) - return t +func (tc TestCase) Given(action ...Action) TestCase { + tc.given = append(tc.given, action...) + return tc } -func (t TestCase) When(action ...Action) TestCase { - t.when = append(t.when, action...) - return t +func (tc TestCase) When(action ...Action) TestCase { + tc.when = append(tc.when, action...) + return tc } -func (t TestCase) Then(action ...Action) TestCase { - t.then = append(t.then, action...) - return t +func (tc TestCase) Then(action ...Action) TestCase { + tc.then = append(tc.then, action...) + return tc } -type TestSuite struct { - t *testing.T - - testCases []TestCase -} - -func NewTestSuite(t *testing.T) *TestSuite { - return &TestSuite{t: t} -} - -func (t *TestSuite) WithTestCases(testCase ...TestCase) *TestSuite { - t.testCases = append(t.testCases, testCase...) - return t -} - -func (t *TestSuite) Run() { - for _, testCase := range t.testCases { +func (tc TestCase) Run(t *testing.T) { + t.Run(tc.Name, func(t *testing.T) { app, ctx := testapp.NewNibiruTestAppAndContextAtTime(time.UnixMilli(0)) var err error var isMandatory bool - for _, action := range testCase.given { + for _, action := range tc.given { ctx, err, isMandatory = action.Do(app, ctx) if isMandatory { - require.NoError(t.t, err, "failed to execute given action: %s", testCase.Name) + require.NoError(t, err, "failed to execute given action: %s", tc.Name) } else { - assert.NoError(t.t, err, "failed to execute given action: %s", testCase.Name) + assert.NoError(t, err, "failed to execute given action: %s", tc.Name) } } - for _, action := range testCase.when { + for _, action := range tc.when { ctx, err, isMandatory = action.Do(app, ctx) if isMandatory { - require.NoError(t.t, err, "failed to execute when action: %s", testCase.Name) + require.NoError(t, err, "failed to execute when action: %s", tc.Name) } else { - assert.NoError(t.t, err, "failed to execute when action: %s", testCase.Name) + assert.NoError(t, err, "failed to execute when action: %s", tc.Name) } } - for _, action := range testCase.then { + for _, action := range tc.then { ctx, err, isMandatory = action.Do(app, ctx) if isMandatory { - require.NoError(t.t, err, "failed to execute then action: %s", testCase.Name) + require.NoError(t, err, "failed to execute then action: %s", tc.Name) } else { - assert.NoError(t.t, err, "failed to execute then action: %s", testCase.Name) + assert.NoError(t, err, "failed to execute then action: %s", tc.Name) } } + }) +} + +type TestSuite struct { + t *testing.T + + testCases []TestCase +} + +func NewTestSuite(t *testing.T) *TestSuite { + return &TestSuite{t: t} +} + +func (ts *TestSuite) WithTestCases(testCase ...TestCase) *TestSuite { + ts.testCases = append(ts.testCases, testCase...) + return ts +} + +func (ts *TestSuite) Run() { + for _, testCase := range ts.testCases { + testCase.Run(ts.t) } } diff --git a/x/perp/v2/integration/action/market.go b/x/perp/v2/integration/action/market.go index 00408b7f9..a28ec7e3b 100644 --- a/x/perp/v2/integration/action/market.go +++ b/x/perp/v2/integration/action/market.go @@ -35,7 +35,8 @@ type createMarketAction struct { } func (c createMarketAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - app.PerpKeeperV2.MarketLastVersion.Insert(ctx, c.Market.Pair, types.MarketLastVersion{Version: c.Market.Version}) + app.PerpKeeperV2.MarketLastVersion.Insert( + ctx, c.Market.Pair, types.MarketLastVersion{Version: c.Market.Version}) app.PerpKeeperV2.SaveMarket(ctx, c.Market) app.PerpKeeperV2.SaveAMM(ctx, c.AMM) @@ -171,7 +172,7 @@ type createPool struct { } func (c createPool) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - err := app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err := app.PerpKeeperV2.Admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: c.pair, PriceMultiplier: c.amm.PriceMultiplier, SqrtDepth: c.amm.SqrtDepth, diff --git a/x/perp/v2/integration/action/settlement.go b/x/perp/v2/integration/action/settlement.go index 8a28697e3..c297093fa 100644 --- a/x/perp/v2/integration/action/settlement.go +++ b/x/perp/v2/integration/action/settlement.go @@ -17,7 +17,7 @@ type closeMarket struct { } func (c closeMarket) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - err := app.PerpKeeperV2.CloseMarket(ctx, c.pair) + err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) if err != nil { return ctx, err, false } @@ -35,7 +35,7 @@ type closeMarketShouldFail struct { } func (c closeMarketShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - err := app.PerpKeeperV2.CloseMarket(ctx, c.pair) + err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) if err == nil { return ctx, err, false } diff --git a/x/perp/v2/keeper/admin.go b/x/perp/v2/keeper/admin.go index fda963c64..6345f6958 100644 --- a/x/perp/v2/keeper/admin.go +++ b/x/perp/v2/keeper/admin.go @@ -12,21 +12,16 @@ import ( types "github.com/NibiruChain/nibiru/x/perp/v2/types" ) -// Admin is syntactic sugar to separate admin calls off from the other Keeper -// methods. +// Extends the Keeper with admin functions. Admin is syntactic sugar to separate +// admin calls off from the other Keeper methods. // // These Admin functions should: -// 1. Not be wired into the MsgServer or +// 1. Not be wired into the MsgServer. // 2. Not be called in other methods in the x/perp module. -// 3. Only be callable from x/wasm/binding via sudo contracts. +// 3. Only be callable from nibiru/wasmbinding via sudo contracts. // // The intention here is to make it more obvious to the developer that an unsafe -// function is being used when it's called on the Admin() struct. -func (k Keeper) Admin() admin { - return admin{&k} -} - -// Extends the Keeper with admin functions. +// function is being used when it's called from the PerpKeeper.Admin struct. type admin struct{ *Keeper } /* @@ -63,6 +58,9 @@ type ArgsCreateMarket struct { PriceMultiplier sdk.Dec SqrtDepth sdk.Dec Market *types.Market // pointer makes it optional + // EnableMarket: Optionally enable the default market without explicitly passing + // in each field as an argument. If 'Market' is present, this field is ignored. + EnableMarket bool } // CreateMarket creates a pool for a specific pair. @@ -82,6 +80,7 @@ func (k admin) CreateMarket( baseReserve := sqrtDepth if args.Market == nil { market = types.DefaultMarket(pair) + market.Enabled = args.EnableMarket } else { market = *args.Market } @@ -114,3 +113,34 @@ func (k admin) CreateMarket( return nil } + +// CloseMarket closes the market. From now on, no new position can be opened on +// this market or closed. Only the open positions can be settled by calling +// SettlePosition. +func (k admin) CloseMarket(ctx sdk.Context, pair asset.Pair) (err error) { + market, err := k.GetMarket(ctx, pair) + if err != nil { + return err + } + if !market.Enabled { + return types.ErrMarketNotEnabled + } + + amm, err := k.GetAMM(ctx, pair) + if err != nil { + return err + } + + settlementPrice, _, err := amm.ComputeSettlementPrice() + if err != nil { + return + } + + amm.SettlementPrice = settlementPrice + market.Enabled = false + + k.SaveAMM(ctx, amm) + k.SaveMarket(ctx, market) + + return nil +} diff --git a/x/perp/v2/keeper/admin_test.go b/x/perp/v2/keeper/admin_test.go index cd423cdd0..66fe05d2b 100644 --- a/x/perp/v2/keeper/admin_test.go +++ b/x/perp/v2/keeper/admin_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "testing" + "time" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,6 +16,10 @@ import ( "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/v2/keeper" "github.com/NibiruChain/nibiru/x/perp/v2/types" + + . "github.com/NibiruChain/nibiru/x/common/testutil/action" + . "github.com/NibiruChain/nibiru/x/perp/v2/integration/action" + . "github.com/NibiruChain/nibiru/x/perp/v2/integration/assertion" ) func TestAdmin_WithdrawFromInsuranceFund(t *testing.T) { @@ -52,7 +57,7 @@ func TestAdmin_WithdrawFromInsuranceFund(t *testing.T) { fundModule(t, amountToFund, ctx, nibiru) amountToWithdraw := amountToFund - err := nibiru.PerpKeeperV2.Admin().WithdrawFromInsuranceFund( + err := nibiru.PerpKeeperV2.Admin.WithdrawFromInsuranceFund( ctx, amountToWithdraw, admin) require.NoError(t, err) @@ -72,7 +77,7 @@ func TestAdmin_WithdrawFromInsuranceFund(t *testing.T) { fundModule(t, amountToFund, ctx, nibiru) amountToWithdraw := amountToFund.MulRaw(5) - err := nibiru.PerpKeeperV2.Admin().WithdrawFromInsuranceFund( + err := nibiru.PerpKeeperV2.Admin.WithdrawFromInsuranceFund( ctx, amountToWithdraw, admin) require.Error(t, err) }, @@ -86,10 +91,11 @@ func TestCreateMarket(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) amm := *mock.TestAMMDefault() app, ctx := testapp.NewNibiruTestAppAndContext() + admin := app.PerpKeeperV2.Admin // Error because of invalid market market := types.DefaultMarket(pair).WithMaintenanceMarginRatio(sdk.NewDec(2)) - err := app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err := admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: amm.PriceMultiplier, SqrtDepth: amm.SqrtDepth, @@ -98,7 +104,7 @@ func TestCreateMarket(t *testing.T) { require.ErrorContains(t, err, "maintenance margin ratio ratio must be 0 <= ratio <= 1") // Error because of invalid amm - err = app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err = admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: sdk.NewDec(-1), SqrtDepth: amm.SqrtDepth, @@ -106,10 +112,11 @@ func TestCreateMarket(t *testing.T) { require.ErrorContains(t, err, "init price multiplier must be > 0") // Set it correctly - err = app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err = admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: amm.PriceMultiplier, SqrtDepth: amm.SqrtDepth, + EnableMarket: true, }) require.NoError(t, err) @@ -127,7 +134,7 @@ func TestCreateMarket(t *testing.T) { require.Equal(t, uint64(1), market.Version) // Fail since it already exists and it is not disabled - err = app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err = admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: amm.PriceMultiplier, SqrtDepth: amm.SqrtDepth, @@ -135,10 +142,10 @@ func TestCreateMarket(t *testing.T) { require.ErrorContains(t, err, "already exists") // Close the market to test that we can create it again but with an increased version - err = app.PerpKeeperV2.CloseMarket(ctx, pair) + err = admin.CloseMarket(ctx, pair) require.NoError(t, err) - err = app.PerpKeeperV2.Admin().CreateMarket(ctx, keeper.ArgsCreateMarket{ + err = admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: amm.PriceMultiplier, SqrtDepth: amm.SqrtDepth, @@ -158,3 +165,108 @@ func TestCreateMarket(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(2), market.Version) } + +func TestCloseMarket(t *testing.T) { + pairBtcUsdc := asset.Registry.Pair(denoms.BTC, denoms.NUSD) + startTime := time.Now() + alice := testutil.AccAddress() + + tc := TestCases{ + TC("market can be disabled"). + Given( + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), + SetBlockTime(startTime), + MarketShouldBeEqual( + pairBtcUsdc, + Market_EnableShouldBeEqualTo(true), + ), + ). + When( + CloseMarket(pairBtcUsdc), + ). + Then( + MarketShouldBeEqual( + pairBtcUsdc, + Market_EnableShouldBeEqualTo(false), + ), + ), + TC("cannot open position on disabled market"). + Given( + CreateCustomMarket( + pairBtcUsdc, + WithEnabled(true), + WithPricePeg(sdk.OneDec()), + WithSqrtDepth(sdk.NewDec(100_000)), + ), + SetBlockNumber(1), + SetBlockTime(startTime), + + FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), + ). + When( + CloseMarket(pairBtcUsdc), + ). + Then( + MarketOrderFails( + alice, + pairBtcUsdc, + types.Direction_LONG, + sdk.NewInt(10_000), + sdk.OneDec(), + sdk.ZeroDec(), + types.ErrMarketNotEnabled, + ), + ), + TC("cannot close position on disabled market").When( + CreateCustomMarket( + pairBtcUsdc, + WithPricePeg(sdk.OneDec()), + WithSqrtDepth(sdk.NewDec(100_000)), + WithEnabled(true), + ), + SetBlockNumber(1), + SetBlockTime(startTime), + FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200)))), + MarketOrder( + alice, + pairBtcUsdc, + types.Direction_LONG, + sdk.NewInt(10_000), + sdk.OneDec(), + sdk.ZeroDec(), + ), + ).When( + CloseMarket(pairBtcUsdc), + CloseMarketShouldFail(pairBtcUsdc), + CloseMarketShouldFail("random:pair"), + ).Then( + ClosePositionFails(alice, pairBtcUsdc, types.ErrMarketNotEnabled), + ), + TC("cannot partial close position on disabled market").When( + CreateCustomMarket( + pairBtcUsdc, + WithPricePeg(sdk.OneDec()), + WithSqrtDepth(sdk.NewDec(100_000)), + WithEnabled(true), + ), + SetBlockNumber(1), + SetBlockTime(startTime), + FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200)))), + MarketOrder( + alice, + pairBtcUsdc, + types.Direction_LONG, + sdk.NewInt(10_000), + sdk.OneDec(), + sdk.ZeroDec(), + ), + ).When( + CloseMarket(pairBtcUsdc), + AMMShouldBeEqual(pairBtcUsdc, AMM_SettlementPriceShoulBeEqual(sdk.MustNewDecFromStr("1.1"))), + ).Then( + PartialCloseFails(alice, pairBtcUsdc, sdk.NewDec(5_000), types.ErrMarketNotEnabled), + ), + } + + NewTestSuite(t).WithTestCases(tc...).Run() +} diff --git a/x/perp/v2/keeper/amm_test.go b/x/perp/v2/keeper/amm_test.go index 6a15e57da..6b4cd13a3 100644 --- a/x/perp/v2/keeper/amm_test.go +++ b/x/perp/v2/keeper/amm_test.go @@ -46,7 +46,10 @@ func TestEditPriceMultipler(t *testing.T) { TC("net bias zero"). Given( - CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1000)), WithTotalShort(sdk.NewDec(1000))), + CreateCustomMarket(pair, + WithTotalLong(sdk.NewDec(1000)), WithTotalShort(sdk.NewDec(1000)), + WithEnabled(true), + ), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). @@ -153,12 +156,13 @@ func TestEditPriceMultiplerFail(t *testing.T) { app, ctx := testapp.NewNibiruTestAppAndContext() account := sdk.MustAccAddressFromBech32("cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v") - err := app.PerpKeeperV2.Admin().CreateMarket( + err := app.PerpKeeperV2.Admin.CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: sdk.NewDec(2), SqrtDepth: sdk.NewDec(1_000_000), + EnableMarket: true, }, ) app.PerpKeeperV2.ReserveSnapshots.Insert( @@ -179,11 +183,11 @@ func TestEditPriceMultiplerFail(t *testing.T) { require.NoError(t, err) // Error because of invalid pair - err = app.PerpKeeperV2.Admin().EditPriceMultiplier(ctx, asset.MustNewPair("luna:usdt"), sdk.NewDec(-1)) + err = app.PerpKeeperV2.Admin.EditPriceMultiplier(ctx, asset.MustNewPair("luna:usdt"), sdk.NewDec(-1)) require.ErrorContains(t, err, "market luna:usdt not found") // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin().EditPriceMultiplier(ctx, pair, sdk.NewDec(-1)) + err = app.PerpKeeperV2.Admin.EditPriceMultiplier(ctx, pair, sdk.NewDec(-1)) require.ErrorIs(t, err, types.ErrNonPositivePegMultiplier) // Add market activity @@ -205,11 +209,11 @@ func TestEditPriceMultiplerFail(t *testing.T) { require.NoError(t, err) // Error because no money in perp ef fund - err = app.PerpKeeperV2.Admin().EditPriceMultiplier(ctx, pair, sdk.NewDec(3)) + err = app.PerpKeeperV2.Admin.EditPriceMultiplier(ctx, pair, sdk.NewDec(3)) require.ErrorContains(t, err, "not enough fund in perp ef to pay for repeg") // Works because it goes in the other way - err = app.PerpKeeperV2.Admin().EditPriceMultiplier(ctx, pair, sdk.NewDec(1)) + err = app.PerpKeeperV2.Admin.EditPriceMultiplier(ctx, pair, sdk.NewDec(1)) require.NoError(t, err) } @@ -218,12 +222,13 @@ func TestEditSwapInvariantFail(t *testing.T) { app, ctx := testapp.NewNibiruTestAppAndContext() account := sdk.MustAccAddressFromBech32("cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v") - err := app.PerpKeeperV2.Admin().CreateMarket( + err := app.PerpKeeperV2.Admin.CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: sdk.NewDec(2), SqrtDepth: sdk.NewDec(1_000), + EnableMarket: true, }, ) app.PerpKeeperV2.ReserveSnapshots.Insert( @@ -244,11 +249,11 @@ func TestEditSwapInvariantFail(t *testing.T) { require.NoError(t, err) // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin().EditSwapInvariant(ctx, asset.MustNewPair("luna:usdt"), sdk.NewDec(-1)) + err = app.PerpKeeperV2.Admin.EditSwapInvariant(ctx, asset.MustNewPair("luna:usdt"), sdk.NewDec(-1)) require.ErrorContains(t, err, "market luna:usdt not found") // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin().EditSwapInvariant(ctx, pair, sdk.NewDec(-1)) + err = app.PerpKeeperV2.Admin.EditSwapInvariant(ctx, pair, sdk.NewDec(-1)) require.ErrorIs(t, err, types.ErrNegativeSwapInvariant) // Add market activity @@ -270,15 +275,15 @@ func TestEditSwapInvariantFail(t *testing.T) { require.NoError(t, err) // Error because no money in perp ef fund - err = app.PerpKeeperV2.Admin().EditSwapInvariant(ctx, pair, sdk.NewDec(2_000_000)) + err = app.PerpKeeperV2.Admin.EditSwapInvariant(ctx, pair, sdk.NewDec(2_000_000)) require.ErrorContains(t, err, "not enough fund in perp ef to pay for repeg") // Fail at validate - err = app.PerpKeeperV2.Admin().EditSwapInvariant(ctx, pair, sdk.NewDec(0)) + err = app.PerpKeeperV2.Admin.EditSwapInvariant(ctx, pair, sdk.NewDec(0)) require.ErrorContains(t, err, "swap multiplier must be > 0") // Works because it goes in the other way - err = app.PerpKeeperV2.Admin().EditSwapInvariant(ctx, pair, sdk.NewDec(500_000)) + err = app.PerpKeeperV2.Admin.EditSwapInvariant(ctx, pair, sdk.NewDec(500_000)) require.NoError(t, err) } @@ -423,22 +428,23 @@ func TestKeeper_GetMarketByPairAndVersion(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) - err := app.PerpKeeperV2.Admin().CreateMarket( + err := app.PerpKeeperV2.Admin.CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: sdk.NewDec(2), SqrtDepth: sdk.NewDec(1_000_000), + EnableMarket: true, }, ) require.NoError(t, err) - market, err := app.PerpKeeperV2.Admin().GetMarketByPairAndVersion(ctx, pair, 1) + market, err := app.PerpKeeperV2.Admin.GetMarketByPairAndVersion(ctx, pair, 1) require.NoError(t, err) require.Equal(t, market.Version, uint64(1)) require.Equal(t, market.Pair, pair) - market, err = app.PerpKeeperV2.Admin().GetMarketByPairAndVersion(ctx, pair, 2) + market, err = app.PerpKeeperV2.Admin.GetMarketByPairAndVersion(ctx, pair, 2) require.ErrorContains(t, err, fmt.Sprintf("market with pair %s and version 2 not found", pair.String())) } @@ -447,21 +453,22 @@ func TestKeeper_GetAMMByPairAndVersion(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) - err := app.PerpKeeperV2.Admin().CreateMarket( + err := app.PerpKeeperV2.Admin.CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: sdk.NewDec(2), SqrtDepth: sdk.NewDec(1_000_000), + EnableMarket: true, }, ) require.NoError(t, err) - amm, err := app.PerpKeeperV2.Admin().GetAMMByPairAndVersion(ctx, pair, 1) + amm, err := app.PerpKeeperV2.Admin.GetAMMByPairAndVersion(ctx, pair, 1) require.NoError(t, err) require.Equal(t, amm.Version, uint64(1)) require.Equal(t, amm.Pair, pair) - amm, err = app.PerpKeeperV2.Admin().GetAMMByPairAndVersion(ctx, pair, 2) + amm, err = app.PerpKeeperV2.Admin.GetAMMByPairAndVersion(ctx, pair, 2) require.ErrorContains(t, err, fmt.Sprintf("amm with pair %s and version 2 not found", pair.String())) } diff --git a/x/perp/v2/keeper/clearing_house_test.go b/x/perp/v2/keeper/clearing_house_test.go index b2cc2e30a..713176cbd 100644 --- a/x/perp/v2/keeper/clearing_house_test.go +++ b/x/perp/v2/keeper/clearing_house_test.go @@ -34,6 +34,7 @@ func TestMarketOrder(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -59,7 +60,9 @@ func TestMarketOrder(t *testing.T) { TC("new long position"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, + WithEnabled(true), + ), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1020)))), @@ -124,7 +127,7 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockNumber(1), SetBlockTime(startBlockTime), - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(2040)))), MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(1000), sdk.NewDec(10), sdk.ZeroDec()), ). @@ -180,6 +183,7 @@ func TestMarketOrder(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.89")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -215,7 +219,7 @@ func TestMarketOrder(t *testing.T) { TC("existing long position, close a bit but there's bad debt"). Given( CreateCustomMarket( - pairBtcNusd, + pairBtcNusd, WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.89")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -251,7 +255,7 @@ func TestMarketOrder(t *testing.T) { TC("open big long position and then close after reducing swap invariant"). Given( CreateCustomMarket( - pairBtcNusd, + pairBtcNusd, WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -271,7 +275,7 @@ func TestMarketOrder(t *testing.T) { TC("existing long position, decrease a bit"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1030)))), @@ -330,6 +334,7 @@ func TestMarketOrder(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.89")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -364,7 +369,7 @@ func TestMarketOrder(t *testing.T) { TC("existing long position, decrease a lot"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(4080)))), @@ -422,7 +427,7 @@ func TestMarketOrder(t *testing.T) { TC("existing long position, decrease a lot but there's bad debt"). Given( CreateCustomMarket( - pairBtcNusd, + pairBtcNusd, WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.89")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -487,7 +492,7 @@ func TestMarketOrder(t *testing.T) { TC("new short position"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1020)))), @@ -552,7 +557,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, go more short"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(2040)))), @@ -609,7 +614,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, go more short but there's bad debt"). Given( - CreateCustomMarket(pairBtcNusd, + CreateCustomMarket(pairBtcNusd, WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.11")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -644,7 +649,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, decrease a bit"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1030)))), @@ -702,6 +707,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, decrease a bit but there's bad debt"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.11")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -736,7 +742,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, decrease a lot"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(4080)))), @@ -793,7 +799,7 @@ func TestMarketOrder(t *testing.T) { TC("existing short position, decrease a lot but there's bad debt"). Given( - CreateCustomMarket(pairBtcNusd, + CreateCustomMarket(pairBtcNusd, WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.11")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -859,7 +865,7 @@ func TestMarketOrder(t *testing.T) { TC("user has insufficient funds"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(99)))), @@ -875,7 +881,7 @@ func TestMarketOrder(t *testing.T) { TC("new long position, can not open new position after market is not enabled"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(47_714_285_715)))), @@ -907,7 +913,7 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(47_714_285_715)))), ). When( @@ -922,7 +928,7 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -937,7 +943,7 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -952,7 +958,9 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd, WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), + CreateCustomMarket(pairBtcNusd, + WithEnabled(true), + WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(20_000_000_000+20_000_000)))), ). When( @@ -967,7 +975,10 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd, WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), + CreateCustomMarket( + pairBtcNusd, + WithEnabled(true), + WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -981,7 +992,10 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd, WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), + CreateCustomMarket( + pairBtcNusd, + WithEnabled(true), + WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -996,7 +1010,10 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd, WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), + CreateCustomMarket( + pairBtcNusd, + WithEnabled(true), + WithPricePeg(sdk.MustNewDecFromStr("25001.0112"))), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -1011,7 +1028,10 @@ func TestMarketOrder(t *testing.T) { Given( SetBlockTime(startBlockTime), SetBlockNumber(1), - CreateCustomMarket(pairBtcNusd, WithPricePeg(sdk.MustNewDecFromStr("25000"))), + CreateCustomMarket( + pairBtcNusd, + WithEnabled(true), + WithPricePeg(sdk.MustNewDecFromStr("25000"))), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), ). When( @@ -1171,6 +1191,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1225,6 +1246,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.95")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1279,6 +1301,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.94")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1332,6 +1355,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.59")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1386,6 +1410,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.10")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1440,6 +1465,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.05")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1494,6 +1520,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.09")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1548,6 +1575,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.14")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1602,6 +1630,7 @@ func TestPartialClose(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(10_000)), ), @@ -1630,6 +1659,7 @@ func TestClosePosition(t *testing.T) { TC("close long position with positive PnL"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1676,6 +1706,7 @@ func TestClosePosition(t *testing.T) { TC("close long position with negative PnL"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.99")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1722,6 +1753,7 @@ func TestClosePosition(t *testing.T) { TC("close long position with bad debt"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.89")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1772,6 +1804,7 @@ func TestClosePosition(t *testing.T) { TC("close short position with positive PnL"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.10")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1818,6 +1851,7 @@ func TestClosePosition(t *testing.T) { TC("close short position with negative PnL"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.01")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1864,6 +1898,7 @@ func TestClosePosition(t *testing.T) { TC("close short position with bad debt"). Given( CreateCustomMarket(pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("1.11")), WithLatestMarketCPF(sdk.MustNewDecFromStr("0.0002")), ), @@ -1926,7 +1961,7 @@ func TestUpdateSwapInvariant(t *testing.T) { tc := TestCases{ TC("only long position - no change to swap invariant"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -1941,7 +1976,7 @@ func TestUpdateSwapInvariant(t *testing.T) { ), TC("only short position - no change to swap invariant"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -1956,7 +1991,7 @@ func TestUpdateSwapInvariant(t *testing.T) { ), TC("only long position - increasing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -1976,7 +2011,7 @@ func TestUpdateSwapInvariant(t *testing.T) { ), TC("only short position - increasing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -1997,7 +2032,7 @@ func TestUpdateSwapInvariant(t *testing.T) { TC("only long position - decreasing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -2017,7 +2052,7 @@ func TestUpdateSwapInvariant(t *testing.T) { ), TC("only short position - decreasing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -2038,7 +2073,7 @@ func TestUpdateSwapInvariant(t *testing.T) { TC("long and short position - increasing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), @@ -2069,7 +2104,7 @@ func TestUpdateSwapInvariant(t *testing.T) { ), TC("long and short position - reducing k"). Given( - CreateCustomMarket(pairBtcNusd), + CreateCustomMarket(pairBtcNusd, WithEnabled(true)), SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200_000_000)))), diff --git a/x/perp/v2/keeper/dnr_test.go b/x/perp/v2/keeper/dnr_test.go index fa1450ca1..b1affbaa1 100644 --- a/x/perp/v2/keeper/dnr_test.go +++ b/x/perp/v2/keeper/dnr_test.go @@ -28,6 +28,7 @@ func TestUserVolumes(t *testing.T) { DnREpochIs(1), CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -48,6 +49,7 @@ func TestUserVolumes(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -71,6 +73,7 @@ func TestUserVolumes(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -115,6 +118,7 @@ func TestDiscount(t *testing.T) { Given( CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -135,6 +139,7 @@ func TestDiscount(t *testing.T) { DnREpochIs(2), CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -159,6 +164,7 @@ func TestDiscount(t *testing.T) { DnREpochIs(2), CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), @@ -183,6 +189,7 @@ func TestDiscount(t *testing.T) { DnREpochIs(2), CreateCustomMarket( pairBtcNusd, + WithEnabled(true), WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), ), diff --git a/x/perp/v2/keeper/grpc_query_test.go b/x/perp/v2/keeper/grpc_query_test.go index 09302cac4..671a95330 100644 --- a/x/perp/v2/keeper/grpc_query_test.go +++ b/x/perp/v2/keeper/grpc_query_test.go @@ -25,10 +25,12 @@ func TestQueryPositions(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), ), CreateCustomMarket( pair2, + WithEnabled(true), WithPricePeg(sdk.NewDec(3)), ), ). @@ -85,10 +87,12 @@ func TestQueryPositions(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.OneDec()), ), CreateCustomMarket( pair2, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.95")), ), ). @@ -145,10 +149,12 @@ func TestQueryPositions(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.5")), ), CreateCustomMarket( pair2, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.9")), ), ). @@ -214,6 +220,7 @@ func TestQueryPosition(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), ), ). @@ -247,6 +254,7 @@ func TestQueryPosition(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.OneDec()), ), ). @@ -280,6 +288,7 @@ func TestQueryPosition(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.MustNewDecFromStr("0.5")), ), ). @@ -313,6 +322,7 @@ func TestQueryPosition(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), ), ). @@ -334,6 +344,7 @@ func TestQueryMarkets(t *testing.T) { Given( CreateCustomMarket( pair, + WithEnabled(true), WithPricePeg(sdk.NewDec(2)), ), FundModule("perp_ef", sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10)))), @@ -348,7 +359,9 @@ func TestQueryMarkets(t *testing.T) { ), ). Then( - QueryMarkets(false, QueryMarkets_MarketsShouldContain(types.DefaultMarket(pair))), + QueryMarkets(false, QueryMarkets_MarketsShouldContain( + types.DefaultMarket(pair).WithEnabled(true)), + ), QueryModuleAccounts(QueryModuleAccounts_ModulesBalanceShouldBe( map[string]sdk.Coins{ "perp_ef": sdk.NewCoins( @@ -397,9 +410,9 @@ func TestQueryPositionStore(t *testing.T) { tc := TestCases{ TC("paginated positions in state"). Given( - CreateCustomMarket(pairs[0]), - CreateCustomMarket(pairs[1]), - CreateCustomMarket(pairs[2]), + CreateCustomMarket(pairs[0], WithEnabled(true)), + CreateCustomMarket(pairs[1], WithEnabled(true)), + CreateCustomMarket(pairs[2], WithEnabled(true)), ). When( InsertPosition(WithPair(pairs[2])), @@ -412,7 +425,7 @@ func TestQueryPositionStore(t *testing.T) { TC("get default number of positions per page"). Given( - CreateCustomMarket(pairs[2]), + CreateCustomMarket(pairs[2], WithEnabled(true)), ). When( insertManyPositions(99, pairs[2])..., @@ -425,7 +438,7 @@ func TestQueryPositionStore(t *testing.T) { TC("invalid request (key and offset defined)"). Given( - CreateCustomMarket(pairs[2]), + CreateCustomMarket(pairs[2], WithEnabled(true)), ). When( insertManyPositions(2, pairs[2])..., diff --git a/x/perp/v2/keeper/hooks_test.go b/x/perp/v2/keeper/hooks_test.go index 7b9a67d35..97d38dbc6 100644 --- a/x/perp/v2/keeper/hooks_test.go +++ b/x/perp/v2/keeper/hooks_test.go @@ -23,7 +23,7 @@ func TestAfterEpochEnd(t *testing.T) { tc := TestCases{ TC("index > mark"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockTime(startTime), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.MustNewDecFromStr("5.8")), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -37,7 +37,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("index < mark"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockTime(startTime), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.MustNewDecFromStr("0.52")), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -51,7 +51,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("index > mark - max funding rate"). Given( - CreateCustomMarket(pairBtcUsdc, WithMaxFundingRate(sdk.MustNewDecFromStr("0.001"))), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true), WithMaxFundingRate(sdk.MustNewDecFromStr("0.001"))), SetBlockTime(startTime), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.MustNewDecFromStr("5.8")), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -65,7 +65,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("index < mark - max funding rate"). Given( - CreateCustomMarket(pairBtcUsdc, WithMaxFundingRate(sdk.MustNewDecFromStr("0.001"))), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true), WithMaxFundingRate(sdk.MustNewDecFromStr("0.001"))), SetBlockTime(startTime), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.MustNewDecFromStr("0.52")), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -79,7 +79,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("index == mark"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockTime(startTime), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.OneDec()), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -93,7 +93,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("missing twap"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockTime(startTime), StartEpoch(epochtypes.ThirtyMinuteEpochID), ). @@ -106,7 +106,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("0 price mark"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockTime(startTime), StartEpoch(epochtypes.ThirtyMinuteEpochID), InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.ZeroDec()), @@ -118,9 +118,9 @@ func TestAfterEpochEnd(t *testing.T) { MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())), ), - TC("market not enabled"). + TC("market closed"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), CloseMarket(pairBtcUsdc), SetBlockTime(startTime), StartEpoch(epochtypes.ThirtyMinuteEpochID), @@ -135,7 +135,7 @@ func TestAfterEpochEnd(t *testing.T) { TC("not correct epoch id"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), CloseMarket(pairBtcUsdc), SetBlockTime(startTime), StartEpoch(epochtypes.FifteenMinuteEpochID), diff --git a/x/perp/v2/keeper/keeper.go b/x/perp/v2/keeper/keeper.go index 6d4cab188..60620852a 100644 --- a/x/perp/v2/keeper/keeper.go +++ b/x/perp/v2/keeper/keeper.go @@ -26,6 +26,9 @@ type Keeper struct { OracleKeeper types.OracleKeeper EpochKeeper types.EpochKeeper + // Extends the Keeper with admin functions. See admin.go. + Admin admin + MarketLastVersion collections.Map[asset.Pair, types.MarketLastVersion] Markets collections.Map[collections.Pair[asset.Pair, uint64], types.Market] AMMs collections.Map[collections.Pair[asset.Pair, uint64], types.AMM] @@ -53,7 +56,7 @@ func NewKeeper( panic("The x/perp module account has not been set") } - return Keeper{ + k := Keeper{ cdc: cdc, storeKey: storeKey, BankKeeper: bankKeeper, @@ -105,6 +108,8 @@ func NewKeeper( collections.DecValueEncoder, ), } + k.Admin = admin{&k} + return k } const ( diff --git a/x/perp/v2/keeper/margin_test.go b/x/perp/v2/keeper/margin_test.go index da071743b..cc545eda3 100644 --- a/x/perp/v2/keeper/margin_test.go +++ b/x/perp/v2/keeper/margin_test.go @@ -27,7 +27,7 @@ func TestAddMargin(t *testing.T) { tc := TestCases{ TC("existing long position, add margin"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(2020)))), @@ -77,7 +77,7 @@ func TestAddMargin(t *testing.T) { TC("existing short position, add margin"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(2020)))), @@ -127,8 +127,8 @@ func TestAddMargin(t *testing.T) { TC("Testing fails"). Given( - CreateCustomMarket(pairBtcUsdc), - CreateCustomMarket(pairEthUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), + CreateCustomMarket(pairEthUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), @@ -159,7 +159,7 @@ func TestRemoveMargin(t *testing.T) { tc := TestCases{ TC("existing long position, remove margin"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(1002)))), @@ -207,7 +207,7 @@ func TestRemoveMargin(t *testing.T) { TC("existing long position, remove almost all margin fails"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(1002)))), @@ -234,7 +234,7 @@ func TestRemoveMargin(t *testing.T) { TC("existing short position, remove margin"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(1002)))), @@ -282,7 +282,7 @@ func TestRemoveMargin(t *testing.T) { TC("existing short position, remove almost all margin fails"). Given( - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), SetBlockNumber(1), SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.USDC, sdk.NewInt(1002)))), diff --git a/x/perp/v2/keeper/msg_server_test.go b/x/perp/v2/keeper/msg_server_test.go index 057bbf13c..0c6e8377a 100644 --- a/x/perp/v2/keeper/msg_server_test.go +++ b/x/perp/v2/keeper/msg_server_test.go @@ -26,7 +26,7 @@ func TestMsgServerMarketOrder(t *testing.T) { tests := TestCases{ TC("open long position"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), ). When( @@ -49,7 +49,7 @@ func TestMsgServerMarketOrder(t *testing.T) { TC("open short position"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), ). When( @@ -81,7 +81,7 @@ func TestMsgServerClosePosition(t *testing.T) { tests := TestCases{ TC("close long position"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), MarketOrder(alice, pair, types.Direction_LONG, sdk.OneInt(), sdk.OneDec(), sdk.ZeroDec()), MoveToNextBlock(), @@ -96,7 +96,7 @@ func TestMsgServerClosePosition(t *testing.T) { TC("close short position"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), MarketOrder(alice, pair, types.Direction_LONG, sdk.OneInt(), sdk.OneDec(), sdk.ZeroDec()), MoveToNextBlock(), @@ -120,7 +120,7 @@ func TestMsgServerAddMargin(t *testing.T) { tests := TestCases{ TC("add margin"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), MarketOrder(alice, pair, types.Direction_LONG, sdk.OneInt(), sdk.OneDec(), sdk.ZeroDec()), MoveToNextBlock(), @@ -144,7 +144,7 @@ func TestMsgServerAddMargin(t *testing.T) { ), TC("partial close"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), MarketOrder(alice, pair, types.Direction_LONG, sdk.OneInt(), sdk.OneDec(), sdk.ZeroDec()), MoveToNextBlock(), @@ -178,7 +178,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { tests := TestCases{ TC("add margin"). Given( - CreateCustomMarket(pair), + CreateCustomMarket(pair, WithEnabled(true)), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 100))), MarketOrder(alice, pair, types.Direction_LONG, sdk.NewInt(2), sdk.OneDec(), sdk.ZeroDec()), MoveToNextBlock(), @@ -236,7 +236,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { Given( SetBlockNumber(1), SetBlockTime(startTime), - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), InsertPosition(WithTrader(alice), WithPair(pairBtcUsdc), WithSize(sdk.NewDec(10000)), WithMargin(sdk.NewDec(1000)), WithOpenNotional(sdk.NewDec(10400))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 1000))), ). @@ -269,7 +269,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { Given( SetBlockNumber(1), SetBlockTime(startTime), - CreateCustomMarket(pairBtcUsdc), + CreateCustomMarket(pairBtcUsdc, WithEnabled(true)), InsertPosition(WithTrader(alice), WithPair(pairBtcUsdc), WithSize(sdk.NewDec(10000)), WithMargin(sdk.NewDec(1000)), WithOpenNotional(sdk.NewDec(10600))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 1000))), ). diff --git a/x/perp/v2/keeper/settlement.go b/x/perp/v2/keeper/settlement.go index 62df34791..970cd3a37 100644 --- a/x/perp/v2/keeper/settlement.go +++ b/x/perp/v2/keeper/settlement.go @@ -7,36 +7,6 @@ import ( "github.com/NibiruChain/nibiru/x/perp/v2/types" ) -// CloseMarket closes the market. From now on, no new position can be opened on this market or closed. -// Only the open positions can be settled by calling SettlePosition. -func (k Keeper) CloseMarket(ctx sdk.Context, pair asset.Pair) (err error) { - market, err := k.GetMarket(ctx, pair) - if err != nil { - return err - } - if !market.Enabled { - return types.ErrMarketNotEnabled - } - - amm, err := k.GetAMM(ctx, pair) - if err != nil { - return err - } - - settlementPrice, _, err := amm.ComputeSettlementPrice() - if err != nil { - return - } - - amm.SettlementPrice = settlementPrice - market.Enabled = false - - k.SaveAMM(ctx, amm) - k.SaveMarket(ctx, market) - - return nil -} - // SettlePosition settles a position and transfer the margin and funding payments to the trader. func (k Keeper) SettlePosition(ctx sdk.Context, pair asset.Pair, version uint64, traderAddr sdk.AccAddress) (resp *types.PositionResp, err error) { market, err := k.GetMarketByPairAndVersion(ctx, pair, version) diff --git a/x/perp/v2/keeper/settlement_test.go b/x/perp/v2/keeper/settlement_test.go index 23b501ef1..74b748457 100644 --- a/x/perp/v2/keeper/settlement_test.go +++ b/x/perp/v2/keeper/settlement_test.go @@ -16,108 +16,6 @@ import ( "github.com/NibiruChain/nibiru/x/perp/v2/types" ) -func TestDisableMarket(t *testing.T) { - pairBtcUsdc := asset.Registry.Pair(denoms.BTC, denoms.NUSD) - startTime := time.Now() - alice := testutil.AccAddress() - - tc := TestCases{ - TC("market can be disabled"). - Given( - CreateCustomMarket(pairBtcUsdc), - SetBlockTime(startTime), - MarketShouldBeEqual( - pairBtcUsdc, - Market_EnableShouldBeEqualTo(true), - ), - ). - When( - CloseMarket(pairBtcUsdc), - ). - Then( - MarketShouldBeEqual( - pairBtcUsdc, - Market_EnableShouldBeEqualTo(false), - ), - ), - TC("cannot open position on disabled market"). - Given( - CreateCustomMarket( - pairBtcUsdc, - WithPricePeg(sdk.OneDec()), - WithSqrtDepth(sdk.NewDec(100_000)), - ), - SetBlockNumber(1), - SetBlockTime(startTime), - - FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)))), - ). - When( - CloseMarket(pairBtcUsdc), - ). - Then( - MarketOrderFails( - alice, - pairBtcUsdc, - types.Direction_LONG, - sdk.NewInt(10_000), - sdk.OneDec(), - sdk.ZeroDec(), - types.ErrMarketNotEnabled, - ), - ), - TC("cannot close position on disabled market").When( - CreateCustomMarket( - pairBtcUsdc, - WithPricePeg(sdk.OneDec()), - WithSqrtDepth(sdk.NewDec(100_000)), - ), - SetBlockNumber(1), - SetBlockTime(startTime), - FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200)))), - MarketOrder( - alice, - pairBtcUsdc, - types.Direction_LONG, - sdk.NewInt(10_000), - sdk.OneDec(), - sdk.ZeroDec(), - ), - ).When( - CloseMarket(pairBtcUsdc), - CloseMarketShouldFail(pairBtcUsdc), - CloseMarketShouldFail("random:pair"), - ).Then( - ClosePositionFails(alice, pairBtcUsdc, types.ErrMarketNotEnabled), - ), - TC("cannot partial close position on disabled market").When( - CreateCustomMarket( - pairBtcUsdc, - WithPricePeg(sdk.OneDec()), - WithSqrtDepth(sdk.NewDec(100_000)), - ), - SetBlockNumber(1), - SetBlockTime(startTime), - FundAccount(alice, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10_200)))), - MarketOrder( - alice, - pairBtcUsdc, - types.Direction_LONG, - sdk.NewInt(10_000), - sdk.OneDec(), - sdk.ZeroDec(), - ), - ).When( - CloseMarket(pairBtcUsdc), - AMMShouldBeEqual(pairBtcUsdc, AMM_SettlementPriceShoulBeEqual(sdk.MustNewDecFromStr("1.1"))), - ).Then( - PartialCloseFails(alice, pairBtcUsdc, sdk.NewDec(5_000), types.ErrMarketNotEnabled), - ), - } - - NewTestSuite(t).WithTestCases(tc...).Run() -} - func TestSettlePosition(t *testing.T) { pairBtcUsdc := asset.Registry.Pair(denoms.BTC, denoms.NUSD) startTime := time.Now() @@ -131,6 +29,7 @@ func TestSettlePosition(t *testing.T) { pairBtcUsdc, WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), + WithEnabled(true), ), SetBlockNumber(1), SetBlockTime(startTime), @@ -155,6 +54,7 @@ func TestSettlePosition(t *testing.T) { pairBtcUsdc, WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), + WithEnabled(true), ), SetBlockNumber(1), SetBlockTime(startTime), @@ -223,6 +123,7 @@ func TestSettlePosition(t *testing.T) { pairBtcUsdc, WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), + WithEnabled(true), ), SetBlockNumber(1), SetBlockTime(startTime), @@ -245,6 +146,7 @@ func TestSettlePosition(t *testing.T) { WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), WithVersion(1), + WithEnabled(true), ), SetBlockNumber(1), SetBlockTime(startTime), @@ -264,6 +166,7 @@ func TestSettlePosition(t *testing.T) { WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), WithVersion(2), + WithEnabled(true), ), SetBlockNumber(2), MarketOrder( @@ -289,6 +192,7 @@ func TestSettlePosition(t *testing.T) { WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), WithVersion(1), + WithEnabled(true), ), SetBlockNumber(1), SetBlockTime(startTime), @@ -308,6 +212,7 @@ func TestSettlePosition(t *testing.T) { WithPricePeg(sdk.OneDec()), WithSqrtDepth(sdk.NewDec(100_000)), WithVersion(2), + WithEnabled(true), ), SetBlockNumber(2), MarketOrder( diff --git a/x/perp/v2/module/abci_test.go b/x/perp/v2/module/abci_test.go index 8d0411607..4da2dbc78 100644 --- a/x/perp/v2/module/abci_test.go +++ b/x/perp/v2/module/abci_test.go @@ -34,7 +34,7 @@ func TestSnapshotUpdates(t *testing.T) { ctx = ctx.WithBlockTime(time.Date(2015, 10, 21, 0, 0, 0, 0, time.UTC)).WithBlockHeight(1) - require.NoError(t, app.PerpKeeperV2.Admin().CreateMarket( + require.NoError(t, app.PerpKeeperV2.Admin.CreateMarket( /* ctx */ ctx, keeper.ArgsCreateMarket{ Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), PriceMultiplier: initialAmm.PriceMultiplier, @@ -119,7 +119,7 @@ func TestEndBlocker(t *testing.T) { runBlock(5 * time.Second) - require.NoError(t, app.PerpKeeperV2.Admin().CreateMarket( + require.NoError(t, app.PerpKeeperV2.Admin.CreateMarket( /* ctx */ ctx, keeper.ArgsCreateMarket{ Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), PriceMultiplier: initialAmm.PriceMultiplier, diff --git a/x/perp/v2/types/genesis.go b/x/perp/v2/types/genesis.go index 4a070e9fb..ae9628a9d 100644 --- a/x/perp/v2/types/genesis.go +++ b/x/perp/v2/types/genesis.go @@ -50,7 +50,7 @@ func (gs GenesisState) Validate() error { func DefaultMarket(pair asset.Pair) Market { return Market{ Pair: pair, - Enabled: true, + Enabled: false, Version: 1, LatestCumulativePremiumFraction: sdk.ZeroDec(), ExchangeFeeRatio: sdk.MustNewDecFromStr("0.0010"),