Skip to content

Commit

Permalink
Merge pull request irisnet#9 from terra-money/feat/rewards
Browse files Browse the repository at this point in the history
feat: tx to claim delegation rewards
  • Loading branch information
javiersuweijie authored Oct 18, 2022
2 parents 165eae0 + d2bfc2b commit 9e69a84
Show file tree
Hide file tree
Showing 30 changed files with 2,094 additions and 280 deletions.
20 changes: 11 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,16 @@ var (

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -493,6 +494,7 @@ func New(
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
allianceModule := alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.interfaceRegistry)
Expand Down
155 changes: 127 additions & 28 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ paths:
properties:
reward_delay_time:
type: string
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -219,6 +228,15 @@ paths:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand Down Expand Up @@ -385,6 +403,15 @@ paths:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand Down Expand Up @@ -553,6 +580,15 @@ paths:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand Down Expand Up @@ -44845,7 +44881,34 @@ paths:
tags:
- Query
definitions:
alliance.Delegation:
alliance.alliance.AllianceAsset:
type: object
properties:
denom:
type: string
title: Denom of the asset. It could either be a native token or an IBC token
reward_weight:
type: string
description: >-
The reward weight specifies the ratio of rewards that will be given to
each alliance asset

It does not need to sum to 1. rate = weight / total_weight

Native asset is always assumed to have a weight of 1.
take_rate:
type: string
title: >-
A positive take rate is used for liquid staking derivatives. It
defines an annualized reward rate that

will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
alliance.alliance.Delegation:
type: object
properties:
delegator_address:
Expand All @@ -44860,7 +44923,16 @@ definitions:
shares:
type: string
description: shares define the delegation shares received.
alliance.DelegationResponse:
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
alliance.alliance.DelegationResponse:
type: object
properties:
delegation:
Expand All @@ -44878,6 +44950,15 @@ definitions:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand All @@ -44893,33 +44974,8 @@ definitions:
description: |-
DelegationResponse is equivalent to Delegation except that it contains a
balance in addition to shares which is more suitable for client responses.
alliance.alliance.AllianceAsset:
alliance.alliance.MsgClaimDelegationRewardsResponse:
type: object
properties:
denom:
type: string
title: Denom of the asset. It could either be a native token or an IBC token
reward_weight:
type: string
description: >-
The reward weight specifies the ratio of rewards that will be given to
each alliance asset

It does not need to sum to 1. rate = weight / total_weight

Native asset is always assumed to have a weight of 1.
take_rate:
type: string
title: >-
A positive take rate is used for liquid staking derivatives. It
defines an annualized reward rate that

will be redirected to the distribution rewards pool
total_tokens:
type: string
total_shares:
type: string
title: 'key: denom value: AllianceAsset'
alliance.alliance.MsgCreateAllianceResponse:
type: object
alliance.alliance.MsgDelegateResponse:
Expand All @@ -44937,6 +44993,15 @@ definitions:
properties:
reward_delay_time:
type: string
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
alliance.alliance.QueryAllianceDelegationResponse:
type: object
properties:
Expand All @@ -44962,6 +45027,15 @@ definitions:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand Down Expand Up @@ -45042,6 +45116,15 @@ definitions:
shares:
type: string
description: shares define the delegation shares received.
reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
balance:
type: object
properties:
Expand Down Expand Up @@ -45157,6 +45240,22 @@ definitions:
properties:
reward_delay_time:
type: string
global_reward_indices:
type: array
items:
type: object
properties:
denom:
type: string
index:
type: string
alliance.alliance.RewardIndex:
type: object
properties:
denom:
type: string
index:
type: string
cosmos.base.query.v1beta1.PageRequest:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ 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
16 changes: 16 additions & 0 deletions proto/alliance/alliance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package alliance.alliance;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "alliance/x/alliance/types";
Expand Down Expand Up @@ -66,3 +67,18 @@ message UpdateAssetProposal {
string description = 2;
AllianceAsset asset = 3;
}

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

string global_index = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string reward_weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.Coin balance = 3 [(gogoproto.nullable) = false];
}
34 changes: 19 additions & 15 deletions proto/alliance/delegations.proto
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
syntax = "proto3";
package alliance;
package alliance.alliance;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "alliance/params.proto";

option go_package = "alliance/x/alliance/types";

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

// delegator_address is the bech32-encoded address of the delegator.
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// validator_address is the bech32-encoded address of the validator.
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// denom of token staked
string denom = 3;
// shares define the delegation shares received.
string shares = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// delegator_address is the bech32-encoded address of the delegator.
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// validator_address is the bech32-encoded address of the validator.
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// denom of token staked
string denom = 3;
// shares define the delegation shares received.
string shares = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated RewardIndex reward_indices = 5 [
(gogoproto.nullable) = false
];
}

// DelegationResponse is equivalent to Delegation except that it contains a
Expand Down
14 changes: 14 additions & 0 deletions proto/alliance/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package alliance.alliance;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/duration.proto";

option go_package = "alliance/x/alliance/types";
Expand All @@ -12,4 +13,17 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
repeated RewardIndex global_reward_indices = 2 [
(gogoproto.nullable) = false
];
}

message RewardIndex {
option (gogoproto.equal) = true;
string denom = 1;
string index = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
Loading

0 comments on commit 9e69a84

Please sign in to comment.