Skip to content

Commit

Permalink
feat: add get percentage claimed (#1519)
Browse files Browse the repository at this point in the history
* wip: add get percentage claimed

* fix merge conflict err

* add keeper test for get claimed percentage

* add get percentage by claim type

* add msg claim to grpc, make proto-gen

* add test for claimPercentage grpc query

* add tests for grpc

* add grpc endpoints

* linting

* add stricter error tests, and refactor claimType validation

---------

Co-authored-by: Jacob Gadikian <[email protected]>
  • Loading branch information
tuantran1702 and faddat authored May 2, 2024
1 parent 3b6587e commit 89b98da
Show file tree
Hide file tree
Showing 12 changed files with 1,550 additions and 260 deletions.
130 changes: 126 additions & 4 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,10 @@ paths:
protobuf release, and it is not used for type URLs
beginning with
type.googleapis.com.
type.googleapis.com. As of May 2023, there are no widely
used type server
implementations and no plans to implement one.
Schemes other than `http`, `https` (or the empty scheme)
Expand Down Expand Up @@ -1704,6 +1707,10 @@ paths:
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or ...
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}
Example 3: Pack and unpack a message in Python.
Expand Down Expand Up @@ -1743,7 +1750,6 @@ paths:
name "y.z".
JSON
====
Expand Down Expand Up @@ -1970,7 +1976,10 @@ paths:
protobuf release, and it is not used for type URLs
beginning with
type.googleapis.com.
type.googleapis.com. As of May 2023, there are no widely
used type server
implementations and no plans to implement one.
Schemes other than `http`, `https` (or the empty scheme)
Expand Down Expand Up @@ -2015,6 +2024,10 @@ paths:
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or ...
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}
Example 3: Pack and unpack a message in Python.
Expand Down Expand Up @@ -2054,7 +2067,6 @@ paths:
name "y.z".
JSON
====
Expand Down Expand Up @@ -2561,6 +2573,116 @@ paths:
type: string
tags:
- Msg
/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}:
get:
summary: >-
CLaimedPercentage provides data on the claimed percentage for a given
zone
operationId: ClaimedPercentage
responses:
'200':
description: A successful response.
schema:
type: object
properties:
percentage:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: chain_id
in: path
required: true
type: string
- name: claim_type
description: ' - ClaimTypeUndefined: Undefined action (per protobuf spec)'
in: query
required: false
type: string
enum:
- ClaimTypeUndefined
- ClaimTypeLiquidToken
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
tags:
- QueryInterchainStaking
/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}/{claim_type}:
get:
summary: >-
ClaimedPercentageByClaimType provides data on the claimed percentage of
a given claim type in a given zone
operationId: ClaimedPercentageByClaimType
responses:
'200':
description: A successful response.
schema:
type: object
properties:
percentage:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: chain_id
in: path
required: true
type: string
- name: claim_type
in: path
required: true
type: string
enum:
- ClaimTypeUndefined
- ClaimTypeLiquidToken
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
tags:
- QueryInterchainStaking
/quicksilver/interchainstaking/v1/delegator_intents/{delegator_address}:
get:
summary: >-
Expand Down
24 changes: 24 additions & 0 deletions proto/quicksilver/interchainstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "quicksilver/claimsmanager/v1/claimsmanager.proto";
import "quicksilver/interchainstaking/v1/interchainstaking.proto";

option go_package = "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types";
Expand Down Expand Up @@ -101,6 +102,16 @@ service Query {
rpc MappedAccounts(QueryMappedAccountsRequest) returns (QueryMappedAccountsResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/mapped_addresses/{address}";
}

// CLaimedPercentage provides data on the claimed percentage for a given zone
rpc ClaimedPercentage(QueryClaimedPercentageRequest) returns (QueryClaimedPercentageResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}";
}

// ClaimedPercentageByClaimType provides data on the claimed percentage of a given claim type in a given zone
rpc ClaimedPercentageByClaimType(QueryClaimedPercentageRequest) returns (QueryClaimedPercentageResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}/{claim_type}";
}
}

message Statistics {
Expand Down Expand Up @@ -287,3 +298,16 @@ message QueryDenyListResponse {
repeated string validators = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryClaimedPercentageRequest {
string chain_id = 1;
quicksilver.claimsmanager.v1.ClaimType claim_type = 2;
}

message QueryClaimedPercentageResponse {
string percentage = 1 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
88 changes: 44 additions & 44 deletions x/airdrop/types/messages.pb.go

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

8 changes: 4 additions & 4 deletions x/interchainquery/types/messages.pb.go

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

46 changes: 46 additions & 0 deletions x/interchainstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/quicksilver-zone/quicksilver/utils/addressutils"
claimsmanagertypes "github.com/quicksilver-zone/quicksilver/x/claimsmanager/types"
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
)

Expand Down Expand Up @@ -362,3 +363,48 @@ func (k *Keeper) ValidatorDenyList(c context.Context, req *types.QueryDenyListRe

return &types.QueryDenyListResponse{Validators: validators}, nil
}

func (k *Keeper) ClaimedPercentage(c context.Context, req *types.QueryClaimedPercentageRequest) (*types.QueryClaimedPercentageResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
zone, found := k.GetZone(ctx, req.ChainId)
if !found {
return nil, status.Error(codes.NotFound, fmt.Sprintf("no zone found matching %s", req.GetChainId()))
}

percentage, err := k.GetClaimedPercentage(ctx, &zone)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryClaimedPercentageResponse{Percentage: percentage}, nil
}

func (k *Keeper) ClaimedPercentageByClaimType(c context.Context, req *types.QueryClaimedPercentageRequest) (*types.QueryClaimedPercentageResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if req.ChainId == "" {
return nil, status.Error(codes.InvalidArgument, "chain id and claim type cannot be empty")
}
ctx := sdk.UnwrapSDKContext(c)
zone, found := k.GetZone(ctx, req.ChainId)
if !found {
return nil, status.Error(codes.NotFound, fmt.Sprintf("no zone found matching %s", req.GetChainId()))
}

claimTypeInt := int(req.ClaimType)

if claimTypeInt < 1 || claimTypeInt > len(claimsmanagertypes.ClaimType_value) {
return nil, status.Error(codes.InvalidArgument, "claim type must be a valid number")
}

percentage, err := k.GetClaimedPercentageByClaimType(ctx, &zone, req.ClaimType)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryClaimedPercentageResponse{Percentage: percentage}, nil
}
Loading

0 comments on commit 89b98da

Please sign in to comment.