Skip to content

Commit

Permalink
phase 2 - trade route query (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Nov 27, 2023
1 parent 126fac2 commit f0f74a6
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 74 deletions.
13 changes: 13 additions & 0 deletions proto/stride/stakeibc/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "stride/stakeibc/validator.proto";
import "stride/stakeibc/host_zone.proto";
import "stride/stakeibc/epoch_tracker.proto";
import "stride/stakeibc/address_unbonding.proto";
import "stride/stakeibc/trade_route.proto";

option go_package = "github.com/Stride-Labs/stride/v16/x/stakeibc/types";

Expand Down Expand Up @@ -73,6 +74,12 @@ service Query {
option (google.api.http).get =
"/Stride-Labs/stride/stakeibc/unbondings/{address}";
}

// Queries all trade routes
rpc AllTradeRoutes(QueryAllTradeRoutes)
returns (QueryAllTradeRoutesResponse) {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/trade_routes";
}
}

// QueryInterchainAccountFromAddressRequest is the request type for the
Expand Down Expand Up @@ -146,3 +153,9 @@ message QueryAddressUnbondingsResponse {
repeated AddressUnbonding address_unbondings = 1
[ (gogoproto.nullable) = false ];
}

message QueryAllTradeRoutes {};

message QueryAllTradeRoutesResponse {
repeated TradeRoute trade_routes = 1 [ (gogoproto.nullable) = false ];
}
1 change: 1 addition & 0 deletions x/stakeibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdListEpochTracker())
cmd.AddCommand(CmdShowEpochTracker())
cmd.AddCommand(CmdNextPacketSequence())
cmd.AddCommand(CmdListTradeRoutes())

return cmd
}
36 changes: 36 additions & 0 deletions x/stakeibc/client/cli/query_trade_routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"context"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/Stride-Labs/stride/v16/x/stakeibc/types"
)

func CmdListTradeRoutes() *cobra.Command {
cmd := &cobra.Command{
Use: "list-trade-routes",
Short: "list all trade routes",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllTradeRoutes{}
res, err := queryClient.AllTradeRoutes(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)

return cmd
}
23 changes: 23 additions & 0 deletions x/stakeibc/keeper/grpc_query_trade_routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/Stride-Labs/stride/v16/x/stakeibc/types"
)

func (k Keeper) AllTradeRoutes(c context.Context, req *types.QueryAllTradeRoutes) (*types.QueryAllTradeRoutesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

routes := k.GetAllTradeRoutes(ctx)

return &types.QueryAllTradeRoutesResponse{TradeRoutes: routes}, nil
}
1 change: 1 addition & 0 deletions x/stakeibc/keeper/reward_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func (k Keeper) SwapAllRewardTokens(ctx sdk.Context) {

// Helper function to be run hourly, kicks off query to get and update the swap price in keeper data
func (k Keeper) UpdateAllSwapPrices(ctx sdk.Context) {
k.SetTradeRoute(ctx, types.TradeRoute{RewardDenomOnHostZone: "A", TargetDenomOnHostZone: "B"})
for _, route := range k.GetAllTradeRoutes(ctx) {
// ICQ swap price for the specific pair on this route and update keeper on callback
k.PoolSpotPriceQuery(ctx, route)

Check failure on line 441 in x/stakeibc/keeper/reward_converter.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `k.PoolSpotPriceQuery` is not checked (errcheck)
Expand Down
491 changes: 417 additions & 74 deletions x/stakeibc/types/query.pb.go

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions x/stakeibc/types/query.pb.gw.go

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

0 comments on commit f0f74a6

Please sign in to comment.