Skip to content

Commit

Permalink
add reward statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jan 20, 2025
1 parent 68a1d19 commit d7c3dbb
Show file tree
Hide file tree
Showing 12 changed files with 3,263 additions and 686 deletions.
1,200 changes: 996 additions & 204 deletions api/side/incentive/incentive.pulsar.go

Large diffs are not rendered by default.

1,372 changes: 1,136 additions & 236 deletions api/side/incentive/query.pulsar.go

Large diffs are not rendered by default.

75 changes: 57 additions & 18 deletions api/side/incentive/query_grpc.pb.go

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

15 changes: 12 additions & 3 deletions proto/side/incentive/incentive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/sideprotocol/side/x/incentive/types";

// Reward
message Reward {
// Rewards
message Rewards {
string address = 1;
uint64 deposit_count = 2;
uint64 withdraw_count = 3;
cosmos.base.v1beta1.Coin totalAmount = 4 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin deposit_reward = 4 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin withdraw_reward = 5 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin total_amount = 6 [(gogoproto.nullable) = false];
}

// Reward Statistics
message RewardStats {
uint64 address_count = 1;
uint64 tx_count = 2;
cosmos.base.v1beta1.Coin total_reward_amount = 3 [(gogoproto.nullable) = false];
}
29 changes: 21 additions & 8 deletions proto/side/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package side.incentive;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "side/incentive/params.proto";
import "side/incentive/incentive.proto";
import "side/incentive/params.proto";

option go_package = "github.com/sideprotocol/side/x/incentive/types";

Expand All @@ -14,20 +14,33 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/side/incentive/params";
}
// Reward queries the reward of the given address.
rpc Reward(QueryRewardRequest) returns (QueryRewardResponse) {
// Rewards queries the rewards of the given address.
rpc Rewards(QueryRewardsRequest) returns (QueryRewardsResponse) {
option (google.api.http).get = "/side/incentive/rewards/{address}";
}
// RewardStats queries total reward statistics.
rpc RewardStats(QueryRewardStatsRequest) returns (QueryRewardStatsResponse) {
option (google.api.http).get = "/side/incentive/rewards/stats";
}
}

// QueryRewardRequest is request type for the Query/Reward RPC method.
message QueryRewardRequest {
// QueryRewardsRequest is request type for the Query/Rewards RPC method.
message QueryRewardsRequest {
string address = 1;
}

// QueryRewardResponse is response type for the Query/Reward RPC method.
message QueryRewardResponse {
Reward reward = 1;
// QueryRewardsResponse is response type for the Query/Rewards RPC method.
message QueryRewardsResponse {
Rewards rewards = 1;
}

// QueryRewardStatsRequest is request type for the Query/RewardStats RPC method.
message QueryRewardStatsRequest {
}

// QueryRewardStatsResponse is response type for the Query/RewardStats RPC method.
message QueryRewardStatsResponse {
RewardStats reward_stats = 1;
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down
38 changes: 33 additions & 5 deletions x/incentive/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func GetQueryCmd(_ string) *cobra.Command {
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdQueryReward())
cmd.AddCommand(CmdQueryRewards())
cmd.AddCommand(CmdQueryRewardStats())
// this line is used by starport scaffolding # 1

return cmd
Expand Down Expand Up @@ -58,10 +59,10 @@ func CmdQueryParams() *cobra.Command {
return cmd
}

func CmdQueryReward() *cobra.Command {
func CmdQueryRewards() *cobra.Command {
cmd := &cobra.Command{
Use: "reward",
Short: "Query the reward of the given address",
Use: "rewards",
Short: "Query the rewards of the given address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -71,7 +72,7 @@ func CmdQueryReward() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Reward(cmd.Context(), &types.QueryRewardRequest{
res, err := queryClient.Rewards(cmd.Context(), &types.QueryRewardsRequest{
Address: args[0],
})
if err != nil {
Expand All @@ -86,3 +87,30 @@ func CmdQueryReward() *cobra.Command {

return cmd
}

func CmdQueryRewardStats() *cobra.Command {
cmd := &cobra.Command{
Use: "reward-stats",
Short: "Query total reward statistics",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.RewardStats(cmd.Context(), &types.QueryRewardStatsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 15 additions & 3 deletions x/incentive/keeper/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*t
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
}

func (k Keeper) Reward(goCtx context.Context, req *types.QueryRewardRequest) (*types.QueryRewardResponse, error) {
func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (*types.QueryRewardsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryRewardResponse{
Reward: k.GetReward(ctx, req.Address),
return &types.QueryRewardsResponse{
Rewards: k.GetRewards(ctx, req.Address),
}, nil
}

func (k Keeper) RewardStats(goCtx context.Context, req *types.QueryRewardStatsRequest) (*types.QueryRewardStatsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryRewardStatsResponse{
RewardStats: k.GetRewardStats(ctx),
}, nil
}
Loading

0 comments on commit d7c3dbb

Please sign in to comment.