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(x/tokenfactory): Add query for querying all before send hooks #7623

Merged
merged 7 commits into from
Feb 28, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7562](https://github.com/osmosis-labs/osmosis/pull/7562) Speedup Protorev estimation logic by removing unnecessary taker fee simulations.
* [#7595](https://github.com/osmosis-labs/osmosis/pull/7595) Fix cosmwasm pool model code ID migration.
* [#7619](https://github.com/osmosis-labs/osmosis/pull/7619) Slight speedup/gas improvement to CL GetTotalPoolLiquidity queries
* [#7623](https://github.com/osmosis-labs/osmosis/pull/7623) Add query for querying all before send hooks
* [#7622](https://github.com/osmosis-labs/osmosis/pull/7622) Remove duplicate CL accumulator update logic.

### State Compatible
Expand Down
21 changes: 21 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ service Query {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/denoms/{denom}/before_send_hook";
}

// AllBeforeSendHooksAddresses defines a gRPC query method for
// getting all addresses with before send hook registered.
// The response returns two arrays, an array with a list of denom and an array
// of before send hook addresses. The idx of denom corresponds to before send
// hook addresse's idx.
rpc AllBeforeSendHooksAddresses(QueryAllBeforeSendHooksAddressesRequest)
returns (QueryAllBeforeSendHooksAddressesResponse) {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/all_before_send_hooks";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand Down Expand Up @@ -87,4 +98,14 @@ message QueryBeforeSendHookAddressRequest {
message QueryBeforeSendHookAddressResponse {
string cosmwasm_address = 1
[ (gogoproto.moretags) = "yaml:\"cosmwasm_address\"" ];
}

message QueryAllBeforeSendHooksAddressesRequest {}

// QueryAllBeforeSendHooksAddressesResponse defines the response structure for
// the AllBeforeSendHooksAddresses gRPC query.
message QueryAllBeforeSendHooksAddressesResponse {
repeated string denoms = 1 [ (gogoproto.moretags) = "yaml:\"denoms\"" ];
repeated string before_send_hook_addresses = 2
[ (gogoproto.moretags) = "yaml:\"before_send_addresses\"" ];
}
7 changes: 7 additions & 0 deletions x/tokenfactory/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func GetQueryCmd() *cobra.Command {

osmocli.AddQueryCmd(cmd, types.NewQueryClient, GetCmdDenomAuthorityMetadata)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, GetCmdDenomsFromCreator)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, GetCmdAllBeforeSendHooks)

cmd.AddCommand(
osmocli.GetParams[*types.QueryParamsRequest](
Expand All @@ -47,6 +48,12 @@ func GetCmdDenomsFromCreator() (*osmocli.QueryDescriptor, *types.QueryDenomsFrom
{{.CommandPrefix}} <address>`,
}, &types.QueryDenomsFromCreatorRequest{}
}
func GetCmdAllBeforeSendHooks() (*osmocli.QueryDescriptor, *types.QueryAllBeforeSendHooksAddressesRequest) {
return &osmocli.QueryDescriptor{
Use: "all-before-send-hooks",
Short: "Returns a list of all before send hooks registered",
}, &types.QueryAllBeforeSendHooksAddressesRequest{}
}

// GetCmdDenomAuthorityMetadata returns the authority metadata for a queried denom
func GetCmdDenomBeforeSendHook() *cobra.Command {
Expand Down
18 changes: 18 additions & 0 deletions x/tokenfactory/keeper/before_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func (k Keeper) GetBeforeSendHook(ctx sdk.Context, denom string) string {
return string(bz)
}

func (k Keeper) GetAllBeforeSendHooks(ctx sdk.Context) ([]string, []string) {
denomsList := []string{}
beforeSendHooksList := []string{}

iterator := k.GetAllDenomsIterator(ctx)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Value())

beforeSendHook := k.GetBeforeSendHook(ctx, denom)
if beforeSendHook != "" {
denomsList = append(denomsList, denom)
beforeSendHooksList = append(beforeSendHooksList, beforeSendHook)
}
}
return denomsList, beforeSendHooksList
}

// Hooks wrapper struct for bank keeper
type Hooks struct {
k Keeper
Expand Down
4 changes: 4 additions & 0 deletions x/tokenfactory/keeper/before_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (s *KeeperTestSuite) TestBeforeSendHook() {
_, err = s.msgServer.SetBeforeSendHook(sdk.WrapSDKContext(s.Ctx), types.NewMsgSetBeforeSendHook(s.TestAccs[0].String(), denom, cosmwasmAddress.String()))
s.Require().NoError(err, "test: %v", tc.desc)

denoms, beforeSendHooks := s.App.TokenFactoryKeeper.GetAllBeforeSendHooks(s.Ctx)
s.Require().Equal(beforeSendHooks, []string{cosmwasmAddress.String()})
s.Require().Equal(denoms, []string{denom})

for _, sendTc := range tc.sendMsgs {
_, err := s.bankMsgServer.Send(sdk.WrapSDKContext(s.Ctx), sendTc.msg(denom))
if sendTc.expectPass {
Expand Down
7 changes: 7 additions & 0 deletions x/tokenfactory/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ func (k Keeper) BeforeSendHookAddress(ctx context.Context, req *types.QueryBefor

return &types.QueryBeforeSendHookAddressResponse{CosmwasmAddress: cosmwasmAddress}, nil
}

func (k Keeper) AllBeforeSendHooksAddresses(ctx context.Context, req *types.QueryAllBeforeSendHooksAddressesRequest) (*types.QueryAllBeforeSendHooksAddressesResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
denoms, beforesendHookAddresses := k.GetAllBeforeSendHooks(sdkCtx)

return &types.QueryAllBeforeSendHooksAddressesResponse{Denoms: denoms, BeforeSendHookAddresses: beforesendHookAddresses}, nil
}
Loading