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: implement simplified unbonding and rewards queries #313

Merged
merged 5 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
86 changes: 78 additions & 8 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@
- [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse)
- [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest)
- [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse)
- [QueryAllianceRedelegationsByDelegatorRequest](#alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest)
- [QueryAllianceRedelegationsByDelegatorResponse](#alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse)
- [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest)
- [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse)
- [QueryAllianceRequest](#alliance.alliance.QueryAllianceRequest)
- [QueryAllianceResponse](#alliance.alliance.QueryAllianceResponse)
- [QueryAllianceUnbondingsByDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest)
- [QueryAllianceUnbondingsByDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse)
- [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest)
- [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse)
- [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest)
Expand Down Expand Up @@ -675,6 +679,7 @@ UnbondingDelegation defines an unbonding object with relevant metadata.
| `completion_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | completion_time is the unix time for unbonding completion. |
| `validator_address` | [string](#string) | | validator_address is the bech32-encoded address of the validator. |
| `amount` | [string](#string) | | amount defines the tokens to receive at completion. |
| `denom` | [string](#string) | | alliance denom of the unbonding delegation |



Expand Down Expand Up @@ -810,6 +815,38 @@ AllianceDelegation



<a name="alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest"></a>

### QueryAllianceRedelegationsByDelegatorRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator_addr` | [string](#string) | | |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | |






<a name="alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse"></a>

### QueryAllianceRedelegationsByDelegatorResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `redelegations` | [RedelegationEntry](#alliance.alliance.RedelegationEntry) | repeated | |
| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | |






<a name="alliance.alliance.QueryAllianceRedelegationsRequest"></a>

### QueryAllianceRedelegationsRequest
Expand Down Expand Up @@ -873,6 +910,37 @@ Alliance



<a name="alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest"></a>

### QueryAllianceUnbondingsByDelegatorRequest
AllianceDelegation


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator_addr` | [string](#string) | | |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | |






<a name="alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse"></a>

### QueryAllianceUnbondingsByDelegatorResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `unbondings` | [UnbondingDelegation](#alliance.alliance.UnbondingDelegation) | repeated | |






<a name="alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest"></a>

### QueryAllianceUnbondingsByDenomAndDelegatorRequest
Expand Down Expand Up @@ -1107,18 +1175,20 @@ Params

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Params` | [QueryParamsRequest](#alliance.alliance.QueryParamsRequest) | [QueryParamsResponse](#alliance.alliance.QueryParamsResponse) | | GET|/terra/alliances/params|
| `Alliances` | [QueryAlliancesRequest](#alliance.alliance.QueryAlliancesRequest) | [QueryAlliancesResponse](#alliance.alliance.QueryAlliancesResponse) | Query paginated alliances | GET|/terra/alliances|
| `AllAlliancesDelegations` | [QueryAllAlliancesDelegationsRequest](#alliance.alliance.QueryAllAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations | GET|/terra/alliances/delegations|
| `Params` | [QueryParamsRequest](#alliance.alliance.QueryParamsRequest) | [QueryParamsResponse](#alliance.alliance.QueryParamsResponse) | Query Alliance module parameters more info about the params https://docs.alliance.money/tech/parameters | GET|/terra/alliances/params|
| `Alliances` | [QueryAlliancesRequest](#alliance.alliance.QueryAlliancesRequest) | [QueryAlliancesResponse](#alliance.alliance.QueryAlliancesResponse) | Query all alliances with pagination | GET|/terra/alliances|
| `AllAlliancesDelegations` | [QueryAllAlliancesDelegationsRequest](#alliance.alliance.QueryAllAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all alliances delegations with pagination | GET|/terra/alliances/delegations|
| `AllianceValidator` | [QueryAllianceValidatorRequest](#alliance.alliance.QueryAllianceValidatorRequest) | [QueryAllianceValidatorResponse](#alliance.alliance.QueryAllianceValidatorResponse) | Query alliance validator | GET|/terra/alliances/validators/{validator_addr}|
| `AllAllianceValidators` | [QueryAllAllianceValidatorsRequest](#alliance.alliance.QueryAllAllianceValidatorsRequest) | [QueryAllianceValidatorsResponse](#alliance.alliance.QueryAllianceValidatorsResponse) | Query all paginated alliance validators | GET|/terra/alliances/validators|
| `AlliancesDelegation` | [QueryAlliancesDelegationsRequest](#alliance.alliance.QueryAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations for a delegator addr | GET|/terra/alliances/delegations/{delegator_addr}|
| `AlliancesDelegationByValidator` | [QueryAlliancesDelegationByValidatorRequest](#alliance.alliance.QueryAlliancesDelegationByValidatorRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations for a delegator addr and validator_addr | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}|
| `AllianceDelegation` | [QueryAllianceDelegationRequest](#alliance.alliance.QueryAllianceDelegationRequest) | [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse) | Query a delegation to an alliance by delegator addr, validator_addr and denom | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceDelegationRewards` | [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest) | [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/rewards/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceUnbondingsByDenomAndDelegator` | [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest) | [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}|
| `AllianceUnbondings` | [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest) | [QueryAllianceUnbondingsResponse](#alliance.alliance.QueryAllianceUnbondingsResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}/{validator_addr}|
| `AllianceRedelegations` | [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest) | [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse) | Query redelegations by denom and delegator address | GET|/terra/alliances/redelegations/{denom}/{delegator_addr}|
| `AllianceDelegation` | [QueryAllianceDelegationRequest](#alliance.alliance.QueryAllianceDelegationRequest) | [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse) | Query a specific delegation by delegator addr, validator addr and denom | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceDelegationRewards` | [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest) | [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse) | Query a specific delegation rewards by delegator addr, validator addr and denom | GET|/terra/alliances/rewards/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceUnbondingsByDelegator` | [QueryAllianceUnbondingsByDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest) | [QueryAllianceUnbondingsByDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse) | Query unbondings by delegator address | GET|/terra/alliances/unbondings/{delegator_addr}|
| `AllianceUnbondingsByDenomAndDelegator` | [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest) | [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse) | Query unbondings by denom, delegator addr | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}|
| `AllianceUnbondings` | [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest) | [QueryAllianceUnbondingsResponse](#alliance.alliance.QueryAllianceUnbondingsResponse) | Query unbondings by denom, delegator addr, validator addr | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}/{validator_addr}|
| `AllianceRedelegationsByDelegator` | [QueryAllianceRedelegationsByDelegatorRequest](#alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest) | [QueryAllianceRedelegationsByDelegatorResponse](#alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse) | Query paginated redelegations delegator addr | GET|/terra/alliances/redelegations/{delegator_addr}|
| `AllianceRedelegations` | [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest) | [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse) | Query paginated redelegations by denom and delegator addr | GET|/terra/alliances/redelegations/{denom}/{delegator_addr}|
| `Alliance` | [QueryAllianceRequest](#alliance.alliance.QueryAllianceRequest) | [QueryAllianceResponse](#alliance.alliance.QueryAllianceResponse) | Query a specific alliance by denom | GET|/terra/alliances/{denom}|

<!-- end services -->
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/terra-money/alliance

go 1.21

toolchain go1.21.5
toolchain go1.21.4

require (
cosmossdk.io/core v0.11.0
Expand Down
61 changes: 54 additions & 7 deletions proto/alliance/alliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ import "alliance/alliance/redelegations.proto";
option go_package = "github.com/terra-money/alliance/x/alliance/types";

service Query {

// Query Alliance module parameters more info about the params
// https://docs.alliance.money/tech/parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/terra/alliances/params";
}

// Query paginated alliances
// Query all alliances with pagination
rpc Alliances(QueryAlliancesRequest) returns (QueryAlliancesResponse) {
option (google.api.http).get = "/terra/alliances";
}

// Query all paginated alliance delegations
// Query all alliances delegations with pagination
rpc AllAlliancesDelegations(QueryAllAlliancesDelegationsRequest) returns (QueryAlliancesDelegationsResponse) {
option (google.api.http).get = "/terra/alliances/delegations";
}
Expand All @@ -48,27 +51,37 @@ service Query {
option (google.api.http).get = "/terra/alliances/delegations/{delegator_addr}/{validator_addr}";
}

// Query a delegation to an alliance by delegator addr, validator_addr and denom
// Query a specific delegation by delegator addr, validator addr and denom
rpc AllianceDelegation(QueryAllianceDelegationRequest) returns (QueryAllianceDelegationResponse) {
option (google.api.http).get = "/terra/alliances/delegations/{delegator_addr}/{validator_addr}/{denom}";
}

// Query for rewards by delegator addr, validator_addr and denom
// Query a specific delegation rewards by delegator addr, validator addr and denom
rpc AllianceDelegationRewards(QueryAllianceDelegationRewardsRequest) returns (QueryAllianceDelegationRewardsResponse) {
option (google.api.http).get = "/terra/alliances/rewards/{delegator_addr}/{validator_addr}/{denom}";
}

// Query for rewards by delegator addr, validator_addr and denom
// Query unbondings by delegator address
rpc AllianceUnbondingsByDelegator(QueryAllianceUnbondingsByDelegatorRequest) returns (QueryAllianceUnbondingsByDelegatorResponse) {
option (google.api.http).get = "/terra/alliances/unbondings/{delegator_addr}";
}

// Query unbondings by denom, delegator addr
rpc AllianceUnbondingsByDenomAndDelegator(QueryAllianceUnbondingsByDenomAndDelegatorRequest) returns (QueryAllianceUnbondingsByDenomAndDelegatorResponse) {
option (google.api.http).get = "/terra/alliances/unbondings/{denom}/{delegator_addr}";
}

// Query for rewards by delegator addr, validator_addr and denom
// Query unbondings by denom, delegator addr, validator addr
rpc AllianceUnbondings(QueryAllianceUnbondingsRequest) returns (QueryAllianceUnbondingsResponse) {
option (google.api.http).get = "/terra/alliances/unbondings/{denom}/{delegator_addr}/{validator_addr}";
}

// Query redelegations by denom and delegator address
// Query paginated redelegations delegator addr
rpc AllianceRedelegationsByDelegator(QueryAllianceRedelegationsByDelegatorRequest) returns (QueryAllianceRedelegationsByDelegatorResponse) {
option (google.api.http).get = "/terra/alliances/redelegations/{delegator_addr}";
}

// Query paginated redelegations by denom and delegator addr
rpc AllianceRedelegations(QueryAllianceRedelegationsRequest) returns (QueryAllianceRedelegationsResponse) {
option (google.api.http).get = "/terra/alliances/redelegations/{denom}/{delegator_addr}";
}
Expand Down Expand Up @@ -222,6 +235,23 @@ message QueryAllianceValidatorsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// AllianceDelegation
message QueryAllianceUnbondingsByDelegatorRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string delegator_addr = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

message QueryAllianceUnbondingsByDelegatorResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

repeated UnbondingDelegation unbondings = 1 [(gogoproto.nullable) = false];
}


// AllianceDelegation
message QueryAllianceUnbondingsByDenomAndDelegatorRequest {
option (gogoproto.equal) = false;
Expand Down Expand Up @@ -272,6 +302,23 @@ message QueryAllianceRedelegationsResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

repeated RedelegationEntry redelegations = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}


message QueryAllianceRedelegationsByDelegatorRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string delegator_addr = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryAllianceRedelegationsByDelegatorResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

repeated RedelegationEntry redelegations = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
2 changes: 2 additions & 0 deletions proto/alliance/alliance/unbonding.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ message UnbondingDelegation {
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// alliance denom of the unbonding delegation
string denom = 4;
}
60 changes: 60 additions & 0 deletions x/alliance/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ func (k QueryServer) AllianceDelegation(c context.Context, req *types.QueryAllia
}, nil
}

func (k QueryServer) AllianceUnbondingsByDelegator(c context.Context, req *types.QueryAllianceUnbondingsByDelegatorRequest) (*types.QueryAllianceUnbondingsByDelegatorResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

delAddr, err := sdk.AccAddressFromBech32(req.DelegatorAddr)
if err != nil {
return nil, err
}

res, err := k.GetUnbondingsByDelegator(ctx, delAddr)

return &types.QueryAllianceUnbondingsByDelegatorResponse{
Unbondings: res,
}, err
}

func (k QueryServer) AllianceUnbondingsByDenomAndDelegator(c context.Context, req *types.QueryAllianceUnbondingsByDenomAndDelegatorRequest) (*types.QueryAllianceUnbondingsByDenomAndDelegatorResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

Expand Down Expand Up @@ -524,6 +539,51 @@ func (k QueryServer) AllianceRedelegations(c context.Context, req *types.QueryAl
}, err
}

func (k QueryServer) AllianceRedelegationsByDelegator(c context.Context, req *types.QueryAllianceRedelegationsByDelegatorRequest) (*types.QueryAllianceRedelegationsByDelegatorResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

delAddr, err := sdk.AccAddressFromBech32(req.DelegatorAddr)
if err != nil {
return nil, err
}

// Get the key-value module store using the store key
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))

// Get the part of the store that keeps assets
redelegationsStore := prefix.NewStore(store, types.GetRedelegationsKeyByDelegator(delAddr))

var redelegationEntries []types.RedelegationEntry

// Paginate the assets store based on PageRequest
pageRes, err := query.Paginate(redelegationsStore, req.Pagination, func(key []byte, value []byte) error {
var redelegation types.Redelegation
k.cdc.MustUnmarshal(value, &redelegation)
// get the completion time from the latest bytes of the key
completionTime := types.ParseRedelegationPaginationKeyTime(key)

redelegationEntry := types.RedelegationEntry{
DelegatorAddress: redelegation.DelegatorAddress,
SrcValidatorAddress: redelegation.SrcValidatorAddress,
DstValidatorAddress: redelegation.DstValidatorAddress,
Balance: redelegation.Balance,
CompletionTime: completionTime,
}

redelegationEntries = append(redelegationEntries, redelegationEntry)
return nil
})
// Throw an error if pagination failed
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryAllianceRedelegationsByDelegatorResponse{
Redelegations: redelegationEntries,
Pagination: pageRes,
}, err
}

func NewQueryServerImpl(keeper Keeper) types.QueryServer {
return &QueryServer{
Keeper: keeper,
Expand Down
Loading
Loading