diff --git a/protocol/x/vault/keeper/msg_server_update_default_quoting_params.go b/protocol/x/vault/keeper/msg_server_update_default_quoting_params.go index 77efb73728..043c41f0a9 100644 --- a/protocol/x/vault/keeper/msg_server_update_default_quoting_params.go +++ b/protocol/x/vault/keeper/msg_server_update_default_quoting_params.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) @@ -15,15 +14,18 @@ func (k msgServer) UpdateDefaultQuotingParams( goCtx context.Context, msg *types.MsgUpdateDefaultQuotingParams, ) (*types.MsgUpdateDefaultQuotingParamsResponse, error) { - if !k.HasAuthority(msg.Authority) { + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + operator := k.GetOperatorParams(ctx).Operator + + // Check if authority is valid (must be a module authority or operator). + if !k.HasAuthority(msg.Authority) && msg.Authority != operator { return nil, errorsmod.Wrapf( - govtypes.ErrInvalidSigner, + types.ErrInvalidAuthority, "invalid authority %s", msg.Authority, ) } - ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) if err := k.SetDefaultQuotingParams(ctx, msg.DefaultQuotingParams); err != nil { return nil, err } diff --git a/protocol/x/vault/keeper/msg_server_update_default_quoting_params_test.go b/protocol/x/vault/keeper/msg_server_update_default_quoting_params_test.go index 64da998a17..c905bab018 100644 --- a/protocol/x/vault/keeper/msg_server_update_default_quoting_params_test.go +++ b/protocol/x/vault/keeper/msg_server_update_default_quoting_params_test.go @@ -9,28 +9,39 @@ import ( testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + "github.com/cometbft/cometbft/types" "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" - "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" + vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" ) func TestMsgUpdateDefaultQuotingParams(t *testing.T) { tests := map[string]struct { // Msg. - msg *types.MsgUpdateDefaultQuotingParams + msg *vaulttypes.MsgUpdateDefaultQuotingParams + // Operator. + operator string // Expected error expectedErr string }{ - "Success. Update to default": { - msg: &types.MsgUpdateDefaultQuotingParams{ + "Success. Update to default. Gov Authority": { + msg: &vaulttypes.MsgUpdateDefaultQuotingParams{ Authority: lib.GovModuleAddress.String(), - DefaultQuotingParams: types.DefaultQuotingParams(), + DefaultQuotingParams: vaulttypes.DefaultQuotingParams(), }, + operator: constants.AliceAccAddress.String(), + }, + "Success. Update to default. Operator Authority": { + msg: &vaulttypes.MsgUpdateDefaultQuotingParams{ + Authority: constants.CarlAccAddress.String(), + DefaultQuotingParams: vaulttypes.DefaultQuotingParams(), + }, + operator: constants.CarlAccAddress.String(), }, "Success. Update to non-default": { - msg: &types.MsgUpdateDefaultQuotingParams{ + msg: &vaulttypes.MsgUpdateDefaultQuotingParams{ Authority: lib.GovModuleAddress.String(), - DefaultQuotingParams: types.QuotingParams{ + DefaultQuotingParams: vaulttypes.QuotingParams{ Layers: 3, SpreadMinPpm: 234_567, SpreadBufferPpm: 6_789, @@ -40,18 +51,20 @@ func TestMsgUpdateDefaultQuotingParams(t *testing.T) { ActivationThresholdQuoteQuantums: dtypes.NewInt(2_121_343_787), }, }, + operator: constants.AliceAccAddress.String(), }, "Failure - Invalid Authority": { - msg: &types.MsgUpdateDefaultQuotingParams{ + msg: &vaulttypes.MsgUpdateDefaultQuotingParams{ Authority: constants.AliceAccAddress.String(), - DefaultQuotingParams: types.DefaultQuotingParams(), + DefaultQuotingParams: vaulttypes.DefaultQuotingParams(), }, + operator: constants.BobAccAddress.String(), expectedErr: "invalid authority", }, "Failure - Invalid Params": { - msg: &types.MsgUpdateDefaultQuotingParams{ + msg: &vaulttypes.MsgUpdateDefaultQuotingParams{ Authority: lib.GovModuleAddress.String(), - DefaultQuotingParams: types.QuotingParams{ + DefaultQuotingParams: vaulttypes.QuotingParams{ Layers: 3, SpreadMinPpm: 4_000, SpreadBufferPpm: 2_000, @@ -61,13 +74,26 @@ func TestMsgUpdateDefaultQuotingParams(t *testing.T) { ActivationThresholdQuoteQuantums: dtypes.NewInt(1_000_000_000), }, }, - expectedErr: types.ErrInvalidOrderSizePctPpm.Error(), + operator: constants.AliceAccAddress.String(), + expectedErr: vaulttypes.ErrInvalidOrderSizePctPpm.Error(), }, } for name, tc := range tests { t.Run(name, func(t *testing.T) { - tApp := testapp.NewTestAppBuilder(t).Build() + tApp := testapp.NewTestAppBuilder(t).WithGenesisDocFn(func() (genesis types.GenesisDoc) { + genesis = testapp.DefaultGenesis() + // Set megavault operator. + testapp.UpdateGenesisDocWithAppStateForModule( + &genesis, + func(genesisState *vaulttypes.GenesisState) { + genesisState.OperatorParams = vaulttypes.OperatorParams{ + Operator: tc.operator, + } + }, + ) + return genesis + }).Build() ctx := tApp.InitChain() k := tApp.App.VaultKeeper ms := keeper.NewMsgServerImpl(k) @@ -75,7 +101,7 @@ func TestMsgUpdateDefaultQuotingParams(t *testing.T) { _, err := ms.UpdateDefaultQuotingParams(ctx, tc.msg) if tc.expectedErr != "" { require.ErrorContains(t, err, tc.expectedErr) - require.Equal(t, types.DefaultQuotingParams(), k.GetDefaultQuotingParams(ctx)) + require.Equal(t, vaulttypes.DefaultQuotingParams(), k.GetDefaultQuotingParams(ctx)) } else { require.NoError(t, err) require.Equal(t, tc.msg.DefaultQuotingParams, k.GetDefaultQuotingParams(ctx))