Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant #1680

Merged
merged 21 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
596c664
chore(deps): Bump cosmossdk.io/math from 1.1.2 to 1.2.0
dependabot[bot] Nov 17, 2023
8722fce
feat(perp): msg server methods for shift peg and shift swap invariant
Unique-Divine Nov 28, 2023
e295eb3
(wasmbinding): remove pegshitft and depth shift
Unique-Divine Nov 28, 2023
0232852
test(perp): msg tests
Unique-Divine Nov 28, 2023
1220834
change log
Unique-Divine Nov 28, 2023
696d636
Merge branch 'master' into realu/perp-sg
Unique-Divine Nov 28, 2023
63b72aa
Update x/perp/v2/types/msgs.go
Unique-Divine Nov 28, 2023
b081818
PR comments changes
Unique-Divine Nov 28, 2023
1b5c836
add events for logging purposes
Unique-Divine Nov 28, 2023
2f0a125
refactor: consistent error name usage PR comment
Unique-Divine Nov 28, 2023
552a2d5
refactor: more PR comments
Unique-Divine Nov 28, 2023
fe1fe03
Address Gimeno PR comments + more tests
Unique-Divine Nov 29, 2023
c3ef701
fix strange address name conflicts
Unique-Divine Nov 29, 2023
a2ee8aa
test: fix all tests
Unique-Divine Dec 1, 2023
ad8c56b
test: more calls of EnsureNibiruPrefix
Unique-Divine Dec 1, 2023
3ff816f
Merge branch 'master' into realu/perp-sg
Unique-Divine Dec 1, 2023
f5415fd
Merge branch 'master' into dependabot/go_modules/cosmossdk.io/math-1.2.0
Unique-Divine Dec 1, 2023
bd55994
Updated changelog - dependabot
Unique-Divine Dec 1, 2023
46cd514
Merge branch 'master' into dependabot/go_modules/cosmossdk.io/math-1.2.0
Unique-Divine Dec 1, 2023
05810f3
Merge branch 'dependabot/go_modules/cosmossdk.io/math-1.2.0' into rea…
Unique-Divine Dec 1, 2023
7de9341
test: fix no error cases in tests
Unique-Divine Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1617](https://github.com/NibiruChain/nibiru/pull/1617) - fix(app)!: non-nil snapshot manager is not guaranteed in testapp
* [#1645](https://github.com/NibiruChain/nibiru/pull/1645) - fix(tokenfactory)!: token supply in bank keeper must be correct after MsgBurn.
* [#1646](https://github.com/NibiruChain/nibiru/pull/1646) - feat(wasmbinding)!: whitelisted stargate queries for QueryRequest::Stargate: auth, bank, gov, tokenfactory, epochs, inflation, oracle, sudo, devgas
* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant.

### Improvements

Expand Down
1 change: 1 addition & 0 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
gen := ModuleBasics.DefaultGenesis(cdc)

authGenesis := new(authtypes.GenesisState)
authtypes.DefaultGenesisState()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to authtypes.DefaultGenesisState() is not being used. If the intention was to set the default genesis state for the auth module, it should be assigned to authGenesis:

- authtypes.DefaultGenesisState()
+ *authGenesis = authtypes.DefaultGenesisState()

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
authtypes.DefaultGenesisState()
*authGenesis = authtypes.DefaultGenesisState()

cdc.MustUnmarshalJSON(gen[authtypes.ModuleName], authGenesis)

return gen
Expand Down
1 change: 1 addition & 0 deletions app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// init changes the value of 'DefaultTestingAppInit' to use custom initialization.
func init() {
ibctesting.DefaultTestingAppInit = SetupNibiruTestingApp
testapp.EnsureNibiruPrefix()
}

/*
Expand Down
22 changes: 11 additions & 11 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ func (app *NibiruApp) InitKeepers(
tkeys := app.tkeys
memKeys := app.memKeys

govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
app.paramsKeeper = initParamsKeeper(
appCodec, legacyAmino, keys[paramstypes.StoreKey],
tkeys[paramstypes.TStoreKey],
)

// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], govModuleAddr)
bApp.SetParamStore(&app.ConsensusParamsKeeper)

/* Add capabilityKeeper and ScopeToModule for the ibc module
Expand Down Expand Up @@ -274,21 +275,21 @@ func (app *NibiruApp) InitKeepers(
authtypes.ProtoBaseAccount,
maccPerms,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.stakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec,
Expand All @@ -297,7 +298,7 @@ func (app *NibiruApp) InitKeepers(
app.BankKeeper,
app.stakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
Expand All @@ -307,7 +308,7 @@ func (app *NibiruApp) InitKeepers(
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
Expand All @@ -326,7 +327,7 @@ func (app *NibiruApp) InitKeepers(
appCodec,
homePath,
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

// register the staking hooks
Expand All @@ -336,7 +337,7 @@ func (app *NibiruApp) InitKeepers(
legacyAmino,
keys[slashingtypes.StoreKey],
app.stakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

app.stakingKeeper.SetHooks(
Expand Down Expand Up @@ -442,12 +443,11 @@ func (app *NibiruApp) InitKeepers(
wasmDir,
wasmConfig,
supportedFeatures,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
GetWasmOpts(*app, appOpts)...,
)

// DevGas uses WasmKeeper
govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
app.DevGasKeeper = devgaskeeper.NewKeeper(
keys[devgastypes.StoreKey],
appCodec,
Expand Down Expand Up @@ -553,7 +553,7 @@ func (app *NibiruApp) InitKeepers(
app.stakingKeeper,
app.MsgServiceRouter(),
govConfig,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
govKeeper.SetLegacyRouter(govRouter)

Expand Down
26 changes: 26 additions & 0 deletions proto/nibiru/perp/v2/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,29 @@ message MarketUpdatedEvent {
// the final state of the market
nibiru.perp.v2.Market final_market = 1 [ (gogoproto.nullable) = false ];
}

// EventShiftPegMultiplier: ABCI event emitted from MsgShiftPegMultiplier
message EventShiftPegMultiplier {
string old_peg_multiplier = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string new_peg_multiplier = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin cost_paid = 3 [ (gogoproto.nullable) = false ];
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
}

// EventShiftSwapInvariant: ABCI event emitted from MsgShiftSwapInvariant
message EventShiftSwapInvariant {
string old_swap_invariant = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string new_swap_invariant = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin cost_paid = 3 [ (gogoproto.nullable) = false ];
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
}
58 changes: 55 additions & 3 deletions proto/nibiru/perp/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,26 @@ service Msg {
rpc DonateToEcosystemFund(MsgDonateToEcosystemFund)
returns (MsgDonateToEcosystemFundResponse) {}

// ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it
// is possible to make an sdk.Coin using it. [Admin] Only callable by sudoers.
rpc ChangeCollateralDenom(MsgChangeCollateralDenom)
returns (MsgChangeCollateralDenomResponse) {}

rpc AllocateEpochRebates(MsgAllocateEpochRebates) returns (MsgAllocateEpochRebatesResponse) {}
rpc AllocateEpochRebates(MsgAllocateEpochRebates)
returns (MsgAllocateEpochRebatesResponse) {}

rpc WithdrawEpochRebates(MsgWithdrawEpochRebates) returns (MsgWithdrawEpochRebatesResponse) {}
rpc WithdrawEpochRebates(MsgWithdrawEpochRebates)
returns (MsgWithdrawEpochRebatesResponse) {}

// ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier.
// [Admin] Only callable by sudoers.
rpc ShiftPegMultiplier(MsgShiftPegMultiplier)
returns (MsgShiftPegMultiplierResponse) {}

// ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant.
// [Admin] Only callable by sudoers.
rpc ShiftSwapInvariant(MsgShiftSwapInvariant)
returns (MsgShiftSwapInvariantResponse) {}
}

// -------------------------- Settle Position --------------------------
Expand Down Expand Up @@ -376,4 +390,42 @@ message MsgWithdrawEpochRebatesResponse {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
}

// -------------------------- ShiftPegMultiplier --------------------------

// ShiftPegMultiplier: gRPC tx msg for changing the peg multiplier.
// Admin-only.
message MsgShiftPegMultiplier {
string sender = 1;
string pair = 2 [
(gogoproto.customtype) =
"github.com/NibiruChain/nibiru/x/common/asset.Pair",
(gogoproto.nullable) = false
];
string new_peg_mult = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MsgShiftPegMultiplierResponse {}

// -------------------------- ShiftSwapInvariant --------------------------

// ShiftSwapInvariant: gRPC tx msg for changing the swap invariant.
// Admin-only.
message MsgShiftSwapInvariant {
string sender = 1;
string pair = 2 [
(gogoproto.customtype) =
"github.com/NibiruChain/nibiru/x/common/asset.Pair",
(gogoproto.nullable) = false
];
string new_swap_invariant = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

message MsgShiftSwapInvariantResponse {}
12 changes: 0 additions & 12 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type NibiruMsg struct {
RemoveMargin *RemoveMargin `json:"remove_margin,omitempty"`
DonateToInsuranceFund *DonateToInsuranceFund `json:"donate_to_insurance_fund,omitempty"` // TODO
InsuranceFundWithdraw *InsuranceFundWithdraw `json:"insurance_fund_withdraw,omitempty"`
PegShift *PegShift `json:"peg_shift,omitempty"`
DepthShift *DepthShift `json:"depth_shift,omitempty"`
SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"`
CreateMarket *CreateMarket `json:"create_market,omitempty"`

Expand Down Expand Up @@ -62,16 +60,6 @@ type RemoveMargin struct {
Margin sdk.Coin `json:"margin"`
}

type PegShift struct {
Pair string `json:"pair"`
PegMult sdk.Dec `json:"peg_mult"`
}

type DepthShift struct {
Pair string `json:"pair"`
DepthMult sdk.Dec `json:"depth_mult"`
}

type DonateToInsuranceFund struct {
Sender string `json:"sender"`
Donation sdk.Coin `json:"donation"`
Expand Down
33 changes: 0 additions & 33 deletions wasmbinding/exec_perp.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,6 @@ func (exec *ExecutorPerp) RemoveMargin(
return exec.MsgServer().RemoveMargin(goCtx, sdkMsg)
}

func (exec *ExecutorPerp) PegShift(
cwMsg *bindings.PegShift, contractAddr sdk.AccAddress, ctx sdk.Context,
) (err error) {
if cwMsg == nil {
return wasmvmtypes.InvalidRequest{Err: "null msg"}
}

pair, err := asset.TryNewPair(cwMsg.Pair)
if err != nil {
return err
}

return exec.PerpV2.EditPriceMultiplier(
ctx,
// contractAddr,
pair,
cwMsg.PegMult,
)
}

func (exec *ExecutorPerp) DepthShift(cwMsg *bindings.DepthShift, ctx sdk.Context) (err error) {
if cwMsg == nil {
return wasmvmtypes.InvalidRequest{Err: "null msg"}
}

pair, err := asset.TryNewPair(cwMsg.Pair)
if err != nil {
return err
}

return exec.PerpV2.EditSwapInvariant(ctx, pair, cwMsg.DepthMult)
}

func (exec *ExecutorPerp) InsuranceFundWithdraw(
cwMsg *bindings.InsuranceFundWithdraw, ctx sdk.Context,
) (err error) {
Expand Down
31 changes: 0 additions & 31 deletions wasmbinding/exec_perp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (s *TestSuitePerpExecutor) TestOpenAddRemoveClose() {
s.DoRemoveIncorrectMarginTest(pair, incorrectMargin),
s.DoRemoveMarginTest(pair, margin),
s.DoClosePositionTest(pair),
s.DoPegShiftTest(pair),
s.DoInsuranceFundWithdrawTest(sdk.NewInt(69), s.contractDeployer),
s.DoCreateMarketTest(asset.MustNewPair("ufoo:ubar")),
s.DoCreateMarketTestWithParams(asset.MustNewPair("ufoo2:ubar")),
Expand Down Expand Up @@ -212,27 +211,6 @@ func (s *TestSuitePerpExecutor) DoClosePositionTest(pair asset.Pair) error {
return err
}

func (s *TestSuitePerpExecutor) DoPegShiftTest(pair asset.Pair) error {
contractAddr := s.contractPerp
cwMsg := &bindings.PegShift{
Pair: pair.String(),
PegMult: sdk.NewDec(420),
}

err := s.exec.PegShift(cwMsg, contractAddr, s.ctx)
return err
}

func (s *TestSuitePerpExecutor) DoDepthShiftTest(pair asset.Pair) error {
cwMsg := &bindings.DepthShift{
Pair: pair.String(),
DepthMult: sdk.NewDec(420),
}

err := s.exec.DepthShift(cwMsg, s.ctx)
return err
}

func (s *TestSuitePerpExecutor) DoInsuranceFundWithdrawTest(
amt sdkmath.Int, to sdk.AccAddress,
) error {
Expand Down Expand Up @@ -302,13 +280,6 @@ func (s *TestSuitePerpExecutor) TestSadPaths_Nil() {
_, err = s.exec.ClosePosition(nil, nil, s.ctx)
s.Error(err)

err = s.exec.PegShift(
nil, sdk.AccAddress([]byte("contract")), s.ctx)
s.Error(err)

err = s.exec.DepthShift(nil, s.ctx)
s.Error(err)

err = s.exec.InsuranceFundWithdraw(nil, s.ctx)
s.Error(err)
}
Expand Down Expand Up @@ -348,8 +319,6 @@ func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() {
s.DoAddMarginTest(pair, margin),
s.DoRemoveMarginTest(pair, margin),
s.DoClosePositionTest(pair),
s.DoPegShiftTest(pair),
s.DoDepthShiftTest(pair),
s.DoSetMarketEnabledTest(pair, true),
s.DoSetMarketEnabledTest(pair, false),
s.DoCreateMarketTest(pair),
Expand Down
Loading
Loading