Skip to content

Commit

Permalink
Merge pull request irisnet#13 from terra-money/feat/rewards
Browse files Browse the repository at this point in the history
fix: reward delegation scoped by validators
  • Loading branch information
emidev98 authored Oct 19, 2022
2 parents a0c4643 + 3d7bdfe commit a49549a
Show file tree
Hide file tree
Showing 31 changed files with 1,960 additions and 528 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ func (app *App) ModuleAccountAddrs() map[string]bool {
func (app *App) BlockedModuleAccountAddrs() map[string]bool {
modAccAddrs := app.ModuleAccountAddrs()
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(alliancemoduletypes.ModuleName).String())

return modAccAddrs
}
Expand Down
170 changes: 133 additions & 37 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ paths:
will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
pagination:
type: object
Expand Down Expand Up @@ -174,15 +172,6 @@ paths:
type: string
format: date-time
title: Last application of `take_rate` on assets
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
default:
description: An unexpected error response.
schema:
Expand All @@ -203,6 +192,122 @@ paths:
additionalProperties: {}
tags:
- Query
'/terra/alliances/{delegator_addr_1}/{validator_addr}/{denom}':
get:
summary: 'Query for rewards by delegator addr, validator_addr and denom'
operationId: AllianceAllianceAllianceDelegationRewards
responses:
'200':
description: A successful response.
schema:
type: object
properties:
rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: delegator_addr_1
in: path
required: true
type: string
- name: validator_addr
in: path
required: true
type: string
- name: denom
in: path
required: true
type: string
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
querying the next page most efficiently. Only one of offset or key
should be set.
in: query
required: false
type: string
format: byte
- name: pagination.offset
description: >-
offset is a numeric offset that can be used when key is unavailable.

It is less efficient than using key. Only one of offset or key
should

be set.
in: query
required: false
type: string
format: uint64
- name: pagination.limit
description: >-
limit is the total number of results to be returned in the result
page.

If left empty it will default to a value to be set by each app.
in: query
required: false
type: string
format: uint64
- name: pagination.count_total
description: >-
count_total is set to true to indicate that the result set should
include

a count of the total number of items available for pagination in
UIs.

count_total is only respected when offset is used. It is ignored
when key

is set.
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/terra/alliances/{delegator_addr}':
get:
summary: Query all paginated alliance delegations for a delegator addr
Expand Down Expand Up @@ -744,8 +849,6 @@ paths:
will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
default:
description: An unexpected error response.
Expand Down Expand Up @@ -44914,9 +45017,24 @@ definitions:
will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
alliance.alliance.AllianceDelegationRewardsResponse:
type: object
properties:
rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
alliance.alliance.Delegation:
type: object
properties:
Expand Down Expand Up @@ -45009,15 +45127,6 @@ definitions:
type: string
format: date-time
title: Last application of `take_rate` on assets
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
alliance.alliance.QueryAllianceDelegationResponse:
type: object
properties:
Expand Down Expand Up @@ -45102,8 +45211,6 @@ definitions:
will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
alliance.alliance.QueryAlliancesDelegationsResponse:
type: object
Expand Down Expand Up @@ -45219,8 +45326,6 @@ definitions:
will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
pagination:
type: object
Expand Down Expand Up @@ -45263,15 +45368,6 @@ definitions:
type: string
format: date-time
title: Last application of `take_rate` on assets
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
alliance.alliance.RewardIndex:
type: object
properties:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 h1:kr3j8iIMR4ywO/O0rvksXaJvauGGCMg2zAZIiNZ9uIQ=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0/go.mod h1:ummNFgdgLhhX7aIiy35vVmQNS0rWXknfPE0qe6fmFXg=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
4 changes: 0 additions & 4 deletions proto/alliance/alliance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ message AllianceAsset {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string total_shares = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message AddAssetProposal {
Expand Down
15 changes: 15 additions & 0 deletions proto/alliance/delegations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ message QueuedUndelegation {
option (gogoproto.goproto_getters) = false;
repeated Undelegation entries = 1;
}

message Validator {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
repeated RewardIndex reward_indices = 2 [
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.Coin total_tokens = 3 [
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.DecCoin total_shares = 4 [
(gogoproto.nullable) = false
];
}
3 changes: 0 additions & 3 deletions proto/alliance/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
repeated RewardIndex global_reward_indices = 4 [
(gogoproto.nullable) = false
];
}

message RewardIndex {
Expand Down
27 changes: 27 additions & 0 deletions proto/alliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "alliance/params.proto";
import "alliance/alliance.proto";
import "cosmos/base/v1beta1/coin.proto";
import "alliance/delegations.proto";

option go_package = "alliance/x/alliance/types";
Expand Down Expand Up @@ -39,6 +40,11 @@ service Query {
rpc AllianceDelegation(QueryAllianceDelegationRequest) returns (QueryAllianceDelegationResponse) {
option (google.api.http).get = "/terra/alliances/{delegator_addr}/{validator_addr}/{denom}";
}

// Query for rewards by delegator addr, validator_addr and denom
rpc AllianceDelegationRewards(AllianceDelegationRewardsRequest) returns (AllianceDelegationRewardsResponse) {
option (google.api.http).get = "/terra/alliances/{delegator_addr}/{validator_addr}/{denom}";
}
}

// Params
Expand Down Expand Up @@ -104,4 +110,25 @@ message QueryAllianceDelegationRequest {

message QueryAllianceDelegationResponse {
DelegationResponse delegation = 1 [(gogoproto.nullable) = false];
}

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

string delegator_addr = 1;
string validator_addr = 2;
string denom = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 4;
}

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

repeated cosmos.base.v1beta1.Coin rewards = 1 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}
1 change: 0 additions & 1 deletion testutil/keeper/alliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func CreateNewAllianceAsset(Keeper *keeper.Keeper, ctx sdk.Context, n int64) typ
RewardWeight: sdk.NewDec(1),
TakeRate: sdk.NewDec(1),
TotalTokens: math.NewInt(10 * n),
TotalShares: sdk.NewDec(10).Mul(sdk.NewDec(n)),
}
}

Expand Down
14 changes: 14 additions & 0 deletions testutil/keeper/mocks.go

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

1 change: 1 addition & 0 deletions x/alliance/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func GetQueryCmd() *cobra.Command {
cmd.AddCommand(CmdQueryAlliancesDelegation())
cmd.AddCommand(CmdQueryAlliancesDelegationByValidator())
cmd.AddCommand(CmdQueryAllianceDelegation())
cmd.AddCommand(CmdQueryRewards())

return cmd
}
Loading

0 comments on commit a49549a

Please sign in to comment.