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

fix: clean up market map hooks #778

Merged
merged 4 commits into from
Sep 30, 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
4 changes: 4 additions & 0 deletions x/marketmap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,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 288 in x/marketmap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/keeper/msg_server.go#L288

Added line #L288 was 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
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
}
22 changes: 11 additions & 11 deletions x/marketmap/types/mocks/MarketMapHooks.go

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

5 changes: 3 additions & 2 deletions x/oracle/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@

// AfterMarketRemoved is the marketmap hook for x/oracle that is run after a market is removed in
// the marketmap.
func (h Hooks) AfterMarketRemoved(ctx sdk.Context, market marketmaptypes.Market) error {
ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", market.Ticker.String()))
func (h Hooks) AfterMarketRemoved(ctx sdk.Context, key string) error {
ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", key))

Check warning on line 53 in x/oracle/keeper/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/oracle/keeper/hooks.go#L52-L53

Added lines #L52 - L53 were not covered by tests

return nil
}
Loading