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

chore: backport https://github.com/skip-mev/connect/pull/778 #868

Merged
merged 2 commits into from
Dec 11, 2024
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
176 changes: 88 additions & 88 deletions api/slinky/marketmap/v1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions proto/slinky/marketmap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ message MsgRemoveMarketAuthoritiesResponse {}
// 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" ];

// Markets is the list of markets to remove.
repeated string markets = 2;
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/slinky_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ func (s *SlinkyIntegrationSuite) 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
14 changes: 7 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 @@

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 All @@ -283,6 +279,10 @@
ctx.Logger().Info(fmt.Sprintf("deleted market %s", market))
deletedMarkets = append(deletedMarkets, market)
}

if err := ms.k.hooks.AfterMarketRemoved(ctx, market); err != nil {
return nil, fmt.Errorf("unable to run market removal hook: %w", err)
}

Check warning on line 285 in x/marketmap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/keeper/msg_server.go#L284-L285

Added lines #L284 - L285 were not covered by tests
}

// check if the resulting state is valid: it may not be valid if the removed market is used as a normalization pair
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
8 changes: 4 additions & 4 deletions x/marketmap/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
AfterMarketGenesis(ctx sdk.Context, tickers map[string]Market) error

// AfterMarketRemoved is called after a market is removed.
AfterMarketRemoved(ctx sdk.Context, market Market) error
AfterMarketRemoved(ctx sdk.Context, key string) error
}

var _ MarketMapHooks = &MultiMarketMapHooks{}
Expand Down Expand Up @@ -58,9 +58,9 @@
}

// AfterMarketRemoved calls all AfterMarketRemoved hooks registered to the MultiMarketMapHooks.
func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, market Market) error {
func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, key string) error {

Check warning on line 61 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L61

Added line #L61 was not covered by tests
for i := range mh {
if err := mh[i].AfterMarketRemoved(ctx, market); err != nil {
if err := mh[i].AfterMarketRemoved(ctx, key); err != nil {

Check warning on line 63 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L63

Added line #L63 was not covered by tests
return err
}
}
Expand Down Expand Up @@ -88,6 +88,6 @@
return nil
}

func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ Market) error {
func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ string) error {

Check warning on line 91 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L91

Added line #L91 was not covered by tests
return nil
}
10 changes: 5 additions & 5 deletions x/marketmap/types/mocks/MarketMapHooks.go

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

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
Loading
Loading