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: Allow market authority to remove disabled markets #838

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions proto/connect/marketmap/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@
// MsgRemoveMarkets defines the Msg/RemoveMarkets request type. It contains the
// new markets to be removed from the market map.
message MsgRemoveMarkets {
option (cosmos.msg.v1.signer) = "admin";
option (cosmos.msg.v1.signer) = "authority";

// Admin defines the authority that is the x/marketmap
// Admin account. This account is set in the module parameters.
string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Authority is the signer of this transaction. This authority must be
// authorized by the module to execute the message.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

Check failure on line 150 in proto/connect/marketmap/v2/tx.proto

View workflow job for this annotation

GitHub Actions / build

Field "1" with name "authority" on message "MsgRemoveMarkets" changed option "json_name" from "admin" to "authority".

Check failure on line 150 in proto/connect/marketmap/v2/tx.proto

View workflow job for this annotation

GitHub Actions / build

Field "1" on message "MsgRemoveMarkets" changed name from "admin" to "authority".

// Markets is the list of markets to remove.
repeated string markets = 2;
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/connect_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ func (s *ConnectIntegrationSuite) RemoveMarket(
}

msg := &mmtypes.MsgRemoveMarkets{
Admin: s.user.FormattedAddress(),
Markets: marketString,
Authority: s.user.FormattedAddress(),
Markets: marketString,
}

tx := CreateTx(s.T(), s.chain, s.user, gasPrice, msg)
Expand Down
10 changes: 3 additions & 7 deletions x/marketmap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,9 @@ func (ms msgServer) RemoveMarkets(

ctx := sdk.UnwrapSDKContext(goCtx)

params, err := ms.k.GetParams(ctx)
if err != nil {
return nil, err
}

if msg.Admin != params.Admin {
return nil, fmt.Errorf("request admin %s does not match module admin %s", msg.Admin, params.Admin)
// perform basic msg validity checks
if err := ms.verifyMarketAuthorities(ctx, msg); err != nil {
return nil, fmt.Errorf("unable to verify market authorities: %w", err)
}

deletedMarkets := make([]string, 0, len(msg.Markets))
Expand Down
34 changes: 17 additions & 17 deletions x/marketmap/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("unable to process for invalid authority", func() {
msg := &types.MsgRemoveMarkets{
Admin: "invalid",
Authority: "invalid",
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().Error(err)
Expand All @@ -540,8 +540,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("only remove existing markets - no error", func() {
msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{"BTC/USD", "ETH/USDT"},
Authority: s.marketAuthorities[0],
Markets: []string{"BTC/USD", "ETH/USDT"},
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().NoError(err)
Expand All @@ -550,8 +550,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("unable to remove non-existent market - single", func() {
msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{"BTC/USD"},
Authority: s.marketAuthorities[0],
Markets: []string{"BTC/USD"},
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().NoError(err)
Expand All @@ -563,8 +563,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
copyBTC.Ticker.Enabled = false

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

err := s.keeper.CreateMarket(s.ctx, copyBTC)
Expand All @@ -587,8 +587,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down Expand Up @@ -638,13 +638,13 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msgRemoveBTC := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

msgRemoveETH := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msgRemoveBTC)
Expand Down Expand Up @@ -673,8 +673,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down Expand Up @@ -713,8 +713,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down
2 changes: 1 addition & 1 deletion x/marketmap/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *MsgRemoveMarketAuthorities) ValidateBasic() error {
// whether the signer is a valid acc-address.
func (m *MsgRemoveMarkets) ValidateBasic() error {
// validate signer address
if _, err := sdk.AccAddressFromBech32(m.Admin); err != nil {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return err
}

Expand Down
18 changes: 9 additions & 9 deletions x/marketmap/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,39 +528,39 @@ func TestValidateBasicMsgRemoveMarkets(t *testing.T) {
{
"if the Authority is not an acc-address - fail",
types.MsgRemoveMarkets{
Admin: "invalid",
Authority: "invalid",
},
false,
},
{
name: "invalid message (no markets) - fail",
msg: types.MsgRemoveMarkets{
Markets: nil,
Admin: sample.Address(rng),
Markets: nil,
Authority: sample.Address(rng),
},
expectPass: false,
},
{
name: "valid message - single market",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD"},
Authority: sample.Address(rng),
},
expectPass: true,
},
{
name: "valid message - multiple markets",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD", "ETH/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD", "ETH/USD"},
Authority: sample.Address(rng),
},
expectPass: true,
},
{
name: "invalid message (duplicate markets",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD", "USDT/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD", "USDT/USD"},
Authority: sample.Address(rng),
},
expectPass: false,
},
Expand Down
120 changes: 60 additions & 60 deletions x/marketmap/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading