diff --git a/.golangci.yml b/.golangci.yml index e2f110ca..d693bb89 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,12 +2,6 @@ run: tests: false # timeout for analysis, e.g. 30s, 5m, default is 1m timeout: 5m - skip-dirs: - - tests/ - skip-files: - - ".*\\.pb\\.go$" - - ".*\\.pb\\.gw\\.go$" - linters: disable-all: true enable: @@ -33,6 +27,11 @@ linters: - unused issues: + exclude-dirs: + - tests/ + exclude-files: + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.go$" exclude-rules: - text: "Use of weak random number generator" linters: @@ -59,6 +58,7 @@ issues: - gosec text: "G115: integer overflow conversion" + max-issues-per-linter: 10000 max-same-issues: 10000 diff --git a/Makefile b/Makefile index 381bffc2..c99a6971 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,7 @@ docker-build-all: docker-build-debug docker-build-hermes mockgen_cmd=$(rundep) github.com/golang/mock/mockgen mocks-gen: + $(mockgen_cmd) -source=x/distribution/types/expected_keepers.go -package testutil -destination x/distribution/testutil/expected_keepers_mocks.go $(mockgen_cmd) -source=x/gov/testutil/expected_keepers.go -package testutil -destination x/gov/testutil/expected_keepers_mocks.go $(mockgen_cmd) -source=x/photon/types/expected_keepers.go -package testutil -destination x/photon/testutil/expected_keepers_mocks.go $(mockgen_cmd) -source=x/photon/ante/expected_keepers.go -package ante_test -destination x/photon/ante/expected_keepers_mocks_test.go @@ -249,6 +250,7 @@ format: lint-fix -not -path "*.git*" \ -not -name "*.pb.go" \ -not -name "*.pb.gw.go" \ + -not -name "*_mocks.go" \ | xargs $(rundep) mvdan.cc/gofumpt -w -l .PHONY: format lint lint-fix diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index ba5591b2..3bc9dd37 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -38,8 +38,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/consensus" consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/params" @@ -51,6 +49,8 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + distrkeeper "github.com/atomone-hub/atomone/x/distribution/keeper" + distrtypes "github.com/atomone-hub/atomone/x/distribution/types" dynamicfeekeeper "github.com/atomone-hub/atomone/x/dynamicfee/keeper" dynamicfeetypes "github.com/atomone-hub/atomone/x/dynamicfee/types" govkeeper "github.com/atomone-hub/atomone/x/gov/keeper" diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 25152327..bb681f06 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -14,12 +14,12 @@ import ( authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + distrtypes "github.com/atomone-hub/atomone/x/distribution/types" dynamicfeetypes "github.com/atomone-hub/atomone/x/dynamicfee/types" govtypes "github.com/atomone-hub/atomone/x/gov/types" photontypes "github.com/atomone-hub/atomone/x/photon/types" diff --git a/app/modules.go b/app/modules.go index 95a7bd49..cfc810a6 100644 --- a/app/modules.go +++ b/app/modules.go @@ -26,8 +26,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/consensus" consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - distr "github.com/cosmos/cosmos-sdk/x/distribution" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/mint" @@ -39,6 +37,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + distr "github.com/atomone-hub/atomone/x/distribution" + distrtypes "github.com/atomone-hub/atomone/x/distribution/types" "github.com/atomone-hub/atomone/x/dynamicfee" dynamicfeetypes "github.com/atomone-hub/atomone/x/dynamicfee/types" "github.com/atomone-hub/atomone/x/gov" @@ -85,7 +85,7 @@ func appModules( ), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), photon.NewAppModule(appCodec, *app.PhotonKeeper, app.BankKeeper, app.AccountKeeper, app.StakingKeeper), upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()), diff --git a/app/upgrades/v3/upgrades.go b/app/upgrades/v3/upgrades.go index 1ea4f97b..5026867d 100644 --- a/app/upgrades/v3/upgrades.go +++ b/app/upgrades/v3/upgrades.go @@ -11,10 +11,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/atomone-hub/atomone/app/keepers" + distrkeeper "github.com/atomone-hub/atomone/x/distribution/keeper" + distrtypes "github.com/atomone-hub/atomone/x/distribution/types" govkeeper "github.com/atomone-hub/atomone/x/gov/keeper" v1 "github.com/atomone-hub/atomone/x/gov/types/v1" photontypes "github.com/atomone-hub/atomone/x/photon/types" diff --git a/proto/atomone/distribution/module/v1/module.proto b/proto/atomone/distribution/module/v1/module.proto new file mode 100644 index 00000000..6422bda6 --- /dev/null +++ b/proto/atomone/distribution/module/v1/module.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package atomone.distribution.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the distribution module. +message Module { + option (cosmos.app.v1alpha1.module) = {go_import: "github.com/atomone-hub/atomone/x/distribution"}; + + string fee_collector_name = 1; + + // authority defines the custom module authority. If not set, defaults to the + // governance module. + string authority = 2; +} diff --git a/proto/atomone/distribution/v1beta1/distribution.proto b/proto/atomone/distribution/v1beta1/distribution.proto new file mode 100644 index 00000000..e4aac4da --- /dev/null +++ b/proto/atomone/distribution/v1beta1/distribution.proto @@ -0,0 +1,155 @@ +syntax = "proto3"; +package atomone.distribution.v1beta1; + +import "amino/amino.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/atomone-hub/atomone/x/distribution/types"; +option (gogoproto.equal_all) = true; + +// Params defines the set of params for the distribution module. +message Params { + option (amino.name) = "cosmos-sdk/x/distribution/Params"; + + string community_tax = 1 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (amino.dont_omitempty) = true, + (gogoproto.nullable) = false + ]; + + bool withdraw_addr_enabled = 4; +} + +// ValidatorHistoricalRewards represents historical rewards for a validator. +// Height is implicit within the store key. +// Cumulative reward ratio is the sum from the zeroeth period +// until this period of rewards / tokens, per the spec. +// The reference count indicates the number of objects +// which might need to reference this historical entry at any point. +// ReferenceCount = +// number of outstanding delegations which ended the associated period (and +// might need to read that record) +// + number of slashes which ended the associated period (and might need to +// read that record) +// + one per validator for the zeroeth period, set on initialization +message ValidatorHistoricalRewards { + repeated cosmos.base.v1beta1.DecCoin cumulative_reward_ratio = 1 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + uint32 reference_count = 2; +} + +// ValidatorCurrentRewards represents current rewards and current +// period for a validator kept as a running counter and incremented +// each block as long as the validator's tokens remain constant. +message ValidatorCurrentRewards { + repeated cosmos.base.v1beta1.DecCoin rewards = 1 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + uint64 period = 2; +} + +// ValidatorAccumulatedCommission represents accumulated commission +// for a validator kept as a running counter, can be withdrawn at any time. +message ValidatorAccumulatedCommission { + repeated cosmos.base.v1beta1.DecCoin commission = 1 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorOutstandingRewards represents outstanding (un-withdrawn) rewards +// for a validator inexpensive to track, allows simple sanity checks. +message ValidatorOutstandingRewards { + repeated cosmos.base.v1beta1.DecCoin rewards = 1 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorSlashEvent represents a validator slash event. +// Height is implicit within the store key. +// This is needed to calculate appropriate amount of staking tokens +// for delegations which are withdrawn after a slash has occurred. +message ValidatorSlashEvent { + uint64 validator_period = 1; + string fraction = 2 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; +} + +// ValidatorSlashEvents is a collection of ValidatorSlashEvent messages. +message ValidatorSlashEvents { + repeated ValidatorSlashEvent validator_slash_events = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// FeePool is the global fee pool for distribution. +message FeePool { + repeated cosmos.base.v1beta1.DecCoin community_pool = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" + ]; +} + +// DelegatorStartingInfo represents the starting info for a delegator reward +// period. It tracks the previous validator period, the delegation's amount of +// staking token, and the creation height (to check later on if any slashes have +// occurred). NOTE: Even though validators are slashed to whole staking tokens, +// the delegators within the validator may be left with less than a full token, +// thus sdk.Dec is used. +message DelegatorStartingInfo { + uint64 previous_period = 1; + string stake = 2 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + uint64 height = 3 [ + (gogoproto.jsontag) = "creation_height", + (amino.field_name) = "creation_height", + (amino.dont_omitempty) = true + ]; +} + +// DelegationDelegatorReward represents the properties +// of a delegator's delegation reward. +message DelegationDelegatorReward { + option (gogoproto.goproto_getters) = false; + + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + repeated cosmos.base.v1beta1.DecCoin reward = 2 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// CommunityPoolSpendProposalWithDeposit defines a CommunityPoolSpendProposal +// with a deposit +message CommunityPoolSpendProposalWithDeposit { + option (gogoproto.goproto_getters) = false; + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + + string title = 1; + string description = 2; + string recipient = 3; + string amount = 4; + string deposit = 5; +} diff --git a/proto/atomone/distribution/v1beta1/genesis.proto b/proto/atomone/distribution/v1beta1/genesis.proto new file mode 100644 index 00000000..37c64c45 --- /dev/null +++ b/proto/atomone/distribution/v1beta1/genesis.proto @@ -0,0 +1,190 @@ +syntax = "proto3"; +package atomone.distribution.v1beta1; + +import "amino/amino.proto"; +import "atomone/distribution/v1beta1/distribution.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/atomone-hub/atomone/x/distribution/types"; +option (gogoproto.equal_all) = true; + +// DelegatorWithdrawInfo is the address for where distributions rewards are +// withdrawn to by default this struct is only used at genesis to feed in +// default withdraw addresses. +message DelegatorWithdrawInfo { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // delegator_address is the address of the delegator. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // withdraw_address is the address to withdraw the delegation rewards to. + string withdraw_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// ValidatorOutstandingRewardsRecord is used for import/export via genesis json. +message ValidatorOutstandingRewardsRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator_address is the address of the validator. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // outstanding_rewards represents the outstanding rewards of a validator. + repeated cosmos.base.v1beta1.DecCoin outstanding_rewards = 2 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorAccumulatedCommissionRecord is used for import / export via genesis +// json. +message ValidatorAccumulatedCommissionRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator_address is the address of the validator. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // accumulated is the accumulated commission of a validator. + ValidatorAccumulatedCommission accumulated = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorHistoricalRewardsRecord is used for import / export via genesis +// json. +message ValidatorHistoricalRewardsRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator_address is the address of the validator. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // period defines the period the historical rewards apply to. + uint64 period = 2; + + // rewards defines the historical rewards of a validator. + ValidatorHistoricalRewards rewards = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorCurrentRewardsRecord is used for import / export via genesis json. +message ValidatorCurrentRewardsRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator_address is the address of the validator. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // rewards defines the current rewards of a validator. + ValidatorCurrentRewards rewards = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// DelegatorStartingInfoRecord used for import / export via genesis json. +message DelegatorStartingInfoRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // delegator_address is the address of the delegator. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // validator_address is the address of the validator. + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // starting_info defines the starting info of a delegator. + DelegatorStartingInfo starting_info = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// ValidatorSlashEventRecord is used for import / export via genesis json. +message ValidatorSlashEventRecord { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator_address is the address of the validator. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + // height defines the block height at which the slash event occurred. + uint64 height = 2; + // period is the period of the slash event. + uint64 period = 3; + // validator_slash_event describes the slash event. + ValidatorSlashEvent validator_slash_event = 4 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// GenesisState defines the distribution module's genesis state. +message GenesisState { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // params defines all the parameters of the module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the fee pool at genesis. + FeePool fee_pool = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the delegator withdraw infos at genesis. + repeated DelegatorWithdrawInfo delegator_withdraw_infos = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the previous proposer at genesis. + string previous_proposer = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // fee_pool defines the outstanding rewards of all validators at genesis. + repeated ValidatorOutstandingRewardsRecord outstanding_rewards = 5 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the accumulated commissions of all validators at genesis. + repeated ValidatorAccumulatedCommissionRecord validator_accumulated_commissions = 6 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the historical rewards of all validators at genesis. + repeated ValidatorHistoricalRewardsRecord validator_historical_rewards = 7 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the current rewards of all validators at genesis. + repeated ValidatorCurrentRewardsRecord validator_current_rewards = 8 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the delegator starting infos at genesis. + repeated DelegatorStartingInfoRecord delegator_starting_infos = 9 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // fee_pool defines the validator slash events at genesis. + repeated ValidatorSlashEventRecord validator_slash_events = 10 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/atomone/distribution/v1beta1/query.proto b/proto/atomone/distribution/v1beta1/query.proto new file mode 100644 index 00000000..a3520cc6 --- /dev/null +++ b/proto/atomone/distribution/v1beta1/query.proto @@ -0,0 +1,269 @@ +syntax = "proto3"; +package atomone.distribution.v1beta1; + +import "amino/amino.proto"; +import "atomone/distribution/v1beta1/distribution.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; + +option go_package = "github.com/atomone-hub/atomone/x/distribution/types"; + +// Query defines the gRPC querier service for distribution module. +service Query { + // Params queries params of the distribution module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/params"; + } + + // ValidatorDistributionInfo queries validator commission and self-delegation rewards for validator + rpc ValidatorDistributionInfo(QueryValidatorDistributionInfoRequest) returns (QueryValidatorDistributionInfoResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}"; + } + + // ValidatorOutstandingRewards queries rewards of a validator address. + rpc ValidatorOutstandingRewards(QueryValidatorOutstandingRewardsRequest) returns (QueryValidatorOutstandingRewardsResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}/outstanding_rewards"; + } + + // ValidatorCommission queries accumulated commission for a validator. + rpc ValidatorCommission(QueryValidatorCommissionRequest) returns (QueryValidatorCommissionResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}/commission"; + } + + // ValidatorSlashes queries slash events of a validator. + rpc ValidatorSlashes(QueryValidatorSlashesRequest) returns (QueryValidatorSlashesResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}/slashes"; + } + + // DelegationRewards queries the total rewards accrued by a delegation. + rpc DelegationRewards(QueryDelegationRewardsRequest) returns (QueryDelegationRewardsResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/rewards/{validator_address}"; + } + + // DelegationTotalRewards queries the total rewards accrued by each + // validator. + rpc DelegationTotalRewards(QueryDelegationTotalRewardsRequest) returns (QueryDelegationTotalRewardsResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/rewards"; + } + + // DelegatorValidators queries the validators of a delegator. + rpc DelegatorValidators(QueryDelegatorValidatorsRequest) returns (QueryDelegatorValidatorsResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/validators"; + } + + // DelegatorWithdrawAddress queries withdraw address of a delegator. + rpc DelegatorWithdrawAddress(QueryDelegatorWithdrawAddressRequest) returns (QueryDelegatorWithdrawAddressResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/withdraw_address"; + } + + // CommunityPool queries the community pool coins. + // + // WARNING: This query will fail if an external community pool is used. + rpc CommunityPool(QueryCommunityPoolRequest) returns (QueryCommunityPoolResponse) { + option (google.api.http).get = "/cosmos/distribution/v1beta1/community_pool"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// QueryValidatorDistributionInfoRequest is the request type for the +// Query/ValidatorDistributionInfo RPC method. +message QueryValidatorDistributionInfoRequest { + // validator_address defines the validator address to query for. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// QueryValidatorDistributionInfoResponse is the response type for the +// Query/ValidatorDistributionInfo RPC method. +message QueryValidatorDistributionInfoResponse { + // operator_address defines the validator operator address. + string operator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + // self_bond_rewards defines the self delegations rewards. + repeated cosmos.base.v1beta1.DecCoin self_bond_rewards = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" + ]; + // commission defines the commission the validator received. + repeated cosmos.base.v1beta1.DecCoin commission = 3 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false + ]; +} + +// QueryValidatorOutstandingRewardsRequest is the request type for the +// Query/ValidatorOutstandingRewards RPC method. +message QueryValidatorOutstandingRewardsRequest { + // validator_address defines the validator address to query for. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// QueryValidatorOutstandingRewardsResponse is the response type for the +// Query/ValidatorOutstandingRewards RPC method. +message QueryValidatorOutstandingRewardsResponse { + ValidatorOutstandingRewards rewards = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// QueryValidatorCommissionRequest is the request type for the +// Query/ValidatorCommission RPC method +message QueryValidatorCommissionRequest { + // validator_address defines the validator address to query for. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// QueryValidatorCommissionResponse is the response type for the +// Query/ValidatorCommission RPC method +message QueryValidatorCommissionResponse { + // commission defines the commission the validator received. + ValidatorAccumulatedCommission commission = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// QueryValidatorSlashesRequest is the request type for the +// Query/ValidatorSlashes RPC method +message QueryValidatorSlashesRequest { + option (gogoproto.goproto_getters) = false; + + // validator_address defines the validator address to query for. + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + // starting_height defines the optional starting height to query the slashes. + uint64 starting_height = 2; + // starting_height defines the optional ending height to query the slashes. + uint64 ending_height = 3; + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 4; +} + +// QueryValidatorSlashesResponse is the response type for the +// Query/ValidatorSlashes RPC method. +message QueryValidatorSlashesResponse { + // slashes defines the slashes the validator received. + repeated ValidatorSlashEvent slashes = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryDelegationRewardsRequest is the request type for the +// Query/DelegationRewards RPC method. +message QueryDelegationRewardsRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // delegator_address defines the delegator address to query for. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // validator_address defines the validator address to query for. + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// QueryDelegationRewardsResponse is the response type for the +// Query/DelegationRewards RPC method. +message QueryDelegationRewardsResponse { + // rewards defines the rewards accrued by a delegation. + repeated cosmos.base.v1beta1.DecCoin rewards = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" + ]; +} + +// QueryDelegationTotalRewardsRequest is the request type for the +// Query/DelegationTotalRewards RPC method. +message QueryDelegationTotalRewardsRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + // delegator_address defines the delegator address to query for. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// QueryDelegationTotalRewardsResponse is the response type for the +// Query/DelegationTotalRewards RPC method. +message QueryDelegationTotalRewardsResponse { + // rewards defines all the rewards accrued by a delegator. + repeated DelegationDelegatorReward rewards = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // total defines the sum of all the rewards. + repeated cosmos.base.v1beta1.DecCoin total = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" + ]; +} + +// QueryDelegatorValidatorsRequest is the request type for the +// Query/DelegatorValidators RPC method. +message QueryDelegatorValidatorsRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // delegator_address defines the delegator address to query for. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// QueryDelegatorValidatorsResponse is the response type for the +// Query/DelegatorValidators RPC method. +message QueryDelegatorValidatorsResponse { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validators defines the validators a delegator is delegating for. + repeated string validators = 1; +} + +// QueryDelegatorWithdrawAddressRequest is the request type for the +// Query/DelegatorWithdrawAddress RPC method. +message QueryDelegatorWithdrawAddressRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // delegator_address defines the delegator address to query for. + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// QueryDelegatorWithdrawAddressResponse is the response type for the +// Query/DelegatorWithdrawAddress RPC method. +message QueryDelegatorWithdrawAddressResponse { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // withdraw_address defines the delegator address to query for. + string withdraw_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// QueryCommunityPoolRequest is the request type for the Query/CommunityPool RPC +// method. +message QueryCommunityPoolRequest {} + +// QueryCommunityPoolResponse is the response type for the Query/CommunityPool +// RPC method. +message QueryCommunityPoolResponse { + // pool defines community pool's coins. + repeated cosmos.base.v1beta1.DecCoin pool = 1 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/atomone/distribution/v1beta1/tx.proto b/proto/atomone/distribution/v1beta1/tx.proto new file mode 100644 index 00000000..9189353a --- /dev/null +++ b/proto/atomone/distribution/v1beta1/tx.proto @@ -0,0 +1,220 @@ +syntax = "proto3"; +package atomone.distribution.v1beta1; + +import "amino/amino.proto"; +import "atomone/distribution/v1beta1/distribution.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/atomone-hub/atomone/x/distribution/types"; +option (gogoproto.equal_all) = true; + +// Msg defines the distribution Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // SetWithdrawAddress defines a method to change the withdraw address + // for a delegator (or validator self-delegation). + rpc SetWithdrawAddress(MsgSetWithdrawAddress) returns (MsgSetWithdrawAddressResponse); + + // WithdrawDelegatorReward defines a method to withdraw rewards of delegator + // from a single validator. + rpc WithdrawDelegatorReward(MsgWithdrawDelegatorReward) returns (MsgWithdrawDelegatorRewardResponse); + + // WithdrawValidatorCommission defines a method to withdraw the + // full commission to the validator address. + rpc WithdrawValidatorCommission(MsgWithdrawValidatorCommission) returns (MsgWithdrawValidatorCommissionResponse); + + // FundCommunityPool defines a method to allow an account to directly + // fund the community pool. + rpc FundCommunityPool(MsgFundCommunityPool) returns (MsgFundCommunityPoolResponse); + + // UpdateParams defines a governance operation for updating the x/distribution + // module parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); + + // CommunityPoolSpend defines a governance operation for sending tokens from + // the community pool in the x/distribution module to another account, which + // could be the governance module itself. The authority is defined in the + // keeper. + // + // Since: cosmos-sdk 0.47 + rpc CommunityPoolSpend(MsgCommunityPoolSpend) returns (MsgCommunityPoolSpendResponse); + + // DepositValidatorRewardsPool defines a method to provide additional rewards + // to delegators to a specific validator. + // + // Since: cosmos-sdk 0.50 + rpc DepositValidatorRewardsPool(MsgDepositValidatorRewardsPool) returns (MsgDepositValidatorRewardsPoolResponse); +} + +// MsgSetWithdrawAddress sets the withdraw address for +// a delegator (or validator self-delegation). +message MsgSetWithdrawAddress { + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgModifyWithdrawAddress"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string withdraw_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// MsgSetWithdrawAddressResponse defines the Msg/SetWithdrawAddress response +// type. +message MsgSetWithdrawAddressResponse {} + +// MsgWithdrawDelegatorReward represents delegation withdrawal to a delegator +// from a single validator. +message MsgWithdrawDelegatorReward { + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgWithdrawDelegationReward"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// MsgWithdrawDelegatorRewardResponse defines the Msg/WithdrawDelegatorReward +// response type. +message MsgWithdrawDelegatorRewardResponse { + // Since: cosmos-sdk 0.46 + repeated cosmos.base.v1beta1.Coin amount = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (amino.encoding) = "legacy_coins", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgWithdrawValidatorCommission withdraws the full commission to the validator +// address. +message MsgWithdrawValidatorCommission { + option (cosmos.msg.v1.signer) = "validator_address"; + option (amino.name) = "cosmos-sdk/MsgWithdrawValCommission"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// MsgWithdrawValidatorCommissionResponse defines the +// Msg/WithdrawValidatorCommission response type. +message MsgWithdrawValidatorCommissionResponse { + // Since: cosmos-sdk 0.46 + repeated cosmos.base.v1beta1.Coin amount = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (amino.encoding) = "legacy_coins", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgFundCommunityPool allows an account to directly +// fund the community pool. +message MsgFundCommunityPool { + option (cosmos.msg.v1.signer) = "depositor"; + option (amino.name) = "cosmos-sdk/MsgFundCommunityPool"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + repeated cosmos.base.v1beta1.Coin amount = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (amino.encoding) = "legacy_coins", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + string depositor = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// MsgFundCommunityPoolResponse defines the Msg/FundCommunityPool response type. +message MsgFundCommunityPoolResponse {} + +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "cosmos-sdk/distribution/MsgUpdateParams"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // params defines the x/distribution parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateParamsResponse {} + +// MsgCommunityPoolSpend defines a message for sending tokens from the community +// pool to another account. This message is typically executed via a governance +// proposal with the governance module being the executing authority. +// +// Since: cosmos-sdk 0.47 +message MsgCommunityPoolSpend { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "cosmos-sdk/distr/MsgCommunityPoolSpend"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string recipient = 2; + repeated cosmos.base.v1beta1.Coin amount = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (amino.encoding) = "legacy_coins", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgCommunityPoolSpendResponse defines the response to executing a +// MsgCommunityPoolSpend message. +// +// Since: cosmos-sdk 0.47 +message MsgCommunityPoolSpendResponse {} + +// DepositValidatorRewardsPool defines the request structure to provide +// additional rewards to delegators from a specific validator. +// +// Since: cosmos-sdk 0.50 +message MsgDepositValidatorRewardsPool { + option (amino.name) = "cosmos-sdk/distr/MsgDepositValRewards"; + option (cosmos.msg.v1.signer) = "depositor"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string depositor = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + repeated cosmos.base.v1beta1.Coin amount = 3 [ + (gogoproto.nullable) = false, + (amino.encoding) = "legacy_coins", + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgDepositValidatorRewardsPoolResponse defines the response to executing a +// MsgDepositValidatorRewardsPool message. +// +// Since: cosmos-sdk 0.50 +message MsgDepositValidatorRewardsPoolResponse {} diff --git a/tests/e2e/chain_test.go b/tests/e2e/chain_test.go index 50b21722..d806feef 100644 --- a/tests/e2e/chain_test.go +++ b/tests/e2e/chain_test.go @@ -5,14 +5,14 @@ import ( "os" "cosmossdk.io/log" - atomone "github.com/atomone-hub/atomone/app" tmrand "github.com/cometbft/cometbft/libs/rand" - dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + + atomone "github.com/atomone-hub/atomone/app" ) const ( diff --git a/tests/e2e/e2e_distribution_test.go b/tests/e2e/e2e_distribution_test.go index 88a0ea0c..e08ee8cf 100644 --- a/tests/e2e/e2e_distribution_test.go +++ b/tests/e2e/e2e_distribution_test.go @@ -7,7 +7,8 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + + distrtypes "github.com/atomone-hub/atomone/x/distribution/types" ) func (s *IntegrationTestSuite) testDistribution() { diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 30a427a0..4abb7db4 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -20,10 +20,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + distributiontypes "github.com/atomone-hub/atomone/x/distribution/types" govtypes "github.com/atomone-hub/atomone/x/gov/types" photontypes "github.com/atomone-hub/atomone/x/photon/types" ) diff --git a/tests/e2e/e2e_gov_test.go b/tests/e2e/e2e_gov_test.go index 35114daa..54f70661 100644 --- a/tests/e2e/e2e_gov_test.go +++ b/tests/e2e/e2e_gov_test.go @@ -750,7 +750,7 @@ func (s *IntegrationTestSuite) writeGovCommunitySpendProposal(c *chain, amount s { "messages":[ { - "@type": "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + "@type": "/atomone.distribution.v1beta1.MsgCommunityPoolSpend", "authority": "%s", "recipient": "%s", "amount": [{ diff --git a/tests/e2e/genesis_test.go b/tests/e2e/genesis_test.go index f773daff..8783f327 100644 --- a/tests/e2e/genesis_test.go +++ b/tests/e2e/genesis_test.go @@ -140,10 +140,10 @@ func modifyGenesis(cdc codec.Codec, path, moniker, amountStr string, addrAll []s "/cosmos.authz.v1beta1.MsgRevoke", "/cosmos.bank.v1beta1.MsgSend", "/cosmos.bank.v1beta1.MsgMultiSend", - "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", - "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", - "/cosmos.distribution.v1beta1.MsgFundCommunityPool", - "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", + "/atomone.distribution.v1beta1.MsgSetWithdrawAddress", + "/atomone.distribution.v1beta1.MsgWithdrawValidatorCommission", + "/atomone.distribution.v1beta1.MsgFundCommunityPool", + "/atomone.distribution.v1beta1.MsgWithdrawDelegatorReward", "/cosmos.feegrant.v1beta1.MsgGrantAllowance", "/cosmos.feegrant.v1beta1.MsgRevokeAllowance", "/cosmos.gov.v1beta1.MsgVoteWeighted", diff --git a/tests/e2e/query_test.go b/tests/e2e/query_test.go index 7f51fc28..a91be38c 100644 --- a/tests/e2e/query_test.go +++ b/tests/e2e/query_test.go @@ -16,9 +16,9 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + disttypes "github.com/atomone-hub/atomone/x/distribution/types" dynamicfeetypes "github.com/atomone-hub/atomone/x/dynamicfee/types" govtypesv1 "github.com/atomone-hub/atomone/x/gov/types/v1" govtypesv1beta1 "github.com/atomone-hub/atomone/x/gov/types/v1beta1" diff --git a/x/distribution/README.md b/x/distribution/README.md new file mode 100644 index 00000000..1363bb05 --- /dev/null +++ b/x/distribution/README.md @@ -0,0 +1,1048 @@ +--- +sidebar_position: 1 +--- + +# `x/distribution` + +## Overview + +This _simple_ distribution mechanism describes a functional way to passively +distribute rewards between validators and delegators. Note that this mechanism does +not distribute funds in as precisely as active reward distribution mechanisms and +will therefore be upgraded in the future. + +The mechanism operates as follows. Collected rewards are pooled globally and +divided out passively to validators and delegators. Each validator has the +opportunity to charge commission to the delegators on the rewards collected on +behalf of the delegators. Fees are collected directly into a global reward pool +and validator proposer-reward pool. Due to the nature of passive accounting, +whenever changes to parameters which affect the rate of reward distribution +occurs, withdrawal of rewards must also occur. + +* Whenever withdrawing, one must withdraw the maximum amount they are entitled + to, leaving nothing in the pool. +* Whenever bonding, unbonding, or re-delegating tokens to an existing account, a + full withdrawal of the rewards must occur (as the rules for lazy accounting + change). +* Whenever a validator chooses to change the commission on rewards, all accumulated + commission rewards must be simultaneously withdrawn. + +The above scenarios are covered in `hooks.md`. + +The distribution mechanism outlined herein is used to lazily distribute the +following rewards between validators and associated delegators: + +* multi-token fees to be socially distributed +* inflated staked asset provisions +* validator commission on all rewards earned by their delegators stake + +Fees are pooled within a global pool. The mechanisms used allow for validators +and delegators to independently and lazily withdraw their rewards. + +## Shortcomings + +As a part of the lazy computations, each delegator holds an accumulation term +specific to each validator which is used to estimate what their approximate +fair portion of tokens held in the global fee pool is owed to them. + +```text +entitlement = delegator-accumulation / all-delegators-accumulation +``` + +Under the circumstance that there was constant and equal flow of incoming +reward tokens every block, this distribution mechanism would be equal to the +active distribution (distribute individually to all delegators each block). +However, this is unrealistic so deviations from the active distribution will +occur based on fluctuations of incoming reward tokens as well as timing of +reward withdrawal by other delegators. + +If you happen to know that incoming rewards are about to significantly increase, +you are incentivized to not withdraw until after this event, increasing the +worth of your existing _accum_. See [#2764](https://github.com/cosmos/cosmos-sdk/issues/2764) +for further details. + +## Effect on Staking + +Charging commission on Atom provisions while also allowing for Atom-provisions +to be auto-bonded (distributed directly to the validators bonded stake) is +problematic within BPoS. Fundamentally, these two mechanisms are mutually +exclusive. If both commission and auto-bonding mechanisms are simultaneously +applied to the staking-token then the distribution of staking-tokens between +any validator and its delegators will change with each block. This then +necessitates a calculation for each delegation records for each block - +which is considered computationally expensive. + +In conclusion, we can only have Atom commission and unbonded atoms +provisions or bonded atom provisions with no Atom commission, and we elect to +implement the former. Stakeholders wishing to rebond their provisions may elect +to set up a script to periodically withdraw and rebond rewards. + +## Contents + +* [Concepts](#concepts) +* [State](#state) + * [FeePool](#feepool) + * [Validator Distribution](#validator-distribution) + * [Delegation Distribution](#delegation-distribution) + * [Params](#params) +* [Begin Block](#begin-block) +* [Messages](#messages) +* [Hooks](#hooks) +* [Events](#events) +* [Parameters](#parameters) +* [Client](#client) + * [CLI](#cli) + * [gRPC](#grpc) + +## Concepts + +In Proof of Stake (PoS) blockchains, rewards gained from transaction fees are paid to validators. The fee distribution module fairly distributes the rewards to the validators' constituent delegators. + +Rewards are calculated per period. The period is updated each time a validator's delegation changes, for example, when the validator receives a new delegation. +The rewards for a single validator can then be calculated by taking the total rewards for the period before the delegation started, minus the current total rewards. +To learn more, see the [F1 Fee Distribution paper](https://github.com/cosmos/cosmos-sdk/tree/main/docs/spec/fee_distribution/f1_fee_distr.pdf). + +The commission to the validator is paid when the validator is removed or when the validator requests a withdrawal. +The commission is calculated and incremented at every `BeginBlock` operation to update accumulated fee amounts. + +The rewards to a delegator are distributed when the delegation is changed or removed, or a withdrawal is requested. +Before rewards are distributed, all slashes to the validator that occurred during the current delegation are applied. + +### Reference Counting in F1 Fee Distribution + +In F1 fee distribution, the rewards a delegator receives are calculated when their delegation is withdrawn. This calculation must read the terms of the summation of rewards divided by the share of tokens from the period which they ended when they delegated, and the final period that was created for the withdrawal. + +Additionally, as slashes change the amount of tokens a delegation will have (but we calculate this lazily, +only when a delegator un-delegates), we must calculate rewards in separate periods before / after any slashes +which occurred in between when a delegator delegated and when they withdrew their rewards. Thus slashes, like +delegations, reference the period which was ended by the slash event. + +All stored historical rewards records for periods which are no longer referenced by any delegations +or any slashes can thus be safely removed, as they will never be read (future delegations and future +slashes will always reference future periods). This is implemented by tracking a `ReferenceCount` +along with each historical reward storage entry. Each time a new object (delegation or slash) +is created which might need to reference the historical record, the reference count is incremented. +Each time one object which previously needed to reference the historical record is deleted, the reference +count is decremented. If the reference count hits zero, the historical record is deleted. + +## State + +### FeePool + +All globally tracked parameters for distribution are stored within +`FeePool`. Rewards are collected and added to the reward pool and +distributed to validators/delegators from here. + +Note that the reward pool holds decimal coins (`DecCoins`) to allow +for fractions of coins to be received from operations like inflation. +When coins are distributed from the pool they are truncated back to +`sdk.Coins` which are non-decimal. + +* FeePool: `0x00 -> ProtocolBuffer(FeePool)` + +```go +// coins with decimal +type DecCoins []DecCoin + +type DecCoin struct { + Amount math.LegacyDec + Denom string +} +``` + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/distribution.proto#L116-L123 +``` + +### Validator Distribution + +Validator distribution information for the relevant validator is updated each time: + +1. delegation amount to a validator is updated, +2. any delegator withdraws from a validator, or +3. the validator withdraws its commission. + +* ValidatorDistInfo: `0x02 | ValOperatorAddrLen (1 byte) | ValOperatorAddr -> ProtocolBuffer(validatorDistribution)` + +```go +type ValidatorDistInfo struct { + OperatorAddress sdk.AccAddress + SelfBondRewards sdkmath.DecCoins + ValidatorCommission types.ValidatorAccumulatedCommission +} +``` + +### Delegation Distribution + +Each delegation distribution only needs to record the height at which it last +withdrew fees. Because a delegation must withdraw fees each time it's +properties change (aka bonded tokens etc.) its properties will remain constant +and the delegator's _accumulation_ factor can be calculated passively knowing +only the height of the last withdrawal and its current properties. + +* DelegationDistInfo: `0x02 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValOperatorAddrLen (1 byte) | ValOperatorAddr -> ProtocolBuffer(delegatorDist)` + +```go +type DelegationDistInfo struct { + WithdrawalHeight int64 // last time this delegation withdrew rewards +} +``` + +### Params + +The distribution module stores it's params in state with the prefix of `0x09`, +it can be updated with governance or the address with authority. + +* Params: `0x09 | ProtocolBuffer(Params)` + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/distribution.proto#L12-L42 +``` + +## Begin Block + +At each `BeginBlock`, all fees received in the previous block are transferred to +the distribution `ModuleAccount` account. When a delegator or validator +withdraws their rewards, they are taken out of the `ModuleAccount`. During begin +block, the different claims on the fees collected are updated as follows: + +* The reserve community tax is charged. +* The remainder is distributed proportionally by voting power to all bonded validators + +### The Distribution Scheme + +See [params](#params) for description of parameters. + +Let `fees` be the total fees collected in the previous block, including +inflationary rewards to the stake. All fees are collected in a specific module +account during the block. During `BeginBlock`, they are sent to the +`"distribution"` `ModuleAccount`. No other sending of tokens occurs. Instead, the +rewards each account is entitled to are stored, and withdrawals can be triggered +through the messages `FundCommunityPool`, `WithdrawValidatorCommission` and +`WithdrawDelegatorReward`. + +#### Reward to the Community Pool + +The community pool gets `community_tax * fees`, plus any remaining dust after +validators get their rewards that are always rounded down to the nearest +integer value. + +#### Reward To the Validators + +The proposer receives no extra rewards. All fees are distributed among all the +bonded validators, including the proposer, in proportion to their consensus power. + +```text +powFrac = validator power / total bonded validator power +voteMul = 1 - community_tax +``` + +All validators receive `fees * voteMul * powFrac`. + +#### Rewards to Delegators + +Each validator's rewards are distributed to its delegators. The validator also +has a self-delegation that is treated like a regular delegation in +distribution calculations. + +The validator sets a commission rate. The commission rate is flexible, but each +validator sets a maximum rate and a maximum daily increase. These maximums cannot be exceeded and protect delegators from sudden increases of validator commission rates to prevent validators from taking all of the rewards. + +The outstanding rewards that the operator is entitled to are stored in +`ValidatorAccumulatedCommission`, while the rewards the delegators are entitled +to are stored in `ValidatorCurrentRewards`. The [F1 fee distribution scheme](#concepts) is used to calculate the rewards per delegator as they +withdraw or update their delegation, and is thus not handled in `BeginBlock`. + +#### Example Distribution + +For this example distribution, the underlying consensus engine selects block proposers in +proportion to their power relative to the entire bonded power. + +All validators are equally performant at including pre-commits in their proposed +blocks. Then hold `(pre_commits included) / (total bonded validator power)` +constant so that the amortized block reward for the validator is `( validator power / total bonded power) * (1 - community tax rate)` of +the total rewards. Consequently, the reward for a single delegator is: + +```text +(delegator proportion of the validator power / validator power) * (validator power / total bonded power) + * (1 - community tax rate) * (1 - validator commission rate) += (delegator proportion of the validator power / total bonded power) * (1 - +community tax rate) * (1 - validator commission rate) +``` + +## Messages + +### MsgSetWithdrawAddress + +By default, the withdraw address is the delegator address. To change its withdraw address, a delegator must send a `MsgSetWithdrawAddress` message. +Changing the withdraw address is possible only if the parameter `WithdrawAddrEnabled` is set to `true`. + +The withdraw address cannot be any of the module accounts. These accounts are blocked from being withdraw addresses by being added to the distribution keeper's `blockedAddrs` array at initialization. + +Response: + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L49-L60 +``` + +```go +func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) error + if k.blockedAddrs[withdrawAddr.String()] { + fail with "`{withdrawAddr}` is not allowed to receive external funds" + } + + if !k.GetWithdrawAddrEnabled(ctx) { + fail with `ErrSetWithdrawAddrDisabled` + } + + k.SetDelegatorWithdrawAddr(ctx, delegatorAddr, withdrawAddr) +``` + +### MsgWithdrawDelegatorReward + +A delegator can withdraw its rewards. +Internally in the distribution module, this transaction simultaneously removes the previous delegation with associated rewards, the same as if the delegator simply started a new delegation of the same value. +The rewards are sent immediately from the distribution `ModuleAccount` to the withdraw address. +Any remainder (truncated decimals) are sent to the community pool. +The starting height of the delegation is set to the current validator period, and the reference count for the previous period is decremented. +The amount withdrawn is deducted from the `ValidatorOutstandingRewards` variable for the validator. + +In the F1 distribution, the total rewards are calculated per validator period, and a delegator receives a piece of those rewards in proportion to their stake in the validator. +In basic F1, the total rewards that all the delegators are entitled to between to periods is calculated the following way. +Let `R(X)` be the total accumulated rewards up to period `X` divided by the tokens staked at that time. The delegator allocation is `R(X) * delegator_stake`. +Then the rewards for all the delegators for staking between periods `A` and `B` are `(R(B) - R(A)) * total stake`. +However, these calculated rewards don't account for slashing. + +Taking the slashes into account requires iteration. +Let `F(X)` be the fraction a validator is to be slashed for a slashing event that happened at period `X`. +If the validator was slashed at periods `P1, ..., PN`, where `A < P1`, `PN < B`, the distribution module calculates the individual delegator's rewards, `T(A, B)`, as follows: + +```go +stake := initial stake +rewards := 0 +previous := A +for P in P1, ..., PN`: + rewards = (R(P) - previous) * stake + stake = stake * F(P) + previous = P +rewards = rewards + (R(B) - R(PN)) * stake +``` + +The historical rewards are calculated retroactively by playing back all the slashes and then attenuating the delegator's stake at each step. +The final calculated stake is equivalent to the actual staked coins in the delegation with a margin of error due to rounding errors. + +Response: + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L66-L77 +``` + +### WithdrawValidatorCommission + +The validator can send the WithdrawValidatorCommission message to withdraw their accumulated commission. +The commission is calculated in every block during `BeginBlock`, so no iteration is required to withdraw. +The amount withdrawn is deducted from the `ValidatorOutstandingRewards` variable for the validator. +Only integer amounts can be sent. If the accumulated awards have decimals, the amount is truncated before the withdrawal is sent, and the remainder is left to be withdrawn later. + +### FundCommunityPool + +This message sends coins directly from the sender to the community pool. + +The transaction fails if the amount cannot be transferred from the sender to the distribution module account. + +```go +func (k Keeper) FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error { + if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { + return err + } + + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) + + if err := k.FeePool.Set(ctx, feePool); err != nil { + return err + } + + return nil +} +``` + +### Common distribution operations + +These operations take place during many different messages. + +#### Initialize delegation + +Each time a delegation is changed, the rewards are withdrawn and the delegation is reinitialized. +Initializing a delegation increments the validator period and keeps track of the starting period of the delegation. + +```go +// initialize starting info for a new delegation +func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) { + // period has already been incremented - we want to store the period ended by this delegation action + previousPeriod := k.GetValidatorCurrentRewards(ctx, val).Period - 1 + + // increment reference count for the period we're going to track + k.incrementReferenceCount(ctx, val, previousPeriod) + + validator := k.stakingKeeper.Validator(ctx, val) + delegation := k.stakingKeeper.Delegation(ctx, del, val) + + // calculate delegation stake in tokens + // we don't store directly, so multiply delegation shares * (tokens per share) + // note: necessary to truncate so we don't allow withdrawing more rewards than owed + stake := validator.TokensFromSharesTruncated(delegation.GetShares()) + k.SetDelegatorStartingInfo(ctx, val, del, types.NewDelegatorStartingInfo(previousPeriod, stake, uint64(ctx.BlockHeight()))) +} +``` + +### MsgUpdateParams + +Distribution module params can be updated through `MsgUpdateParams`, which can be done using governance proposal and the signer will always be gov module account address. + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L133-L147 +``` + +The message handling can fail if: + +* signer is not the gov module account address. + +## Hooks + +Available hooks that can be called by and from this module. + +### Create or modify delegation distribution + +* triggered-by: `staking.MsgDelegate`, `staking.MsgBeginRedelegate`, `staking.MsgUndelegate` + +#### Before + +* The delegation rewards are withdrawn to the withdraw address of the delegator. + The rewards include the current period and exclude the starting period. +* The validator period is incremented. + The validator period is incremented because the validator's power and share distribution might have changed. +* The reference count for the delegator's starting period is decremented. + +#### After + +The starting height of the delegation is set to the previous period. +Because of the `Before`-hook, this period is the last period for which the delegator was rewarded. + +### Validator created + +* triggered-by: `staking.MsgCreateValidator` + +When a validator is created, the following validator variables are initialized: + +* Historical rewards +* Current accumulated rewards +* Accumulated commission +* Total outstanding rewards +* Period + +By default, all values are set to a `0`, except period, which is set to `1`. + +### Validator removed + +* triggered-by: `staking.RemoveValidator` + +Outstanding commission is sent to the validator's self-delegation withdrawal address. +Remaining delegator rewards get sent to the community fee pool. + +Note: The validator gets removed only when it has no remaining delegations. +At that time, all outstanding delegator rewards will have been withdrawn. +Any remaining rewards are dust amounts. + +### Validator is slashed + +* triggered-by: `staking.Slash` +* The current validator period reference count is incremented. + The reference count is incremented because the slash event has created a reference to it. +* The validator period is incremented. +* The slash event is stored for later use. + The slash event will be referenced when calculating delegator rewards. + +## Events + +The distribution module emits the following events: + +### BeginBlocker + +| Type | Attribute Key | Attribute Value | +|-----------------|---------------|--------------------| +| proposer_reward | validator | {validatorAddress} | +| proposer_reward | reward | {proposerReward} | +| commission | amount | {commissionAmount} | +| commission | validator | {validatorAddress} | +| rewards | amount | {rewardAmount} | +| rewards | validator | {validatorAddress} | + +### Handlers + +#### MsgSetWithdrawAddress + +| Type | Attribute Key | Attribute Value | +|----------------------|------------------|----------------------| +| set_withdraw_address | withdraw_address | {withdrawAddress} | +| message | module | distribution | +| message | action | set_withdraw_address | +| message | sender | {senderAddress} | + +#### MsgWithdrawDelegatorReward + +| Type | Attribute Key | Attribute Value | +|---------|---------------|---------------------------| +| withdraw_rewards | amount | {rewardAmount} | +| withdraw_rewards | validator | {validatorAddress} | +| message | module | distribution | +| message | action | withdraw_delegator_reward | +| message | sender | {senderAddress} | + +#### MsgWithdrawValidatorCommission + +| Type | Attribute Key | Attribute Value | +|------------|---------------|-------------------------------| +| withdraw_commission | amount | {commissionAmount} | +| message | module | distribution | +| message | action | withdraw_validator_commission | +| message | sender | {senderAddress} | + +## Parameters + +The distribution module contains the following parameters: + +| Key | Type | Example | +| ------------------- | ------------ | -------------------------- | +| communitytax | string (dec) | "0.020000000000000000" [0] | +| withdrawaddrenabled | bool | true | + +* [0] `communitytax` must be positive and cannot exceed 1.00. + +:::note +The reserve pool is the pool of collected funds for use by governance taken via the `CommunityTax`. +Currently with the Cosmos SDK, tokens collected by the CommunityTax are accounted for but unspendable. +::: + +## Client + +## CLI + +A user can query and interact with the `distribution` module using the CLI. + +#### Query + +The `query` commands allow users to query `distribution` state. + +```shell +simd query distribution --help +``` + +##### commission + +The `commission` command allows users to query validator commission rewards by address. + +```shell +simd query distribution commission [address] [flags] +``` + +Example: + +```shell +simd query distribution commission cosmosvaloper1... +``` + +Example Output: + +```yml +commission: +- amount: "1000000.000000000000000000" + denom: stake +``` + +##### community-pool + +The `community-pool` command allows users to query all coin balances within the community pool. + +```shell +simd query distribution community-pool [flags] +``` + +Example: + +```shell +simd query distribution community-pool +``` + +Example Output: + +```yml +pool: +- amount: "1000000.000000000000000000" + denom: stake +``` + +##### params + +The `params` command allows users to query the parameters of the `distribution` module. + +```shell +simd query distribution params [flags] +``` + +Example: + +```shell +simd query distribution params +``` + +Example Output: + +```yml +base_proposer_reward: "0.000000000000000000" +bonus_proposer_reward: "0.000000000000000000" +community_tax: "0.020000000000000000" +withdraw_addr_enabled: true +``` + +##### rewards + +The `rewards` command allows users to query delegator rewards. Users can optionally include the validator address to query rewards earned from a specific validator. + +```shell +simd query distribution rewards [delegator-addr] [validator-addr] [flags] +``` + +Example: + +```shell +simd query distribution rewards cosmos1... +``` + +Example Output: + +```yml +rewards: +- reward: + - amount: "1000000.000000000000000000" + denom: stake + validator_address: cosmosvaloper1.. +total: +- amount: "1000000.000000000000000000" + denom: stake +``` + +##### slashes + +The `slashes` command allows users to query all slashes for a given block range. + +```shell +simd query distribution slashes [validator] [start-height] [end-height] [flags] +``` + +Example: + +```shell +simd query distribution slashes cosmosvaloper1... 1 1000 +``` + +Example Output: + +```yml +pagination: + next_key: null + total: "0" +slashes: +- validator_period: 20, + fraction: "0.009999999999999999" +``` + +##### validator-outstanding-rewards + +The `validator-outstanding-rewards` command allows users to query all outstanding (un-withdrawn) rewards for a validator and all their delegations. + +```shell +simd query distribution validator-outstanding-rewards [validator] [flags] +``` + +Example: + +```shell +simd query distribution validator-outstanding-rewards cosmosvaloper1... +``` + +Example Output: + +```yml +rewards: +- amount: "1000000.000000000000000000" + denom: stake +``` + +##### validator-distribution-info + +The `validator-distribution-info` command allows users to query validator commission and self-delegation rewards for validator. + +````shell +simd query distribution validator-distribution-info cosmosvaloper1... +``` + +Example Output: + +```yml +commission: +- amount: "100000.000000000000000000" + denom: stake +operator_address: cosmosvaloper1... +self_bond_rewards: +- amount: "100000.000000000000000000" + denom: stake +``` + +#### Transactions + +The `tx` commands allow users to interact with the `distribution` module. + +```shell +simd tx distribution --help +``` + +##### fund-community-pool + +The `fund-community-pool` command allows users to send funds to the community pool. + +```shell +simd tx distribution fund-community-pool [amount] [flags] +``` + +Example: + +```shell +simd tx distribution fund-community-pool 100stake --from cosmos1... +``` + +##### set-withdraw-addr + +The `set-withdraw-addr` command allows users to set the withdraw address for rewards associated with a delegator address. + +```shell +simd tx distribution set-withdraw-addr [withdraw-addr] [flags] +``` + +Example: + +```shell +simd tx distribution set-withdraw-addr cosmos1... --from cosmos1... +``` + +##### withdraw-all-rewards + +The `withdraw-all-rewards` command allows users to withdraw all rewards for a delegator. + +```shell +simd tx distribution withdraw-all-rewards [flags] +``` + +Example: + +```shell +simd tx distribution withdraw-all-rewards --from cosmos1... +``` + +##### withdraw-rewards + +The `withdraw-rewards` command allows users to withdraw all rewards from a given delegation address, +and optionally withdraw validator commission if the delegation address given is a validator operator and the user proves the `--commission` flag. + +```shell +simd tx distribution withdraw-rewards [validator-addr] [flags] +``` + +Example: + +```shell +simd tx distribution withdraw-rewards cosmosvaloper1... --from cosmos1... --commission +``` + +### gRPC + +A user can query the `distribution` module using gRPC endpoints. + +#### Params + +The `Params` endpoint allows users to query parameters of the `distribution` module. + +Example: + +```shell +grpcurl -plaintext \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/Params +``` + +Example Output: + +```json +{ + "params": { + "communityTax": "20000000000000000", + "baseProposerReward": "00000000000000000", + "bonusProposerReward": "00000000000000000", + "withdrawAddrEnabled": true + } +} +``` + +#### ValidatorDistributionInfo + +The `ValidatorDistributionInfo` queries validator commission and self-delegation rewards for validator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"validator_address":"cosmosvalop1..."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/ValidatorDistributionInfo +``` + +Example Output: + +```json +{ + "commission": { + "commission": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] + }, + "self_bond_rewards": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ], + "validator_address": "cosmosvalop1..." +} +``` + +#### ValidatorOutstandingRewards + +The `ValidatorOutstandingRewards` endpoint allows users to query rewards of a validator address. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"validator_address":"cosmosvalop1.."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/ValidatorOutstandingRewards +``` + +Example Output: + +```json +{ + "rewards": { + "rewards": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] + } +} +``` + +#### ValidatorCommission + +The `ValidatorCommission` endpoint allows users to query accumulated commission for a validator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"validator_address":"cosmosvalop1.."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/ValidatorCommission +``` + +Example Output: + +```json +{ + "commission": { + "commission": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] + } +} +``` + +#### ValidatorSlashes + +The `ValidatorSlashes` endpoint allows users to query slash events of a validator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"validator_address":"cosmosvalop1.."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/ValidatorSlashes +``` + +Example Output: + +```json +{ + "slashes": [ + { + "validator_period": "20", + "fraction": "0.009999999999999999" + } + ], + "pagination": { + "total": "1" + } +} +``` + +#### DelegationRewards + +The `DelegationRewards` endpoint allows users to query the total rewards accrued by a delegation. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"delegator_address":"cosmos1...","validator_address":"cosmosvalop1..."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/DelegationRewards +``` + +Example Output: + +```json +{ + "rewards": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] +} +``` + +#### DelegationTotalRewards + +The `DelegationTotalRewards` endpoint allows users to query the total rewards accrued by each validator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"delegator_address":"cosmos1..."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/DelegationTotalRewards +``` + +Example Output: + +```json +{ + "rewards": [ + { + "validatorAddress": "cosmosvaloper1...", + "reward": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] + } + ], + "total": [ + { + "denom": "stake", + "amount": "1000000000000000" + } + ] +} +``` + +#### DelegatorValidators + +The `DelegatorValidators` endpoint allows users to query all validators for given delegator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"delegator_address":"cosmos1..."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/DelegatorValidators +``` + +Example Output: + +```json +{ + "validators": ["cosmosvaloper1..."] +} +``` + +#### DelegatorWithdrawAddress + +The `DelegatorWithdrawAddress` endpoint allows users to query the withdraw address of a delegator. + +Example: + +```shell +grpcurl -plaintext \ + -d '{"delegator_address":"cosmos1..."}' \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/DelegatorWithdrawAddress +``` + +Example Output: + +```json +{ + "withdrawAddress": "cosmos1..." +} +``` + +#### CommunityPool + +The `CommunityPool` endpoint allows users to query the community pool coins. + +Example: + +```shell +grpcurl -plaintext \ + localhost:9090 \ + cosmos.distribution.v1beta1.Query/CommunityPool +``` + +Example Output: + +```json +{ + "pool": [ + { + "denom": "stake", + "amount": "1000000000000000000" + } + ] +} +``` diff --git a/x/distribution/autocli.go b/x/distribution/autocli.go new file mode 100644 index 00000000..fc636669 --- /dev/null +++ b/x/distribution/autocli.go @@ -0,0 +1,160 @@ +package distribution + +import ( + "fmt" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + distirbuitonv1beta1 "cosmossdk.io/api/cosmos/distribution/v1beta1" + + "github.com/cosmos/cosmos-sdk/version" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: distirbuitonv1beta1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Query the current distribution parameters.", + }, + { + RpcMethod: "ValidatorDistributionInfo", + Use: "validator-distribution-info [validator]", + Short: "Query validator distribution info", + Example: fmt.Sprintf(`Example: $ %s query distribution validator-distribution-info [validator-address]`, version.AppName), + + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "ValidatorOutstandingRewards", + Use: "validator-outstanding-rewards [validator]", + Short: "Query distribution outstanding (un-withdrawn) rewards for a validator and all their delegations", + Example: fmt.Sprintf(`$ %s query distribution validator-outstanding-rewards [validator-address]`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "ValidatorCommission", + Use: "commission [validator]", + Short: "Query distribution validator commission", + Example: fmt.Sprintf(`$ %s query distribution commission [validator-address]`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "ValidatorSlashes", + Use: "slashes [validator] [start-height] [end-height]", + Short: "Query distribution validator slashes", + Example: fmt.Sprintf(`$ %s query distribution slashes [validator-address] 0 100`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + {ProtoField: "starting_height"}, + {ProtoField: "ending_height"}, + }, + }, + { + RpcMethod: "DelegationRewards", + Use: "rewards-by-validator [delegator-addr] [validator-addr]", + Short: "Query all distribution delegator from a particular validator", + Example: fmt.Sprintf("$ %s query distribution rewards [delegator-address] [validator-address]", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "delegator_address"}, + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "DelegationTotalRewards", + Use: "rewards [delegator-addr]", + Short: "Query all distribution delegator rewards", + Long: "Query all rewards earned by a delegator", + Example: fmt.Sprintf("$ %s query distribution rewards [delegator-address]", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "delegator_address"}, + }, + }, + { + RpcMethod: "CommunityPool", + Use: "community-pool", + Short: "Query the amount of coins in the community pool", + Example: fmt.Sprintf(`$ %s query distribution community-pool`, version.AppName), + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: distirbuitonv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "SetWithdrawAddress", + Use: "set-withdraw-addr [withdraw-addr]", + Short: "Change the default withdraw address for rewards associated with an address", + Example: fmt.Sprintf("%s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "withdraw_address"}, + }, + }, + { + RpcMethod: "WithdrawDelegatorReward", + Use: "withdraw-rewards [validator-addr]", + Short: "Withdraw rewards from a given delegation address", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "WithdrawValidatorCommission", + Use: "withdraw-validator-commission [validator-addr]", + Short: "Withdraw commissions from a validator address (must be a validator operator)", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + }, + }, + { + RpcMethod: "DepositValidatorRewardsPool", + Use: "fund-validator-rewards-pool [validator-addr] [amount]", + Short: "Fund the validator rewards pool with the specified amount", + Example: fmt.Sprintf("%s tx distribution fund-validator-rewards-pool cosmosvaloper1x20lytyf6zkcrv5edpkfkn8sz578qg5sqfyqnp 100uatom --from mykey", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "validator_address"}, + {ProtoField: "amount", Varargs: true}, + }, + }, + { + RpcMethod: "FundCommunityPool", + Use: "fund-community-pool [amount]", + Short: "Funds the community pool with the specified amount", + Example: fmt.Sprintf(`$ %s tx distribution fund-community-pool 100uatom --from mykey`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "amount", Varargs: true}, + }, + }, + { + RpcMethod: "UpdateParams", + Use: "update-params-proposal [params]", + Short: "Submit a proposal to update distribution module params. Note: the entire params must be provided.", + Example: fmt.Sprintf(`%s tx distribution update-params-proposal '{ "community_tax": "20000", "base_proposer_reward": "0", "bonus_proposer_reward": "0", "withdraw_addr_enabled": true }'`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}}, + GovProposal: true, + }, + { + RpcMethod: "CommunityPoolSpend", + Use: "community-pool-spend-proposal [recipient] [amount]", + Example: fmt.Sprintf(`$ %s tx distribution community-pool-spend-proposal [recipient] 100uatom`, version.AppName), + Short: "Submit a proposal to spend from the community pool", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "recipient"}, + {ProtoField: "amount", Varargs: true}, + }, + GovProposal: true, + }, + }, + EnhanceCustomCommand: false, // use custom commands only until v0.51 + }, + } +} diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go new file mode 100644 index 00000000..020975b4 --- /dev/null +++ b/x/distribution/client/cli/tx.go @@ -0,0 +1,305 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "cosmossdk.io/core/address" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Transaction flags for the x/distribution module +const ( + FlagCommission = "commission" + FlagMaxMessagesPerTx = "max-msgs" + + MaxMessagesPerTxDefault = 0 +) + +// NewTxCmd returns a root CLI command handler for all x/distribution transaction commands. +func NewTxCmd(valAc, ac address.Codec) *cobra.Command { + distTxCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Distribution transactions subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + distTxCmd.AddCommand( + NewWithdrawRewardsCmd(valAc, ac), + NewWithdrawAllRewardsCmd(valAc, ac), + NewSetWithdrawAddrCmd(ac), + NewFundCommunityPoolCmd(ac), + NewDepositValidatorRewardsPoolCmd(valAc, ac), + ) + + return distTxCmd +} + +type newGenerateOrBroadcastFunc func(client.Context, *pflag.FlagSet, ...sdk.Msg) error + +func newSplitAndApply( + genOrBroadcastFn newGenerateOrBroadcastFunc, clientCtx client.Context, + fs *pflag.FlagSet, msgs []sdk.Msg, chunkSize int, +) error { + if chunkSize == 0 { + return genOrBroadcastFn(clientCtx, fs, msgs...) + } + + // split messages into slices of length chunkSize + totalMessages := len(msgs) + for i := 0; i < len(msgs); i += chunkSize { + sliceEnd := min(i+chunkSize, totalMessages) + msgChunk := msgs[i:sliceEnd] + if err := genOrBroadcastFn(clientCtx, fs, msgChunk...); err != nil { + return err + } + } + + return nil +} + +// NewWithdrawRewardsCmd returns a CLI command handler for creating a MsgWithdrawDelegatorReward transaction. +func NewWithdrawRewardsCmd(valCodec, ac address.Codec) *cobra.Command { + bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix() + + cmd := &cobra.Command{ + Use: "withdraw-rewards [validator-addr]", + Short: "Withdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw rewards from a given delegation address, +and optionally withdraw validator commission if the delegation address given is a validator operator. + +Example: +$ %s tx distribution withdraw-rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey +$ %s tx distribution withdraw-rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --commission +`, + version.AppName, bech32PrefixValAddr, version.AppName, bech32PrefixValAddr, + ), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + delAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + _, err = valCodec.StringToBytes(args[0]) + if err != nil { + return err + } + + msgs := []sdk.Msg{types.NewMsgWithdrawDelegatorReward(delAddr, args[0])} + + if commission, _ := cmd.Flags().GetBool(FlagCommission); commission { + msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(args[0])) + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msgs...) + }, + } + + cmd.Flags().Bool(FlagCommission, false, "Withdraw the validator's commission in addition to the rewards") + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// NewWithdrawAllRewardsCmd returns a CLI command handler for creating a MsgWithdrawDelegatorReward transaction. +func NewWithdrawAllRewardsCmd(valCodec, ac address.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "withdraw-all-rewards", + Short: "withdraw all delegations rewards for a delegator", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw all rewards for a single delegator. +Note that if you use this command with --%[2]s=%[3]s or --%[2]s=%[4]s, the %[5]s flag will automatically be set to 0. + +Example: +$ %[1]s tx distribution withdraw-all-rewards --from mykey +`, + version.AppName, flags.FlagBroadcastMode, flags.BroadcastSync, flags.BroadcastAsync, FlagMaxMessagesPerTx, + ), + ), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + delAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + // The transaction cannot be generated offline since it requires a query + // to get all the validators. + if clientCtx.Offline { + return fmt.Errorf("cannot generate tx in offline mode") + } + + queryClient := types.NewQueryClient(clientCtx) + delValsRes, err := queryClient.DelegatorValidators(cmd.Context(), &types.QueryDelegatorValidatorsRequest{DelegatorAddress: delAddr}) + if err != nil { + return err + } + + validators := delValsRes.Validators + // build multi-message transaction + msgs := make([]sdk.Msg, 0, len(validators)) + for _, valAddr := range validators { + _, err := valCodec.StringToBytes(valAddr) + if err != nil { + return err + } + + msg := types.NewMsgWithdrawDelegatorReward(delAddr, valAddr) + msgs = append(msgs, msg) + } + + chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) + + return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize) + }, + } + + cmd.Flags().Int(FlagMaxMessagesPerTx, MaxMessagesPerTxDefault, "Limit the number of messages per tx (0 for unlimited)") + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// NewSetWithdrawAddrCmd returns a CLI command handler for creating a MsgSetWithdrawAddress transaction. +func NewSetWithdrawAddrCmd(ac address.Codec) *cobra.Command { + bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix() + + cmd := &cobra.Command{ + Use: "set-withdraw-addr [withdraw-addr]", + Short: "change the default withdraw address for rewards associated with an address", + Long: strings.TrimSpace( + fmt.Sprintf(`Set the withdraw address for rewards associated with a delegator address. + +Example: +$ %s tx distribution set-withdraw-addr %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey +`, + version.AppName, bech32PrefixAccAddr, + ), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + delAddr := clientCtx.GetFromAddress() + withdrawAddr, err := ac.StringToBytes(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// NewFundCommunityPoolCmd returns a CLI command handler for creating a MsgFundCommunityPool transaction. +func NewFundCommunityPoolCmd(ac address.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "fund-community-pool [amount]", + Args: cobra.ExactArgs(1), + Short: "Funds the community pool with the specified amount", + Long: strings.TrimSpace( + fmt.Sprintf(`Funds the community pool with the specified amount + +Example: +$ %s tx distribution fund-community-pool 100uatom --from mykey +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + depositorAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + amount, err := sdk.ParseCoinsNormalized(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgFundCommunityPool(amount, depositorAddr) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// NewDepositValidatorRewardsPoolCmd returns a CLI command handler for creating +// a MsgDepositValidatorRewardsPool transaction. +func NewDepositValidatorRewardsPoolCmd(valCodec, ac address.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "fund-validator-rewards-pool [val_addr] [amount]", + Args: cobra.ExactArgs(2), + Short: "Fund the validator rewards pool with the specified amount", + Example: fmt.Sprintf( + "%s tx distribution fund-validator-rewards-pool cosmosvaloper1x20lytyf6zkcrv5edpkfkn8sz578qg5sqfyqnp 100uatom --from mykey", + version.AppName, + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + depositorAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + _, err = valCodec.StringToBytes(args[0]) + if err != nil { + return err + } + + amount, err := sdk.ParseCoinsNormalized(args[1]) + if err != nil { + return err + } + + msg := types.NewMsgDepositValidatorRewardsPool(depositorAddr, args[0], amount) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go new file mode 100644 index 00000000..a73fcb6f --- /dev/null +++ b/x/distribution/client/cli/tx_test.go @@ -0,0 +1,293 @@ +package cli_test + +import ( + "context" + "fmt" + "io" + "testing" + + sdkmath "cosmossdk.io/math" + abci "github.com/cometbft/cometbft/abci/types" + rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + "github.com/cosmos/cosmos-sdk/testutil" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/cosmos/cosmos-sdk/testutil/network" + sdk "github.com/cosmos/cosmos-sdk/types" + testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/gov" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/suite" + + "github.com/atomone-hub/atomone/x/distribution/client/cli" + distrtestutil "github.com/atomone-hub/atomone/x/distribution/testutil" +) + +type CLITestSuite struct { + suite.Suite + + kr keyring.Keyring + encCfg testutilmod.TestEncodingConfig + baseCtx client.Context + clientCtx client.Context +} + +func TestCLITestSuite(t *testing.T) { + suite.Run(t, new(CLITestSuite)) +} + +func (s *CLITestSuite) SetupSuite() { + s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModuleBasic{}, bank.AppModuleBasic{}) + s.kr = keyring.NewInMemory(s.encCfg.Codec) + s.baseCtx = client.Context{}. + WithKeyring(s.kr). + WithTxConfig(s.encCfg.TxConfig). + WithCodec(s.encCfg.Codec). + WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}). + WithAccountRetriever(client.MockAccountRetriever{}). + WithOutput(io.Discard). + WithChainID("test-chain") + + ctxGen := func() client.Context { + bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) + c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ + Value: bz, + }) + return s.baseCtx.WithClient(c) + } + s.clientCtx = ctxGen() + + cfg, err := network.DefaultConfigWithAppConfig(distrtestutil.AppConfig) + s.Require().NoError(err) + + genesisState := cfg.GenesisState + var mintData minttypes.GenesisState + s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) + + inflation := sdkmath.LegacyMustNewDecFromStr("1.0") + mintData.Minter.Inflation = inflation + mintData.Params.InflationMin = inflation + mintData.Params.InflationMax = inflation + + mintDataBz, err := cfg.Codec.MarshalJSON(&mintData) + s.Require().NoError(err) + genesisState[minttypes.ModuleName] = mintDataBz + cfg.GenesisState = genesisState +} + +func (s *CLITestSuite) TestTxWithdrawRewardsCmd() { + val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) + + testCases := []struct { + name string + valAddr fmt.Stringer + args []string + expectErrMsg string + }{ + { + "invalid validator address", + val[0].Address, + []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + "hrp does not match bech32 prefix", + }, + { + "valid transaction", + sdk.ValAddress(val[0].Address), + []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + "", + }, + { + "valid transaction (with commission)", + sdk.ValAddress(val[0].Address), + []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=true", cli.FlagCommission), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + "", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + args := append([]string{tc.valAddr.String()}, tc.args...) + + ctx := svrcmd.CreateExecuteContext(context.Background()) + cmd := cli.NewWithdrawRewardsCmd(address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos")) + cmd.SetContext(ctx) + cmd.SetArgs(args) + s.Require().NoError(client.SetCmdClientContextHandler(s.clientCtx, cmd)) + + out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args) + if tc.expectErrMsg != "" { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expectErrMsg) + } else { + s.Require().NoError(err) + msg := &sdk.TxResponse{} + s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), msg), out.String()) + } + }) + } +} + +func (s *CLITestSuite) TestTxWithdrawAllRewardsCmd() { + val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) + + testCases := []struct { + name string + args []string + expectErrMsg string + }{ + { + "invalid transaction (offline)", + []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagOffline), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + "cannot generate tx in offline mode", + }, + { + "valid transaction", + []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + "", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + cmd := cli.NewWithdrawAllRewardsCmd(address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos")) + + out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) + if tc.expectErrMsg != "" { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expectErrMsg) + } else { + s.Require().NoError(err) + msg := &sdk.TxResponse{} + s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), msg), out.String()) + } + }) + } +} + +func (s *CLITestSuite) TestTxSetWithdrawAddrCmd() { + val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) + + testCases := []struct { + name string + args []string + expectErr bool + respType proto.Message + }{ + { + "invalid withdraw address", + []string{ + "foo", + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + true, nil, + }, + { + "valid transaction", + []string{ + val[0].Address.String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + false, &sdk.TxResponse{}, + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + cmd := cli.NewSetWithdrawAddrCmd(address.NewBech32Codec("cosmos")) + + out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) + if tc.expectErr { + s.Require().Error(err) + } else { + s.Require().NoError(err) + s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) + } + }) + } +} + +func (s *CLITestSuite) TestTxFundCommunityPoolCmd() { + val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) + + testCases := []struct { + name string + args []string + expectErr bool + respType proto.Message + }{ + { + "invalid funding amount", + []string{ + "-43foocoin", + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + true, nil, + }, + { + "valid transaction", + []string{ + sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(5431))).String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), + }, + false, &sdk.TxResponse{}, + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + cmd := cli.NewFundCommunityPoolCmd(address.NewBech32Codec("cosmos")) + + out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) + if tc.expectErr { + s.Require().Error(err) + } else { + s.Require().NoError(err) + s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) + } + }) + } +} diff --git a/x/distribution/client/cli/util_test.go b/x/distribution/client/cli/util_test.go new file mode 100644 index 00000000..919b8818 --- /dev/null +++ b/x/distribution/client/cli/util_test.go @@ -0,0 +1,58 @@ +package cli + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/pflag" + "github.com/stretchr/testify/require" +) + +func Test_splitAndCall_NoMessages(t *testing.T) { + clientCtx := client.Context{} + + err := newSplitAndApply(nil, clientCtx, nil, nil, 10) + require.NoError(t, err, "") +} + +func Test_splitAndCall_Splitting(t *testing.T) { + clientCtx := client.Context{} + + addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + + // Add five messages + msgs := []sdk.Msg{ + testdata.NewTestMsg(addr), + testdata.NewTestMsg(addr), + testdata.NewTestMsg(addr), + testdata.NewTestMsg(addr), + testdata.NewTestMsg(addr), + } + + // Keep track of number of calls + const chunkSize = 2 + + callCount := 0 + err := newSplitAndApply( + func(clientCtx client.Context, fs *pflag.FlagSet, msgs ...sdk.Msg) error { + callCount++ + + require.NotNil(t, clientCtx) + require.NotNil(t, msgs) + + if callCount < 3 { + require.Equal(t, len(msgs), 2) + } else { + require.Equal(t, len(msgs), 1) + } + + return nil + }, + clientCtx, nil, msgs, chunkSize) + + require.NoError(t, err, "") + require.Equal(t, 3, callCount) +} diff --git a/x/distribution/client/common/common.go b/x/distribution/client/common/common.go new file mode 100644 index 00000000..bdd81746 --- /dev/null +++ b/x/distribution/client/common/common.go @@ -0,0 +1,33 @@ +package common + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// QueryDelegationRewards queries a delegation rewards between a delegator and a +// validator. +func QueryDelegationRewards(clientCtx client.Context, delAddr, valAddr string) ([]byte, int64, error) { + delegatorAddr, err := sdk.AccAddressFromBech32(delAddr) + if err != nil { + return nil, 0, err + } + + validatorAddr, err := sdk.ValAddressFromBech32(valAddr) + if err != nil { + return nil, 0, err + } + + params := types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr) + bz, err := clientCtx.LegacyAmino.MarshalJSON(params) + if err != nil { + return nil, 0, fmt.Errorf("failed to marshal params: %w", err) + } + + route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryDelegationRewards) + return clientCtx.QueryWithData(route, bz) +} diff --git a/x/distribution/client/common/common_test.go b/x/distribution/client/common/common_test.go new file mode 100644 index 00000000..de4b1161 --- /dev/null +++ b/x/distribution/client/common/common_test.go @@ -0,0 +1,37 @@ +package common + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec/legacy" + "github.com/stretchr/testify/require" +) + +func TestQueryDelegationRewardsAddrValidation(t *testing.T) { + clientCtx := client.Context{}.WithLegacyAmino(legacy.Cdc) + + type args struct { + delAddr string + valAddr string + } + + tests := []struct { + name string + args args + want []byte + wantErr bool + }{ + {"invalid delegator address", args{"invalid", ""}, nil, true}, + {"empty delegator address", args{"", ""}, nil, true}, + {"invalid validator address", args{"cosmos1zxcsu7l5qxs53lvp0fqgd09a9r2g6kqrk2cdpa", "invalid"}, nil, true}, + {"empty validator address", args{"cosmos1zxcsu7l5qxs53lvp0fqgd09a9r2g6kqrk2cdpa", ""}, nil, true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, _, err := QueryDelegationRewards(clientCtx, tt.args.delAddr, tt.args.valAddr) + require.True(t, err != nil, tt.wantErr) + }) + } +} diff --git a/x/distribution/doc.go b/x/distribution/doc.go new file mode 100644 index 00000000..8b9966c0 --- /dev/null +++ b/x/distribution/doc.go @@ -0,0 +1,6 @@ +/* +Package distribution implements a Cosmos SDK module, that provides an implementation +of the F1 fee distribution algorithm. It handles reward tracking, allocation, and +distribution. Please refer to the specification under /spec for further information. +*/ +package distribution diff --git a/x/distribution/keeper/abci.go b/x/distribution/keeper/abci.go new file mode 100644 index 00000000..e814592c --- /dev/null +++ b/x/distribution/keeper/abci.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +// BeginBlocker sets the proposer for determining distribution during endblock +// and distribute rewards for the previous block. +func (k Keeper) BeginBlocker(ctx context.Context) error { + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) + c := sdk.UnwrapSDKContext(ctx) + + // determine the total power signing the block + var previousTotalPower int64 + for _, voteInfo := range c.VoteInfos() { + previousTotalPower += voteInfo.Validator.Power + } + + // TODO this is Tendermint-dependent + // ref https://github.com/cosmos/cosmos-sdk/issues/3095 + if c.BlockHeight() > 1 { + if err := k.AllocateTokens(ctx, previousTotalPower, c.VoteInfos()); err != nil { + return err + } + } + + // record the proposer for when we payout on the next block + consAddr := sdk.ConsAddress(c.BlockHeader().ProposerAddress) + return k.SetPreviousProposerConsAddr(ctx, consAddr) +} diff --git a/x/distribution/keeper/alias_functions.go b/x/distribution/keeper/alias_functions.go new file mode 100644 index 00000000..69265e84 --- /dev/null +++ b/x/distribution/keeper/alias_functions.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// GetValidatorOutstandingRewardsCoins get outstanding rewards +func (k Keeper) GetValidatorOutstandingRewardsCoins(ctx context.Context, val sdk.ValAddress) (sdk.DecCoins, error) { + rewards, err := k.GetValidatorOutstandingRewards(ctx, val) + if err != nil { + return nil, err + } + + return rewards.Rewards, nil +} + +// GetDistributionAccount returns the distribution ModuleAccount +func (k Keeper) GetDistributionAccount(ctx context.Context) sdk.ModuleAccountI { + return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) +} diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go new file mode 100644 index 00000000..198ac534 --- /dev/null +++ b/x/distribution/keeper/allocation.go @@ -0,0 +1,144 @@ +package keeper + +import ( + "context" + + abci "github.com/cometbft/cometbft/abci/types" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// AllocateTokens performs reward and fee distribution to all validators based +// on the F1 fee distribution specification. +func (k Keeper) AllocateTokens(ctx context.Context, totalPreviousPower int64, bondedVotes []abci.VoteInfo) error { + // fetch and clear the collected fees for distribution, since this is + // called in BeginBlock, collected fees will be from the previous block + // (and distributed to the previous proposer) + feeCollector := k.authKeeper.GetModuleAccount(ctx, k.feeCollectorName) + feesCollectedInt := k.bankKeeper.GetAllBalances(ctx, feeCollector.GetAddress()) + feesCollected := sdk.NewDecCoinsFromCoins(feesCollectedInt...) + + // transfer collected fees to the distribution module account + err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, k.feeCollectorName, types.ModuleName, feesCollectedInt) + if err != nil { + return err + } + + // temporary workaround to keep CanWithdrawInvariant happy + // general discussions here: https://github.com/cosmos/cosmos-sdk/issues/2906#issuecomment-441867634 + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + + if totalPreviousPower == 0 { + feePool.CommunityPool = feePool.CommunityPool.Add(feesCollected...) + return k.FeePool.Set(ctx, feePool) + } + + // calculate fraction allocated to validators + remaining := feesCollected + communityTax, err := k.GetCommunityTax(ctx) + if err != nil { + return err + } + + voteMultiplier := math.LegacyOneDec().Sub(communityTax) + feeMultiplier := feesCollected.MulDecTruncate(voteMultiplier) + + // allocate tokens proportionally to voting power + // + // TODO: Consider parallelizing later + // + // Ref: https://github.com/cosmos/cosmos-sdk/pull/3099#discussion_r246276376 + for _, vote := range bondedVotes { + validator, err := k.stakingKeeper.ValidatorByConsAddr(ctx, vote.Validator.Address) + if err != nil { + return err + } + + // TODO: Consider micro-slashing for missing votes. + // + // Ref: https://github.com/cosmos/cosmos-sdk/issues/2525#issuecomment-430838701 + powerFraction := math.LegacyNewDec(vote.Validator.Power).QuoTruncate(math.LegacyNewDec(totalPreviousPower)) + reward := feeMultiplier.MulDecTruncate(powerFraction) + + err = k.AllocateTokensToValidator(ctx, validator, reward) + if err != nil { + return err + } + + remaining = remaining.Sub(reward) + } + + // allocate community funding + feePool.CommunityPool = feePool.CommunityPool.Add(remaining...) + return k.FeePool.Set(ctx, feePool) +} + +// AllocateTokensToValidator allocate tokens to a particular validator, +// splitting according to commission. +func (k Keeper) AllocateTokensToValidator(ctx context.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) error { + // split tokens between validator and delegators according to commission + commission := tokens.MulDec(val.GetCommission()) + shared := tokens.Sub(commission) + + valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + return err + } + + // update current commission + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCommission, + sdk.NewAttribute(sdk.AttributeKeyAmount, commission.String()), + sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator()), + ), + ) + currentCommission, err := k.GetValidatorAccumulatedCommission(ctx, valBz) + if err != nil { + return err + } + + currentCommission.Commission = currentCommission.Commission.Add(commission...) + err = k.SetValidatorAccumulatedCommission(ctx, valBz, currentCommission) + if err != nil { + return err + } + + // update current rewards + currentRewards, err := k.GetValidatorCurrentRewards(ctx, valBz) + if err != nil { + return err + } + + currentRewards.Rewards = currentRewards.Rewards.Add(shared...) + err = k.SetValidatorCurrentRewards(ctx, valBz, currentRewards) + if err != nil { + return err + } + + // update outstanding rewards + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeRewards, + sdk.NewAttribute(sdk.AttributeKeyAmount, tokens.String()), + sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator()), + ), + ) + + outstanding, err := k.GetValidatorOutstandingRewards(ctx, valBz) + if err != nil { + return err + } + + outstanding.Rewards = outstanding.Rewards.Add(tokens...) + return k.SetValidatorOutstandingRewards(ctx, valBz, outstanding) +} diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go new file mode 100644 index 00000000..5ebc1a0b --- /dev/null +++ b/x/distribution/keeper/allocation_test.go @@ -0,0 +1,340 @@ +package keeper_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + abci "github.com/cometbft/cometbft/abci/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution" + "github.com/atomone-hub/atomone/x/distribution/keeper" + distrtestutil "github.com/atomone-hub/atomone/x/distribution/testutil" + disttypes "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestAllocateTokensToValidatorWithCommission(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + valCodec := address.NewBech32Codec("cosmosvaloper") + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(valCodec).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // create validator with 50% commission + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk0)).Return(val, nil).AnyTimes() + + // allocate tokens + tokens := sdk.DecCoins{ + {Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(10)}, + } + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // check commission + expected := sdk.DecCoins{ + {Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(5)}, + } + + valBz, err := valCodec.StringToBytes(val.GetOperator()) + require.NoError(t, err) + + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valBz) + require.NoError(t, err) + require.Equal(t, expected, valCommission.Commission) + + // check current rewards + currentRewards, err := distrKeeper.GetValidatorCurrentRewards(ctx, valBz) + require.NoError(t, err) + require.Equal(t, expected, currentRewards.Rewards) +} + +func TestAllocateTokensToManyValidators(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + feeCollectorAcc := authtypes.NewEmptyModuleAccount("fee_collector") + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), "fee_collector").Return(feeCollectorAcc) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec("cosmosvaloper")).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool & set params + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + + // create validator with 50% commission + valAddr0 := sdk.ValAddress(valConsAddr0) + val0, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + val0.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk0)).Return(val0, nil).AnyTimes() + + // create second validator with 0% commission + valAddr1 := sdk.ValAddress(valConsAddr1) + val1, err := distrtestutil.CreateValidator(valConsPk1, math.NewInt(100)) + require.NoError(t, err) + val1.Commission = stakingtypes.NewCommission(math.LegacyNewDec(0), math.LegacyNewDec(0), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk1)).Return(val1, nil).AnyTimes() + + abciValA := abci.Validator{ + Address: valConsPk0.Address(), + Power: 100, + } + abciValB := abci.Validator{ + Address: valConsPk1.Address(), + Power: 100, + } + + // assert initial state: zero outstanding rewards, zero community pool, zero commission, zero current rewards + val0OutstandingRewards, err := distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0OutstandingRewards.Rewards.IsZero()) + + val1OutstandingRewards, err := distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1OutstandingRewards.Rewards.IsZero()) + + feePool, err := distrKeeper.FeePool.Get(ctx) + require.NoError(t, err) + require.True(t, feePool.CommunityPool.IsZero()) + + val0Commission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0Commission.Commission.IsZero()) + + val1Commission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1Commission.Commission.IsZero()) + + val0CurrentRewards, err := distrKeeper.GetValidatorCurrentRewards(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0CurrentRewards.Rewards.IsZero()) + + val1CurrentRewards, err := distrKeeper.GetValidatorCurrentRewards(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1CurrentRewards.Rewards.IsZero()) + + // allocate tokens as if both had voted and second was proposer + fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) + bankKeeper.EXPECT().GetAllBalances(gomock.Any(), feeCollectorAcc.GetAddress()).Return(fees) + bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), "fee_collector", disttypes.ModuleName, fees) + + votes := []abci.VoteInfo{ + { + Validator: abciValA, + }, + { + Validator: abciValB, + }, + } + require.NoError(t, distrKeeper.AllocateTokens(ctx, 200, votes)) + + // 98 outstanding rewards (100 less 2 to community pool) + val0OutstandingRewards, err = distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr0) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecWithPrec(490, 1)}}, val0OutstandingRewards.Rewards) + + val1OutstandingRewards, err = distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr1) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecWithPrec(490, 1)}}, val1OutstandingRewards.Rewards) + + // 2 community pool coins + feePool, err = distrKeeper.FeePool.Get(ctx) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(2)}}, feePool.CommunityPool) + + // 50% commission for first proposer, (0.5 * 98%) * 100 / 2 = 23.25 + val0Commission, err = distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr0) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecWithPrec(2450, 2)}}, val0Commission.Commission) + + // zero commission for second proposer + val1Commission, err = distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1Commission.Commission.IsZero()) + + // just staking.proportional for first proposer less commission = (0.5 * 98%) * 100 / 2 = 24.50 + val0CurrentRewards, err = distrKeeper.GetValidatorCurrentRewards(ctx, valAddr0) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecWithPrec(2450, 2)}}, val0CurrentRewards.Rewards) + + // proposer reward + staking.proportional for second proposer = (0.5 * (98%)) * 100 = 49 + val1CurrentRewards, err = distrKeeper.GetValidatorCurrentRewards(ctx, valAddr1) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecWithPrec(490, 1)}}, val1CurrentRewards.Rewards) +} + +func TestAllocateTokensTruncation(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + feeCollectorAcc := authtypes.NewEmptyModuleAccount("fee_collector") + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), "fee_collector").Return(feeCollectorAcc) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec("cosmosvaloper")).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 10% commission + valAddr0 := sdk.ValAddress(valConsAddr0) + val0, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + val0.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk0)).Return(val0, nil).AnyTimes() + + // create second validator with 10% commission + valAddr1 := sdk.ValAddress(valConsAddr1) + val1, err := distrtestutil.CreateValidator(valConsPk1, math.NewInt(100)) + require.NoError(t, err) + val1.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk1)).Return(val1, nil).AnyTimes() + + // create third validator with 10% commission + valAddr2 := sdk.ValAddress(valConsAddr2) + val2, err := stakingtypes.NewValidator(sdk.ValAddress(valConsAddr2).String(), valConsPk1, stakingtypes.Description{}) + require.NoError(t, err) + val2.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDec(0)) + stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk2)).Return(val2, nil).AnyTimes() + + abciValA := abci.Validator{ + Address: valConsPk0.Address(), + Power: 11, + } + abciValB := abci.Validator{ + Address: valConsPk1.Address(), + Power: 10, + } + abciValC := abci.Validator{ + Address: valConsPk2.Address(), + Power: 10, + } + + // assert initial state: zero outstanding rewards, zero community pool, zero commission, zero current rewards + val0OutstandingRewards, err := distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0OutstandingRewards.Rewards.IsZero()) + + val1OutstandingRewards, err := distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1OutstandingRewards.Rewards.IsZero()) + + feePool, err := distrKeeper.FeePool.Get(ctx) + require.NoError(t, err) + require.True(t, feePool.CommunityPool.IsZero()) + + val0Commission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0Commission.Commission.IsZero()) + + val1Commission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1Commission.Commission.IsZero()) + + val0CurrentRewards, err := distrKeeper.GetValidatorCurrentRewards(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0CurrentRewards.Rewards.IsZero()) + + val1CurrentRewards, err := distrKeeper.GetValidatorCurrentRewards(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1CurrentRewards.Rewards.IsZero()) + + // allocate tokens as if both had voted and second was proposer + fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(634195840))) + bankKeeper.EXPECT().GetAllBalances(gomock.Any(), feeCollectorAcc.GetAddress()).Return(fees) + bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), "fee_collector", disttypes.ModuleName, fees) + + votes := []abci.VoteInfo{ + { + Validator: abciValA, + }, + { + Validator: abciValB, + }, + { + Validator: abciValC, + }, + } + require.NoError(t, distrKeeper.AllocateTokens(ctx, 31, votes)) + + val0OutstandingRewards, err = distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr0) + require.NoError(t, err) + require.True(t, val0OutstandingRewards.Rewards.IsValid()) + + val1OutstandingRewards, err = distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr1) + require.NoError(t, err) + require.True(t, val1OutstandingRewards.Rewards.IsValid()) + + val2OutstandingRewards, err := distrKeeper.GetValidatorOutstandingRewards(ctx, valAddr2) + require.NoError(t, err) + require.True(t, val2OutstandingRewards.Rewards.IsValid()) +} diff --git a/x/distribution/keeper/common_test.go b/x/distribution/keeper/common_test.go new file mode 100644 index 00000000..8bd7a311 --- /dev/null +++ b/x/distribution/keeper/common_test.go @@ -0,0 +1,23 @@ +package keeper_test + +import ( + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +var ( + PKS = simtestutil.CreateTestPubKeys(5) + + valConsPk0 = PKS[0] + valConsPk1 = PKS[1] + valConsPk2 = PKS[2] + + valConsAddr0 = sdk.ConsAddress(valConsPk0.Address()) + valConsAddr1 = sdk.ConsAddress(valConsPk1.Address()) + valConsAddr2 = sdk.ConsAddress(valConsPk2.Address()) + + distrAcc = authtypes.NewEmptyModuleAccount(types.ModuleName) +) diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go new file mode 100644 index 00000000..3e2e91d0 --- /dev/null +++ b/x/distribution/keeper/delegation.go @@ -0,0 +1,321 @@ +package keeper + +import ( + "context" + "fmt" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// initializeDelegation initializes starting info for a new delegation +func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) error { + // period has already been incremented - we want to store the period ended by this delegation action + valCurrentRewards, err := k.GetValidatorCurrentRewards(ctx, val) + if err != nil { + return err + } + previousPeriod := valCurrentRewards.Period - 1 + + // increment reference count for the period we're going to track + err = k.incrementReferenceCount(ctx, val, previousPeriod) + if err != nil { + return err + } + + validator, err := k.stakingKeeper.Validator(ctx, val) + if err != nil { + return err + } + + delegation, err := k.stakingKeeper.Delegation(ctx, del, val) + if err != nil { + return err + } + + // calculate delegation stake in tokens + // we don't store directly, so multiply delegation shares * (tokens per share) + // note: necessary to truncate so we don't allow withdrawing more rewards than owed + stake := validator.TokensFromSharesTruncated(delegation.GetShares()) + sdkCtx := sdk.UnwrapSDKContext(ctx) + return k.SetDelegatorStartingInfo(ctx, val, del, types.NewDelegatorStartingInfo(previousPeriod, stake, uint64(sdkCtx.BlockHeight()))) +} + +// calculateDelegationRewardsBetween calculates the rewards accrued by a delegation between two periods +func (k Keeper) calculateDelegationRewardsBetween(ctx context.Context, val stakingtypes.ValidatorI, + startingPeriod, endingPeriod uint64, stake math.LegacyDec, +) (sdk.DecCoins, error) { + // sanity check + if startingPeriod > endingPeriod { + panic("startingPeriod cannot be greater than endingPeriod") + } + + // sanity check + if stake.IsNegative() { + panic("stake should not be negative") + } + + valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + panic(err) + } + + // return staking * (ending - starting) + starting, err := k.GetValidatorHistoricalRewards(ctx, valBz, startingPeriod) + if err != nil { + return sdk.DecCoins{}, err + } + + ending, err := k.GetValidatorHistoricalRewards(ctx, valBz, endingPeriod) + if err != nil { + return sdk.DecCoins{}, err + } + + difference := ending.CumulativeRewardRatio.Sub(starting.CumulativeRewardRatio) + if difference.IsAnyNegative() { + panic("negative rewards should not be possible") + } + // note: necessary to truncate so we don't allow withdrawing more rewards than owed + rewards := difference.MulDecTruncate(stake) + return rewards, nil +} + +// CalculateDelegationRewards calculates the total rewards accrued by a delegation +func (k Keeper) CalculateDelegationRewards(ctx context.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins, err error) { + addrCodec := k.authKeeper.AddressCodec() + delAddr, err := addrCodec.StringToBytes(del.GetDelegatorAddr()) + if err != nil { + return sdk.DecCoins{}, err + } + + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(del.GetValidatorAddr()) + if err != nil { + return sdk.DecCoins{}, err + } + + // fetch starting info for delegation + startingInfo, err := k.GetDelegatorStartingInfo(ctx, valAddr, delAddr) + if err != nil { + return sdk.DecCoins{}, err + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + if startingInfo.Height == uint64(sdkCtx.BlockHeight()) { + // started this height, no rewards yet + return sdk.DecCoins{}, nil + } + + startingPeriod := startingInfo.PreviousPeriod + stake := startingInfo.Stake + + // Iterate through slashes and withdraw with calculated staking for + // distribution periods. These period offsets are dependent on *when* slashes + // happen - namely, in BeginBlock, after rewards are allocated... + // Slashes which happened in the first block would have been before this + // delegation existed, UNLESS they were slashes of a redelegation to this + // validator which was itself slashed (from a fault committed by the + // redelegation source validator) earlier in the same BeginBlock. + startingHeight := startingInfo.Height + // Slashes this block happened after reward allocation, but we have to account + // for them for the stake sanity check below. + endingHeight := uint64(sdkCtx.BlockHeight()) + if endingHeight > startingHeight { + k.IterateValidatorSlashEventsBetween(ctx, valAddr, startingHeight, endingHeight, + func(height uint64, event types.ValidatorSlashEvent) (stop bool) { + endingPeriod := event.ValidatorPeriod + if endingPeriod > startingPeriod { + delRewards, err := k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake) + if err != nil { + panic(err) + } + rewards = rewards.Add(delRewards...) + + // Note: It is necessary to truncate so we don't allow withdrawing + // more rewards than owed. + stake = stake.MulTruncate(math.LegacyOneDec().Sub(event.Fraction)) + startingPeriod = endingPeriod + } + return false + }, + ) + } + + // A total stake sanity check; Recalculated final stake should be less than or + // equal to current stake here. We cannot use Equals because stake is truncated + // when multiplied by slash fractions (see above). We could only use equals if + // we had arbitrary-precision rationals. + currentStake := val.TokensFromShares(del.GetShares()) + + if stake.GT(currentStake) { + // AccountI for rounding inconsistencies between: + // + // currentStake: calculated as in staking with a single computation + // stake: calculated as an accumulation of stake + // calculations across validator's distribution periods + // + // These inconsistencies are due to differing order of operations which + // will inevitably have different accumulated rounding and may lead to + // the smallest decimal place being one greater in stake than + // currentStake. When we calculated slashing by period, even if we + // round down for each slash fraction, it's possible due to how much is + // being rounded that we slash less when slashing by period instead of + // for when we slash without periods. In other words, the single slash, + // and the slashing by period could both be rounding down but the + // slashing by period is simply rounding down less, thus making stake > + // currentStake + // + // A small amount of this error is tolerated and corrected for, + // however any greater amount should be considered a breach in expected + // behavior. + marginOfErr := math.LegacySmallestDec().MulInt64(3) + if stake.LTE(currentStake.Add(marginOfErr)) { + stake = currentStake + } else { + panic(fmt.Sprintf("calculated final stake for delegator %s greater than current stake"+ + "\n\tfinal stake:\t%s"+ + "\n\tcurrent stake:\t%s", + del.GetDelegatorAddr(), stake, currentStake)) + } + } + + // calculate rewards for final period + delRewards, err := k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake) + if err != nil { + return sdk.DecCoins{}, err + } + + rewards = rewards.Add(delRewards...) + return rewards, nil +} + +func (k Keeper) withdrawDelegationRewards(ctx context.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI) (sdk.Coins, error) { + addrCodec := k.authKeeper.AddressCodec() + delAddr, err := addrCodec.StringToBytes(del.GetDelegatorAddr()) + if err != nil { + return nil, err + } + + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(del.GetValidatorAddr()) + if err != nil { + return nil, err + } + + // check existence of delegator starting info + hasInfo, err := k.HasDelegatorStartingInfo(ctx, sdk.ValAddress(valAddr), sdk.AccAddress(delAddr)) + if err != nil { + return nil, err + } + + if !hasInfo { + return nil, types.ErrEmptyDelegationDistInfo + } + + // end current period and calculate rewards + endingPeriod, err := k.IncrementValidatorPeriod(ctx, val) + if err != nil { + return nil, err + } + + rewardsRaw, err := k.CalculateDelegationRewards(ctx, val, del, endingPeriod) + if err != nil { + return nil, err + } + + outstanding, err := k.GetValidatorOutstandingRewardsCoins(ctx, sdk.ValAddress(valAddr)) + if err != nil { + return nil, err + } + + // defensive edge case may happen on the very final digits + // of the decCoins due to operation order of the distribution mechanism. + rewards := rewardsRaw.Intersect(outstanding) + if !rewards.Equal(rewardsRaw) { + logger := k.Logger(ctx) + logger.Info( + "rounding error withdrawing rewards from validator", + "delegator", del.GetDelegatorAddr(), + "validator", val.GetOperator(), + "got", rewards.String(), + "expected", rewardsRaw.String(), + ) + } + + // truncate reward dec coins, return remainder to community pool + finalRewards, remainder := rewards.TruncateDecimal() + + // add coins to user account + if !finalRewards.IsZero() { + withdrawAddr, err := k.GetDelegatorWithdrawAddr(ctx, delAddr) + if err != nil { + return nil, err + } + + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, finalRewards) + if err != nil { + return nil, err + } + } + + // update the outstanding rewards and the community pool only if the + // transaction was successful + err = k.SetValidatorOutstandingRewards(ctx, sdk.ValAddress(valAddr), types.ValidatorOutstandingRewards{Rewards: outstanding.Sub(rewards)}) + if err != nil { + return nil, err + } + + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return nil, err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(remainder...) + err = k.FeePool.Set(ctx, feePool) + if err != nil { + return nil, err + } + + // decrement reference count of starting period + startingInfo, err := k.GetDelegatorStartingInfo(ctx, sdk.ValAddress(valAddr), sdk.AccAddress(delAddr)) + if err != nil { + return nil, err + } + + startingPeriod := startingInfo.PreviousPeriod + err = k.decrementReferenceCount(ctx, sdk.ValAddress(valAddr), startingPeriod) + if err != nil { + return nil, err + } + + // remove delegator starting info + err = k.DeleteDelegatorStartingInfo(ctx, sdk.ValAddress(valAddr), sdk.AccAddress(delAddr)) + if err != nil { + return nil, err + } + + if finalRewards.IsZero() { + baseDenom, _ := sdk.GetBaseDenom() + if baseDenom == "" { + baseDenom = sdk.DefaultBondDenom + } + + // Note, we do not call the NewCoins constructor as we do not want the zero + // coin removed. + finalRewards = sdk.Coins{sdk.NewCoin(baseDenom, math.ZeroInt())} + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeWithdrawRewards, + sdk.NewAttribute(sdk.AttributeKeyAmount, finalRewards.String()), + sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator()), + sdk.NewAttribute(types.AttributeKeyDelegator, del.GetDelegatorAddr()), + ), + ) + + return finalRewards, nil +} diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go new file mode 100644 index 00000000..a14217d8 --- /dev/null +++ b/x/distribution/keeper/delegation_test.go @@ -0,0 +1,1059 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution" + "github.com/atomone-hub/atomone/x/distribution/keeper" + distrtestutil "github.com/atomone-hub/atomone/x/distribution/testutil" + disttypes "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestCalculateRewardsBasic(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(1000)) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // delegation mock + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(3) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // historical count should be 2 (once for validator init, once for delegation init) + require.Equal(t, uint64(2), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // historical count should be 2 still + require.Equal(t, uint64(2), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // calculate delegation rewards + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be zero + require.True(t, rewards.IsZero()) + + // allocate some rewards + initial := int64(10) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial)}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be half the tokens + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 2)}}, rewards) + + // commission should be the other half + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 2)}}, valCommission.Commission) +} + +func TestCalculateRewardsAfterSlash(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + valPower := int64(100) + stake := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction) + val, err := distrtestutil.CreateValidator(valConsPk0, stake) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + + // set mock calls + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(4) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be zero + require.True(t, rewards.IsZero()) + + // start out block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // slash the validator by 50% (simulated with manual calls; we assume the validator is bonded) + slashedTokens := distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + require.True(t, slashedTokens.IsPositive(), "expected positive slashed tokens, got: %s", slashedTokens) + + // increase block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // allocate some rewards + initial := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial)}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be half the tokens + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial.QuoRaw(2))}}, rewards) + + // commission should be the other half + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial.QuoRaw(2))}}, + valCommission.Commission) +} + +func TestCalculateRewardsAfterManySlashes(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + valPower := int64(100) + stake := sdk.TokensFromConsensusPower(valPower, sdk.DefaultPowerReduction) + val, err := distrtestutil.CreateValidator(valConsPk0, stake) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // delegation mocks + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(4) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be zero + require.True(t, rewards.IsZero()) + + // start out block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // slash the validator by 50% (simulated with manual calls; we assume the validator is bonded) + slashedTokens := distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + require.True(t, slashedTokens.IsPositive(), "expected positive slashed tokens, got: %s", slashedTokens) + + // expect a call for the next slash with the updated validator + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(1) + + // increase block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // allocate some rewards + initial := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial)}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // slash the validator by 50% again + slashedTokens = distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower/2, + math.LegacyNewDecWithPrec(2, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + require.True(t, slashedTokens.IsPositive(), "expected positive slashed tokens, got: %s", slashedTokens) + + // increase block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be half the tokens + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial)}}, rewards) + + // commission should be the other half + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDecFromInt(initial)}}, + valCommission.Commission) +} + +func TestCalculateRewardsMultiDelegator(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr0 := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + del0 := stakingtypes.NewDelegation(addr0.String(), valAddr.String(), val.DelegatorShares) + + // set mock calls + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(4) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr0, valAddr).Return(del0, nil).Times(1) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr0, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + initial := int64(20) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial)}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // second delegation + addr1 := sdk.AccAddress(valConsAddr1) + _, del1, err := distrtestutil.Delegate(ctx, distrKeeper, addr1, &val, math.NewInt(100), nil, stakingKeeper) + require.NoError(t, err) + + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr1, valAddr).Return(del1, nil) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(1) + + // call necessary hooks to update a delegation + err = distrKeeper.Hooks().AfterDelegationModified(ctx, addr1, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards for del1 + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del0, endingPeriod) + require.NoError(t, err) + + // rewards for del0 should be 3/4 initial + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial * 3 / 4)}}, rewards) + + // calculate delegation rewards for del2 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del1, endingPeriod) + require.NoError(t, err) + + // rewards for del2 should be 1/4 initial + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial * 1 / 4)}}, rewards) + + // commission should be equal to initial (50% twice) + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial)}}, valCommission.Commission) +} + +func TestWithdrawDelegationRewardsBasic(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // delegation mock + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(5) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil).Times(3) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + initial := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction) + tokens := sdk.DecCoins{sdk.NewDecCoin(sdk.DefaultBondDenom, initial)} + + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // historical count should be 2 (initial + latest for delegation) + require.Equal(t, uint64(2), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // withdraw rewards (the bank keeper should be called with the right amount of tokens to transfer) + expRewards := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, initial.QuoRaw(2))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expRewards) + _, err = distrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddr), valAddr) + require.Nil(t, err) + + // historical count should still be 2 (added one record, cleared one) + require.Equal(t, uint64(2), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // withdraw commission (the bank keeper should be called with the right amount of tokens to transfer) + expCommission := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, initial.QuoRaw(2))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expCommission) + _, err = distrKeeper.WithdrawValidatorCommission(ctx, valAddr) + require.Nil(t, err) +} + +func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // delegation mock + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(5) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be zero + require.True(t, rewards.IsZero()) + + // start out block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // allocate some rewards + initial := math.LegacyNewDecFromInt(sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + valPower := int64(100) + // slash the validator by 50% (simulated with manual calls; we assume the validator is bonded) + distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + + // slash the validator by 50% again + // stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower/2, math.LegacyNewDecWithPrec(5, 1)) + distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower/2, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + + // increase block height + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards should be half the tokens + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial}}, rewards) + + // commission should be the other half + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial}}, valCommission.Commission) +} + +func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + valPower := int64(100) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, sdk.TokensFromConsensusPower(valPower, sdk.DefaultPowerReduction)) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // validator and delegation mocks + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(3) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(2) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + initial := math.LegacyNewDecFromInt(sdk.TokensFromConsensusPower(30, sdk.DefaultPowerReduction)) + tokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial}} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // slash the validator + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // update validator mock + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(1) + + // second delegation + _, del2, err := distrtestutil.Delegate( + ctx, + distrKeeper, + sdk.AccAddress(valConsAddr1), + &val, + sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + nil, + stakingKeeper, + ) + require.NoError(t, err) + + // new delegation mock and update validator mock + stakingKeeper.EXPECT().Delegation(gomock.Any(), sdk.AccAddress(valConsAddr1), valAddr).Return(del2, nil) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(1) + + // call necessary hooks to update a delegation + err = distrKeeper.Hooks().AfterDelegationModified(ctx, sdk.AccAddress(valConsAddr1), valAddr) + require.NoError(t, err) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // slash the validator again + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + distrtestutil.SlashValidator( + ctx, + valConsAddr0, + ctx.BlockHeight(), + valPower, + math.LegacyNewDecWithPrec(5, 1), + &val, + &distrKeeper, + stakingKeeper, + ) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards for del1 + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards for del1 should be 2/3 initial (half initial first period, 1/6 initial second period) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial.QuoInt64(2).Add(initial.QuoInt64(6))}}, rewards) + + // calculate delegation rewards for del2 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del2, endingPeriod) + require.NoError(t, err) + + // rewards for del2 should be initial / 3 + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial.QuoInt64(3)}}, rewards) + + // commission should be equal to initial (twice 50% commission, unaffected by slashing) + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: initial}}, valCommission.Commission) +} + +func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)) + + // validator and delegation mocks + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(3) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil).Times(5) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(2) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + initial := int64(20) + tokens := sdk.DecCoins{sdk.NewDecCoin(sdk.DefaultBondDenom, math.NewInt(initial))} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // historical count should be 2 (validator init, delegation init) + require.Equal(t, uint64(2), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // second delegation + _, del2, err := distrtestutil.Delegate( + ctx, + distrKeeper, + sdk.AccAddress(valConsAddr1), + &val, + math.NewInt(100), + nil, + stakingKeeper, + ) + require.NoError(t, err) + + // new delegation mock and update validator mock + stakingKeeper.EXPECT().Delegation(gomock.Any(), sdk.AccAddress(valConsAddr1), valAddr).Return(del2, nil).Times(3) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(6) + + // call necessary hooks to update a delegation + err = distrKeeper.Hooks().AfterDelegationModified(ctx, sdk.AccAddress(valConsAddr1), valAddr) + require.NoError(t, err) + + // historical count should be 3 (second delegation init) + require.Equal(t, uint64(3), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // first delegator withdraws + expRewards := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(initial*3/4))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expRewards) + _, err = distrKeeper.WithdrawDelegationRewards(ctx, addr, valAddr) + require.NoError(t, err) + + // second delegator withdraws + expRewards = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(initial*1/4))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, sdk.AccAddress(valConsAddr1), expRewards) + _, err = distrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valConsAddr1), valAddr) + require.NoError(t, err) + + // historical count should be 3 (validator init + two delegations) + require.Equal(t, uint64(3), distrKeeper.GetValidatorHistoricalReferenceCount(ctx)) + + // validator withdraws commission + expCommission := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(initial))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expCommission) + _, err = distrKeeper.WithdrawValidatorCommission(ctx, valAddr) + require.NoError(t, err) + + // end period + endingPeriod, _ := distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards for del1 + rewards, err := distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards for del1 should be zero + require.True(t, rewards.IsZero()) + + // calculate delegation rewards for del2 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del2, endingPeriod) + require.NoError(t, err) + + // rewards for del2 should be zero + require.True(t, rewards.IsZero()) + + // commission should be zero + valCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.True(t, valCommission.Commission.IsZero()) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // first delegator withdraws again + expCommission = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(initial*1/4))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expCommission) + _, err = distrKeeper.WithdrawDelegationRewards(ctx, addr, valAddr) + require.NoError(t, err) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards for del1 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards for del1 should be zero + require.True(t, rewards.IsZero()) + + // calculate delegation rewards for del2 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del2, endingPeriod) + require.NoError(t, err) + + // rewards for del2 should be 1/4 initial + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 4)}}, rewards) + + // commission should be half initial + valCommission, err = distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 2)}}, valCommission.Commission) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // withdraw commission + expCommission = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(initial))} + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, disttypes.ModuleName, addr, expCommission) + _, err = distrKeeper.WithdrawValidatorCommission(ctx, valAddr) + require.NoError(t, err) + + // end period + endingPeriod, _ = distrKeeper.IncrementValidatorPeriod(ctx, val) + + // calculate delegation rewards for del1 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) + require.NoError(t, err) + + // rewards for del1 should be 1/4 initial + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 4)}}, rewards) + + // calculate delegation rewards for del2 + rewards, err = distrKeeper.CalculateDelegationRewards(ctx, val, del2, endingPeriod) + require.NoError(t, err) + + // rewards for del2 should be 1/2 initial + require.Equal(t, sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initial / 2)}}, rewards) + + // commission should be zero + valCommission, err = distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + require.True(t, valCommission.Commission.IsZero()) +} + +func Test100PercentCommissionReward(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec(sdk.Bech32PrefixValAddr)).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return(sdk.DefaultBondDenom, nil).AnyTimes() + accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec(sdk.Bech32MainPrefix)).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, disttypes.InitialFeePool())) + require.NoError(t, distrKeeper.Params.Set(ctx, disttypes.DefaultParams())) + + // create validator with 50% commission + valAddr := sdk.ValAddress(valConsAddr0) + addr := sdk.AccAddress(valAddr) + val, err := distrtestutil.CreateValidator(valConsPk0, math.NewInt(100)) + require.NoError(t, err) + val.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(10, 1), math.LegacyNewDecWithPrec(10, 1), math.LegacyNewDec(0)) + + // validator and delegation mocks + del := stakingtypes.NewDelegation(addr.String(), valAddr.String(), val.DelegatorShares) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(3) + stakingKeeper.EXPECT().Delegation(gomock.Any(), addr, valAddr).Return(del, nil).Times(3) + + // run the necessary hooks manually (given that we are not running an actual staking module) + err = distrtestutil.CallCreateValidatorHooks(ctx, distrKeeper, addr, valAddr) + require.NoError(t, err) + stakingKeeper.EXPECT().Validator(gomock.Any(), valAddr).Return(val, nil).Times(2) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + initial := int64(20) + tokens := sdk.DecCoins{sdk.NewDecCoin(sdk.DefaultBondDenom, math.NewInt(initial))} + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + // next block + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // allocate some more rewards + require.NoError(t, distrKeeper.AllocateTokensToValidator(ctx, val, tokens)) + + rewards, err := distrKeeper.WithdrawDelegationRewards(ctx, addr, valAddr) + require.NoError(t, err) + + zeroRewards := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.ZeroInt())} + require.True(t, rewards.Equal(zeroRewards)) + + events := ctx.EventManager().Events() + lastEvent := events[len(events)-1] + + var hasValue bool + for _, attr := range lastEvent.Attributes { + if attr.Key == "amount" && attr.Value == "0stake" { + hasValue = true + } + } + require.True(t, hasValue) +} diff --git a/x/distribution/keeper/fee_pool.go b/x/distribution/keeper/fee_pool.go new file mode 100644 index 00000000..46bbdc1e --- /dev/null +++ b/x/distribution/keeper/fee_pool.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// DistributeFromFeePool distributes funds from the distribution module account to +// a receiver address while updating the community pool +func (k Keeper) DistributeFromFeePool(ctx context.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error { + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + + // NOTE the community pool isn't a module account, however its coins + // are held in the distribution module account. Thus the community pool + // must be reduced separately from the SendCoinsFromModuleToAccount call + newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...)) + if negative { + return types.ErrBadDistribution + } + + feePool.CommunityPool = newPool + + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount) + if err != nil { + return err + } + + return k.FeePool.Set(ctx, feePool) +} diff --git a/x/distribution/keeper/genesis.go b/x/distribution/keeper/genesis.go new file mode 100644 index 00000000..baa3b9dd --- /dev/null +++ b/x/distribution/keeper/genesis.go @@ -0,0 +1,235 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// InitGenesis sets distribution information for genesis +func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { + var moduleHoldings sdk.DecCoins + + err := k.FeePool.Set(ctx, data.FeePool) + if err != nil { + panic(err) + } + + if err := k.Params.Set(ctx, data.Params); err != nil { + panic(err) + } + + for _, dwi := range data.DelegatorWithdrawInfos { + delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(dwi.DelegatorAddress) + if err != nil { + panic(err) + } + withdrawAddress, err := k.authKeeper.AddressCodec().StringToBytes(dwi.WithdrawAddress) + if err != nil { + panic(err) + } + err = k.SetDelegatorWithdrawAddr(ctx, delegatorAddress, withdrawAddress) + if err != nil { + panic(err) + } + } + + var previousProposer sdk.ConsAddress + if data.PreviousProposer != "" { + var err error + previousProposer, err = k.stakingKeeper.ConsensusAddressCodec().StringToBytes(data.PreviousProposer) + if err != nil { + panic(err) + } + } + + if err = k.SetPreviousProposerConsAddr(ctx, previousProposer); err != nil { + panic(err) + } + + for _, rew := range data.OutstandingRewards { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(rew.ValidatorAddress) + if err != nil { + panic(err) + } + err = k.SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: rew.OutstandingRewards}) + if err != nil { + panic(err) + } + moduleHoldings = moduleHoldings.Add(rew.OutstandingRewards...) + } + for _, acc := range data.ValidatorAccumulatedCommissions { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(acc.ValidatorAddress) + if err != nil { + panic(err) + } + err = k.SetValidatorAccumulatedCommission(ctx, valAddr, acc.Accumulated) + if err != nil { + panic(err) + } + } + for _, his := range data.ValidatorHistoricalRewards { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(his.ValidatorAddress) + if err != nil { + panic(err) + } + err = k.SetValidatorHistoricalRewards(ctx, valAddr, his.Period, his.Rewards) + if err != nil { + panic(err) + } + } + for _, cur := range data.ValidatorCurrentRewards { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(cur.ValidatorAddress) + if err != nil { + panic(err) + } + err = k.SetValidatorCurrentRewards(ctx, valAddr, cur.Rewards) + if err != nil { + panic(err) + } + } + for _, del := range data.DelegatorStartingInfos { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(del.ValidatorAddress) + if err != nil { + panic(err) + } + delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(del.DelegatorAddress) + if err != nil { + panic(err) + } + + err = k.SetDelegatorStartingInfo(ctx, valAddr, delegatorAddress, del.StartingInfo) + if err != nil { + panic(err) + } + } + for _, evt := range data.ValidatorSlashEvents { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(evt.ValidatorAddress) + if err != nil { + panic(err) + } + err = k.SetValidatorSlashEvent(ctx, valAddr, evt.Height, evt.Period, evt.ValidatorSlashEvent) + if err != nil { + panic(err) + } + } + + moduleHoldings = moduleHoldings.Add(data.FeePool.CommunityPool...) + moduleHoldingsInt, _ := moduleHoldings.TruncateDecimal() + + // check if the module account exists + moduleAcc := k.GetDistributionAccount(ctx) + if moduleAcc == nil { + panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) + } + + balances := k.bankKeeper.GetAllBalances(ctx, moduleAcc.GetAddress()) + if balances.IsZero() { + k.authKeeper.SetModuleAccount(ctx, moduleAcc) + } + if !balances.Equal(moduleHoldingsInt) { + panic(fmt.Sprintf("distribution module balance does not match the module holdings: %s <-> %s", balances, moduleHoldingsInt)) + } +} + +// ExportGenesis returns a GenesisState for a given context and keeper. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + feePool, err := k.FeePool.Get(ctx) + if err != nil { + panic(err) + } + + params, err := k.Params.Get(ctx) + if err != nil { + panic(err) + } + + dwi := make([]types.DelegatorWithdrawInfo, 0) + k.IterateDelegatorWithdrawAddrs(ctx, func(del, addr sdk.AccAddress) (stop bool) { + dwi = append(dwi, types.DelegatorWithdrawInfo{ + DelegatorAddress: del.String(), + WithdrawAddress: addr.String(), + }) + return false + }) + + pp, err := k.GetPreviousProposerConsAddr(ctx) + if err != nil { + panic(err) + } + + outstanding := make([]types.ValidatorOutstandingRewardsRecord, 0) + + k.IterateValidatorOutstandingRewards(ctx, + func(addr sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { + outstanding = append(outstanding, types.ValidatorOutstandingRewardsRecord{ + ValidatorAddress: addr.String(), + OutstandingRewards: rewards.Rewards, + }) + return false + }, + ) + + acc := make([]types.ValidatorAccumulatedCommissionRecord, 0) + k.IterateValidatorAccumulatedCommissions(ctx, + func(addr sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool) { + acc = append(acc, types.ValidatorAccumulatedCommissionRecord{ + ValidatorAddress: addr.String(), + Accumulated: commission, + }) + return false + }, + ) + + his := make([]types.ValidatorHistoricalRewardsRecord, 0) + k.IterateValidatorHistoricalRewards(ctx, + func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool) { + his = append(his, types.ValidatorHistoricalRewardsRecord{ + ValidatorAddress: val.String(), + Period: period, + Rewards: rewards, + }) + return false + }, + ) + + cur := make([]types.ValidatorCurrentRewardsRecord, 0) + k.IterateValidatorCurrentRewards(ctx, + func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool) { + cur = append(cur, types.ValidatorCurrentRewardsRecord{ + ValidatorAddress: val.String(), + Rewards: rewards, + }) + return false + }, + ) + + dels := make([]types.DelegatorStartingInfoRecord, 0) + k.IterateDelegatorStartingInfos(ctx, + func(val sdk.ValAddress, del sdk.AccAddress, info types.DelegatorStartingInfo) (stop bool) { + dels = append(dels, types.DelegatorStartingInfoRecord{ + ValidatorAddress: val.String(), + DelegatorAddress: del.String(), + StartingInfo: info, + }) + return false + }, + ) + + slashes := make([]types.ValidatorSlashEventRecord, 0) + k.IterateValidatorSlashEvents(ctx, + func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool) { + slashes = append(slashes, types.ValidatorSlashEventRecord{ + ValidatorAddress: val.String(), + Height: height, + Period: event.ValidatorPeriod, + ValidatorSlashEvent: event, + }) + return false + }, + ) + + return types.NewGenesisState(params, feePool, dwi, pp, outstanding, acc, his, cur, dels, slashes) +} diff --git a/x/distribution/keeper/grpc_query.go b/x/distribution/keeper/grpc_query.go new file mode 100644 index 00000000..6a3e112b --- /dev/null +++ b/x/distribution/keeper/grpc_query.go @@ -0,0 +1,372 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "cosmossdk.io/errors" + "cosmossdk.io/store/prefix" + + "github.com/cosmos/cosmos-sdk/runtime" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +var _ types.QueryServer = Querier{} + +type Querier struct { + Keeper +} + +func NewQuerier(keeper Keeper) Querier { + return Querier{Keeper: keeper} +} + +// Params queries params of distribution module +func (k Querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params, err := k.Keeper.Params.Get(ctx) + if err != nil { + return nil, err + } + + return &types.QueryParamsResponse{Params: params}, nil +} + +// ValidatorDistributionInfo query validator's commission and self-delegation rewards +func (k Querier) ValidatorDistributionInfo(ctx context.Context, req *types.QueryValidatorDistributionInfoRequest) (*types.QueryValidatorDistributionInfoResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.ValidatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty validator address") + } + + valAdr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(req.ValidatorAddress) + if err != nil { + return nil, err + } + + // self-delegation rewards + val, err := k.stakingKeeper.Validator(ctx, valAdr) + if err != nil { + return nil, err + } + + if val == nil { + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) + } + + delAdr := sdk.AccAddress(valAdr) + + del, err := k.stakingKeeper.Delegation(ctx, delAdr, valAdr) + if err != nil { + return nil, err + } + + if del == nil { + return nil, types.ErrNoDelegationExists + } + + endingPeriod, err := k.IncrementValidatorPeriod(ctx, val) + if err != nil { + return nil, err + } + + rewards, err := k.CalculateDelegationRewards(ctx, val, del, endingPeriod) + if err != nil { + return nil, err + } + + // validator's commission + validatorCommission, err := k.GetValidatorAccumulatedCommission(ctx, valAdr) + if err != nil { + return nil, err + } + + return &types.QueryValidatorDistributionInfoResponse{ + Commission: validatorCommission.Commission, + OperatorAddress: delAdr.String(), + SelfBondRewards: rewards, + }, nil +} + +// ValidatorOutstandingRewards queries rewards of a validator address +func (k Querier) ValidatorOutstandingRewards(ctx context.Context, req *types.QueryValidatorOutstandingRewardsRequest) (*types.QueryValidatorOutstandingRewardsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.ValidatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty validator address") + } + + valAdr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(req.ValidatorAddress) + if err != nil { + return nil, err + } + + validator, err := k.stakingKeeper.Validator(ctx, valAdr) + if err != nil { + return nil, err + } + + if validator == nil { + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) + } + + rewards, err := k.GetValidatorOutstandingRewards(ctx, valAdr) + if err != nil { + return nil, err + } + + return &types.QueryValidatorOutstandingRewardsResponse{Rewards: rewards}, nil +} + +// ValidatorCommission queries accumulated commission for a validator +func (k Querier) ValidatorCommission(ctx context.Context, req *types.QueryValidatorCommissionRequest) (*types.QueryValidatorCommissionResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.ValidatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty validator address") + } + + valAdr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(req.ValidatorAddress) + if err != nil { + return nil, err + } + + validator, err := k.stakingKeeper.Validator(ctx, valAdr) + if err != nil { + return nil, err + } + + if validator == nil { + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) + } + commission, err := k.GetValidatorAccumulatedCommission(ctx, valAdr) + if err != nil { + return nil, err + } + + return &types.QueryValidatorCommissionResponse{Commission: commission}, nil +} + +// ValidatorSlashes queries slash events of a validator +func (k Querier) ValidatorSlashes(ctx context.Context, req *types.QueryValidatorSlashesRequest) (*types.QueryValidatorSlashesResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.ValidatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty validator address") + } + + if req.EndingHeight < req.StartingHeight { + return nil, status.Errorf(codes.InvalidArgument, "starting height greater than ending height (%d > %d)", req.StartingHeight, req.EndingHeight) + } + + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(req.ValidatorAddress) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid validator address") + } + + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + slashesStore := prefix.NewStore(store, types.GetValidatorSlashEventPrefix(valAddr)) + + events, pageRes, err := query.GenericFilteredPaginate(k.cdc, slashesStore, req.Pagination, func(key []byte, result *types.ValidatorSlashEvent) (*types.ValidatorSlashEvent, error) { + if result.ValidatorPeriod < req.StartingHeight || result.ValidatorPeriod > req.EndingHeight { + return nil, nil + } + + return result, nil + }, func() *types.ValidatorSlashEvent { + return &types.ValidatorSlashEvent{} + }) + if err != nil { + return nil, err + } + + slashes := []types.ValidatorSlashEvent{} + for _, event := range events { + slashes = append(slashes, *event) + } + + return &types.QueryValidatorSlashesResponse{Slashes: slashes, Pagination: pageRes}, nil +} + +// DelegationRewards the total rewards accrued by a delegation +func (k Querier) DelegationRewards(ctx context.Context, req *types.QueryDelegationRewardsRequest) (*types.QueryDelegationRewardsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.DelegatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty delegator address") + } + + if req.ValidatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty validator address") + } + + valAdr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(req.ValidatorAddress) + if err != nil { + return nil, err + } + + val, err := k.stakingKeeper.Validator(ctx, valAdr) + if err != nil { + return nil, err + } + + if val == nil { + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) + } + + delAdr, err := k.authKeeper.AddressCodec().StringToBytes(req.DelegatorAddress) + if err != nil { + return nil, err + } + del, err := k.stakingKeeper.Delegation(ctx, delAdr, valAdr) + if err != nil { + return nil, err + } + + if del == nil { + return nil, types.ErrNoDelegationExists + } + + endingPeriod, err := k.IncrementValidatorPeriod(ctx, val) + if err != nil { + return nil, err + } + + rewards, err := k.CalculateDelegationRewards(ctx, val, del, endingPeriod) + if err != nil { + return nil, err + } + + return &types.QueryDelegationRewardsResponse{Rewards: rewards}, nil +} + +// DelegationTotalRewards the total rewards accrued by a each validator +func (k Querier) DelegationTotalRewards(ctx context.Context, req *types.QueryDelegationTotalRewardsRequest) (*types.QueryDelegationTotalRewardsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.DelegatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty delegator address") + } + + total := sdk.DecCoins{} + var delRewards []types.DelegationDelegatorReward + + delAdr, err := k.authKeeper.AddressCodec().StringToBytes(req.DelegatorAddress) + if err != nil { + return nil, err + } + + err = k.stakingKeeper.IterateDelegations( + ctx, delAdr, + func(_ int64, del stakingtypes.DelegationI) (stop bool) { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(del.GetValidatorAddr()) + if err != nil { + panic(err) + } + + val, err := k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + panic(err) + } + + endingPeriod, err := k.IncrementValidatorPeriod(ctx, val) + if err != nil { + panic(err) + } + + delReward, err := k.CalculateDelegationRewards(ctx, val, del, endingPeriod) + if err != nil { + panic(err) + } + + delRewards = append(delRewards, types.NewDelegationDelegatorReward(del.GetValidatorAddr(), delReward)) + total = total.Add(delReward...) + return false + }, + ) + if err != nil { + return nil, err + } + + return &types.QueryDelegationTotalRewardsResponse{Rewards: delRewards, Total: total}, nil +} + +// DelegatorValidators queries the validators list of a delegator +func (k Querier) DelegatorValidators(ctx context.Context, req *types.QueryDelegatorValidatorsRequest) (*types.QueryDelegatorValidatorsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.DelegatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty delegator address") + } + + delAdr, err := k.authKeeper.AddressCodec().StringToBytes(req.DelegatorAddress) + if err != nil { + return nil, err + } + var validators []string + + err = k.stakingKeeper.IterateDelegations( + ctx, delAdr, + func(_ int64, del stakingtypes.DelegationI) (stop bool) { + validators = append(validators, del.GetValidatorAddr()) + return false + }, + ) + if err != nil { + return nil, err + } + + return &types.QueryDelegatorValidatorsResponse{Validators: validators}, nil +} + +// DelegatorWithdrawAddress queries Query/delegatorWithdrawAddress +func (k Querier) DelegatorWithdrawAddress(ctx context.Context, req *types.QueryDelegatorWithdrawAddressRequest) (*types.QueryDelegatorWithdrawAddressResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.DelegatorAddress == "" { + return nil, status.Error(codes.InvalidArgument, "empty delegator address") + } + delAdr, err := k.authKeeper.AddressCodec().StringToBytes(req.DelegatorAddress) + if err != nil { + return nil, err + } + + withdrawAddr, err := k.GetDelegatorWithdrawAddr(ctx, delAdr) + if err != nil { + return nil, err + } + + return &types.QueryDelegatorWithdrawAddressResponse{WithdrawAddress: withdrawAddr.String()}, nil +} + +// CommunityPool queries the community pool coins +func (k Querier) CommunityPool(ctx context.Context, _ *types.QueryCommunityPoolRequest) (*types.QueryCommunityPoolResponse, error) { + pool, err := k.FeePool.Get(ctx) + if err != nil { + return nil, err + } + + return &types.QueryCommunityPoolResponse{Pool: pool.CommunityPool}, nil +} diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go new file mode 100644 index 00000000..0c6f32ba --- /dev/null +++ b/x/distribution/keeper/hooks.go @@ -0,0 +1,183 @@ +package keeper + +import ( + "context" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Hooks Wrapper struct +type Hooks struct { + k Keeper +} + +var _ stakingtypes.StakingHooks = Hooks{} + +// Hooks creates new distribution hooks +func (k Keeper) Hooks() Hooks { + return Hooks{k} +} + +// AfterValidatorCreated initializes validator distribution record +func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress) error { + val, err := h.k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return err + } + return h.k.initializeValidator(ctx, val) +} + +// AfterValidatorRemoved performs clean up after a validator is removed +func (h Hooks) AfterValidatorRemoved(ctx context.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error { + // fetch outstanding + outstanding, err := h.k.GetValidatorOutstandingRewardsCoins(ctx, valAddr) + if err != nil { + return err + } + + // force-withdraw commission + valCommission, err := h.k.GetValidatorAccumulatedCommission(ctx, valAddr) + if err != nil { + return err + } + + commission := valCommission.Commission + + if !commission.IsZero() { + // subtract from outstanding + outstanding = outstanding.Sub(commission) + + // split into integral & remainder + coins, remainder := commission.TruncateDecimal() + + // remainder to community pool + feePool, err := h.k.FeePool.Get(ctx) + if err != nil { + return err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(remainder...) + err = h.k.FeePool.Set(ctx, feePool) + if err != nil { + return err + } + + // add to validator account + if !coins.IsZero() { + accAddr := sdk.AccAddress(valAddr) + withdrawAddr, err := h.k.GetDelegatorWithdrawAddr(ctx, accAddr) + if err != nil { + return err + } + + if err := h.k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins); err != nil { + return err + } + } + } + + // Add outstanding to community pool + // The validator is removed only after it has no more delegations. + // This operation sends only the remaining dust to the community pool. + feePool, err := h.k.FeePool.Get(ctx) + if err != nil { + return err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(outstanding...) + err = h.k.FeePool.Set(ctx, feePool) + if err != nil { + return err + } + + // delete outstanding + err = h.k.DeleteValidatorOutstandingRewards(ctx, valAddr) + if err != nil { + return err + } + + // remove commission record + err = h.k.DeleteValidatorAccumulatedCommission(ctx, valAddr) + if err != nil { + return err + } + + // clear slashes + h.k.DeleteValidatorSlashEvents(ctx, valAddr) + + // clear historical rewards + h.k.DeleteValidatorHistoricalRewards(ctx, valAddr) + + // clear current rewards + err = h.k.DeleteValidatorCurrentRewards(ctx, valAddr) + if err != nil { + return err + } + + return nil +} + +// BeforeDelegationCreated BeforeDelegationCreated increments period +func (h Hooks) BeforeDelegationCreated(ctx context.Context, _ sdk.AccAddress, valAddr sdk.ValAddress) error { + val, err := h.k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return err + } + + _, err = h.k.IncrementValidatorPeriod(ctx, val) + return err +} + +// BeforeDelegationSharesModified withdraws delegation rewards (which also increments period) +func (h Hooks) BeforeDelegationSharesModified(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { + val, err := h.k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return err + } + + del, err := h.k.stakingKeeper.Delegation(ctx, delAddr, valAddr) + if err != nil { + return err + } + + if _, err := h.k.withdrawDelegationRewards(ctx, val, del); err != nil { + return err + } + + return nil +} + +// AfterDelegationModified creates a new delegation period record +func (h Hooks) AfterDelegationModified(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { + return h.k.initializeDelegation(ctx, valAddr, delAddr) +} + +// BeforeValidatorSlashed records the slash event +func (h Hooks) BeforeValidatorSlashed(ctx context.Context, valAddr sdk.ValAddress, fraction sdkmath.LegacyDec) error { + return h.k.updateValidatorSlashFraction(ctx, valAddr, fraction) +} + +func (h Hooks) BeforeValidatorModified(_ context.Context, _ sdk.ValAddress) error { + return nil +} + +func (h Hooks) AfterValidatorBonded(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { + return nil +} + +func (h Hooks) AfterValidatorBeginUnbonding(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { + return nil +} + +func (h Hooks) BeforeDelegationRemoved(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { + return nil +} + +func (h Hooks) AfterUnbondingInitiated(_ context.Context, _ uint64) error { + return nil +} diff --git a/x/distribution/keeper/invariants.go b/x/distribution/keeper/invariants.go new file mode 100644 index 00000000..dccc1f84 --- /dev/null +++ b/x/distribution/keeper/invariants.go @@ -0,0 +1,193 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// RegisterInvariants register all distribution invariants +func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) { + ir.RegisterRoute(types.ModuleName, "nonnegative-outstanding", + NonNegativeOutstandingInvariant(k)) + ir.RegisterRoute(types.ModuleName, "can-withdraw", + CanWithdrawInvariant(k)) + ir.RegisterRoute(types.ModuleName, "reference-count", + ReferenceCountInvariant(k)) + ir.RegisterRoute(types.ModuleName, "module-account", + ModuleAccountInvariant(k)) +} + +// AllInvariants runs all invariants of the distribution module +func AllInvariants(k Keeper) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + res, stop := CanWithdrawInvariant(k)(ctx) + if stop { + return res, stop + } + res, stop = NonNegativeOutstandingInvariant(k)(ctx) + if stop { + return res, stop + } + res, stop = ReferenceCountInvariant(k)(ctx) + if stop { + return res, stop + } + return ModuleAccountInvariant(k)(ctx) + } +} + +// NonNegativeOutstandingInvariant checks that outstanding unwithdrawn fees are never negative +func NonNegativeOutstandingInvariant(k Keeper) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + var msg string + var count int + var outstanding sdk.DecCoins + + k.IterateValidatorOutstandingRewards(ctx, func(addr sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { + outstanding = rewards.GetRewards() + if outstanding.IsAnyNegative() { + count++ + msg += fmt.Sprintf("\t%v has negative outstanding coins: %v\n", addr, outstanding) + } + return false + }) + broken := count != 0 + + return sdk.FormatInvariant(types.ModuleName, "nonnegative outstanding", + fmt.Sprintf("found %d validators with negative outstanding rewards\n%s", count, msg)), broken + } +} + +// CanWithdrawInvariant checks that current rewards can be completely withdrawn +func CanWithdrawInvariant(k Keeper) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + // cache, we don't want to write changes + ctx, _ = ctx.CacheContext() + + var remaining sdk.DecCoins + + valDelegationAddrs := make(map[string][][]byte) + allDelegations, err := k.stakingKeeper.GetAllSDKDelegations(ctx) + if err != nil { + panic(err) + } + + for _, del := range allDelegations { + delAddr, err := k.authKeeper.AddressCodec().StringToBytes(del.GetDelegatorAddr()) + if err != nil { + panic(err) + } + valAddr := del.GetValidatorAddr() + valDelegationAddrs[valAddr] = append(valDelegationAddrs[valAddr], delAddr) + } + + // iterate over all validators + err = k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + valBz, err1 := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + panic(err1) + } + _, _ = k.WithdrawValidatorCommission(ctx, valBz) + + delegationAddrs, ok := valDelegationAddrs[val.GetOperator()] + if ok { + for _, delAddr := range delegationAddrs { + if _, err := k.WithdrawDelegationRewards(ctx, delAddr, valBz); err != nil { + panic(err) + } + } + } + + var err error + remaining, err = k.GetValidatorOutstandingRewardsCoins(ctx, valBz) + if err != nil { + panic(err) + } + + if len(remaining) > 0 && remaining[0].Amount.IsNegative() { + return true + } + + return false + }) + if err != nil { + panic(err) + } + + broken := len(remaining) > 0 && remaining[0].Amount.IsNegative() + return sdk.FormatInvariant(types.ModuleName, "can withdraw", + fmt.Sprintf("remaining coins: %v\n", remaining)), broken + } +} + +// ReferenceCountInvariant checks that the number of historical rewards records is correct +func ReferenceCountInvariant(k Keeper) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + valCount := uint64(0) + err := k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + valCount++ + return false + }) + if err != nil { + panic(err) + } + + dels, err := k.stakingKeeper.GetAllSDKDelegations(ctx) + if err != nil { + panic(err) + } + + slashCount := uint64(0) + k.IterateValidatorSlashEvents(ctx, + func(_ sdk.ValAddress, _ uint64, _ types.ValidatorSlashEvent) (stop bool) { + slashCount++ + return false + }) + + // one record per validator (last tracked period), one record per + // delegation (previous period), one record per slash (previous period) + expected := valCount + uint64(len(dels)) + slashCount + count := k.GetValidatorHistoricalReferenceCount(ctx) + broken := count != expected + + return sdk.FormatInvariant(types.ModuleName, "reference count", + fmt.Sprintf("expected historical reference count: %d = %v validators + %v delegations + %v slashes\n"+ + "total validator historical reference count: %d\n", + expected, valCount, len(dels), slashCount, count)), broken + } +} + +// ModuleAccountInvariant checks that the coins held by the distr ModuleAccount +// is consistent with the sum of validator outstanding rewards +func ModuleAccountInvariant(k Keeper) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + var expectedCoins sdk.DecCoins + k.IterateValidatorOutstandingRewards(ctx, func(_ sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { + expectedCoins = expectedCoins.Add(rewards.Rewards...) + return false + }) + + communityPool, err := k.FeePool.Get(ctx) + if err != nil { + panic(err) + } + + expectedInt, _ := expectedCoins.Add(communityPool.CommunityPool...).TruncateDecimal() + + macc := k.GetDistributionAccount(ctx) + balances := k.bankKeeper.GetAllBalances(ctx, macc.GetAddress()) + + broken := !balances.Equal(expectedInt) + return sdk.FormatInvariant( + types.ModuleName, "ModuleAccount coins", + fmt.Sprintf("\texpected ModuleAccount coins: %s\n"+ + "\tdistribution ModuleAccount coins: %s\n", + expectedInt, balances, + ), + ), broken + } +} diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go new file mode 100644 index 00000000..437531d6 --- /dev/null +++ b/x/distribution/keeper/keeper.go @@ -0,0 +1,226 @@ +package keeper + +import ( + "context" + "fmt" + + "cosmossdk.io/collections" + "cosmossdk.io/core/store" + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/log" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Keeper of the distribution store +type Keeper struct { + storeService store.KVStoreService + cdc codec.BinaryCodec + authKeeper types.AccountKeeper + bankKeeper types.BankKeeper + stakingKeeper types.StakingKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string + + Schema collections.Schema + Params collections.Item[types.Params] + FeePool collections.Item[types.FeePool] + + feeCollectorName string // name of the FeeCollector ModuleAccount +} + +// NewKeeper creates a new distribution Keeper instance +func NewKeeper( + cdc codec.BinaryCodec, + storeService store.KVStoreService, + ak types.AccountKeeper, + bk types.BankKeeper, + sk types.StakingKeeper, + feeCollectorName, + authority string, +) Keeper { + // ensure distribution module account is set + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { + panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) + } + + sb := collections.NewSchemaBuilder(storeService) + k := Keeper{ + storeService: storeService, + cdc: cdc, + authKeeper: ak, + bankKeeper: bk, + stakingKeeper: sk, + feeCollectorName: feeCollectorName, + authority: authority, + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + FeePool: collections.NewItem(sb, types.FeePoolKey, "fee_pool", codec.CollValue[types.FeePool](cdc)), + } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + return k +} + +// GetAuthority returns the x/distribution module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) + return sdkCtx.Logger().With(log.ModuleKey, "x/"+types.ModuleName) +} + +// SetWithdrawAddr sets a new address that will receive the rewards upon withdrawal +func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr, withdrawAddr sdk.AccAddress) error { + if k.bankKeeper.BlockedAddr(withdrawAddr) { + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", withdrawAddr) + } + + withdrawAddrEnabled, err := k.GetWithdrawAddrEnabled(ctx) + if err != nil { + return err + } + + if !withdrawAddrEnabled { + return types.ErrSetWithdrawAddrDisabled + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSetWithdrawAddress, + sdk.NewAttribute(types.AttributeKeyWithdrawAddress, withdrawAddr.String()), + ), + ) + + return k.SetDelegatorWithdrawAddr(ctx, delegatorAddr, withdrawAddr) +} + +// WithdrawDelegationRewards withdraw rewards from a delegation +func (k Keeper) WithdrawDelegationRewards(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) { + val, err := k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return nil, err + } + + if val == nil { + return nil, types.ErrNoValidatorDistInfo + } + + del, err := k.stakingKeeper.Delegation(ctx, delAddr, valAddr) + if err != nil { + return nil, err + } + + if del == nil { + return nil, types.ErrEmptyDelegationDistInfo + } + + // withdraw rewards + rewards, err := k.withdrawDelegationRewards(ctx, val, del) + if err != nil { + return nil, err + } + + // reinitialize the delegation + err = k.initializeDelegation(ctx, valAddr, delAddr) + if err != nil { + return nil, err + } + return rewards, nil +} + +// WithdrawValidatorCommission withdraw validator commission +func (k Keeper) WithdrawValidatorCommission(ctx context.Context, valAddr sdk.ValAddress) (sdk.Coins, error) { + // fetch validator accumulated commission + accumCommission, err := k.GetValidatorAccumulatedCommission(ctx, valAddr) + if err != nil { + return nil, err + } + + if accumCommission.Commission.IsZero() { + return nil, types.ErrNoValidatorCommission + } + + commission, remainder := accumCommission.Commission.TruncateDecimal() + + err = k.SetValidatorAccumulatedCommission(ctx, valAddr, types.ValidatorAccumulatedCommission{Commission: remainder}) // leave remainder to withdraw later + if err != nil { + return nil, err + } + + // update outstanding + outstanding, err := k.GetValidatorOutstandingRewards(ctx, valAddr) + if err != nil { + return nil, err + } + + err = k.SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: outstanding.Rewards.Sub(sdk.NewDecCoinsFromCoins(commission...))}) + if err != nil { + return nil, err + } + + if !commission.IsZero() { + accAddr := sdk.AccAddress(valAddr) + withdrawAddr, err := k.GetDelegatorWithdrawAddr(ctx, accAddr) + if err != nil { + return nil, err + } + + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, commission) + if err != nil { + return nil, err + } + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeWithdrawCommission, + sdk.NewAttribute(sdk.AttributeKeyAmount, commission.String()), + ), + ) + + return commission, nil +} + +// GetTotalRewards returns the total amount of fee distribution rewards held in the store +func (k Keeper) GetTotalRewards(ctx context.Context) (totalRewards sdk.DecCoins) { + k.IterateValidatorOutstandingRewards(ctx, + func(_ sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { + totalRewards = totalRewards.Add(rewards.Rewards...) + return false + }, + ) + + return totalRewards +} + +// FundCommunityPool allows an account to directly fund the community fund pool. +// The amount is first added to the distribution module account and then directly +// added to the pool. An error is returned if the amount cannot be sent to the +// module account. +func (k Keeper) FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error { + if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { + return err + } + + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) + return k.FeePool.Set(ctx, feePool) +} diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go new file mode 100644 index 00000000..fb6a4291 --- /dev/null +++ b/x/distribution/keeper/keeper_test.go @@ -0,0 +1,210 @@ +package keeper_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution" + "github.com/atomone-hub/atomone/x/distribution/keeper" + distrtestutil "github.com/atomone-hub/atomone/x/distribution/testutil" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestSetWithdrawAddr(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + addrs := simtestutil.CreateIncrementalAccounts(2) + + delegatorAddr := addrs[0] + withdrawAddr := addrs[1] + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + + bankKeeper.EXPECT().BlockedAddr(withdrawAddr).Return(false).AnyTimes() + bankKeeper.EXPECT().BlockedAddr(distrAcc.GetAddress()).Return(true).AnyTimes() + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + params := types.DefaultParams() + params.WithdrawAddrEnabled = false + require.NoError(t, distrKeeper.Params.Set(ctx, params)) + + err := distrKeeper.SetWithdrawAddr(ctx, delegatorAddr, withdrawAddr) + require.NotNil(t, err) + + params.WithdrawAddrEnabled = true + require.NoError(t, distrKeeper.Params.Set(ctx, params)) + + err = distrKeeper.SetWithdrawAddr(ctx, delegatorAddr, withdrawAddr) + require.Nil(t, err) + + require.Error(t, distrKeeper.SetWithdrawAddr(ctx, delegatorAddr, distrAcc.GetAddress())) +} + +func TestWithdrawValidatorCommission(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + addrs := simtestutil.CreateIncrementalAccounts(1) + + valAddr := sdk.ValAddress(addrs[0]) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + + valCommission := sdk.DecCoins{ + sdk.NewDecCoinFromDec("mytoken", math.LegacyNewDec(5).Quo(math.LegacyNewDec(4))), + sdk.NewDecCoinFromDec("stake", math.LegacyNewDec(3).Quo(math.LegacyNewDec(2))), + } + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // set outstanding rewards + require.NoError(t, distrKeeper.SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission})) + + // set commission + require.NoError(t, distrKeeper.SetValidatorAccumulatedCommission(ctx, valAddr, types.ValidatorAccumulatedCommission{Commission: valCommission})) + + // withdraw commission + coins := sdk.NewCoins(sdk.NewCoin("mytoken", math.NewInt(1)), sdk.NewCoin("stake", math.NewInt(1))) + // if SendCoinsFromModuleToAccount is called, we know that the withdraw was successful + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), "distribution", addrs[0], coins).Return(nil) + + _, err := distrKeeper.WithdrawValidatorCommission(ctx, valAddr) + require.NoError(t, err) + + // check remainder + remainderValCommission, err := distrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) + require.NoError(t, err) + remainder := remainderValCommission.Commission + require.Equal(t, sdk.DecCoins{ + sdk.NewDecCoinFromDec("mytoken", math.LegacyNewDec(1).Quo(math.LegacyNewDec(4))), + sdk.NewDecCoinFromDec("stake", math.LegacyNewDec(1).Quo(math.LegacyNewDec(2))), + }, remainder) +} + +func TestGetTotalRewards(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + addrs := simtestutil.CreateIncrementalAccounts(2) + + valAddr0 := sdk.ValAddress(addrs[0]) + valAddr1 := sdk.ValAddress(addrs[1]) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + valCommission := sdk.DecCoins{ + sdk.NewDecCoinFromDec("mytoken", math.LegacyNewDec(5).Quo(math.LegacyNewDec(4))), + sdk.NewDecCoinFromDec("stake", math.LegacyNewDec(3).Quo(math.LegacyNewDec(2))), + } + + require.NoError(t, distrKeeper.SetValidatorOutstandingRewards(ctx, valAddr0, types.ValidatorOutstandingRewards{Rewards: valCommission})) + require.NoError(t, distrKeeper.SetValidatorOutstandingRewards(ctx, valAddr1, types.ValidatorOutstandingRewards{Rewards: valCommission})) + + expectedRewards := valCommission.MulDec(math.LegacyNewDec(2)) + totalRewards := distrKeeper.GetTotalRewards(ctx) + + require.Equal(t, expectedRewards, totalRewards) +} + +func TestFundCommunityPool(t *testing.T) { + ctrl := gomock.NewController(t) + key := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(key) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + addrs := simtestutil.CreateIncrementalAccounts(1) + + bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) + accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) + + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) + + distrKeeper := keeper.NewKeeper( + encCfg.Codec, + storeService, + accountKeeper, + bankKeeper, + stakingKeeper, + "fee_collector", + authtypes.NewModuleAddress("gov").String(), + ) + + // reset fee pool + require.NoError(t, distrKeeper.FeePool.Set(ctx, types.InitialFeePool())) + + initPool, err := distrKeeper.FeePool.Get(ctx) + require.NoError(t, err) + require.Empty(t, initPool.CommunityPool) + + amount := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) + bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), addrs[0], "distribution", amount).Return(nil) + err = distrKeeper.FundCommunityPool(ctx, amount, addrs[0]) + require.NoError(t, err) + + feePool, err := distrKeeper.FeePool.Get(ctx) + require.NoError(t, err) + require.Equal(t, initPool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...), feePool.CommunityPool) +} diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go new file mode 100644 index 00000000..dd2bd0a4 --- /dev/null +++ b/x/distribution/keeper/msg_server.go @@ -0,0 +1,263 @@ +package keeper + +import ( + "context" + "fmt" + + "github.com/hashicorp/go-metrics" + + "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +type msgServer struct { + Keeper +} + +var _ types.MsgServer = msgServer{} + +// NewMsgServerImpl returns an implementation of the distribution MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (k msgServer) SetWithdrawAddress(ctx context.Context, msg *types.MsgSetWithdrawAddress) (*types.MsgSetWithdrawAddressResponse, error) { + delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(msg.DelegatorAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err) + } + + withdrawAddress, err := k.authKeeper.AddressCodec().StringToBytes(msg.WithdrawAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid withdraw address: %s", err) + } + + err = k.SetWithdrawAddr(ctx, delegatorAddress, withdrawAddress) + if err != nil { + return nil, err + } + + return &types.MsgSetWithdrawAddressResponse{}, nil +} + +func (k msgServer) WithdrawDelegatorReward(ctx context.Context, msg *types.MsgWithdrawDelegatorReward) (*types.MsgWithdrawDelegatorRewardResponse, error) { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(msg.ValidatorAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) + } + + delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(msg.DelegatorAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err) + } + + amount, err := k.WithdrawDelegationRewards(ctx, delegatorAddress, valAddr) + if err != nil { + return nil, err + } + + defer func() { + for _, a := range amount { + if a.Amount.IsInt64() { + telemetry.SetGaugeWithLabels( + []string{"tx", "msg", "withdraw_reward"}, + float32(a.Amount.Int64()), + []metrics.Label{telemetry.NewLabel("denom", a.Denom)}, + ) + } + } + }() + + return &types.MsgWithdrawDelegatorRewardResponse{Amount: amount}, nil +} + +func (k msgServer) WithdrawValidatorCommission(ctx context.Context, msg *types.MsgWithdrawValidatorCommission) (*types.MsgWithdrawValidatorCommissionResponse, error) { + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(msg.ValidatorAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) + } + + amount, err := k.Keeper.WithdrawValidatorCommission(ctx, valAddr) + if err != nil { + return nil, err + } + + defer func() { + for _, a := range amount { + if a.Amount.IsInt64() { + telemetry.SetGaugeWithLabels( + []string{"tx", "msg", "withdraw_commission"}, + float32(a.Amount.Int64()), + []metrics.Label{telemetry.NewLabel("denom", a.Denom)}, + ) + } + } + }() + + return &types.MsgWithdrawValidatorCommissionResponse{Amount: amount}, nil +} + +func (k msgServer) FundCommunityPool(ctx context.Context, msg *types.MsgFundCommunityPool) (*types.MsgFundCommunityPoolResponse, error) { + depositor, err := k.authKeeper.AddressCodec().StringToBytes(msg.Depositor) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid depositor address: %s", err) + } + + if err := validateAmount(msg.Amount); err != nil { + return nil, err + } + + if err := k.Keeper.FundCommunityPool(ctx, msg.Amount, depositor); err != nil { + return nil, err + } + + return &types.MsgFundCommunityPoolResponse{}, nil +} + +func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if err := k.validateAuthority(msg.Authority); err != nil { + return nil, err + } + + if err := msg.Params.ValidateBasic(); err != nil { + return nil, err + } + + if err := k.Params.Set(ctx, msg.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} + +func (k msgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommunityPoolSpend) (*types.MsgCommunityPoolSpendResponse, error) { + if err := k.validateAuthority(msg.Authority); err != nil { + return nil, err + } + + if err := validateAmount(msg.Amount); err != nil { + return nil, err + } + + recipient, err := k.authKeeper.AddressCodec().StringToBytes(msg.Recipient) + if err != nil { + return nil, err + } + + if k.bankKeeper.BlockedAddr(recipient) { + return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", msg.Recipient) + } + + if err := k.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil { + return nil, err + } + + logger := k.Logger(ctx) + logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient) + + return &types.MsgCommunityPoolSpendResponse{}, nil +} + +func (k msgServer) DepositValidatorRewardsPool(ctx context.Context, msg *types.MsgDepositValidatorRewardsPool) (*types.MsgDepositValidatorRewardsPoolResponse, error) { + depositor, err := k.authKeeper.AddressCodec().StringToBytes(msg.Depositor) + if err != nil { + return nil, err + } + + // deposit coins from depositor's account to the distribution module + if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleName, msg.Amount); err != nil { + return nil, err + } + + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(msg.ValidatorAddress) + if err != nil { + return nil, err + } + + validator, err := k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return nil, err + } + + if validator == nil { + return nil, errors.Wrap(types.ErrNoValidatorExists, msg.ValidatorAddress) + } + + // Allocate tokens from the distribution module to the validator, which are + // then distributed to the validator's delegators. + reward := sdk.NewDecCoinsFromCoins(msg.Amount...) + if err = k.AllocateTokensToValidator(ctx, validator, reward); err != nil { + return nil, err + } + + // make sure the reward pool isn't already full. + if !validator.GetTokens().IsZero() { + rewards, err := k.GetValidatorCurrentRewards(ctx, valAddr) + if err != nil { + return nil, err + } + current := rewards.Rewards + historical, err := k.GetValidatorHistoricalRewards(ctx, valAddr, rewards.Period-1) + if err != nil { + return nil, err + } + if !historical.CumulativeRewardRatio.IsZero() { + rewardRatio := historical.CumulativeRewardRatio + var panicErr error + func() { + defer func() { + if r := recover(); r != nil { + panicErr = fmt.Errorf("deposit is too large: %v", r) + } + }() + rewardRatio.Add(current...) + }() + + // Check if the deferred function caught a panic + if panicErr != nil { + return nil, fmt.Errorf("unable to deposit coins: %w", panicErr) + } + } + } + + logger := k.Logger(ctx) + logger.Info( + "transferred from rewards to validator rewards pool", + "depositor", msg.Depositor, + "amount", msg.Amount.String(), + "validator", msg.ValidatorAddress, + ) + + return &types.MsgDepositValidatorRewardsPoolResponse{}, nil +} + +func (k *Keeper) validateAuthority(authority string) error { + if _, err := k.authKeeper.AddressCodec().StringToBytes(authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + + if k.authority != authority { + return errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, authority) + } + + return nil +} + +func validateAmount(amount sdk.Coins) error { + if amount == nil { + return errors.Wrap(sdkerrors.ErrInvalidCoins, "amount cannot be nil") + } + + if err := amount.Validate(); err != nil { + return errors.Wrap(sdkerrors.ErrInvalidCoins, amount.String()) + } + + return nil +} diff --git a/x/distribution/keeper/params.go b/x/distribution/keeper/params.go new file mode 100644 index 00000000..60b352b2 --- /dev/null +++ b/x/distribution/keeper/params.go @@ -0,0 +1,28 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/math" +) + +// GetCommunityTax returns the current distribution community tax. +func (k Keeper) GetCommunityTax(ctx context.Context) (math.LegacyDec, error) { + params, err := k.Params.Get(ctx) + if err != nil { + return math.LegacyDec{}, err + } + + return params.CommunityTax, nil +} + +// GetWithdrawAddrEnabled returns the current distribution withdraw address +// enabled parameter. +func (k Keeper) GetWithdrawAddrEnabled(ctx context.Context) (enabled bool, err error) { + params, err := k.Params.Get(ctx) + if err != nil { + return false, err + } + + return params.WithdrawAddrEnabled, nil +} diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go new file mode 100644 index 00000000..bfc84494 --- /dev/null +++ b/x/distribution/keeper/store.go @@ -0,0 +1,440 @@ +package keeper + +import ( + "context" + "errors" + + gogotypes "github.com/cosmos/gogoproto/types" + + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/runtime" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// GetDelegatorWithdrawAddr get the delegator withdraw address, defaulting to the delegator address +func (k Keeper) GetDelegatorWithdrawAddr(ctx context.Context, delAddr sdk.AccAddress) (sdk.AccAddress, error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetDelegatorWithdrawAddrKey(delAddr)) + if b == nil { + return delAddr, err + } + return sdk.AccAddress(b), nil +} + +// SetDelegatorWithdrawAddr set the delegator withdraw address +func (k Keeper) SetDelegatorWithdrawAddr(ctx context.Context, delAddr, withdrawAddr sdk.AccAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Set(types.GetDelegatorWithdrawAddrKey(delAddr), withdrawAddr.Bytes()) +} + +// DeleteDelegatorWithdrawAddr delete a delegator withdraw addr +func (k Keeper) DeleteDelegatorWithdrawAddr(ctx context.Context, delAddr, withdrawAddr sdk.AccAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetDelegatorWithdrawAddrKey(delAddr)) +} + +// IterateDelegatorWithdrawAddrs iterate over delegator withdraw addrs +func (k Keeper) IterateDelegatorWithdrawAddrs(ctx context.Context, handler func(del, addr sdk.AccAddress) (stop bool)) { + store := k.storeService.OpenKVStore(ctx) + iter := storetypes.KVStorePrefixIterator(runtime.KVStoreAdapter(store), types.DelegatorWithdrawAddrPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + addr := sdk.AccAddress(iter.Value()) + del := types.GetDelegatorWithdrawInfoAddress(iter.Key()) + if handler(del, addr) { + break + } + } +} + +// GetPreviousProposerConsAddr returns the proposer consensus address for the +// current block. +func (k Keeper) GetPreviousProposerConsAddr(ctx context.Context) (sdk.ConsAddress, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ProposerKey) + if err != nil { + return nil, err + } + + if bz == nil { + return nil, errors.New("previous proposer not set") + } + + addrValue := gogotypes.BytesValue{} + err = k.cdc.Unmarshal(bz, &addrValue) + if err != nil { + return nil, err + } + + return addrValue.GetValue(), nil +} + +// SetPreviousProposerConsAddr set the proposer public key for this block +func (k Keeper) SetPreviousProposerConsAddr(ctx context.Context, consAddr sdk.ConsAddress) error { + store := k.storeService.OpenKVStore(ctx) + bz := k.cdc.MustMarshal(&gogotypes.BytesValue{Value: consAddr}) + return store.Set(types.ProposerKey, bz) +} + +// GetDelegatorStartingInfo get the starting info associated with a delegator +func (k Keeper) GetDelegatorStartingInfo(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) (period types.DelegatorStartingInfo, err error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetDelegatorStartingInfoKey(val, del)) + if err != nil { + return + } + + err = k.cdc.Unmarshal(b, &period) + return period, err +} + +// SetDelegatorStartingInfo set the starting info associated with a delegator +func (k Keeper) SetDelegatorStartingInfo(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress, period types.DelegatorStartingInfo) error { + store := k.storeService.OpenKVStore(ctx) + b, err := k.cdc.Marshal(&period) + if err != nil { + return err + } + + return store.Set(types.GetDelegatorStartingInfoKey(val, del), b) +} + +// HasDelegatorStartingInfo check existence of the starting info associated with a delegator +func (k Keeper) HasDelegatorStartingInfo(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) (bool, error) { + store := k.storeService.OpenKVStore(ctx) + return store.Has(types.GetDelegatorStartingInfoKey(val, del)) +} + +// DeleteDelegatorStartingInfo delete the starting info associated with a delegator +func (k Keeper) DeleteDelegatorStartingInfo(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetDelegatorStartingInfoKey(val, del)) +} + +// IterateDelegatorStartingInfos iterate over delegator starting infos +func (k Keeper) IterateDelegatorStartingInfos(ctx context.Context, handler func(val sdk.ValAddress, del sdk.AccAddress, info types.DelegatorStartingInfo) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.DelegatorStartingInfoPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var info types.DelegatorStartingInfo + k.cdc.MustUnmarshal(iter.Value(), &info) + val, del := types.GetDelegatorStartingInfoAddresses(iter.Key()) + if handler(val, del, info) { + break + } + } +} + +// GetValidatorHistoricalRewards get historical rewards for a particular period +func (k Keeper) GetValidatorHistoricalRewards(ctx context.Context, val sdk.ValAddress, period uint64) (rewards types.ValidatorHistoricalRewards, err error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetValidatorHistoricalRewardsKey(val, period)) + if err != nil { + return + } + + err = k.cdc.Unmarshal(b, &rewards) + return +} + +// SetValidatorHistoricalRewards set historical rewards for a particular period +func (k Keeper) SetValidatorHistoricalRewards(ctx context.Context, val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) error { + store := k.storeService.OpenKVStore(ctx) + b, err := k.cdc.Marshal(&rewards) + if err != nil { + return err + } + + return store.Set(types.GetValidatorHistoricalRewardsKey(val, period), b) +} + +// IterateValidatorHistoricalRewards iterate over historical rewards +func (k Keeper) IterateValidatorHistoricalRewards(ctx context.Context, handler func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var rewards types.ValidatorHistoricalRewards + k.cdc.MustUnmarshal(iter.Value(), &rewards) + addr, period := types.GetValidatorHistoricalRewardsAddressPeriod(iter.Key()) + if handler(addr, period, rewards) { + break + } + } +} + +// DeleteValidatorHistoricalReward delete a historical reward +func (k Keeper) DeleteValidatorHistoricalReward(ctx context.Context, val sdk.ValAddress, period uint64) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetValidatorHistoricalRewardsKey(val, period)) +} + +// DeleteValidatorHistoricalRewards delete historical rewards for a validator +func (k Keeper) DeleteValidatorHistoricalRewards(ctx context.Context, val sdk.ValAddress) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.GetValidatorHistoricalRewardsPrefix(val)) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + store.Delete(iter.Key()) + } +} + +// DeleteAllValidatorHistoricalRewards delete all historical rewards +func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx context.Context) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + store.Delete(iter.Key()) + } +} + +// GetValidatorHistoricalReferenceCount historical reference count (used for testcases) +func (k Keeper) GetValidatorHistoricalReferenceCount(ctx context.Context) (count uint64) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var rewards types.ValidatorHistoricalRewards + k.cdc.MustUnmarshal(iter.Value(), &rewards) + count += uint64(rewards.ReferenceCount) + } + return +} + +// GetValidatorCurrentRewards get current rewards for a validator +func (k Keeper) GetValidatorCurrentRewards(ctx context.Context, val sdk.ValAddress) (rewards types.ValidatorCurrentRewards, err error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetValidatorCurrentRewardsKey(val)) + if err != nil { + return + } + + err = k.cdc.Unmarshal(b, &rewards) + return +} + +// SetValidatorCurrentRewards set current rewards for a validator +func (k Keeper) SetValidatorCurrentRewards(ctx context.Context, val sdk.ValAddress, rewards types.ValidatorCurrentRewards) error { + store := k.storeService.OpenKVStore(ctx) + b, err := k.cdc.Marshal(&rewards) + if err != nil { + return err + } + + return store.Set(types.GetValidatorCurrentRewardsKey(val), b) +} + +// DeleteValidatorCurrentRewards delete current rewards for a validator +func (k Keeper) DeleteValidatorCurrentRewards(ctx context.Context, val sdk.ValAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetValidatorCurrentRewardsKey(val)) +} + +// IterateValidatorCurrentRewards iterate over current rewards +func (k Keeper) IterateValidatorCurrentRewards(ctx context.Context, handler func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorCurrentRewardsPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var rewards types.ValidatorCurrentRewards + k.cdc.MustUnmarshal(iter.Value(), &rewards) + addr := types.GetValidatorCurrentRewardsAddress(iter.Key()) + if handler(addr, rewards) { + break + } + } +} + +// GetValidatorAccumulatedCommission get accumulated commission for a validator +func (k Keeper) GetValidatorAccumulatedCommission(ctx context.Context, val sdk.ValAddress) (commission types.ValidatorAccumulatedCommission, err error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetValidatorAccumulatedCommissionKey(val)) + if err != nil { + return types.ValidatorAccumulatedCommission{}, err + } + + if b == nil { + return types.ValidatorAccumulatedCommission{}, nil + } + + err = k.cdc.Unmarshal(b, &commission) + if err != nil { + return types.ValidatorAccumulatedCommission{}, err + } + return +} + +// SetValidatorAccumulatedCommission set accumulated commission for a validator +func (k Keeper) SetValidatorAccumulatedCommission(ctx context.Context, val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) error { + var ( + bz []byte + err error + ) + + store := k.storeService.OpenKVStore(ctx) + if commission.Commission.IsZero() { + bz, err = k.cdc.Marshal(&types.ValidatorAccumulatedCommission{}) + } else { + bz, err = k.cdc.Marshal(&commission) + } + + if err != nil { + return err + } + + return store.Set(types.GetValidatorAccumulatedCommissionKey(val), bz) +} + +// DeleteValidatorAccumulatedCommission delete accumulated commission for a validator +func (k Keeper) DeleteValidatorAccumulatedCommission(ctx context.Context, val sdk.ValAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetValidatorAccumulatedCommissionKey(val)) +} + +// IterateValidatorAccumulatedCommissions iterate over accumulated commissions +func (k Keeper) IterateValidatorAccumulatedCommissions(ctx context.Context, handler func(val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorAccumulatedCommissionPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var commission types.ValidatorAccumulatedCommission + k.cdc.MustUnmarshal(iter.Value(), &commission) + addr := types.GetValidatorAccumulatedCommissionAddress(iter.Key()) + if handler(addr, commission) { + break + } + } +} + +// GetValidatorOutstandingRewards get validator outstanding rewards +func (k Keeper) GetValidatorOutstandingRewards(ctx context.Context, val sdk.ValAddress) (rewards types.ValidatorOutstandingRewards, err error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.GetValidatorOutstandingRewardsKey(val)) + if err != nil { + return + } + err = k.cdc.Unmarshal(bz, &rewards) + return +} + +// SetValidatorOutstandingRewards set validator outstanding rewards +func (k Keeper) SetValidatorOutstandingRewards(ctx context.Context, val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) error { + store := k.storeService.OpenKVStore(ctx) + b, err := k.cdc.Marshal(&rewards) + if err != nil { + return err + } + return store.Set(types.GetValidatorOutstandingRewardsKey(val), b) +} + +// DeleteValidatorOutstandingRewards delete validator outstanding rewards +func (k Keeper) DeleteValidatorOutstandingRewards(ctx context.Context, val sdk.ValAddress) error { + store := k.storeService.OpenKVStore(ctx) + return store.Delete(types.GetValidatorOutstandingRewardsKey(val)) +} + +// IterateValidatorOutstandingRewards iterate validator outstanding rewards +func (k Keeper) IterateValidatorOutstandingRewards(ctx context.Context, handler func(val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorOutstandingRewardsPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + rewards := types.ValidatorOutstandingRewards{} + k.cdc.MustUnmarshal(iter.Value(), &rewards) + addr := types.GetValidatorOutstandingRewardsAddress(iter.Key()) + if handler(addr, rewards) { + break + } + } +} + +// GetValidatorSlashEvent get slash event for height +func (k Keeper) GetValidatorSlashEvent(ctx context.Context, val sdk.ValAddress, height, period uint64) (event types.ValidatorSlashEvent, found bool, err error) { + store := k.storeService.OpenKVStore(ctx) + b, err := store.Get(types.GetValidatorSlashEventKey(val, height, period)) + if err != nil { + return types.ValidatorSlashEvent{}, false, err + } + + if b == nil { + return types.ValidatorSlashEvent{}, false, nil + } + + err = k.cdc.Unmarshal(b, &event) + if err != nil { + return types.ValidatorSlashEvent{}, false, err + } + + return event, true, nil +} + +// SetValidatorSlashEvent set slash event for height +func (k Keeper) SetValidatorSlashEvent(ctx context.Context, val sdk.ValAddress, height, period uint64, event types.ValidatorSlashEvent) error { + store := k.storeService.OpenKVStore(ctx) + b, err := k.cdc.Marshal(&event) + if err != nil { + return err + } + + return store.Set(types.GetValidatorSlashEventKey(val, height, period), b) +} + +// IterateValidatorSlashEventsBetween iterate over slash events between heights, inclusive +func (k Keeper) IterateValidatorSlashEventsBetween(ctx context.Context, val sdk.ValAddress, startingHeight, endingHeight uint64, + handler func(height uint64, event types.ValidatorSlashEvent) (stop bool), +) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := store.Iterator( + types.GetValidatorSlashEventKeyPrefix(val, startingHeight), + types.GetValidatorSlashEventKeyPrefix(val, endingHeight+1), + ) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var event types.ValidatorSlashEvent + k.cdc.MustUnmarshal(iter.Value(), &event) + _, height := types.GetValidatorSlashEventAddressHeight(iter.Key()) + if handler(height, event) { + break + } + } +} + +// IterateValidatorSlashEvents iterate over all slash events +func (k Keeper) IterateValidatorSlashEvents(ctx context.Context, handler func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool)) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + var event types.ValidatorSlashEvent + k.cdc.MustUnmarshal(iter.Value(), &event) + val, height := types.GetValidatorSlashEventAddressHeight(iter.Key()) + if handler(val, height, event) { + break + } + } +} + +// DeleteValidatorSlashEvents delete slash events for a particular validator +func (k Keeper) DeleteValidatorSlashEvents(ctx context.Context, val sdk.ValAddress) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.GetValidatorSlashEventPrefix(val)) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + store.Delete(iter.Key()) + } +} + +// DeleteAllValidatorSlashEvents delete all slash events +func (k Keeper) DeleteAllValidatorSlashEvents(ctx context.Context) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + store.Delete(iter.Key()) + } +} diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go new file mode 100644 index 00000000..d863d585 --- /dev/null +++ b/x/distribution/keeper/validator.go @@ -0,0 +1,177 @@ +package keeper + +import ( + "context" + "fmt" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// initializeValidator initializes rewards for a new validator +func (k Keeper) initializeValidator(ctx context.Context, val stakingtypes.ValidatorI) error { + valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + return err + } + // set initial historical rewards (period 0) with reference count of 1 + err = k.SetValidatorHistoricalRewards(ctx, valBz, 0, types.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1)) + if err != nil { + return err + } + + // set current rewards (starting at period 1) + err = k.SetValidatorCurrentRewards(ctx, valBz, types.NewValidatorCurrentRewards(sdk.DecCoins{}, 1)) + if err != nil { + return err + } + + // set accumulated commission + err = k.SetValidatorAccumulatedCommission(ctx, valBz, types.InitialValidatorAccumulatedCommission()) + if err != nil { + return err + } + + // set outstanding rewards + err = k.SetValidatorOutstandingRewards(ctx, valBz, types.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}}) + return err +} + +// IncrementValidatorPeriod increments validator period, returning the period just ended +func (k Keeper) IncrementValidatorPeriod(ctx context.Context, val stakingtypes.ValidatorI) (uint64, error) { + valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + return 0, err + } + + // fetch current rewards + rewards, err := k.GetValidatorCurrentRewards(ctx, valBz) + if err != nil { + return 0, err + } + + // calculate current ratio + var current sdk.DecCoins + if val.GetTokens().IsZero() { + + // can't calculate ratio for zero-token validators + // ergo we instead add to the community pool + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return 0, err + } + + outstanding, err := k.GetValidatorOutstandingRewards(ctx, valBz) + if err != nil { + return 0, err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(rewards.Rewards...) + outstanding.Rewards = outstanding.GetRewards().Sub(rewards.Rewards) + err = k.FeePool.Set(ctx, feePool) + if err != nil { + return 0, err + } + + err = k.SetValidatorOutstandingRewards(ctx, valBz, outstanding) + if err != nil { + return 0, err + } + + current = sdk.DecCoins{} + } else { + // note: necessary to truncate so we don't allow withdrawing more rewards than owed + current = rewards.Rewards.QuoDecTruncate(math.LegacyNewDecFromInt(val.GetTokens())) + } + + // fetch historical rewards for last period + historical, err := k.GetValidatorHistoricalRewards(ctx, valBz, rewards.Period-1) + if err != nil { + return 0, err + } + + cumRewardRatio := historical.CumulativeRewardRatio + + // decrement reference count + err = k.decrementReferenceCount(ctx, valBz, rewards.Period-1) + if err != nil { + return 0, err + } + + // set new historical rewards with reference count of 1 + err = k.SetValidatorHistoricalRewards(ctx, valBz, rewards.Period, types.NewValidatorHistoricalRewards(cumRewardRatio.Add(current...), 1)) + if err != nil { + return 0, err + } + + // set current rewards, incrementing period by 1 + err = k.SetValidatorCurrentRewards(ctx, valBz, types.NewValidatorCurrentRewards(sdk.DecCoins{}, rewards.Period+1)) + if err != nil { + return 0, err + } + + return rewards.Period, nil +} + +// increment the reference count for a historical rewards value +func (k Keeper) incrementReferenceCount(ctx context.Context, valAddr sdk.ValAddress, period uint64) error { + historical, err := k.GetValidatorHistoricalRewards(ctx, valAddr, period) + if err != nil { + return err + } + if historical.ReferenceCount > 2 { + panic("reference count should never exceed 2") + } + historical.ReferenceCount++ + return k.SetValidatorHistoricalRewards(ctx, valAddr, period, historical) +} + +// decrement the reference count for a historical rewards value, and delete if zero references remain +func (k Keeper) decrementReferenceCount(ctx context.Context, valAddr sdk.ValAddress, period uint64) error { + historical, err := k.GetValidatorHistoricalRewards(ctx, valAddr, period) + if err != nil { + return err + } + + if historical.ReferenceCount == 0 { + panic("cannot set negative reference count") + } + historical.ReferenceCount-- + if historical.ReferenceCount == 0 { + return k.DeleteValidatorHistoricalReward(ctx, valAddr, period) + } + + return k.SetValidatorHistoricalRewards(ctx, valAddr, period, historical) +} + +func (k Keeper) updateValidatorSlashFraction(ctx context.Context, valAddr sdk.ValAddress, fraction math.LegacyDec) error { + if fraction.GT(math.LegacyOneDec()) || fraction.IsNegative() { + panic(fmt.Sprintf("fraction must be >=0 and <=1, current fraction: %v", fraction)) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + val, err := k.stakingKeeper.Validator(ctx, valAddr) + if err != nil { + return err + } + + // increment current period + newPeriod, err := k.IncrementValidatorPeriod(ctx, val) + if err != nil { + return err + } + + // increment reference count on a period we need to track + if err := k.incrementReferenceCount(ctx, valAddr, newPeriod); err != nil { + return err + } + + slashEvent := types.NewValidatorSlashEvent(newPeriod, fraction) + height := uint64(sdkCtx.BlockHeight()) + + return k.SetValidatorSlashEvent(ctx, valAddr, height, newPeriod, slashEvent) +} diff --git a/x/distribution/module.go b/x/distribution/module.go new file mode 100644 index 00000000..99768646 --- /dev/null +++ b/x/distribution/module.go @@ -0,0 +1,247 @@ +package distribution + +import ( + "context" + "encoding/json" + "fmt" + + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/store" + "cosmossdk.io/depinject" + + sdkclient "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + staking "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/client/cli" + "github.com/atomone-hub/atomone/x/distribution/keeper" + "github.com/atomone-hub/atomone/x/distribution/simulation" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// ConsensusVersion defines the current x/distribution module consensus version. +const ConsensusVersion = 3 + +var ( + _ module.AppModuleBasic = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} +) + +// AppModuleBasic defines the basic application module used by the distribution module. +type AppModuleBasic struct { + cdc codec.Codec + ac address.Codec +} + +// Name returns the distribution module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the distribution module's types for the given codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// DefaultGenesis returns default genesis state as raw bytes for the distribution +// module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the distribution module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(&data) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root tx command for the distribution module. +func (ab AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd(ab.cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), ab.cdc.InterfaceRegistry().SigningContext().AddressCodec()) +} + +// RegisterInterfaces implements InterfaceModule +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// AppModule implements an application module for the distribution module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + stakingKeeper types.StakingKeeper +} + +// NewAppModule creates a new AppModule object +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, + stakingKeeper types.StakingKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{cdc: cdc, ac: accountKeeper.AddressCodec()}, + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + stakingKeeper: stakingKeeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +// RegisterInvariants registers the distribution module invariants. +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { + keeper.RegisterInvariants(ir, am.keeper) +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) +} + +// InitGenesis performs genesis initialization for the distribution module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) +} + +// ExportGenesis returns the exported genesis state as raw bytes for the distribution +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } + +// BeginBlock returns the begin blocker for the distribution module. +func (am AppModule) BeginBlock(ctx context.Context) error { + return am.keeper.BeginBlocker(ctx) +} + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the distribution module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() +} + +// RegisterStoreDecoder registers a decoder for distribution module's types +func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) +} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return simulation.WeightedOperations( + simState.AppParams, simState.Cdc, simState.TxConfig, + am.accountKeeper, am.bankKeeper, am.keeper, am.stakingKeeper, + ) +} + +// +// App Wiring Setup +// + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Config *modulev1.Module + StoreService store.KVStoreService + Cdc codec.Codec + + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper + StakingKeeper types.StakingKeeper +} + +type ModuleOutputs struct { + depinject.Out + + DistrKeeper keeper.Keeper + Module appmodule.AppModule + Hooks staking.StakingHooksWrapper +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + feeCollectorName := in.Config.FeeCollectorName + if feeCollectorName == "" { + feeCollectorName = authtypes.FeeCollectorName + } + + // default to governance authority if not provided + authority := authtypes.NewModuleAddress(govtypes.ModuleName) + if in.Config.Authority != "" { + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + } + + k := keeper.NewKeeper( + in.Cdc, + in.StoreService, + in.AccountKeeper, + in.BankKeeper, + in.StakingKeeper, + feeCollectorName, + authority.String(), + ) + + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper) + + return ModuleOutputs{ + DistrKeeper: k, + Module: m, + Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, + } +} diff --git a/x/distribution/simulation/decoder.go b/x/distribution/simulation/decoder.go new file mode 100644 index 00000000..a4ad0b61 --- /dev/null +++ b/x/distribution/simulation/decoder.go @@ -0,0 +1,71 @@ +package simulation + +import ( + "bytes" + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's +// Value to the corresponding distribution type. +func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { + return func(kvA, kvB kv.Pair) string { + switch { + case bytes.Equal(kvA.Key[:1], types.FeePoolKey): + var feePoolA, feePoolB types.FeePool + cdc.MustUnmarshal(kvA.Value, &feePoolA) + cdc.MustUnmarshal(kvB.Value, &feePoolB) + return fmt.Sprintf("%v\n%v", feePoolA, feePoolB) + + case bytes.Equal(kvA.Key[:1], types.ProposerKey): + return fmt.Sprintf("%v\n%v", sdk.ConsAddress(kvA.Value), sdk.ConsAddress(kvB.Value)) + + case bytes.Equal(kvA.Key[:1], types.ValidatorOutstandingRewardsPrefix): + var rewardsA, rewardsB types.ValidatorOutstandingRewards + cdc.MustUnmarshal(kvA.Value, &rewardsA) + cdc.MustUnmarshal(kvB.Value, &rewardsB) + return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) + + case bytes.Equal(kvA.Key[:1], types.DelegatorWithdrawAddrPrefix): + return fmt.Sprintf("%v\n%v", sdk.AccAddress(kvA.Value), sdk.AccAddress(kvB.Value)) + + case bytes.Equal(kvA.Key[:1], types.DelegatorStartingInfoPrefix): + var infoA, infoB types.DelegatorStartingInfo + cdc.MustUnmarshal(kvA.Value, &infoA) + cdc.MustUnmarshal(kvB.Value, &infoB) + return fmt.Sprintf("%v\n%v", infoA, infoB) + + case bytes.Equal(kvA.Key[:1], types.ValidatorHistoricalRewardsPrefix): + var rewardsA, rewardsB types.ValidatorHistoricalRewards + cdc.MustUnmarshal(kvA.Value, &rewardsA) + cdc.MustUnmarshal(kvB.Value, &rewardsB) + return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) + + case bytes.Equal(kvA.Key[:1], types.ValidatorCurrentRewardsPrefix): + var rewardsA, rewardsB types.ValidatorCurrentRewards + cdc.MustUnmarshal(kvA.Value, &rewardsA) + cdc.MustUnmarshal(kvB.Value, &rewardsB) + return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) + + case bytes.Equal(kvA.Key[:1], types.ValidatorAccumulatedCommissionPrefix): + var commissionA, commissionB types.ValidatorAccumulatedCommission + cdc.MustUnmarshal(kvA.Value, &commissionA) + cdc.MustUnmarshal(kvB.Value, &commissionB) + return fmt.Sprintf("%v\n%v", commissionA, commissionB) + + case bytes.Equal(kvA.Key[:1], types.ValidatorSlashEventPrefix): + var eventA, eventB types.ValidatorSlashEvent + cdc.MustUnmarshal(kvA.Value, &eventA) + cdc.MustUnmarshal(kvB.Value, &eventB) + return fmt.Sprintf("%v\n%v", eventA, eventB) + + default: + panic(fmt.Sprintf("invalid distribution key prefix %X", kvA.Key[:1])) + } + } +} diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go new file mode 100644 index 00000000..04d93c40 --- /dev/null +++ b/x/distribution/simulation/decoder_test.go @@ -0,0 +1,82 @@ +package simulation_test + +import ( + "fmt" + "testing" + + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution" + "github.com/atomone-hub/atomone/x/distribution/simulation" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +var ( + delPk1 = ed25519.GenPrivKey().PubKey() + delAddr1 = sdk.AccAddress(delPk1.Address()) + valAddr1 = sdk.ValAddress(delPk1.Address()) + consAddr1 = sdk.ConsAddress(delPk1.Address().Bytes()) +) + +func TestDecodeDistributionStore(t *testing.T) { + encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + cdc := encodingConfig.Codec + + dec := simulation.NewDecodeStore(cdc) + + decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyOneDec())} + feePool := types.InitialFeePool() + feePool.CommunityPool = decCoins + info := types.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200) + outstanding := types.ValidatorOutstandingRewards{Rewards: decCoins} + commission := types.ValidatorAccumulatedCommission{Commission: decCoins} + historicalRewards := types.NewValidatorHistoricalRewards(decCoins, 100) + currentRewards := types.NewValidatorCurrentRewards(decCoins, 5) + slashEvent := types.NewValidatorSlashEvent(10, math.LegacyOneDec()) + + kvPairs := kv.Pairs{ + Pairs: []kv.Pair{ + {Key: types.FeePoolKey, Value: cdc.MustMarshal(&feePool)}, + {Key: types.ProposerKey, Value: consAddr1.Bytes()}, + {Key: types.GetValidatorOutstandingRewardsKey(valAddr1), Value: cdc.MustMarshal(&outstanding)}, + {Key: types.GetDelegatorWithdrawAddrKey(delAddr1), Value: delAddr1.Bytes()}, + {Key: types.GetDelegatorStartingInfoKey(valAddr1, delAddr1), Value: cdc.MustMarshal(&info)}, + {Key: types.GetValidatorHistoricalRewardsKey(valAddr1, 100), Value: cdc.MustMarshal(&historicalRewards)}, + {Key: types.GetValidatorCurrentRewardsKey(valAddr1), Value: cdc.MustMarshal(¤tRewards)}, + {Key: types.GetValidatorAccumulatedCommissionKey(valAddr1), Value: cdc.MustMarshal(&commission)}, + {Key: types.GetValidatorSlashEventKeyPrefix(valAddr1, 13), Value: cdc.MustMarshal(&slashEvent)}, + {Key: []byte{0x99}, Value: []byte{0x99}}, + }, + } + + tests := []struct { + name string + expectedLog string + }{ + {"FeePool", fmt.Sprintf("%v\n%v", feePool, feePool)}, + {"Proposer", fmt.Sprintf("%v\n%v", consAddr1, consAddr1)}, + {"ValidatorOutstandingRewards", fmt.Sprintf("%v\n%v", outstanding, outstanding)}, + {"DelegatorWithdrawAddr", fmt.Sprintf("%v\n%v", delAddr1, delAddr1)}, + {"DelegatorStartingInfo", fmt.Sprintf("%v\n%v", info, info)}, + {"ValidatorHistoricalRewards", fmt.Sprintf("%v\n%v", historicalRewards, historicalRewards)}, + {"ValidatorCurrentRewards", fmt.Sprintf("%v\n%v", currentRewards, currentRewards)}, + {"ValidatorAccumulatedCommission", fmt.Sprintf("%v\n%v", commission, commission)}, + {"ValidatorSlashEvent", fmt.Sprintf("%v\n%v", slashEvent, slashEvent)}, + {"other", ""}, + } + for i, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + switch i { + case len(tests) - 1: + require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) + } + }) + } +} diff --git a/x/distribution/simulation/genesis.go b/x/distribution/simulation/genesis.go new file mode 100644 index 00000000..58981933 --- /dev/null +++ b/x/distribution/simulation/genesis.go @@ -0,0 +1,45 @@ +package simulation + +import ( + "math/rand" + + "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Simulation parameter constants +const ( + CommunityTax = "community_tax" + WithdrawEnabled = "withdraw_enabled" +) + +// GenCommunityTax randomized CommunityTax +func GenCommunityTax(r *rand.Rand) math.LegacyDec { + return math.LegacyNewDecWithPrec(1, 2).Add(math.LegacyNewDecWithPrec(int64(r.Intn(30)), 2)) +} + +// GenWithdrawEnabled returns a randomized WithdrawEnabled parameter. +func GenWithdrawEnabled(r *rand.Rand) bool { + return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled +} + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + var communityTax math.LegacyDec + simState.AppParams.GetOrGenerate(CommunityTax, &communityTax, simState.Rand, func(r *rand.Rand) { communityTax = GenCommunityTax(r) }) + + var withdrawEnabled bool + simState.AppParams.GetOrGenerate(WithdrawEnabled, &withdrawEnabled, simState.Rand, func(r *rand.Rand) { withdrawEnabled = GenWithdrawEnabled(r) }) + + distrGenesis := types.GenesisState{ + FeePool: types.InitialFeePool(), + Params: types.Params{ + CommunityTax: communityTax, + WithdrawAddrEnabled: withdrawEnabled, + }, + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&distrGenesis) +} diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go new file mode 100644 index 00000000..24c938d7 --- /dev/null +++ b/x/distribution/simulation/genesis_test.go @@ -0,0 +1,77 @@ +package simulation_test + +import ( + "encoding/json" + "math/rand" + "testing" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution/simulation" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. +// Abonormal scenarios are not tested here. +func TestRandomizedGenState(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + s := rand.NewSource(1) + r := rand.New(s) + + simState := module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + NumBonded: 3, + Accounts: simtypes.RandomAccounts(r, 3), + InitialStake: sdkmath.NewInt(1000), + GenState: make(map[string]json.RawMessage), + } + + simulation.RandomizedGenState(&simState) + + var distrGenesis types.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &distrGenesis) + + dec1, _ := sdkmath.LegacyNewDecFromStr("0.210000000000000000") + + require.Equal(t, dec1, distrGenesis.Params.CommunityTax) + require.Equal(t, true, distrGenesis.Params.WithdrawAddrEnabled) + require.Len(t, distrGenesis.DelegatorStartingInfos, 0) + require.Len(t, distrGenesis.DelegatorWithdrawInfos, 0) + require.Len(t, distrGenesis.ValidatorSlashEvents, 0) +} + +// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. +func TestRandomizedGenState1(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + + s := rand.NewSource(1) + r := rand.New(s) + + // all these tests will panic + tests := []struct { + simState module.SimulationState + panicMsg string + }{ + { // panic => reason: incomplete initialization of the simState + module.SimulationState{}, "invalid memory address or nil pointer dereference"}, + { // panic => reason: incomplete initialization of the simState + module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + }, "assignment to entry in nil map"}, + } + + for _, tt := range tests { + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) + } +} diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go new file mode 100644 index 00000000..f3b98671 --- /dev/null +++ b/x/distribution/simulation/operations.go @@ -0,0 +1,283 @@ +package simulation + +import ( + "errors" + "fmt" + "math/rand" + + "cosmossdk.io/collections" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/atomone-hub/atomone/x/distribution/keeper" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Simulation operation weights constants +// +//nolint:gosec // these are not hard-coded credentials. +const ( + OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address" + OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" + OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" + OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool" + + DefaultWeightMsgSetWithdrawAddress int = 50 + DefaultWeightMsgWithdrawDelegationReward int = 50 + DefaultWeightMsgWithdrawValidatorCommission int = 50 + DefaultWeightMsgFundCommunityPool int = 50 +) + +// WeightedOperations returns all the operations from the module with their respective weights +func WeightedOperations( + appParams simtypes.AppParams, + _ codec.JSONCodec, + txConfig client.TxConfig, + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, + sk types.StakingKeeper, +) simulation.WeightedOperations { + var weightMsgSetWithdrawAddress int + appParams.GetOrGenerate(OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil, func(_ *rand.Rand) { + weightMsgSetWithdrawAddress = DefaultWeightMsgSetWithdrawAddress + }) + + var weightMsgWithdrawDelegationReward int + appParams.GetOrGenerate(OpWeightMsgWithdrawDelegationReward, &weightMsgWithdrawDelegationReward, nil, func(_ *rand.Rand) { + weightMsgWithdrawDelegationReward = DefaultWeightMsgWithdrawDelegationReward + }) + + var weightMsgWithdrawValidatorCommission int + appParams.GetOrGenerate(OpWeightMsgWithdrawValidatorCommission, &weightMsgWithdrawValidatorCommission, nil, func(_ *rand.Rand) { + weightMsgWithdrawValidatorCommission = DefaultWeightMsgWithdrawValidatorCommission + }) + + var weightMsgFundCommunityPool int + appParams.GetOrGenerate(OpWeightMsgFundCommunityPool, &weightMsgFundCommunityPool, nil, func(_ *rand.Rand) { + weightMsgFundCommunityPool = DefaultWeightMsgFundCommunityPool + }) + + return simulation.WeightedOperations{ + simulation.NewWeightedOperation( + weightMsgSetWithdrawAddress, + SimulateMsgSetWithdrawAddress(txConfig, ak, bk, k), + ), + simulation.NewWeightedOperation( + weightMsgWithdrawDelegationReward, + SimulateMsgWithdrawDelegatorReward(txConfig, ak, bk, k, sk), + ), + simulation.NewWeightedOperation( + weightMsgWithdrawValidatorCommission, + SimulateMsgWithdrawValidatorCommission(txConfig, ak, bk, k, sk), + ), + simulation.NewWeightedOperation( + weightMsgFundCommunityPool, + SimulateMsgFundCommunityPool(txConfig, ak, bk, k, sk), + ), + } +} + +// SimulateMsgSetWithdrawAddress generates a MsgSetWithdrawAddress with random values. +func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + isWithdrawAddrEnabled, err := k.GetWithdrawAddrEnabled(ctx) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), "error getting params"), nil, err + } + + if !isWithdrawAddrEnabled { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), "withdrawal is not enabled"), nil, nil + } + + simAccount, _ := simtypes.RandomAcc(r, accs) + simToAccount, _ := simtypes.RandomAcc(r, accs) + + account := ak.GetAccount(ctx, simAccount.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: txConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + CoinsSpentInMsg: spendable, + } + + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +// SimulateMsgWithdrawDelegatorReward generates a MsgWithdrawDelegatorReward with random values. +func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + delegations, err := sk.GetAllDelegatorDelegations(ctx, simAccount.Address) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "error getting delegations"), nil, err + } + if len(delegations) == 0 { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "number of delegators equal 0"), nil, nil + } + + delegation := delegations[r.Intn(len(delegations))] + + delAddr, err := sk.ValidatorAddressCodec().StringToBytes(delegation.GetValidatorAddr()) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "error converting validator address"), nil, err + } + validator, err := sk.Validator(ctx, delAddr) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "error getting validator"), nil, err + } + if validator == nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "validator is nil"), nil, fmt.Errorf("validator %s not found", delegation.GetValidatorAddr()) + } + + account := ak.GetAccount(ctx, simAccount.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address.String(), validator.GetOperator()) + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: txConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + CoinsSpentInMsg: spendable, + } + + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +// SimulateMsgWithdrawValidatorCommission generates a MsgWithdrawValidatorCommission with random values. +func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}) + + allVals, err := sk.GetAllValidators(ctx) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "error getting all validators"), nil, err + } + + validator, ok := testutil.RandSliceElem(r, allVals) + if !ok { + return simtypes.NoOpMsg(types.ModuleName, msgType, "random validator is not ok"), nil, nil + } + + valBz, err := sk.ValidatorAddressCodec().StringToBytes(validator.GetOperator()) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "error converting validator address"), nil, err + } + + commission, err := k.GetValidatorAccumulatedCommission(ctx, valBz) + + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return simtypes.NoOpMsg(types.ModuleName, msgType, "error getting validator commission"), nil, err + } + + if commission.Commission.IsZero() { + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator commission is zero"), nil, nil + } + + simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(valBz)) + if !found { + return simtypes.NoOpMsg(types.ModuleName, msgType, "could not find account"), nil, fmt.Errorf("validator %s not found", validator.GetOperator()) + } + + account := ak.GetAccount(ctx, simAccount.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: txConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + CoinsSpentInMsg: spendable, + } + + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +// SimulateMsgFundCommunityPool simulates MsgFundCommunityPool execution where +// a random account sends a random amount of its funds to the community pool. +func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + funder, _ := simtypes.RandomAcc(r, accs) + + account := ak.GetAccount(ctx, funder.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + fundAmount := simtypes.RandSubsetCoins(r, spendable) + if fundAmount.Empty() { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "fund amount is empty"), nil, nil + } + + var ( + fees sdk.Coins + err error + ) + + coins, hasNeg := spendable.SafeSub(fundAmount...) + if !hasNeg { + fees, err = simtypes.RandomFees(r, ctx, coins) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "unable to generate fees"), nil, err + } + } + + msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address.String()) + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: txConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: funder, + AccountKeeper: ak, + ModuleName: types.ModuleName, + } + + return simulation.GenAndDeliverTx(txCtx, fees) + } +} diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go new file mode 100644 index 00000000..c26f33ae --- /dev/null +++ b/x/distribution/simulation/operations_test.go @@ -0,0 +1,335 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "cosmossdk.io/math" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/suite" + + "github.com/atomone-hub/atomone/x/distribution/keeper" + "github.com/atomone-hub/atomone/x/distribution/simulation" + distrtestutil "github.com/atomone-hub/atomone/x/distribution/testutil" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// TestWeightedOperations tests the weights of the operations. +func (suite *SimTestSuite) TestWeightedOperations() { + appParams := make(simtypes.AppParams) + + weightedOps := simulation.WeightedOperations(appParams, suite.cdc, suite.txConfig, suite.accountKeeper, + suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) + + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accs := suite.getTestingAccounts(r, 3) + + expected := []struct { + weight int + opMsgRoute string + opMsgName string + }{ + {simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{})}, + {simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{})}, + {simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{})}, + {simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{})}, + } + + for i, w := range weightedOps { + operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + suite.Require().NoError(err) + + // the following checks are very much dependent from the ordering of the output given + // by WeightedOperations. if the ordering in WeightedOperations changes some tests + // will fail + suite.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same") + suite.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") + suite.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") + } +} + +// TestSimulateMsgSetWithdrawAddress tests the normal scenario of a valid message of type TypeMsgSetWithdrawAddress. +// Abonormal scenarios, where the message is created by an errors, are not tested here. +func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: suite.app.LastBlockHeight() + 1, + Hash: suite.app.LastCommitID().Hash, + }) + suite.Require().NoError(err) + + // execute operation + op := simulation.SimulateMsgSetWithdrawAddress(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgSetWithdrawAddress + err = proto.Unmarshal(operationMsg.Msg, &msg) + suite.Require().NoError(err) + suite.Require().True(operationMsg.OK) + suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) + suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(&msg)) + suite.Require().Len(futureOperations, 0) +} + +// TestSimulateMsgWithdrawDelegatorReward tests the normal scenario of a valid message +// of type TypeMsgWithdrawDelegatorReward. +// Abonormal scenarios, where the message is created by an errors, are not tested here. +func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { + // setup 3 accounts + s := rand.NewSource(4) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + // setup accounts[0] as validator + validator0 := suite.getTestingValidator0(accounts) + + // setup delegation + delTokens := sdk.TokensFromConsensusPower(2, sdk.DefaultPowerReduction) + validator0, issuedShares := validator0.AddTokensFromDel(delTokens) + delegator := accounts[1] + + delegation := stakingtypes.NewDelegation(delegator.Address.String(), validator0.GetOperator(), issuedShares) + suite.Require().NoError(suite.stakingKeeper.SetDelegation(suite.ctx, delegation)) + valBz, err := address.NewBech32Codec("cosmosvaloper").StringToBytes(validator0.GetOperator()) + suite.Require().NoError(err) + suite.Require().NoError(suite.distrKeeper.SetDelegatorStartingInfo(suite.ctx, valBz, delegator.Address, types.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))) + + suite.setupValidatorRewards(valBz) + + _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: suite.app.LastBlockHeight() + 1, + Hash: suite.app.LastCommitID().Hash, + }) + suite.Require().NoError(err) + + // execute operation + op := simulation.SimulateMsgWithdrawDelegatorReward(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgWithdrawDelegatorReward + err = proto.Unmarshal(operationMsg.Msg, &msg) + suite.Require().NoError(err) + suite.Require().True(operationMsg.OK) + suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) + suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(&msg)) + suite.Require().Len(futureOperations, 0) +} + +// TestSimulateMsgWithdrawValidatorCommission tests the normal scenario of a valid message +// of type TypeMsgWithdrawValidatorCommission. +// Abonormal scenarios, where the message is created by an errors, are not tested here. +func (suite *SimTestSuite) TestSimulateMsgWithdrawValidatorCommission() { + suite.testSimulateMsgWithdrawValidatorCommission("atoken") + suite.testSimulateMsgWithdrawValidatorCommission("tokenxxx") +} + +// all the checks in this function should not fail if we change the tokenName +func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName string) { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + // setup accounts[0] as validator + validator0 := suite.getTestingValidator0(accounts) + + // set module account coins + distrAcc := suite.distrKeeper.GetDistributionAccount(suite.ctx) + suite.Require().NoError(banktestutil.FundModuleAccount(suite.ctx, suite.bankKeeper, distrAcc.GetName(), sdk.NewCoins( + sdk.NewCoin(tokenName, math.NewInt(10)), + sdk.NewCoin("stake", math.NewInt(5)), + ))) + suite.accountKeeper.SetModuleAccount(suite.ctx, distrAcc) + + // set outstanding rewards + valCommission := sdk.NewDecCoins( + sdk.NewDecCoinFromDec(tokenName, math.LegacyNewDec(5).Quo(math.LegacyNewDec(2))), + sdk.NewDecCoinFromDec("stake", math.LegacyNewDec(1).Quo(math.LegacyNewDec(1))), + ) + valCodec := address.NewBech32Codec("cosmosvaloper") + + val0, err := valCodec.StringToBytes(validator0.GetOperator()) + suite.Require().NoError(err) + + genVal0, err := valCodec.StringToBytes(suite.genesisVals[0].GetOperator()) + suite.Require().NoError(err) + + suite.Require().NoError(suite.distrKeeper.SetValidatorOutstandingRewards(suite.ctx, val0, types.ValidatorOutstandingRewards{Rewards: valCommission})) + suite.Require().NoError(suite.distrKeeper.SetValidatorOutstandingRewards(suite.ctx, genVal0, types.ValidatorOutstandingRewards{Rewards: valCommission})) + + // setup validator accumulated commission + suite.Require().NoError(suite.distrKeeper.SetValidatorAccumulatedCommission(suite.ctx, val0, types.ValidatorAccumulatedCommission{Commission: valCommission})) + suite.Require().NoError(suite.distrKeeper.SetValidatorAccumulatedCommission(suite.ctx, genVal0, types.ValidatorAccumulatedCommission{Commission: valCommission})) + + _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: suite.app.LastBlockHeight() + 1, + Hash: suite.app.LastCommitID().Hash, + }) + suite.Require().NoError(err) + + // execute operation + op := simulation.SimulateMsgWithdrawValidatorCommission(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + if !operationMsg.OK { + suite.Require().Equal("could not find account", operationMsg.Comment) + } else { + suite.Require().NoError(err) + + var msg types.MsgWithdrawValidatorCommission + err = proto.Unmarshal(operationMsg.Msg, &msg) + suite.Require().NoError(err) + suite.Require().True(operationMsg.OK) + suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(&msg)) + suite.Require().Len(futureOperations, 0) + } +} + +// TestSimulateMsgFundCommunityPool tests the normal scenario of a valid message of type TypeMsgFundCommunityPool. +// Abonormal scenarios, where the message is created by an errors, are not tested here. +func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: suite.app.LastBlockHeight() + 1, + Hash: suite.app.LastCommitID().Hash, + }) + + // execute operation + op := simulation.SimulateMsgFundCommunityPool(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgFundCommunityPool + err = proto.Unmarshal(operationMsg.Msg, &msg) + suite.Require().NoError(err) + suite.Require().True(operationMsg.OK) + suite.Require().Equal("4896096stake", msg.Amount.String()) + suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(&msg)) + suite.Require().Len(futureOperations, 0) +} + +type SimTestSuite struct { + suite.Suite + + ctx sdk.Context + app *runtime.App + genesisVals []stakingtypes.Validator + + txConfig client.TxConfig + cdc codec.Codec + stakingKeeper *stakingkeeper.Keeper + accountKeeper authkeeper.AccountKeeper + bankKeeper bankkeeper.Keeper + distrKeeper keeper.Keeper +} + +func (suite *SimTestSuite) SetupTest() { + var ( + appBuilder *runtime.AppBuilder + err error + ) + suite.app, err = simtestutil.Setup( + depinject.Configs( + distrtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &suite.accountKeeper, + &suite.bankKeeper, + &suite.cdc, + &appBuilder, + &suite.stakingKeeper, + &suite.distrKeeper, + &suite.txConfig, + ) + + suite.NoError(err) + + suite.ctx = suite.app.BaseApp.NewContext(false) + + genesisVals, err := suite.stakingKeeper.GetAllValidators(suite.ctx) + suite.Require().NoError(err) + suite.Require().Len(genesisVals, 1) + suite.genesisVals = genesisVals +} + +func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { + accounts := simtypes.RandomAccounts(r, n) + + initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200) + initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) + + // add coins to the accounts + for _, account := range accounts { + acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address) + suite.accountKeeper.SetAccount(suite.ctx, acc) + suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins)) + } + + return accounts +} + +func (suite *SimTestSuite) getTestingValidator0(accounts []simtypes.Account) stakingtypes.Validator { + commission0 := stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyOneDec(), math.LegacyOneDec()) + return suite.getTestingValidator(accounts, commission0, 0) +} + +func (suite *SimTestSuite) getTestingValidator(accounts []simtypes.Account, commission stakingtypes.Commission, n int) stakingtypes.Validator { + require := suite.Require() + account := accounts[n] + valPubKey := account.PubKey + valAddr := sdk.ValAddress(account.PubKey.Address().Bytes()) + validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes. + Description{}) + require.NoError(err) + validator, err = validator.SetInitialCommission(commission) + require.NoError(err) + validator.DelegatorShares = math.LegacyNewDec(100) + validator.Tokens = math.NewInt(1000000) + + suite.Require().NoError(suite.stakingKeeper.SetValidator(suite.ctx, validator)) + + return validator +} + +func (suite *SimTestSuite) setupValidatorRewards(valAddress sdk.ValAddress) { + decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyOneDec())} + historicalRewards := types.NewValidatorHistoricalRewards(decCoins, 2) + suite.Require().NoError(suite.distrKeeper.SetValidatorHistoricalRewards(suite.ctx, valAddress, 2, historicalRewards)) + // setup current revards + currentRewards := types.NewValidatorCurrentRewards(decCoins, 3) + suite.Require().NoError(suite.distrKeeper.SetValidatorCurrentRewards(suite.ctx, valAddress, currentRewards)) +} + +func TestSimTestSuite(t *testing.T) { + suite.Run(t, new(SimTestSuite)) +} diff --git a/x/distribution/simulation/proposals.go b/x/distribution/simulation/proposals.go new file mode 100644 index 00000000..3b5289fa --- /dev/null +++ b/x/distribution/simulation/proposals.go @@ -0,0 +1,49 @@ +package simulation + +import ( + "math/rand" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +// Simulation operation weights constants +// +//nolint:gosec // these are not hard-coded credentials. +const ( + DefaultWeightMsgUpdateParams int = 50 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.CommunityTax = simtypes.RandomDecAmount(r, sdkmath.LegacyNewDec(1)) + params.WithdrawAddrEnabled = r.Intn(2) == 0 + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/distribution/simulation/proposals_test.go b/x/distribution/simulation/proposals_test.go new file mode 100644 index 00000000..408e97d4 --- /dev/null +++ b/x/distribution/simulation/proposals_test.go @@ -0,0 +1,43 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + sdkmath "cosmossdk.io/math" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "gotest.tools/v3/assert" + + "github.com/atomone-hub/atomone/x/distribution/simulation" + "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, cmtproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.DeepEqual(t, sdkmath.LegacyNewDec(0), msgUpdateParams.Params.CommunityTax) + assert.Equal(t, true, msgUpdateParams.Params.WithdrawAddrEnabled) +} diff --git a/x/distribution/testutil/app_config.go b/x/distribution/testutil/app_config.go new file mode 100644 index 00000000..3012e544 --- /dev/null +++ b/x/distribution/testutil/app_config.go @@ -0,0 +1,27 @@ +package testutil + +import ( + _ "github.com/atomone-hub/atomone/x/distribution" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring + + "github.com/cosmos/cosmos-sdk/testutil/configurator" +) + +var AppConfig = configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.ParamsModule(), + configurator.GenutilModule(), + configurator.DistributionModule(), + configurator.MintModule(), +) diff --git a/x/distribution/testutil/expected_keepers_mocks.go b/x/distribution/testutil/expected_keepers_mocks.go new file mode 100644 index 00000000..21239b81 --- /dev/null +++ b/x/distribution/testutil/expected_keepers_mocks.go @@ -0,0 +1,517 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/distribution/types/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + address "cosmossdk.io/core/address" + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/cosmos-sdk/x/mint/types" + types1 "github.com/cosmos/cosmos-sdk/x/staking/types" + gomock "github.com/golang/mock/gomock" +) + +// MockMintQueryServer is a mock of MintQueryServer interface. +type MockMintQueryServer struct { + ctrl *gomock.Controller + recorder *MockMintQueryServerMockRecorder +} + +// MockMintQueryServerMockRecorder is the mock recorder for MockMintQueryServer. +type MockMintQueryServerMockRecorder struct { + mock *MockMintQueryServer +} + +// NewMockMintQueryServer creates a new mock instance. +func NewMockMintQueryServer(ctrl *gomock.Controller) *MockMintQueryServer { + mock := &MockMintQueryServer{ctrl: ctrl} + mock.recorder = &MockMintQueryServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMintQueryServer) EXPECT() *MockMintQueryServerMockRecorder { + return m.recorder +} + +// AnnualProvisions mocks base method. +func (m *MockMintQueryServer) AnnualProvisions(arg0 context.Context, arg1 *types0.QueryAnnualProvisionsRequest) (*types0.QueryAnnualProvisionsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AnnualProvisions", arg0, arg1) + ret0, _ := ret[0].(*types0.QueryAnnualProvisionsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AnnualProvisions indicates an expected call of AnnualProvisions. +func (mr *MockMintQueryServerMockRecorder) AnnualProvisions(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AnnualProvisions", reflect.TypeOf((*MockMintQueryServer)(nil).AnnualProvisions), arg0, arg1) +} + +// Params mocks base method. +func (m *MockMintQueryServer) Params(arg0 context.Context, arg1 *types0.QueryParamsRequest) (*types0.QueryParamsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Params", arg0, arg1) + ret0, _ := ret[0].(*types0.QueryParamsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Params indicates an expected call of Params. +func (mr *MockMintQueryServerMockRecorder) Params(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Params", reflect.TypeOf((*MockMintQueryServer)(nil).Params), arg0, arg1) +} + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// AddressCodec mocks base method. +func (m *MockAccountKeeper) AddressCodec() address.Codec { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 +} + +// AddressCodec indicates an expected call of AddressCodec. +func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec)) +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// GetModuleAccount mocks base method. +func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, name string) types.ModuleAccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAccount", ctx, name) + ret0, _ := ret[0].(types.ModuleAccountI) + return ret0 +} + +// GetModuleAccount indicates an expected call of GetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, name) +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", name) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name) +} + +// SetModuleAccount mocks base method. +func (m *MockAccountKeeper) SetModuleAccount(arg0 context.Context, arg1 types.ModuleAccountI) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetModuleAccount", arg0, arg1) +} + +// SetModuleAccount indicates an expected call of SetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), arg0, arg1) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// BlockedAddr mocks base method. +func (m *MockBankKeeper) BlockedAddr(addr types.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockedAddr", addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// BlockedAddr indicates an expected call of BlockedAddr. +func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockedAddr", reflect.TypeOf((*MockBankKeeper)(nil).BlockedAddr), addr) +} + +// GetAllBalances mocks base method. +func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// GetAllBalances indicates an expected call of GetAllBalances. +func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr) +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// SendCoinsFromModuleToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToModule indicates an expected call of SendCoinsFromModuleToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToModule(ctx, senderModule, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToModule), ctx, senderModule, recipientModule, amt) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// MockStakingKeeper is a mock of StakingKeeper interface. +type MockStakingKeeper struct { + ctrl *gomock.Controller + recorder *MockStakingKeeperMockRecorder +} + +// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper. +type MockStakingKeeperMockRecorder struct { + mock *MockStakingKeeper +} + +// NewMockStakingKeeper creates a new mock instance. +func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper { + mock := &MockStakingKeeper{ctrl: ctrl} + mock.recorder = &MockStakingKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { + return m.recorder +} + +// BondDenom mocks base method. +func (m *MockStakingKeeper) BondDenom(ctx context.Context) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BondDenom", ctx) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BondDenom indicates an expected call of BondDenom. +func (mr *MockStakingKeeperMockRecorder) BondDenom(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BondDenom", reflect.TypeOf((*MockStakingKeeper)(nil).BondDenom), ctx) +} + +// ConsensusAddressCodec mocks base method. +func (m *MockStakingKeeper) ConsensusAddressCodec() address.Codec { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusAddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 +} + +// ConsensusAddressCodec indicates an expected call of ConsensusAddressCodec. +func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusAddressCodec", reflect.TypeOf((*MockStakingKeeper)(nil).ConsensusAddressCodec)) +} + +// Delegation mocks base method. +func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types.AccAddress, arg2 types.ValAddress) (types1.DelegationI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2) + ret0, _ := ret[0].(types1.DelegationI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Delegation indicates an expected call of Delegation. +func (mr *MockStakingKeeperMockRecorder) Delegation(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delegation", reflect.TypeOf((*MockStakingKeeper)(nil).Delegation), arg0, arg1, arg2) +} + +// GetAllDelegatorDelegations mocks base method. +func (m *MockStakingKeeper) GetAllDelegatorDelegations(ctx context.Context, delegator types.AccAddress) ([]types1.Delegation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllDelegatorDelegations", ctx, delegator) + ret0, _ := ret[0].([]types1.Delegation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAllDelegatorDelegations indicates an expected call of GetAllDelegatorDelegations. +func (mr *MockStakingKeeperMockRecorder) GetAllDelegatorDelegations(ctx, delegator interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllDelegatorDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).GetAllDelegatorDelegations), ctx, delegator) +} + +// GetAllSDKDelegations mocks base method. +func (m *MockStakingKeeper) GetAllSDKDelegations(ctx context.Context) ([]types1.Delegation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllSDKDelegations", ctx) + ret0, _ := ret[0].([]types1.Delegation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAllSDKDelegations indicates an expected call of GetAllSDKDelegations. +func (mr *MockStakingKeeperMockRecorder) GetAllSDKDelegations(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllSDKDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).GetAllSDKDelegations), ctx) +} + +// GetAllValidators mocks base method. +func (m *MockStakingKeeper) GetAllValidators(ctx context.Context) ([]types1.Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllValidators", ctx) + ret0, _ := ret[0].([]types1.Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAllValidators indicates an expected call of GetAllValidators. +func (mr *MockStakingKeeperMockRecorder) GetAllValidators(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllValidators", reflect.TypeOf((*MockStakingKeeper)(nil).GetAllValidators), ctx) +} + +// GetBondedValidatorsByPower mocks base method. +func (m *MockStakingKeeper) GetBondedValidatorsByPower(ctx context.Context) ([]types1.Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBondedValidatorsByPower", ctx) + ret0, _ := ret[0].([]types1.Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBondedValidatorsByPower indicates an expected call of GetBondedValidatorsByPower. +func (mr *MockStakingKeeperMockRecorder) GetBondedValidatorsByPower(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBondedValidatorsByPower", reflect.TypeOf((*MockStakingKeeper)(nil).GetBondedValidatorsByPower), ctx) +} + +// IterateDelegations mocks base method. +func (m *MockStakingKeeper) IterateDelegations(ctx context.Context, delegator types.AccAddress, fn func(int64, types1.DelegationI) bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IterateDelegations", ctx, delegator, fn) + ret0, _ := ret[0].(error) + return ret0 +} + +// IterateDelegations indicates an expected call of IterateDelegations. +func (mr *MockStakingKeeperMockRecorder) IterateDelegations(ctx, delegator, fn interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).IterateDelegations), ctx, delegator, fn) +} + +// IterateValidators mocks base method. +func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types1.ValidatorI) bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IterateValidators", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// IterateValidators indicates an expected call of IterateValidators. +func (mr *MockStakingKeeperMockRecorder) IterateValidators(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateValidators", reflect.TypeOf((*MockStakingKeeper)(nil).IterateValidators), arg0, arg1) +} + +// Validator mocks base method. +func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types.ValAddress) (types1.ValidatorI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validator", arg0, arg1) + ret0, _ := ret[0].(types1.ValidatorI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Validator indicates an expected call of Validator. +func (mr *MockStakingKeeperMockRecorder) Validator(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validator", reflect.TypeOf((*MockStakingKeeper)(nil).Validator), arg0, arg1) +} + +// ValidatorAddressCodec mocks base method. +func (m *MockStakingKeeper) ValidatorAddressCodec() address.Codec { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidatorAddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 +} + +// ValidatorAddressCodec indicates an expected call of ValidatorAddressCodec. +func (mr *MockStakingKeeperMockRecorder) ValidatorAddressCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorAddressCodec", reflect.TypeOf((*MockStakingKeeper)(nil).ValidatorAddressCodec)) +} + +// ValidatorByConsAddr mocks base method. +func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types.ConsAddress) (types1.ValidatorI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1) + ret0, _ := ret[0].(types1.ValidatorI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidatorByConsAddr indicates an expected call of ValidatorByConsAddr. +func (mr *MockStakingKeeperMockRecorder) ValidatorByConsAddr(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorByConsAddr", reflect.TypeOf((*MockStakingKeeper)(nil).ValidatorByConsAddr), arg0, arg1) +} + +// MockStakingHooks is a mock of StakingHooks interface. +type MockStakingHooks struct { + ctrl *gomock.Controller + recorder *MockStakingHooksMockRecorder +} + +// MockStakingHooksMockRecorder is the mock recorder for MockStakingHooks. +type MockStakingHooksMockRecorder struct { + mock *MockStakingHooks +} + +// NewMockStakingHooks creates a new mock instance. +func NewMockStakingHooks(ctrl *gomock.Controller) *MockStakingHooks { + mock := &MockStakingHooks{ctrl: ctrl} + mock.recorder = &MockStakingHooksMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingHooks) EXPECT() *MockStakingHooksMockRecorder { + return m.recorder +} + +// AfterDelegationModified mocks base method. +func (m *MockStakingHooks) AfterDelegationModified(ctx context.Context, delAddr types.AccAddress, valAddr types.ValAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AfterDelegationModified", ctx, delAddr, valAddr) + ret0, _ := ret[0].(error) + return ret0 +} + +// AfterDelegationModified indicates an expected call of AfterDelegationModified. +func (mr *MockStakingHooksMockRecorder) AfterDelegationModified(ctx, delAddr, valAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterDelegationModified", reflect.TypeOf((*MockStakingHooks)(nil).AfterDelegationModified), ctx, delAddr, valAddr) +} + +// AfterValidatorCreated mocks base method. +func (m *MockStakingHooks) AfterValidatorCreated(ctx context.Context, valAddr types.ValAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AfterValidatorCreated", ctx, valAddr) + ret0, _ := ret[0].(error) + return ret0 +} + +// AfterValidatorCreated indicates an expected call of AfterValidatorCreated. +func (mr *MockStakingHooksMockRecorder) AfterValidatorCreated(ctx, valAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterValidatorCreated", reflect.TypeOf((*MockStakingHooks)(nil).AfterValidatorCreated), ctx, valAddr) +} diff --git a/x/distribution/testutil/staking_helper.go b/x/distribution/testutil/staking_helper.go new file mode 100644 index 00000000..c69b285a --- /dev/null +++ b/x/distribution/testutil/staking_helper.go @@ -0,0 +1,147 @@ +package testutil + +import ( + "fmt" + + "cosmossdk.io/math" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/atomone-hub/atomone/x/distribution/keeper" +) + +func CreateValidator(pk cryptotypes.PubKey, stake math.Int) (stakingtypes.Validator, error) { + valConsAddr := sdk.GetConsAddress(pk) + val, err := stakingtypes.NewValidator(sdk.ValAddress(valConsAddr).String(), pk, stakingtypes.Description{Moniker: "TestValidator"}) + if err != nil { + return val, err + } + val.Tokens = stake + val.DelegatorShares = math.LegacyNewDecFromInt(val.Tokens) + return val, err +} + +func CallCreateValidatorHooks(ctx sdk.Context, k keeper.Keeper, addr sdk.AccAddress, valAddr sdk.ValAddress) error { + err := k.Hooks().AfterValidatorCreated(ctx, valAddr) + if err != nil { + return err + } + + err = k.Hooks().BeforeDelegationCreated(ctx, addr, valAddr) + if err != nil { + return err + } + + err = k.Hooks().AfterDelegationModified(ctx, addr, valAddr) + if err != nil { + return err + } + + return nil +} + +// SlashValidator copies what x/staking Slash does. It should be used for testing only. +// And it must be updated whenever the original function is updated. +// The passed validator will get its tokens updated. +func SlashValidator( + ctx sdk.Context, + consAddr sdk.ConsAddress, + infractionHeight int64, + power int64, + slashFactor math.LegacyDec, + validator *stakingtypes.Validator, + distrKeeper *keeper.Keeper, + sk *MockStakingKeeper, +) math.Int { + if slashFactor.IsNegative() { + panic(fmt.Errorf("attempted to slash with a negative slash factor: %v", slashFactor)) + } + + valBz, err := sk.ValidatorAddressCodec().StringToBytes(validator.GetOperator()) + if err != nil { + panic(err) + } + + // call the before-modification hook + err = distrKeeper.Hooks().BeforeValidatorModified(ctx, valBz) + if err != nil { + panic(err) + } + + // we simplify this part, as we won't be able to test redelegations or + // unbonding delegations + if infractionHeight != ctx.BlockHeight() { + // if a new test lands here we might need to update this function to handle redelegations and unbonding + // or just make it an integration test. + panic("we can't test any other case here") + } + + slashAmountDec := math.LegacyNewDecFromInt(validator.Tokens).Mul(math.LegacyNewDecWithPrec(5, 1)) + slashAmount := slashAmountDec.TruncateInt() + + // cannot decrease balance below zero + tokensToBurn := math.MinInt(slashAmount, validator.Tokens) + tokensToBurn = math.MaxInt(tokensToBurn, math.ZeroInt()) // defensive. + + // we need to calculate the *effective* slash fraction for distribution + if validator.Tokens.IsPositive() { + effectiveFraction := math.LegacyNewDecFromInt(tokensToBurn).QuoRoundUp(math.LegacyNewDecFromInt(validator.Tokens)) + // possible if power has changed + if effectiveFraction.GT(math.LegacyOneDec()) { + effectiveFraction = math.LegacyOneDec() + } + // call the before-slashed hook + err := distrKeeper.Hooks().BeforeValidatorSlashed(ctx, valBz, effectiveFraction) + if err != nil { + panic(err) + } + } + // Deduct from the validator's bonded tokens and update the validator. + // Burn the slashed tokens from the pool account and decrease the total supply. + validator.Tokens = validator.Tokens.Sub(tokensToBurn) + + return tokensToBurn +} + +// Delegate imitates what x/staking Delegate does. It should be used for testing only. +// If a delegation is passed, we are simulating an update to a previous delegation, +// if it's nil, then we simulate a new delegation. +func Delegate( + ctx sdk.Context, + distrKeeper keeper.Keeper, + delegator sdk.AccAddress, + validator *stakingtypes.Validator, + amount math.Int, + delegation *stakingtypes.Delegation, + sk *MockStakingKeeper, +) ( + newShares math.LegacyDec, + updatedDel stakingtypes.Delegation, + err error, +) { + valBz, err := sk.ValidatorAddressCodec().StringToBytes(validator.GetOperator()) + if err != nil { + return math.LegacyZeroDec(), stakingtypes.Delegation{}, err + } + if delegation != nil { + err = distrKeeper.Hooks().BeforeDelegationSharesModified(ctx, delegator, valBz) + } else { + err = distrKeeper.Hooks().BeforeDelegationCreated(ctx, delegator, valBz) + del := stakingtypes.NewDelegation(delegator.String(), validator.GetOperator(), math.LegacyZeroDec()) + delegation = &del + } + + if err != nil { + return math.LegacyZeroDec(), stakingtypes.Delegation{}, err + } + + // Add tokens from delegation to validator + updateVal, newShares := validator.AddTokensFromDel(amount) + *validator = updateVal + + delegation.Shares = delegation.Shares.Add(newShares) + + return newShares, *delegation, nil +} diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go new file mode 100644 index 00000000..0f8d86ac --- /dev/null +++ b/x/distribution/types/codec.go @@ -0,0 +1,39 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterLegacyAminoCodec registers the necessary x/distribution interfaces +// and concrete types on the provided LegacyAmino codec. These types are used +// for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward") + legacy.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValCommission") + legacy.RegisterAminoMsg(cdc, &MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress") + legacy.RegisterAminoMsg(cdc, &MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/distribution/MsgUpdateParams") + legacy.RegisterAminoMsg(cdc, &MsgCommunityPoolSpend{}, "cosmos-sdk/distr/MsgCommunityPoolSpend") + legacy.RegisterAminoMsg(cdc, &MsgDepositValidatorRewardsPool{}, "cosmos-sdk/distr/MsgDepositValRewards") + + cdc.RegisterConcrete(Params{}, "cosmos-sdk/x/distribution/Params", nil) +} + +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgWithdrawDelegatorReward{}, + &MsgWithdrawValidatorCommission{}, + &MsgSetWithdrawAddress{}, + &MsgFundCommunityPool{}, + &MsgUpdateParams{}, + &MsgCommunityPoolSpend{}, + &MsgDepositValidatorRewardsPool{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/x/distribution/types/delegator.go b/x/distribution/types/delegator.go new file mode 100644 index 00000000..e3ff2046 --- /dev/null +++ b/x/distribution/types/delegator.go @@ -0,0 +1,12 @@ +package types + +import sdkmath "cosmossdk.io/math" + +// NewDelegatorStartingInfo creates a new DelegatorStartingInfo +func NewDelegatorStartingInfo(previousPeriod uint64, stake sdkmath.LegacyDec, height uint64) DelegatorStartingInfo { + return DelegatorStartingInfo{ + PreviousPeriod: previousPeriod, + Stake: stake, + Height: height, + } +} diff --git a/x/distribution/types/distribution.pb.go b/x/distribution/types/distribution.pb.go new file mode 100644 index 00000000..bcfbfa1d --- /dev/null +++ b/x/distribution/types/distribution.pb.go @@ -0,0 +1,2927 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: atomone/distribution/v1beta1/distribution.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the set of params for the distribution module. +type Params struct { + CommunityTax cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=community_tax,json=communityTax,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"community_tax"` + WithdrawAddrEnabled bool `protobuf:"varint,4,opt,name=withdraw_addr_enabled,json=withdrawAddrEnabled,proto3" json:"withdraw_addr_enabled,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetWithdrawAddrEnabled() bool { + if m != nil { + return m.WithdrawAddrEnabled + } + return false +} + +// ValidatorHistoricalRewards represents historical rewards for a validator. +// Height is implicit within the store key. +// Cumulative reward ratio is the sum from the zeroeth period +// until this period of rewards / tokens, per the spec. +// The reference count indicates the number of objects +// which might need to reference this historical entry at any point. +// ReferenceCount = +// +// number of outstanding delegations which ended the associated period (and +// might need to read that record) +// + number of slashes which ended the associated period (and might need to +// read that record) +// + one per validator for the zeroeth period, set on initialization +type ValidatorHistoricalRewards struct { + CumulativeRewardRatio github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=cumulative_reward_ratio,json=cumulativeRewardRatio,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"cumulative_reward_ratio"` + ReferenceCount uint32 `protobuf:"varint,2,opt,name=reference_count,json=referenceCount,proto3" json:"reference_count,omitempty"` +} + +func (m *ValidatorHistoricalRewards) Reset() { *m = ValidatorHistoricalRewards{} } +func (m *ValidatorHistoricalRewards) String() string { return proto.CompactTextString(m) } +func (*ValidatorHistoricalRewards) ProtoMessage() {} +func (*ValidatorHistoricalRewards) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{1} +} +func (m *ValidatorHistoricalRewards) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorHistoricalRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorHistoricalRewards.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorHistoricalRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorHistoricalRewards.Merge(m, src) +} +func (m *ValidatorHistoricalRewards) XXX_Size() int { + return m.Size() +} +func (m *ValidatorHistoricalRewards) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorHistoricalRewards.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorHistoricalRewards proto.InternalMessageInfo + +func (m *ValidatorHistoricalRewards) GetCumulativeRewardRatio() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.CumulativeRewardRatio + } + return nil +} + +func (m *ValidatorHistoricalRewards) GetReferenceCount() uint32 { + if m != nil { + return m.ReferenceCount + } + return 0 +} + +// ValidatorCurrentRewards represents current rewards and current +// period for a validator kept as a running counter and incremented +// each block as long as the validator's tokens remain constant. +type ValidatorCurrentRewards struct { + Rewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=rewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"rewards"` + Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` +} + +func (m *ValidatorCurrentRewards) Reset() { *m = ValidatorCurrentRewards{} } +func (m *ValidatorCurrentRewards) String() string { return proto.CompactTextString(m) } +func (*ValidatorCurrentRewards) ProtoMessage() {} +func (*ValidatorCurrentRewards) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{2} +} +func (m *ValidatorCurrentRewards) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorCurrentRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorCurrentRewards.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorCurrentRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorCurrentRewards.Merge(m, src) +} +func (m *ValidatorCurrentRewards) XXX_Size() int { + return m.Size() +} +func (m *ValidatorCurrentRewards) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorCurrentRewards.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorCurrentRewards proto.InternalMessageInfo + +func (m *ValidatorCurrentRewards) GetRewards() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Rewards + } + return nil +} + +func (m *ValidatorCurrentRewards) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +// ValidatorAccumulatedCommission represents accumulated commission +// for a validator kept as a running counter, can be withdrawn at any time. +type ValidatorAccumulatedCommission struct { + Commission github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=commission,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"commission"` +} + +func (m *ValidatorAccumulatedCommission) Reset() { *m = ValidatorAccumulatedCommission{} } +func (m *ValidatorAccumulatedCommission) String() string { return proto.CompactTextString(m) } +func (*ValidatorAccumulatedCommission) ProtoMessage() {} +func (*ValidatorAccumulatedCommission) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{3} +} +func (m *ValidatorAccumulatedCommission) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorAccumulatedCommission) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorAccumulatedCommission.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorAccumulatedCommission) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorAccumulatedCommission.Merge(m, src) +} +func (m *ValidatorAccumulatedCommission) XXX_Size() int { + return m.Size() +} +func (m *ValidatorAccumulatedCommission) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorAccumulatedCommission.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorAccumulatedCommission proto.InternalMessageInfo + +func (m *ValidatorAccumulatedCommission) GetCommission() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Commission + } + return nil +} + +// ValidatorOutstandingRewards represents outstanding (un-withdrawn) rewards +// for a validator inexpensive to track, allows simple sanity checks. +type ValidatorOutstandingRewards struct { + Rewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=rewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"rewards"` +} + +func (m *ValidatorOutstandingRewards) Reset() { *m = ValidatorOutstandingRewards{} } +func (m *ValidatorOutstandingRewards) String() string { return proto.CompactTextString(m) } +func (*ValidatorOutstandingRewards) ProtoMessage() {} +func (*ValidatorOutstandingRewards) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{4} +} +func (m *ValidatorOutstandingRewards) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorOutstandingRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorOutstandingRewards.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorOutstandingRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorOutstandingRewards.Merge(m, src) +} +func (m *ValidatorOutstandingRewards) XXX_Size() int { + return m.Size() +} +func (m *ValidatorOutstandingRewards) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorOutstandingRewards.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorOutstandingRewards proto.InternalMessageInfo + +func (m *ValidatorOutstandingRewards) GetRewards() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Rewards + } + return nil +} + +// ValidatorSlashEvent represents a validator slash event. +// Height is implicit within the store key. +// This is needed to calculate appropriate amount of staking tokens +// for delegations which are withdrawn after a slash has occurred. +type ValidatorSlashEvent struct { + ValidatorPeriod uint64 `protobuf:"varint,1,opt,name=validator_period,json=validatorPeriod,proto3" json:"validator_period,omitempty"` + Fraction cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=fraction,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"fraction"` +} + +func (m *ValidatorSlashEvent) Reset() { *m = ValidatorSlashEvent{} } +func (m *ValidatorSlashEvent) String() string { return proto.CompactTextString(m) } +func (*ValidatorSlashEvent) ProtoMessage() {} +func (*ValidatorSlashEvent) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{5} +} +func (m *ValidatorSlashEvent) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSlashEvent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSlashEvent.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSlashEvent) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSlashEvent.Merge(m, src) +} +func (m *ValidatorSlashEvent) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSlashEvent) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSlashEvent.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSlashEvent proto.InternalMessageInfo + +func (m *ValidatorSlashEvent) GetValidatorPeriod() uint64 { + if m != nil { + return m.ValidatorPeriod + } + return 0 +} + +// ValidatorSlashEvents is a collection of ValidatorSlashEvent messages. +type ValidatorSlashEvents struct { + ValidatorSlashEvents []ValidatorSlashEvent `protobuf:"bytes,1,rep,name=validator_slash_events,json=validatorSlashEvents,proto3" json:"validator_slash_events"` +} + +func (m *ValidatorSlashEvents) Reset() { *m = ValidatorSlashEvents{} } +func (m *ValidatorSlashEvents) String() string { return proto.CompactTextString(m) } +func (*ValidatorSlashEvents) ProtoMessage() {} +func (*ValidatorSlashEvents) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{6} +} +func (m *ValidatorSlashEvents) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSlashEvents) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSlashEvents.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSlashEvents) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSlashEvents.Merge(m, src) +} +func (m *ValidatorSlashEvents) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSlashEvents) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSlashEvents.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSlashEvents proto.InternalMessageInfo + +func (m *ValidatorSlashEvents) GetValidatorSlashEvents() []ValidatorSlashEvent { + if m != nil { + return m.ValidatorSlashEvents + } + return nil +} + +// FeePool is the global fee pool for distribution. +type FeePool struct { + CommunityPool github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=community_pool,json=communityPool,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"community_pool"` +} + +func (m *FeePool) Reset() { *m = FeePool{} } +func (m *FeePool) String() string { return proto.CompactTextString(m) } +func (*FeePool) ProtoMessage() {} +func (*FeePool) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{7} +} +func (m *FeePool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeePool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeePool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *FeePool) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeePool.Merge(m, src) +} +func (m *FeePool) XXX_Size() int { + return m.Size() +} +func (m *FeePool) XXX_DiscardUnknown() { + xxx_messageInfo_FeePool.DiscardUnknown(m) +} + +var xxx_messageInfo_FeePool proto.InternalMessageInfo + +func (m *FeePool) GetCommunityPool() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.CommunityPool + } + return nil +} + +// DelegatorStartingInfo represents the starting info for a delegator reward +// period. It tracks the previous validator period, the delegation's amount of +// staking token, and the creation height (to check later on if any slashes have +// occurred). NOTE: Even though validators are slashed to whole staking tokens, +// the delegators within the validator may be left with less than a full token, +// thus sdk.Dec is used. +type DelegatorStartingInfo struct { + PreviousPeriod uint64 `protobuf:"varint,1,opt,name=previous_period,json=previousPeriod,proto3" json:"previous_period,omitempty"` + Stake cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=stake,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"stake"` + Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"creation_height"` +} + +func (m *DelegatorStartingInfo) Reset() { *m = DelegatorStartingInfo{} } +func (m *DelegatorStartingInfo) String() string { return proto.CompactTextString(m) } +func (*DelegatorStartingInfo) ProtoMessage() {} +func (*DelegatorStartingInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{8} +} +func (m *DelegatorStartingInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelegatorStartingInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelegatorStartingInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DelegatorStartingInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelegatorStartingInfo.Merge(m, src) +} +func (m *DelegatorStartingInfo) XXX_Size() int { + return m.Size() +} +func (m *DelegatorStartingInfo) XXX_DiscardUnknown() { + xxx_messageInfo_DelegatorStartingInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_DelegatorStartingInfo proto.InternalMessageInfo + +func (m *DelegatorStartingInfo) GetPreviousPeriod() uint64 { + if m != nil { + return m.PreviousPeriod + } + return 0 +} + +func (m *DelegatorStartingInfo) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +// DelegationDelegatorReward represents the properties +// of a delegator's delegation reward. +type DelegationDelegatorReward struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Reward github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=reward,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"reward"` +} + +func (m *DelegationDelegatorReward) Reset() { *m = DelegationDelegatorReward{} } +func (m *DelegationDelegatorReward) String() string { return proto.CompactTextString(m) } +func (*DelegationDelegatorReward) ProtoMessage() {} +func (*DelegationDelegatorReward) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{9} +} +func (m *DelegationDelegatorReward) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelegationDelegatorReward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelegationDelegatorReward.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DelegationDelegatorReward) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelegationDelegatorReward.Merge(m, src) +} +func (m *DelegationDelegatorReward) XXX_Size() int { + return m.Size() +} +func (m *DelegationDelegatorReward) XXX_DiscardUnknown() { + xxx_messageInfo_DelegationDelegatorReward.DiscardUnknown(m) +} + +var xxx_messageInfo_DelegationDelegatorReward proto.InternalMessageInfo + +// CommunityPoolSpendProposalWithDeposit defines a CommunityPoolSpendProposal +// with a deposit +type CommunityPoolSpendProposalWithDeposit struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + Recipient string `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"` + Amount string `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"` + Deposit string `protobuf:"bytes,5,opt,name=deposit,proto3" json:"deposit,omitempty"` +} + +func (m *CommunityPoolSpendProposalWithDeposit) Reset() { *m = CommunityPoolSpendProposalWithDeposit{} } +func (m *CommunityPoolSpendProposalWithDeposit) String() string { return proto.CompactTextString(m) } +func (*CommunityPoolSpendProposalWithDeposit) ProtoMessage() {} +func (*CommunityPoolSpendProposalWithDeposit) Descriptor() ([]byte, []int) { + return fileDescriptor_9fb9604425850bf9, []int{10} +} +func (m *CommunityPoolSpendProposalWithDeposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CommunityPoolSpendProposalWithDeposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CommunityPoolSpendProposalWithDeposit.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CommunityPoolSpendProposalWithDeposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_CommunityPoolSpendProposalWithDeposit.Merge(m, src) +} +func (m *CommunityPoolSpendProposalWithDeposit) XXX_Size() int { + return m.Size() +} +func (m *CommunityPoolSpendProposalWithDeposit) XXX_DiscardUnknown() { + xxx_messageInfo_CommunityPoolSpendProposalWithDeposit.DiscardUnknown(m) +} + +var xxx_messageInfo_CommunityPoolSpendProposalWithDeposit proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "atomone.distribution.v1beta1.Params") + proto.RegisterType((*ValidatorHistoricalRewards)(nil), "atomone.distribution.v1beta1.ValidatorHistoricalRewards") + proto.RegisterType((*ValidatorCurrentRewards)(nil), "atomone.distribution.v1beta1.ValidatorCurrentRewards") + proto.RegisterType((*ValidatorAccumulatedCommission)(nil), "atomone.distribution.v1beta1.ValidatorAccumulatedCommission") + proto.RegisterType((*ValidatorOutstandingRewards)(nil), "atomone.distribution.v1beta1.ValidatorOutstandingRewards") + proto.RegisterType((*ValidatorSlashEvent)(nil), "atomone.distribution.v1beta1.ValidatorSlashEvent") + proto.RegisterType((*ValidatorSlashEvents)(nil), "atomone.distribution.v1beta1.ValidatorSlashEvents") + proto.RegisterType((*FeePool)(nil), "atomone.distribution.v1beta1.FeePool") + proto.RegisterType((*DelegatorStartingInfo)(nil), "atomone.distribution.v1beta1.DelegatorStartingInfo") + proto.RegisterType((*DelegationDelegatorReward)(nil), "atomone.distribution.v1beta1.DelegationDelegatorReward") + proto.RegisterType((*CommunityPoolSpendProposalWithDeposit)(nil), "atomone.distribution.v1beta1.CommunityPoolSpendProposalWithDeposit") +} + +func init() { + proto.RegisterFile("atomone/distribution/v1beta1/distribution.proto", fileDescriptor_9fb9604425850bf9) +} + +var fileDescriptor_9fb9604425850bf9 = []byte{ + // 931 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0xb4, 0x89, 0x53, 0x4f, 0x69, 0x42, 0xa7, 0x49, 0xeb, 0xba, 0xc1, 0x36, 0x2b, 0x55, + 0x84, 0x80, 0xbd, 0x4a, 0x2b, 0x21, 0x94, 0x5b, 0x6d, 0x17, 0x81, 0x54, 0x20, 0x6c, 0x10, 0x48, + 0x70, 0x58, 0x8d, 0x77, 0x27, 0xeb, 0x51, 0x76, 0x67, 0x56, 0x33, 0xb3, 0x4e, 0x72, 0xe0, 0x5e, + 0xf5, 0x00, 0x1c, 0x39, 0x22, 0xb8, 0x54, 0x9c, 0x72, 0xc8, 0x0f, 0xe0, 0x58, 0x71, 0xaa, 0x0a, + 0x42, 0x88, 0x43, 0x80, 0xe4, 0x10, 0x89, 0x5f, 0x81, 0x66, 0x67, 0xbc, 0xeb, 0x54, 0x11, 0x12, + 0x48, 0x51, 0x2f, 0x51, 0xde, 0xf7, 0xfc, 0xde, 0xfb, 0xde, 0xf7, 0xf6, 0xbd, 0x5d, 0xe8, 0x62, + 0xc5, 0x13, 0xce, 0x88, 0x1b, 0x52, 0xa9, 0x04, 0x1d, 0x66, 0x8a, 0x72, 0xe6, 0x8e, 0xd7, 0x86, + 0x44, 0xe1, 0xb5, 0x53, 0x60, 0x37, 0x15, 0x5c, 0x71, 0xb4, 0x6c, 0x03, 0xba, 0xa7, 0x7c, 0x36, + 0xa0, 0x71, 0x15, 0x27, 0x94, 0x71, 0x37, 0xff, 0x6b, 0x02, 0x1a, 0xcd, 0x80, 0xcb, 0x84, 0x4b, + 0x77, 0x88, 0x25, 0x29, 0x12, 0x07, 0x9c, 0xda, 0x84, 0x8d, 0x9b, 0xc6, 0xef, 0xe7, 0x96, 0x6b, + 0x0c, 0xeb, 0x5a, 0x8c, 0x78, 0xc4, 0x0d, 0xae, 0xff, 0x33, 0xa8, 0xf3, 0x23, 0x80, 0xd5, 0x0d, + 0x2c, 0x70, 0x22, 0xd1, 0xe7, 0xf0, 0x4a, 0xc0, 0x93, 0x24, 0x63, 0x54, 0xed, 0xf9, 0x0a, 0xef, + 0xd6, 0x41, 0x1b, 0xac, 0xd4, 0x7a, 0x6f, 0x3d, 0x39, 0x6c, 0x55, 0x7e, 0x3f, 0x6c, 0xdd, 0x32, + 0xd9, 0x64, 0xb8, 0xdd, 0xa5, 0xdc, 0x4d, 0xb0, 0x1a, 0x75, 0x1f, 0x90, 0x08, 0x07, 0x7b, 0x03, + 0x12, 0x3c, 0x3b, 0xe8, 0x40, 0x5b, 0x6c, 0x40, 0x82, 0xc7, 0x27, 0xfb, 0xab, 0xc0, 0x7b, 0xa9, + 0x48, 0xf6, 0x31, 0xde, 0x45, 0x77, 0xe0, 0xd2, 0x0e, 0x55, 0xa3, 0x50, 0xe0, 0x1d, 0x1f, 0x87, + 0xa1, 0xf0, 0x09, 0xc3, 0xc3, 0x98, 0x84, 0xf5, 0x99, 0x36, 0x58, 0xb9, 0xe4, 0x5d, 0x9b, 0x38, + 0xef, 0x85, 0xa1, 0xb8, 0x6f, 0x5c, 0xeb, 0xb7, 0x1f, 0x9d, 0xec, 0xaf, 0xb6, 0x4d, 0xde, 0x8e, + 0x0c, 0xb7, 0xdd, 0xdd, 0xd3, 0xc2, 0x1a, 0xde, 0xce, 0xaf, 0x00, 0x36, 0x3e, 0xc1, 0x31, 0x0d, + 0xb1, 0xe2, 0xe2, 0x5d, 0x2a, 0x15, 0x17, 0x34, 0xc0, 0xb1, 0x47, 0x76, 0xb0, 0x08, 0x25, 0xfa, + 0x12, 0xc0, 0x1b, 0x41, 0x96, 0x64, 0x31, 0x56, 0x74, 0x4c, 0x7c, 0x91, 0xc3, 0xbe, 0xc0, 0x8a, + 0xf2, 0x3a, 0x68, 0x5f, 0x5c, 0xb9, 0x7c, 0x67, 0xb9, 0x6b, 0xb9, 0x6b, 0x55, 0x27, 0xea, 0xeb, + 0x46, 0xfa, 0x9c, 0xb2, 0xde, 0xdb, 0xba, 0xff, 0x1f, 0xfe, 0x68, 0xbd, 0x11, 0x51, 0x35, 0xca, + 0x86, 0xdd, 0x80, 0x27, 0x56, 0x58, 0x77, 0x8a, 0x9a, 0xda, 0x4b, 0x89, 0x9c, 0xc4, 0x48, 0xa3, + 0xc0, 0x52, 0x59, 0xd6, 0x90, 0xf1, 0x74, 0x51, 0xf4, 0x1a, 0x5c, 0x10, 0x64, 0x8b, 0x08, 0xc2, + 0x02, 0xe2, 0x07, 0x3c, 0x63, 0xaa, 0x7e, 0xa1, 0x0d, 0x56, 0xae, 0x78, 0xf3, 0x05, 0xdc, 0xd7, + 0xa8, 0xf3, 0x3d, 0x80, 0x37, 0x8a, 0xc6, 0xfa, 0x99, 0x10, 0x84, 0xa9, 0x49, 0x57, 0x29, 0x9c, + 0x33, 0x9d, 0xc8, 0x73, 0x6e, 0x62, 0x52, 0x06, 0x5d, 0x87, 0xd5, 0x94, 0x08, 0xca, 0xc3, 0x9c, + 0xed, 0x8c, 0x67, 0x2d, 0xe7, 0x1b, 0x00, 0x9b, 0x05, 0xcb, 0x7b, 0x81, 0xed, 0x99, 0x84, 0x7d, + 0x9e, 0x24, 0x54, 0x4a, 0xca, 0x19, 0x1a, 0x43, 0x18, 0x14, 0xd6, 0x39, 0xf3, 0x9d, 0xaa, 0xe4, + 0x7c, 0x05, 0xe0, 0xad, 0x82, 0xda, 0x87, 0x99, 0x92, 0x0a, 0xb3, 0x90, 0xb2, 0xe8, 0x85, 0x89, + 0xa8, 0x19, 0x5d, 0x2b, 0x18, 0x6d, 0xc6, 0x58, 0x8e, 0xee, 0x8f, 0x09, 0x53, 0xe8, 0x75, 0xf8, + 0xf2, 0x78, 0x02, 0xfb, 0x56, 0x66, 0x90, 0xcb, 0xbc, 0x50, 0xe0, 0x1b, 0x39, 0x8c, 0xde, 0x87, + 0x97, 0xb6, 0x04, 0x0e, 0xf4, 0x06, 0xe4, 0x93, 0xa8, 0xf5, 0xd6, 0xfe, 0xf3, 0x86, 0x7a, 0x45, + 0x0a, 0xe7, 0x11, 0x80, 0x8b, 0x67, 0x30, 0x92, 0x48, 0xc0, 0xeb, 0x25, 0x25, 0xa9, 0x1d, 0x3e, + 0xc9, 0x3d, 0x56, 0xab, 0xb5, 0xee, 0xbf, 0x1d, 0xaf, 0xee, 0x19, 0x39, 0x7b, 0x35, 0x4d, 0xd4, + 0x28, 0xb2, 0x38, 0x3e, 0xa3, 0xa6, 0xf3, 0x10, 0xc0, 0xb9, 0x77, 0x08, 0xd9, 0xe0, 0x3c, 0x46, + 0x5f, 0xc0, 0xf9, 0xf2, 0x1c, 0xa5, 0x9c, 0xc7, 0xe7, 0x3c, 0xa3, 0xf2, 0xf8, 0xe9, 0xf2, 0xce, + 0x2f, 0x00, 0x2e, 0x0d, 0x48, 0x4c, 0xa2, 0x9c, 0xa3, 0xc2, 0x42, 0x51, 0x16, 0xbd, 0xc7, 0xb6, + 0xf2, 0xfd, 0x4d, 0x05, 0x19, 0x53, 0x9e, 0xc9, 0xd3, 0xa3, 0x9a, 0x9f, 0xc0, 0x76, 0x52, 0x0f, + 0xe0, 0xac, 0x54, 0x78, 0x9b, 0xd8, 0x31, 0xfd, 0xdf, 0x43, 0x6a, 0x92, 0xa0, 0x01, 0xac, 0x8e, + 0x08, 0x8d, 0x46, 0xaa, 0x7e, 0x51, 0x57, 0xeb, 0xbd, 0xf9, 0xf7, 0x61, 0x6b, 0x21, 0x10, 0x44, + 0xdf, 0x14, 0xe6, 0x1b, 0xd7, 0x77, 0x27, 0xfb, 0xab, 0xcf, 0x63, 0x26, 0x89, 0x8d, 0x75, 0xfe, + 0x02, 0xf0, 0xa6, 0x6d, 0x8b, 0x72, 0x56, 0x34, 0x68, 0x36, 0x02, 0x7d, 0x00, 0xaf, 0x96, 0x33, + 0xd7, 0x67, 0x9a, 0x48, 0x69, 0x5f, 0x03, 0xaf, 0x3e, 0x3b, 0xe8, 0xbc, 0x62, 0xa9, 0x95, 0xeb, + 0x6e, 0x7e, 0xb2, 0xa9, 0x84, 0xde, 0xaa, 0xf2, 0x11, 0xb6, 0x38, 0x62, 0xb0, 0x6a, 0x9e, 0xfc, + 0xfa, 0x85, 0x73, 0x9d, 0x9d, 0xad, 0xb2, 0x3e, 0xf3, 0xf0, 0xdb, 0x56, 0xc5, 0xf9, 0x19, 0xc0, + 0xdb, 0xfd, 0xe9, 0x61, 0x6e, 0xa6, 0x84, 0x85, 0x1b, 0x82, 0xa7, 0x5c, 0xe2, 0xf8, 0x53, 0xaa, + 0x46, 0x03, 0x92, 0x72, 0x49, 0x15, 0x5a, 0x84, 0xb3, 0x8a, 0xaa, 0x98, 0x98, 0x1e, 0x3d, 0x63, + 0xa0, 0x36, 0xbc, 0x1c, 0x12, 0x19, 0x08, 0x9a, 0x96, 0x4b, 0xe6, 0x4d, 0x43, 0x68, 0x19, 0xd6, + 0x04, 0x09, 0x68, 0x4a, 0x09, 0x33, 0xe3, 0xa8, 0x79, 0x25, 0xa0, 0x2f, 0x25, 0x4e, 0xf2, 0xbb, + 0x3e, 0x93, 0xbb, 0xac, 0x85, 0xea, 0x70, 0x2e, 0x34, 0x85, 0xeb, 0xb3, 0xb9, 0x63, 0x62, 0xae, + 0x3b, 0x9a, 0xf7, 0x4f, 0x07, 0x9d, 0x86, 0x95, 0x27, 0xe2, 0xe3, 0x42, 0x9d, 0x3e, 0x67, 0x4a, + 0x2f, 0xcf, 0x47, 0x8f, 0x8f, 0x9a, 0xe0, 0xc9, 0x51, 0x13, 0x3c, 0x3d, 0x6a, 0x82, 0x3f, 0x8f, + 0x9a, 0xe0, 0xeb, 0xe3, 0x66, 0xe5, 0xe9, 0x71, 0xb3, 0xf2, 0xdb, 0x71, 0xb3, 0xf2, 0xd9, 0xdd, + 0x29, 0xcd, 0xec, 0x5e, 0x76, 0x46, 0xd9, 0xb0, 0xf8, 0x22, 0x79, 0xee, 0xd5, 0x99, 0x8b, 0x38, + 0xac, 0xe6, 0xdf, 0x00, 0x77, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x06, 0xfe, 0x2d, 0x7a, 0xb8, + 0x08, 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.CommunityTax.Equal(that1.CommunityTax) { + return false + } + if this.WithdrawAddrEnabled != that1.WithdrawAddrEnabled { + return false + } + return true +} +func (this *ValidatorHistoricalRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorHistoricalRewards) + if !ok { + that2, ok := that.(ValidatorHistoricalRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.CumulativeRewardRatio) != len(that1.CumulativeRewardRatio) { + return false + } + for i := range this.CumulativeRewardRatio { + if !this.CumulativeRewardRatio[i].Equal(&that1.CumulativeRewardRatio[i]) { + return false + } + } + if this.ReferenceCount != that1.ReferenceCount { + return false + } + return true +} +func (this *ValidatorCurrentRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorCurrentRewards) + if !ok { + that2, ok := that.(ValidatorCurrentRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Rewards) != len(that1.Rewards) { + return false + } + for i := range this.Rewards { + if !this.Rewards[i].Equal(&that1.Rewards[i]) { + return false + } + } + if this.Period != that1.Period { + return false + } + return true +} +func (this *ValidatorAccumulatedCommission) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorAccumulatedCommission) + if !ok { + that2, ok := that.(ValidatorAccumulatedCommission) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Commission) != len(that1.Commission) { + return false + } + for i := range this.Commission { + if !this.Commission[i].Equal(&that1.Commission[i]) { + return false + } + } + return true +} +func (this *ValidatorOutstandingRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorOutstandingRewards) + if !ok { + that2, ok := that.(ValidatorOutstandingRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Rewards) != len(that1.Rewards) { + return false + } + for i := range this.Rewards { + if !this.Rewards[i].Equal(&that1.Rewards[i]) { + return false + } + } + return true +} +func (this *ValidatorSlashEvent) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSlashEvent) + if !ok { + that2, ok := that.(ValidatorSlashEvent) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ValidatorPeriod != that1.ValidatorPeriod { + return false + } + if !this.Fraction.Equal(that1.Fraction) { + return false + } + return true +} +func (this *ValidatorSlashEvents) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSlashEvents) + if !ok { + that2, ok := that.(ValidatorSlashEvents) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.ValidatorSlashEvents) != len(that1.ValidatorSlashEvents) { + return false + } + for i := range this.ValidatorSlashEvents { + if !this.ValidatorSlashEvents[i].Equal(&that1.ValidatorSlashEvents[i]) { + return false + } + } + return true +} +func (this *FeePool) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*FeePool) + if !ok { + that2, ok := that.(FeePool) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.CommunityPool) != len(that1.CommunityPool) { + return false + } + for i := range this.CommunityPool { + if !this.CommunityPool[i].Equal(&that1.CommunityPool[i]) { + return false + } + } + return true +} +func (this *DelegatorStartingInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DelegatorStartingInfo) + if !ok { + that2, ok := that.(DelegatorStartingInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.PreviousPeriod != that1.PreviousPeriod { + return false + } + if !this.Stake.Equal(that1.Stake) { + return false + } + if this.Height != that1.Height { + return false + } + return true +} +func (this *DelegationDelegatorReward) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DelegationDelegatorReward) + if !ok { + that2, ok := that.(DelegationDelegatorReward) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ValidatorAddress != that1.ValidatorAddress { + return false + } + if len(this.Reward) != len(that1.Reward) { + return false + } + for i := range this.Reward { + if !this.Reward[i].Equal(&that1.Reward[i]) { + return false + } + } + return true +} +func (this *CommunityPoolSpendProposalWithDeposit) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*CommunityPoolSpendProposalWithDeposit) + if !ok { + that2, ok := that.(CommunityPoolSpendProposalWithDeposit) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if this.Recipient != that1.Recipient { + return false + } + if this.Amount != that1.Amount { + return false + } + if this.Deposit != that1.Deposit { + return false + } + return true +} +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawAddrEnabled { + i-- + if m.WithdrawAddrEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x20 + } + { + size := m.CommunityTax.Size() + i -= size + if _, err := m.CommunityTax.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ValidatorHistoricalRewards) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorHistoricalRewards) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorHistoricalRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ReferenceCount != 0 { + i = encodeVarintDistribution(dAtA, i, uint64(m.ReferenceCount)) + i-- + dAtA[i] = 0x10 + } + if len(m.CumulativeRewardRatio) > 0 { + for iNdEx := len(m.CumulativeRewardRatio) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CumulativeRewardRatio[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ValidatorCurrentRewards) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorCurrentRewards) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorCurrentRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Period != 0 { + i = encodeVarintDistribution(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x10 + } + if len(m.Rewards) > 0 { + for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ValidatorAccumulatedCommission) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorAccumulatedCommission) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorAccumulatedCommission) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Commission) > 0 { + for iNdEx := len(m.Commission) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Commission[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ValidatorOutstandingRewards) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorOutstandingRewards) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorOutstandingRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Rewards) > 0 { + for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSlashEvent) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSlashEvent) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSlashEvent) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Fraction.Size() + i -= size + if _, err := m.Fraction.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.ValidatorPeriod != 0 { + i = encodeVarintDistribution(dAtA, i, uint64(m.ValidatorPeriod)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSlashEvents) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSlashEvents) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSlashEvents) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorSlashEvents) > 0 { + for iNdEx := len(m.ValidatorSlashEvents) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorSlashEvents[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *FeePool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FeePool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeePool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CommunityPool) > 0 { + for iNdEx := len(m.CommunityPool) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CommunityPool[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *DelegatorStartingInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DelegatorStartingInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelegatorStartingInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintDistribution(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x18 + } + { + size := m.Stake.Size() + i -= size + if _, err := m.Stake.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.PreviousPeriod != 0 { + i = encodeVarintDistribution(dAtA, i, uint64(m.PreviousPeriod)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *DelegationDelegatorReward) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DelegationDelegatorReward) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelegationDelegatorReward) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Reward) > 0 { + for iNdEx := len(m.Reward) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Reward[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistribution(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CommunityPoolSpendProposalWithDeposit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CommunityPoolSpendProposalWithDeposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CommunityPoolSpendProposalWithDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Deposit) > 0 { + i -= len(m.Deposit) + copy(dAtA[i:], m.Deposit) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.Deposit))) + i-- + dAtA[i] = 0x2a + } + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x22 + } + if len(m.Recipient) > 0 { + i -= len(m.Recipient) + copy(dAtA[i:], m.Recipient) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.Recipient))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintDistribution(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintDistribution(dAtA []byte, offset int, v uint64) int { + offset -= sovDistribution(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.CommunityTax.Size() + n += 1 + l + sovDistribution(uint64(l)) + if m.WithdrawAddrEnabled { + n += 2 + } + return n +} + +func (m *ValidatorHistoricalRewards) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CumulativeRewardRatio) > 0 { + for _, e := range m.CumulativeRewardRatio { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + if m.ReferenceCount != 0 { + n += 1 + sovDistribution(uint64(m.ReferenceCount)) + } + return n +} + +func (m *ValidatorCurrentRewards) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Rewards) > 0 { + for _, e := range m.Rewards { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + if m.Period != 0 { + n += 1 + sovDistribution(uint64(m.Period)) + } + return n +} + +func (m *ValidatorAccumulatedCommission) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Commission) > 0 { + for _, e := range m.Commission { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + return n +} + +func (m *ValidatorOutstandingRewards) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Rewards) > 0 { + for _, e := range m.Rewards { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + return n +} + +func (m *ValidatorSlashEvent) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ValidatorPeriod != 0 { + n += 1 + sovDistribution(uint64(m.ValidatorPeriod)) + } + l = m.Fraction.Size() + n += 1 + l + sovDistribution(uint64(l)) + return n +} + +func (m *ValidatorSlashEvents) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ValidatorSlashEvents) > 0 { + for _, e := range m.ValidatorSlashEvents { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + return n +} + +func (m *FeePool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CommunityPool) > 0 { + for _, e := range m.CommunityPool { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + return n +} + +func (m *DelegatorStartingInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PreviousPeriod != 0 { + n += 1 + sovDistribution(uint64(m.PreviousPeriod)) + } + l = m.Stake.Size() + n += 1 + l + sovDistribution(uint64(l)) + if m.Height != 0 { + n += 1 + sovDistribution(uint64(m.Height)) + } + return n +} + +func (m *DelegationDelegatorReward) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + if len(m.Reward) > 0 { + for _, e := range m.Reward { + l = e.Size() + n += 1 + l + sovDistribution(uint64(l)) + } + } + return n +} + +func (m *CommunityPoolSpendProposalWithDeposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + l = len(m.Recipient) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + l = len(m.Deposit) + if l > 0 { + n += 1 + l + sovDistribution(uint64(l)) + } + return n +} + +func sovDistribution(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDistribution(x uint64) (n int) { + return sovDistribution(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommunityTax", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CommunityTax.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawAddrEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.WithdrawAddrEnabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorHistoricalRewards) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorHistoricalRewards: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorHistoricalRewards: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CumulativeRewardRatio", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CumulativeRewardRatio = append(m.CumulativeRewardRatio, types.DecCoin{}) + if err := m.CumulativeRewardRatio[len(m.CumulativeRewardRatio)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReferenceCount", wireType) + } + m.ReferenceCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ReferenceCount |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorCurrentRewards) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorCurrentRewards: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorCurrentRewards: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Rewards = append(m.Rewards, types.DecCoin{}) + if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorAccumulatedCommission) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorAccumulatedCommission: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorAccumulatedCommission: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commission = append(m.Commission, types.DecCoin{}) + if err := m.Commission[len(m.Commission)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorOutstandingRewards) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorOutstandingRewards: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorOutstandingRewards: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Rewards = append(m.Rewards, types.DecCoin{}) + if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSlashEvent) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSlashEvent: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSlashEvent: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorPeriod", wireType) + } + m.ValidatorPeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ValidatorPeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Fraction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSlashEvents) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSlashEvents: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSlashEvents: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSlashEvents", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorSlashEvents = append(m.ValidatorSlashEvents, ValidatorSlashEvent{}) + if err := m.ValidatorSlashEvents[len(m.ValidatorSlashEvents)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *FeePool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FeePool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeePool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommunityPool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CommunityPool = append(m.CommunityPool, types.DecCoin{}) + if err := m.CommunityPool[len(m.CommunityPool)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DelegatorStartingInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DelegatorStartingInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelegatorStartingInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PreviousPeriod", wireType) + } + m.PreviousPeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PreviousPeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Stake", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Stake.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DelegationDelegatorReward) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DelegationDelegatorReward: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelegationDelegatorReward: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Reward", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Reward = append(m.Reward, types.DecCoin{}) + if err := m.Reward[len(m.Reward)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CommunityPoolSpendProposalWithDeposit) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CommunityPoolSpendProposalWithDeposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CommunityPoolSpendProposalWithDeposit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Recipient = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Deposit", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistribution + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistribution + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistribution + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Deposit = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistribution(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistribution + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDistribution(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDistribution + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDistribution + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDistribution + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDistribution + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDistribution + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDistribution + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDistribution = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDistribution = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDistribution = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/distribution/types/errors.go b/x/distribution/types/errors.go new file mode 100644 index 00000000..c39ca55a --- /dev/null +++ b/x/distribution/types/errors.go @@ -0,0 +1,19 @@ +package types + +import "cosmossdk.io/errors" + +// x/distribution module sentinel errors +var ( + ErrEmptyDelegatorAddr = errors.Register(ModuleName, 102, "delegator address is empty") + ErrEmptyWithdrawAddr = errors.Register(ModuleName, 103, "withdraw address is empty") + ErrEmptyValidatorAddr = errors.Register(ModuleName, 104, "validator address is empty") + ErrEmptyDelegationDistInfo = errors.Register(ModuleName, 105, "no delegation distribution info") + ErrNoValidatorDistInfo = errors.Register(ModuleName, 106, "no validator distribution info") + ErrNoValidatorCommission = errors.Register(ModuleName, 107, "no validator commission to withdraw") + ErrSetWithdrawAddrDisabled = errors.Register(ModuleName, 108, "set withdraw address disabled") + ErrBadDistribution = errors.Register(ModuleName, 109, "community pool does not have sufficient coins to distribute") + ErrInvalidProposalAmount = errors.Register(ModuleName, 110, "invalid community pool spend proposal amount") + ErrEmptyProposalRecipient = errors.Register(ModuleName, 211, "invalid community pool spend proposal recipient") + ErrNoValidatorExists = errors.Register(ModuleName, 212, "validator does not exist") + ErrNoDelegationExists = errors.Register(ModuleName, 213, "delegation does not exist") +) diff --git a/x/distribution/types/events.go b/x/distribution/types/events.go new file mode 100644 index 00000000..e0ea7069 --- /dev/null +++ b/x/distribution/types/events.go @@ -0,0 +1,15 @@ +package types + +// distribution module event types +const ( + EventTypeSetWithdrawAddress = "set_withdraw_address" + EventTypeRewards = "rewards" + EventTypeCommission = "commission" + EventTypeWithdrawRewards = "withdraw_rewards" + EventTypeWithdrawCommission = "withdraw_commission" + EventTypeProposerReward = "proposer_reward" + + AttributeKeyWithdrawAddress = "withdraw_address" + AttributeKeyValidator = "validator" + AttributeKeyDelegator = "delegator" +) diff --git a/x/distribution/types/expected_keepers.go b/x/distribution/types/expected_keepers.go new file mode 100644 index 00000000..f0690e09 --- /dev/null +++ b/x/distribution/types/expected_keepers.go @@ -0,0 +1,73 @@ +package types + +import ( + "context" + + "cosmossdk.io/core/address" + + sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// MintQueryServer defines the expected interface needed to retrieve AnnualProvisions (noalias) +type MintQueryServer interface { + AnnualProvisions(context.Context, *minttypes.QueryAnnualProvisionsRequest) (*minttypes.QueryAnnualProvisionsResponse, error) + Params(context.Context, *minttypes.QueryParamsRequest) (*minttypes.QueryParamsResponse, error) +} + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + AddressCodec() address.Codec + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(context.Context, sdk.ModuleAccountI) +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins + + SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins + + SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + + BlockedAddr(addr sdk.AccAddress) bool +} + +// StakingKeeper expected staking keeper (noalias) +type StakingKeeper interface { + ValidatorAddressCodec() address.Codec + ConsensusAddressCodec() address.Codec + // iterate through validators by operator address, execute func for each validator + IterateValidators(context.Context, + func(index int64, validator stakingtypes.ValidatorI) (stop bool)) error + + Validator(context.Context, sdk.ValAddress) (stakingtypes.ValidatorI, error) // get a particular validator by operator address + ValidatorByConsAddr(context.Context, sdk.ConsAddress) (stakingtypes.ValidatorI, error) // get a particular validator by consensus address + + // Delegation allows for getting a particular delegation for a given validator + // and delegator outside the scope of the staking module. + Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (stakingtypes.DelegationI, error) + + IterateDelegations(ctx context.Context, delegator sdk.AccAddress, + fn func(index int64, delegation stakingtypes.DelegationI) (stop bool)) error + + GetAllSDKDelegations(ctx context.Context) ([]stakingtypes.Delegation, error) + GetAllValidators(ctx context.Context) ([]stakingtypes.Validator, error) + GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]stakingtypes.Delegation, error) + + GetBondedValidatorsByPower(ctx context.Context) ([]stakingtypes.Validator, error) + + BondDenom(ctx context.Context) (string, error) +} + +// StakingHooks event hooks for staking validator object (noalias) +type StakingHooks interface { + AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress) error // Must be called when a validator is created + AfterDelegationModified(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error +} diff --git a/x/distribution/types/fee_pool.go b/x/distribution/types/fee_pool.go new file mode 100644 index 00000000..0c3f9a9f --- /dev/null +++ b/x/distribution/types/fee_pool.go @@ -0,0 +1,24 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// InitialFeePool returns a zero fee pool +func InitialFeePool() FeePool { + return FeePool{ + CommunityPool: sdk.DecCoins{}, + } +} + +// ValidateGenesis validates the fee pool for a genesis state +func (f FeePool) ValidateGenesis() error { + if f.CommunityPool.IsAnyNegative() { + return fmt.Errorf("negative CommunityPool in distribution fee pool, is %v", + f.CommunityPool) + } + + return nil +} diff --git a/x/distribution/types/fee_pool_test.go b/x/distribution/types/fee_pool_test.go new file mode 100644 index 00000000..cd4f2369 --- /dev/null +++ b/x/distribution/types/fee_pool_test.go @@ -0,0 +1,19 @@ +package types_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestValidateGenesis(t *testing.T) { + fp := types.InitialFeePool() + require.Nil(t, fp.ValidateGenesis()) + + fp2 := types.FeePool{CommunityPool: sdk.DecCoins{{Denom: "stake", Amount: math.LegacyNewDec(-1)}}} + require.NotNil(t, fp2.ValidateGenesis()) +} diff --git a/x/distribution/types/genesis.go b/x/distribution/types/genesis.go new file mode 100644 index 00000000..cbb79b47 --- /dev/null +++ b/x/distribution/types/genesis.go @@ -0,0 +1,55 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func NewGenesisState( + params Params, + fp FeePool, + dwis []DelegatorWithdrawInfo, + pp sdk.ConsAddress, + r []ValidatorOutstandingRewardsRecord, + acc []ValidatorAccumulatedCommissionRecord, + historical []ValidatorHistoricalRewardsRecord, + cur []ValidatorCurrentRewardsRecord, + dels []DelegatorStartingInfoRecord, + slashes []ValidatorSlashEventRecord, +) *GenesisState { + return &GenesisState{ + Params: params, + FeePool: fp, + DelegatorWithdrawInfos: dwis, + PreviousProposer: pp.String(), + OutstandingRewards: r, + ValidatorAccumulatedCommissions: acc, + ValidatorHistoricalRewards: historical, + ValidatorCurrentRewards: cur, + DelegatorStartingInfos: dels, + ValidatorSlashEvents: slashes, + } +} + +// DefaultGenesisState returns the default genesis state of distribution. +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + FeePool: InitialFeePool(), + Params: DefaultParams(), + DelegatorWithdrawInfos: []DelegatorWithdrawInfo{}, + PreviousProposer: "", + OutstandingRewards: []ValidatorOutstandingRewardsRecord{}, + ValidatorAccumulatedCommissions: []ValidatorAccumulatedCommissionRecord{}, + ValidatorHistoricalRewards: []ValidatorHistoricalRewardsRecord{}, + ValidatorCurrentRewards: []ValidatorCurrentRewardsRecord{}, + DelegatorStartingInfos: []DelegatorStartingInfoRecord{}, + ValidatorSlashEvents: []ValidatorSlashEventRecord{}, + } +} + +// ValidateGenesis validates the genesis state of distribution genesis input +func ValidateGenesis(gs *GenesisState) error { + if err := gs.Params.ValidateBasic(); err != nil { + return err + } + return gs.FeePool.ValidateGenesis() +} diff --git a/x/distribution/types/genesis.pb.go b/x/distribution/types/genesis.pb.go new file mode 100644 index 00000000..9fb3a406 --- /dev/null +++ b/x/distribution/types/genesis.pb.go @@ -0,0 +1,2479 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: atomone/distribution/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// DelegatorWithdrawInfo is the address for where distributions rewards are +// withdrawn to by default this struct is only used at genesis to feed in +// default withdraw addresses. +type DelegatorWithdrawInfo struct { + // delegator_address is the address of the delegator. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + // withdraw_address is the address to withdraw the delegation rewards to. + WithdrawAddress string `protobuf:"bytes,2,opt,name=withdraw_address,json=withdrawAddress,proto3" json:"withdraw_address,omitempty"` +} + +func (m *DelegatorWithdrawInfo) Reset() { *m = DelegatorWithdrawInfo{} } +func (m *DelegatorWithdrawInfo) String() string { return proto.CompactTextString(m) } +func (*DelegatorWithdrawInfo) ProtoMessage() {} +func (*DelegatorWithdrawInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{0} +} +func (m *DelegatorWithdrawInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelegatorWithdrawInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelegatorWithdrawInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DelegatorWithdrawInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelegatorWithdrawInfo.Merge(m, src) +} +func (m *DelegatorWithdrawInfo) XXX_Size() int { + return m.Size() +} +func (m *DelegatorWithdrawInfo) XXX_DiscardUnknown() { + xxx_messageInfo_DelegatorWithdrawInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_DelegatorWithdrawInfo proto.InternalMessageInfo + +// ValidatorOutstandingRewardsRecord is used for import/export via genesis json. +type ValidatorOutstandingRewardsRecord struct { + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // outstanding_rewards represents the outstanding rewards of a validator. + OutstandingRewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=outstanding_rewards,json=outstandingRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"outstanding_rewards"` +} + +func (m *ValidatorOutstandingRewardsRecord) Reset() { *m = ValidatorOutstandingRewardsRecord{} } +func (m *ValidatorOutstandingRewardsRecord) String() string { return proto.CompactTextString(m) } +func (*ValidatorOutstandingRewardsRecord) ProtoMessage() {} +func (*ValidatorOutstandingRewardsRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{1} +} +func (m *ValidatorOutstandingRewardsRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorOutstandingRewardsRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorOutstandingRewardsRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorOutstandingRewardsRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorOutstandingRewardsRecord.Merge(m, src) +} +func (m *ValidatorOutstandingRewardsRecord) XXX_Size() int { + return m.Size() +} +func (m *ValidatorOutstandingRewardsRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorOutstandingRewardsRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorOutstandingRewardsRecord proto.InternalMessageInfo + +// ValidatorAccumulatedCommissionRecord is used for import / export via genesis +// json. +type ValidatorAccumulatedCommissionRecord struct { + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // accumulated is the accumulated commission of a validator. + Accumulated ValidatorAccumulatedCommission `protobuf:"bytes,2,opt,name=accumulated,proto3" json:"accumulated"` +} + +func (m *ValidatorAccumulatedCommissionRecord) Reset() { *m = ValidatorAccumulatedCommissionRecord{} } +func (m *ValidatorAccumulatedCommissionRecord) String() string { return proto.CompactTextString(m) } +func (*ValidatorAccumulatedCommissionRecord) ProtoMessage() {} +func (*ValidatorAccumulatedCommissionRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{2} +} +func (m *ValidatorAccumulatedCommissionRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorAccumulatedCommissionRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorAccumulatedCommissionRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorAccumulatedCommissionRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorAccumulatedCommissionRecord.Merge(m, src) +} +func (m *ValidatorAccumulatedCommissionRecord) XXX_Size() int { + return m.Size() +} +func (m *ValidatorAccumulatedCommissionRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorAccumulatedCommissionRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorAccumulatedCommissionRecord proto.InternalMessageInfo + +// ValidatorHistoricalRewardsRecord is used for import / export via genesis +// json. +type ValidatorHistoricalRewardsRecord struct { + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // period defines the period the historical rewards apply to. + Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` + // rewards defines the historical rewards of a validator. + Rewards ValidatorHistoricalRewards `protobuf:"bytes,3,opt,name=rewards,proto3" json:"rewards"` +} + +func (m *ValidatorHistoricalRewardsRecord) Reset() { *m = ValidatorHistoricalRewardsRecord{} } +func (m *ValidatorHistoricalRewardsRecord) String() string { return proto.CompactTextString(m) } +func (*ValidatorHistoricalRewardsRecord) ProtoMessage() {} +func (*ValidatorHistoricalRewardsRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{3} +} +func (m *ValidatorHistoricalRewardsRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorHistoricalRewardsRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorHistoricalRewardsRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorHistoricalRewardsRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorHistoricalRewardsRecord.Merge(m, src) +} +func (m *ValidatorHistoricalRewardsRecord) XXX_Size() int { + return m.Size() +} +func (m *ValidatorHistoricalRewardsRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorHistoricalRewardsRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorHistoricalRewardsRecord proto.InternalMessageInfo + +// ValidatorCurrentRewardsRecord is used for import / export via genesis json. +type ValidatorCurrentRewardsRecord struct { + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // rewards defines the current rewards of a validator. + Rewards ValidatorCurrentRewards `protobuf:"bytes,2,opt,name=rewards,proto3" json:"rewards"` +} + +func (m *ValidatorCurrentRewardsRecord) Reset() { *m = ValidatorCurrentRewardsRecord{} } +func (m *ValidatorCurrentRewardsRecord) String() string { return proto.CompactTextString(m) } +func (*ValidatorCurrentRewardsRecord) ProtoMessage() {} +func (*ValidatorCurrentRewardsRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{4} +} +func (m *ValidatorCurrentRewardsRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorCurrentRewardsRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorCurrentRewardsRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorCurrentRewardsRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorCurrentRewardsRecord.Merge(m, src) +} +func (m *ValidatorCurrentRewardsRecord) XXX_Size() int { + return m.Size() +} +func (m *ValidatorCurrentRewardsRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorCurrentRewardsRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorCurrentRewardsRecord proto.InternalMessageInfo + +// DelegatorStartingInfoRecord used for import / export via genesis json. +type DelegatorStartingInfoRecord struct { + // delegator_address is the address of the delegator. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // starting_info defines the starting info of a delegator. + StartingInfo DelegatorStartingInfo `protobuf:"bytes,3,opt,name=starting_info,json=startingInfo,proto3" json:"starting_info"` +} + +func (m *DelegatorStartingInfoRecord) Reset() { *m = DelegatorStartingInfoRecord{} } +func (m *DelegatorStartingInfoRecord) String() string { return proto.CompactTextString(m) } +func (*DelegatorStartingInfoRecord) ProtoMessage() {} +func (*DelegatorStartingInfoRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{5} +} +func (m *DelegatorStartingInfoRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelegatorStartingInfoRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelegatorStartingInfoRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DelegatorStartingInfoRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelegatorStartingInfoRecord.Merge(m, src) +} +func (m *DelegatorStartingInfoRecord) XXX_Size() int { + return m.Size() +} +func (m *DelegatorStartingInfoRecord) XXX_DiscardUnknown() { + xxx_messageInfo_DelegatorStartingInfoRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_DelegatorStartingInfoRecord proto.InternalMessageInfo + +// ValidatorSlashEventRecord is used for import / export via genesis json. +type ValidatorSlashEventRecord struct { + // validator_address is the address of the validator. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // height defines the block height at which the slash event occurred. + Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + // period is the period of the slash event. + Period uint64 `protobuf:"varint,3,opt,name=period,proto3" json:"period,omitempty"` + // validator_slash_event describes the slash event. + ValidatorSlashEvent ValidatorSlashEvent `protobuf:"bytes,4,opt,name=validator_slash_event,json=validatorSlashEvent,proto3" json:"validator_slash_event"` +} + +func (m *ValidatorSlashEventRecord) Reset() { *m = ValidatorSlashEventRecord{} } +func (m *ValidatorSlashEventRecord) String() string { return proto.CompactTextString(m) } +func (*ValidatorSlashEventRecord) ProtoMessage() {} +func (*ValidatorSlashEventRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{6} +} +func (m *ValidatorSlashEventRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSlashEventRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSlashEventRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSlashEventRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSlashEventRecord.Merge(m, src) +} +func (m *ValidatorSlashEventRecord) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSlashEventRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSlashEventRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSlashEventRecord proto.InternalMessageInfo + +// GenesisState defines the distribution module's genesis state. +type GenesisState struct { + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // fee_pool defines the fee pool at genesis. + FeePool FeePool `protobuf:"bytes,2,opt,name=fee_pool,json=feePool,proto3" json:"fee_pool"` + // fee_pool defines the delegator withdraw infos at genesis. + DelegatorWithdrawInfos []DelegatorWithdrawInfo `protobuf:"bytes,3,rep,name=delegator_withdraw_infos,json=delegatorWithdrawInfos,proto3" json:"delegator_withdraw_infos"` + // fee_pool defines the previous proposer at genesis. + PreviousProposer string `protobuf:"bytes,4,opt,name=previous_proposer,json=previousProposer,proto3" json:"previous_proposer,omitempty"` + // fee_pool defines the outstanding rewards of all validators at genesis. + OutstandingRewards []ValidatorOutstandingRewardsRecord `protobuf:"bytes,5,rep,name=outstanding_rewards,json=outstandingRewards,proto3" json:"outstanding_rewards"` + // fee_pool defines the accumulated commissions of all validators at genesis. + ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissionRecord `protobuf:"bytes,6,rep,name=validator_accumulated_commissions,json=validatorAccumulatedCommissions,proto3" json:"validator_accumulated_commissions"` + // fee_pool defines the historical rewards of all validators at genesis. + ValidatorHistoricalRewards []ValidatorHistoricalRewardsRecord `protobuf:"bytes,7,rep,name=validator_historical_rewards,json=validatorHistoricalRewards,proto3" json:"validator_historical_rewards"` + // fee_pool defines the current rewards of all validators at genesis. + ValidatorCurrentRewards []ValidatorCurrentRewardsRecord `protobuf:"bytes,8,rep,name=validator_current_rewards,json=validatorCurrentRewards,proto3" json:"validator_current_rewards"` + // fee_pool defines the delegator starting infos at genesis. + DelegatorStartingInfos []DelegatorStartingInfoRecord `protobuf:"bytes,9,rep,name=delegator_starting_infos,json=delegatorStartingInfos,proto3" json:"delegator_starting_infos"` + // fee_pool defines the validator slash events at genesis. + ValidatorSlashEvents []ValidatorSlashEventRecord `protobuf:"bytes,10,rep,name=validator_slash_events,json=validatorSlashEvents,proto3" json:"validator_slash_events"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_7acf9190d444c000, []int{7} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*DelegatorWithdrawInfo)(nil), "atomone.distribution.v1beta1.DelegatorWithdrawInfo") + proto.RegisterType((*ValidatorOutstandingRewardsRecord)(nil), "atomone.distribution.v1beta1.ValidatorOutstandingRewardsRecord") + proto.RegisterType((*ValidatorAccumulatedCommissionRecord)(nil), "atomone.distribution.v1beta1.ValidatorAccumulatedCommissionRecord") + proto.RegisterType((*ValidatorHistoricalRewardsRecord)(nil), "atomone.distribution.v1beta1.ValidatorHistoricalRewardsRecord") + proto.RegisterType((*ValidatorCurrentRewardsRecord)(nil), "atomone.distribution.v1beta1.ValidatorCurrentRewardsRecord") + proto.RegisterType((*DelegatorStartingInfoRecord)(nil), "atomone.distribution.v1beta1.DelegatorStartingInfoRecord") + proto.RegisterType((*ValidatorSlashEventRecord)(nil), "atomone.distribution.v1beta1.ValidatorSlashEventRecord") + proto.RegisterType((*GenesisState)(nil), "atomone.distribution.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("atomone/distribution/v1beta1/genesis.proto", fileDescriptor_7acf9190d444c000) +} + +var fileDescriptor_7acf9190d444c000 = []byte{ + // 950 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x5f, 0x6b, 0x1d, 0x45, + 0x14, 0xbf, 0x7b, 0x53, 0xd3, 0x64, 0x52, 0xb1, 0x99, 0xa6, 0xf1, 0x26, 0xa6, 0xf7, 0x26, 0xa5, + 0x42, 0xa9, 0x64, 0x97, 0x24, 0x88, 0xf5, 0x0f, 0x8a, 0x37, 0xad, 0x55, 0x04, 0x8d, 0x09, 0x28, + 0x14, 0xe4, 0x32, 0x77, 0x77, 0xb2, 0x77, 0xf0, 0xee, 0xce, 0x32, 0x33, 0xbb, 0x89, 0x08, 0x3e, + 0xf8, 0x52, 0xc1, 0x17, 0x5f, 0x44, 0x7c, 0x2b, 0xf8, 0x52, 0x04, 0xc1, 0x87, 0x7e, 0x88, 0x3e, + 0x96, 0x82, 0xe0, 0x93, 0x4a, 0xf2, 0xa0, 0xe0, 0xa3, 0x5f, 0x40, 0x76, 0x66, 0x76, 0x77, 0x6e, + 0x76, 0xbb, 0x4d, 0x62, 0xef, 0x4b, 0x72, 0x67, 0xe6, 0xfc, 0xf9, 0xfd, 0xce, 0x39, 0x73, 0xce, + 0x2c, 0xb8, 0x86, 0x04, 0x0d, 0x68, 0x88, 0x1d, 0x8f, 0x70, 0xc1, 0x48, 0x3f, 0x16, 0x84, 0x86, + 0x4e, 0xb2, 0xd6, 0xc7, 0x02, 0xad, 0x39, 0x3e, 0x0e, 0x31, 0x27, 0xdc, 0x8e, 0x18, 0x15, 0x14, + 0x2e, 0x69, 0x59, 0xdb, 0x94, 0xb5, 0xb5, 0xec, 0xe2, 0x2c, 0x0a, 0x48, 0x48, 0x1d, 0xf9, 0x57, + 0x29, 0x2c, 0x3a, 0xb5, 0xc6, 0x47, 0xac, 0x28, 0x85, 0xb6, 0x4b, 0x79, 0x40, 0xb9, 0xd3, 0x47, + 0x1c, 0xe7, 0x72, 0x2e, 0x25, 0xd9, 0xf9, 0x82, 0x3a, 0xef, 0xc9, 0x95, 0xa3, 0x16, 0xfa, 0x68, + 0xce, 0xa7, 0x3e, 0x55, 0xfb, 0xe9, 0x2f, 0xb5, 0x7b, 0xf9, 0x67, 0x0b, 0x5c, 0xbc, 0x81, 0x87, + 0xd8, 0x47, 0x82, 0xb2, 0x4f, 0x88, 0x18, 0x78, 0x0c, 0xed, 0xbd, 0x17, 0xee, 0x52, 0x78, 0x13, + 0xcc, 0x7a, 0xd9, 0x41, 0x0f, 0x79, 0x1e, 0xc3, 0x9c, 0xb7, 0xac, 0x65, 0xeb, 0xea, 0x74, 0xb7, + 0xf5, 0xe8, 0xfe, 0xea, 0x9c, 0x36, 0xfe, 0xb6, 0x3a, 0xd9, 0x11, 0x8c, 0x84, 0xfe, 0xf6, 0xf9, + 0x5c, 0x45, 0xef, 0xc3, 0x4d, 0x70, 0x7e, 0x4f, 0x9b, 0xcd, 0xad, 0x34, 0x9f, 0x60, 0xe5, 0xb9, + 0x4c, 0x43, 0x6f, 0xbf, 0x36, 0xf5, 0xf5, 0xdd, 0x4e, 0xe3, 0xef, 0xbb, 0x9d, 0xc6, 0xe5, 0x3b, + 0x4d, 0xb0, 0xf2, 0x31, 0x1a, 0x12, 0x2f, 0xf5, 0xf1, 0x61, 0x2c, 0xb8, 0x40, 0xa1, 0x97, 0xea, + 0xe0, 0x3d, 0xc4, 0x3c, 0xbe, 0x8d, 0x5d, 0xca, 0x3c, 0xf8, 0x01, 0x98, 0x4d, 0x32, 0xa1, 0x23, + 0xd8, 0x57, 0x1e, 0xdd, 0x5f, 0xbd, 0xa4, 0xbd, 0xe6, 0x86, 0x8e, 0x90, 0x48, 0x8e, 0xec, 0xc3, + 0x3b, 0x16, 0xb8, 0x40, 0x0b, 0x67, 0x3d, 0xa6, 0xbc, 0xb5, 0x9a, 0xcb, 0x13, 0x57, 0x67, 0xd6, + 0x97, 0x6c, 0x6d, 0x2f, 0xcd, 0x4a, 0x96, 0x6e, 0xfb, 0x06, 0x76, 0x37, 0x29, 0x09, 0xbb, 0xd7, + 0x1f, 0xfc, 0xde, 0x69, 0xfc, 0xf4, 0x47, 0xe7, 0x25, 0x9f, 0x88, 0x41, 0xdc, 0xb7, 0x5d, 0x1a, + 0xe8, 0xc4, 0xe8, 0x7f, 0xab, 0xdc, 0xfb, 0xcc, 0x11, 0x9f, 0x47, 0x98, 0x67, 0x3a, 0xfc, 0xde, + 0x5f, 0xbf, 0x5c, 0xb3, 0xb6, 0x21, 0x2d, 0xf1, 0x33, 0x22, 0xf1, 0x8f, 0x05, 0xae, 0x14, 0x04, + 0x5c, 0x37, 0x0e, 0xe2, 0x21, 0x12, 0xd8, 0xdb, 0xa4, 0x41, 0x40, 0x38, 0x27, 0x34, 0x1c, 0x53, + 0x30, 0x08, 0x98, 0x41, 0x85, 0x3b, 0x99, 0xcc, 0x99, 0xf5, 0x37, 0xec, 0xba, 0xda, 0xb7, 0xeb, + 0x81, 0x76, 0xa7, 0xd3, 0x18, 0x29, 0xd2, 0xa6, 0x6d, 0x83, 0xed, 0xbf, 0x16, 0x58, 0xce, 0x8d, + 0xbc, 0x4b, 0xb8, 0xa0, 0x8c, 0xb8, 0x68, 0x38, 0xde, 0xb4, 0xcf, 0x83, 0xc9, 0x08, 0x33, 0x42, + 0x15, 0xc9, 0x33, 0xdb, 0x7a, 0x05, 0x3f, 0x05, 0x67, 0xb3, 0x0a, 0x98, 0x90, 0xec, 0xaf, 0x1f, + 0x93, 0x7d, 0x09, 0xb8, 0xc9, 0x3c, 0xb3, 0x69, 0xb0, 0xfe, 0xd5, 0x02, 0x97, 0x72, 0xe5, 0xcd, + 0x98, 0x31, 0x1c, 0x8a, 0xf1, 0x52, 0xbe, 0x5d, 0x50, 0x53, 0x89, 0x7d, 0xf9, 0x98, 0xd4, 0x46, + 0xd1, 0x3d, 0x81, 0xd7, 0x8f, 0x4d, 0xf0, 0x42, 0xde, 0x75, 0x76, 0x04, 0x62, 0x82, 0x84, 0x7e, + 0xda, 0x75, 0x34, 0xab, 0xa7, 0xd4, 0x7b, 0x2a, 0x83, 0xd3, 0x3c, 0x7d, 0x70, 0x5c, 0xf0, 0x2c, + 0xd7, 0x60, 0x7b, 0x24, 0xdc, 0xa5, 0x3a, 0xfb, 0x1b, 0xf5, 0x21, 0xaa, 0x24, 0x6a, 0x06, 0xe8, + 0x1c, 0x37, 0x0e, 0x8c, 0x28, 0x7d, 0xdf, 0x04, 0x0b, 0x39, 0xb6, 0x9d, 0x21, 0xe2, 0x83, 0x9b, + 0x89, 0x0c, 0xf1, 0xb8, 0x8a, 0x7d, 0x80, 0x89, 0x3f, 0x10, 0x59, 0xb1, 0xab, 0x95, 0x71, 0x09, + 0x26, 0x46, 0x2e, 0x41, 0x04, 0x2e, 0x16, 0xfe, 0x79, 0x8a, 0xae, 0x87, 0x53, 0x78, 0xad, 0x33, + 0x32, 0x28, 0x6b, 0xc7, 0xac, 0x9b, 0x82, 0x97, 0x19, 0x92, 0x0b, 0x49, 0xf9, 0xdc, 0x88, 0xcc, + 0x77, 0xd3, 0xe0, 0xdc, 0x2d, 0x35, 0x7a, 0x77, 0x04, 0x12, 0x18, 0xde, 0x02, 0x93, 0x11, 0x62, + 0x28, 0x50, 0x11, 0x98, 0x59, 0xbf, 0x52, 0xef, 0x7d, 0x4b, 0xca, 0x9a, 0x0e, 0xb5, 0x3a, 0x7c, + 0x1f, 0x4c, 0xed, 0x62, 0xdc, 0x8b, 0x28, 0x1d, 0xea, 0x0b, 0xf0, 0x62, 0xbd, 0xa9, 0x77, 0x30, + 0xde, 0xa2, 0x74, 0x38, 0x52, 0xf0, 0xbb, 0x6a, 0x0f, 0xee, 0x83, 0x56, 0x51, 0xc6, 0xf9, 0x14, + 0x4c, 0x2b, 0x27, 0x6d, 0x1c, 0x13, 0x27, 0x28, 0x1d, 0x73, 0x32, 0x9b, 0xae, 0xe6, 0xbd, 0x2a, + 0x09, 0x9e, 0x5e, 0xa0, 0x88, 0xe1, 0x84, 0xd0, 0x58, 0xbe, 0x05, 0x22, 0xca, 0x31, 0x93, 0x89, + 0xa9, 0xbd, 0x40, 0x99, 0xca, 0x96, 0xd6, 0x80, 0x5f, 0x54, 0x8f, 0xbd, 0x67, 0x24, 0xf6, 0xb7, + 0x8e, 0x99, 0xe1, 0xc7, 0x4d, 0x69, 0x93, 0x47, 0xc5, 0xa8, 0x83, 0x3f, 0x58, 0x60, 0xc5, 0xa8, + 0xf0, 0x62, 0x2c, 0xf4, 0xdc, 0x7c, 0x72, 0xf0, 0xd6, 0xa4, 0xc4, 0xd2, 0xfd, 0x3f, 0xe3, 0xa7, + 0x0c, 0xa7, 0x93, 0xd4, 0x2a, 0x70, 0xf8, 0x8d, 0x05, 0x96, 0x0a, 0x6c, 0x83, 0xbc, 0xad, 0xe7, + 0x21, 0x3a, 0x2b, 0x61, 0xbd, 0x79, 0xda, 0xb9, 0x50, 0x86, 0xb4, 0x98, 0x3c, 0x56, 0x18, 0x7e, + 0x65, 0x81, 0x85, 0x02, 0x8d, 0xab, 0x3a, 0x71, 0x0e, 0x65, 0x4a, 0x42, 0x79, 0xfd, 0x54, 0x7d, + 0xbc, 0x8c, 0xe3, 0xf9, 0xa4, 0x5a, 0x12, 0x7e, 0x69, 0x16, 0xfb, 0x48, 0x9b, 0xe4, 0xad, 0x69, + 0x09, 0xe1, 0xd5, 0x53, 0xf4, 0xc9, 0x32, 0x80, 0xa2, 0xe4, 0x4d, 0x39, 0x0e, 0xf7, 0xc1, 0x7c, + 0x65, 0x3f, 0xe2, 0x2d, 0x20, 0xbd, 0xbf, 0x72, 0xe2, 0x86, 0x54, 0xf6, 0x3d, 0x57, 0xd1, 0x96, + 0x8c, 0xb9, 0xd6, 0xfd, 0xe8, 0xde, 0x41, 0xdb, 0x7a, 0x70, 0xd0, 0xb6, 0x1e, 0x1e, 0xb4, 0xad, + 0x3f, 0x0f, 0xda, 0xd6, 0xb7, 0x87, 0xed, 0xc6, 0xc3, 0xc3, 0x76, 0xe3, 0xb7, 0xc3, 0x76, 0xe3, + 0xf6, 0x86, 0xf1, 0x02, 0xd4, 0x58, 0x56, 0x07, 0x71, 0x3f, 0xff, 0x08, 0xd8, 0x1f, 0xfd, 0x0c, + 0x90, 0x4f, 0xc2, 0xfe, 0xa4, 0x7c, 0xa7, 0x6f, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0xd5, 0x03, + 0xa3, 0xf1, 0x88, 0x0c, 0x00, 0x00, +} + +func (m *DelegatorWithdrawInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DelegatorWithdrawInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelegatorWithdrawInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WithdrawAddress) > 0 { + i -= len(m.WithdrawAddress) + copy(dAtA[i:], m.WithdrawAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.WithdrawAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorOutstandingRewardsRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorOutstandingRewardsRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorOutstandingRewardsRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.OutstandingRewards) > 0 { + for iNdEx := len(m.OutstandingRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OutstandingRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorAccumulatedCommissionRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorAccumulatedCommissionRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorAccumulatedCommissionRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Accumulated.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorHistoricalRewardsRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorHistoricalRewardsRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorHistoricalRewardsRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Rewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Period != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x10 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorCurrentRewardsRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorCurrentRewardsRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorCurrentRewardsRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Rewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DelegatorStartingInfoRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DelegatorStartingInfoRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelegatorStartingInfoRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.StartingInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSlashEventRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSlashEventRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSlashEventRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ValidatorSlashEvent.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if m.Period != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x18 + } + if m.Height != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorSlashEvents) > 0 { + for iNdEx := len(m.ValidatorSlashEvents) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorSlashEvents[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } + } + if len(m.DelegatorStartingInfos) > 0 { + for iNdEx := len(m.DelegatorStartingInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatorStartingInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + } + if len(m.ValidatorCurrentRewards) > 0 { + for iNdEx := len(m.ValidatorCurrentRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorCurrentRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + } + if len(m.ValidatorHistoricalRewards) > 0 { + for iNdEx := len(m.ValidatorHistoricalRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorHistoricalRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + } + if len(m.ValidatorAccumulatedCommissions) > 0 { + for iNdEx := len(m.ValidatorAccumulatedCommissions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorAccumulatedCommissions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.OutstandingRewards) > 0 { + for iNdEx := len(m.OutstandingRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OutstandingRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.PreviousProposer) > 0 { + i -= len(m.PreviousProposer) + copy(dAtA[i:], m.PreviousProposer) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PreviousProposer))) + i-- + dAtA[i] = 0x22 + } + if len(m.DelegatorWithdrawInfos) > 0 { + for iNdEx := len(m.DelegatorWithdrawInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatorWithdrawInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.FeePool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DelegatorWithdrawInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.WithdrawAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *ValidatorOutstandingRewardsRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.OutstandingRewards) > 0 { + for _, e := range m.OutstandingRewards { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *ValidatorAccumulatedCommissionRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Accumulated.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *ValidatorHistoricalRewardsRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovGenesis(uint64(m.Period)) + } + l = m.Rewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *ValidatorCurrentRewardsRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Rewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *DelegatorStartingInfoRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.StartingInfo.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *ValidatorSlashEventRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovGenesis(uint64(m.Height)) + } + if m.Period != 0 { + n += 1 + sovGenesis(uint64(m.Period)) + } + l = m.ValidatorSlashEvent.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.FeePool.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.DelegatorWithdrawInfos) > 0 { + for _, e := range m.DelegatorWithdrawInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = len(m.PreviousProposer) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.OutstandingRewards) > 0 { + for _, e := range m.OutstandingRewards { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorAccumulatedCommissions) > 0 { + for _, e := range m.ValidatorAccumulatedCommissions { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorHistoricalRewards) > 0 { + for _, e := range m.ValidatorHistoricalRewards { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorCurrentRewards) > 0 { + for _, e := range m.ValidatorCurrentRewards { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.DelegatorStartingInfos) > 0 { + for _, e := range m.DelegatorStartingInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorSlashEvents) > 0 { + for _, e := range m.ValidatorSlashEvents { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DelegatorWithdrawInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DelegatorWithdrawInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelegatorWithdrawInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WithdrawAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorOutstandingRewardsRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorOutstandingRewardsRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorOutstandingRewardsRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutstandingRewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OutstandingRewards = append(m.OutstandingRewards, types.DecCoin{}) + if err := m.OutstandingRewards[len(m.OutstandingRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorAccumulatedCommissionRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorAccumulatedCommissionRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorAccumulatedCommissionRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Accumulated", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Accumulated.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorHistoricalRewardsRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorHistoricalRewardsRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorHistoricalRewardsRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Rewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorCurrentRewardsRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorCurrentRewardsRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorCurrentRewardsRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Rewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DelegatorStartingInfoRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DelegatorStartingInfoRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelegatorStartingInfoRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartingInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.StartingInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSlashEventRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSlashEventRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSlashEventRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSlashEvent", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ValidatorSlashEvent.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeePool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FeePool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorWithdrawInfos", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorWithdrawInfos = append(m.DelegatorWithdrawInfos, DelegatorWithdrawInfo{}) + if err := m.DelegatorWithdrawInfos[len(m.DelegatorWithdrawInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PreviousProposer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PreviousProposer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutstandingRewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OutstandingRewards = append(m.OutstandingRewards, ValidatorOutstandingRewardsRecord{}) + if err := m.OutstandingRewards[len(m.OutstandingRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAccumulatedCommissions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAccumulatedCommissions = append(m.ValidatorAccumulatedCommissions, ValidatorAccumulatedCommissionRecord{}) + if err := m.ValidatorAccumulatedCommissions[len(m.ValidatorAccumulatedCommissions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorHistoricalRewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorHistoricalRewards = append(m.ValidatorHistoricalRewards, ValidatorHistoricalRewardsRecord{}) + if err := m.ValidatorHistoricalRewards[len(m.ValidatorHistoricalRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCurrentRewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorCurrentRewards = append(m.ValidatorCurrentRewards, ValidatorCurrentRewardsRecord{}) + if err := m.ValidatorCurrentRewards[len(m.ValidatorCurrentRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorStartingInfos", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorStartingInfos = append(m.DelegatorStartingInfos, DelegatorStartingInfoRecord{}) + if err := m.DelegatorStartingInfos[len(m.DelegatorStartingInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSlashEvents", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorSlashEvents = append(m.ValidatorSlashEvents, ValidatorSlashEventRecord{}) + if err := m.ValidatorSlashEvents[len(m.ValidatorSlashEvents)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/distribution/types/keys.go b/x/distribution/types/keys.go new file mode 100644 index 00000000..30aa8923 --- /dev/null +++ b/x/distribution/types/keys.go @@ -0,0 +1,218 @@ +package types + +import ( + "encoding/binary" + + "cosmossdk.io/collections" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/types/kv" +) + +const ( + // ModuleName is the module name constant used in many places + ModuleName = "distribution" + + // StoreKey is the store key string for distribution + StoreKey = ModuleName + + // RouterKey is the message route for distribution + RouterKey = ModuleName +) + +// Keys for distribution store +// Items are stored with the following key: values +// +// - 0x00: FeePol +// +// - 0x01: sdk.ConsAddress +// +// - 0x02: ValidatorOutstandingRewards +// +// - 0x03: sdk.AccAddress +// +// - 0x04: DelegatorStartingInfo +// +// - 0x05: ValidatorHistoricalRewards +// +// - 0x06: ValidatorCurrentRewards +// +// - 0x07: ValidatorCurrentCommission +// +// - 0x08: ValidatorSlashEvent +// +// - 0x09: Params +var ( + FeePoolKey = collections.NewPrefix(0) // key for global distribution state + ProposerKey = []byte{0x01} // key for the proposer operator address + ValidatorOutstandingRewardsPrefix = []byte{0x02} // key for outstanding rewards + + DelegatorWithdrawAddrPrefix = []byte{0x03} // key for delegator withdraw address + DelegatorStartingInfoPrefix = []byte{0x04} // key for delegator starting info + ValidatorHistoricalRewardsPrefix = []byte{0x05} // key for historical validators rewards / stake + ValidatorCurrentRewardsPrefix = []byte{0x06} // key for current validator rewards + ValidatorAccumulatedCommissionPrefix = []byte{0x07} // key for accumulated validator commission + ValidatorSlashEventPrefix = []byte{0x08} // key for validator slash fraction + + ParamsKey = collections.NewPrefix(9) // key for distribution module params +) + +// GetValidatorOutstandingRewardsAddress creates an address from a validator's outstanding rewards key. +func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress) { + // key is in the format: + // 0x02 + + // Remove prefix and address length. + kv.AssertKeyAtLeastLength(key, 3) + addr := key[2:] + kv.AssertKeyLength(addr, int(key[1])) + + return sdk.ValAddress(addr) +} + +// GetDelegatorWithdrawInfoAddress creates an address from a delegator's withdraw info key. +func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) { + // key is in the format: + // 0x03 + + // Remove prefix and address length. + kv.AssertKeyAtLeastLength(key, 3) + addr := key[2:] + kv.AssertKeyLength(addr, int(key[1])) + + return sdk.AccAddress(addr) +} + +// GetDelegatorStartingInfoAddresses creates the addresses from a delegator starting info key. +func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) { + // key is in the format: + // 0x04 + kv.AssertKeyAtLeastLength(key, 2) + valAddrLen := int(key[1]) + kv.AssertKeyAtLeastLength(key, 3+valAddrLen) + valAddr = sdk.ValAddress(key[2 : 2+valAddrLen]) + delAddrLen := int(key[2+valAddrLen]) + kv.AssertKeyAtLeastLength(key, 4+valAddrLen) + delAddr = sdk.AccAddress(key[3+valAddrLen:]) + kv.AssertKeyLength(delAddr.Bytes(), delAddrLen) + + return +} + +// GetValidatorHistoricalRewardsAddressPeriod creates the address & period from a validator's historical rewards key. +func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) { + // key is in the format: + // 0x05 + kv.AssertKeyAtLeastLength(key, 2) + valAddrLen := int(key[1]) + kv.AssertKeyAtLeastLength(key, 3+valAddrLen) + valAddr = sdk.ValAddress(key[2 : 2+valAddrLen]) + b := key[2+valAddrLen:] + kv.AssertKeyLength(b, 8) + period = binary.LittleEndian.Uint64(b) + return +} + +// GetValidatorCurrentRewardsAddress creates the address from a validator's current rewards key. +func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) { + // key is in the format: + // 0x06: ValidatorCurrentRewards + + // Remove prefix and address length. + kv.AssertKeyAtLeastLength(key, 3) + addr := key[2:] + kv.AssertKeyLength(addr, int(key[1])) + + return sdk.ValAddress(addr) +} + +// GetValidatorAccumulatedCommissionAddress creates the address from a validator's accumulated commission key. +func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) { + // key is in the format: + // 0x07: ValidatorCurrentRewards + + // Remove prefix and address length. + kv.AssertKeyAtLeastLength(key, 3) + addr := key[2:] + kv.AssertKeyLength(addr, int(key[1])) + + return sdk.ValAddress(addr) +} + +// GetValidatorSlashEventAddressHeight creates the height from a validator's slash event key. +func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) { + // key is in the format: + // 0x08: ValidatorSlashEvent + kv.AssertKeyAtLeastLength(key, 2) + valAddrLen := int(key[1]) + kv.AssertKeyAtLeastLength(key, 3+valAddrLen) + valAddr = key[2 : 2+valAddrLen] + startB := 2 + valAddrLen + kv.AssertKeyAtLeastLength(key, startB+9) + b := key[startB : startB+8] // the next 8 bytes represent the height + height = binary.BigEndian.Uint64(b) + return +} + +// GetValidatorOutstandingRewardsKey creates the outstanding rewards key for a validator. +func GetValidatorOutstandingRewardsKey(valAddr sdk.ValAddress) []byte { + return append(ValidatorOutstandingRewardsPrefix, address.MustLengthPrefix(valAddr.Bytes())...) +} + +// GetDelegatorWithdrawAddrKey creates the key for a delegator's withdraw addr. +func GetDelegatorWithdrawAddrKey(delAddr sdk.AccAddress) []byte { + return append(DelegatorWithdrawAddrPrefix, address.MustLengthPrefix(delAddr.Bytes())...) +} + +// GetDelegatorStartingInfoKey creates the key for a delegator's starting info. +func GetDelegatorStartingInfoKey(v sdk.ValAddress, d sdk.AccAddress) []byte { + return append(append(DelegatorStartingInfoPrefix, address.MustLengthPrefix(v.Bytes())...), address.MustLengthPrefix(d.Bytes())...) +} + +// GetValidatorHistoricalRewardsPrefix creates the prefix key for a validator's historical rewards. +func GetValidatorHistoricalRewardsPrefix(v sdk.ValAddress) []byte { + return append(ValidatorHistoricalRewardsPrefix, address.MustLengthPrefix(v.Bytes())...) +} + +// GetValidatorHistoricalRewardsKey creates the key for a validator's historical rewards. +func GetValidatorHistoricalRewardsKey(v sdk.ValAddress, k uint64) []byte { + b := make([]byte, 8) + binary.LittleEndian.PutUint64(b, k) + return append(append(ValidatorHistoricalRewardsPrefix, address.MustLengthPrefix(v.Bytes())...), b...) +} + +// GetValidatorCurrentRewardsKey creates the key for a validator's current rewards. +func GetValidatorCurrentRewardsKey(v sdk.ValAddress) []byte { + return append(ValidatorCurrentRewardsPrefix, address.MustLengthPrefix(v.Bytes())...) +} + +// GetValidatorAccumulatedCommissionKey creates the key for a validator's current commission. +func GetValidatorAccumulatedCommissionKey(v sdk.ValAddress) []byte { + return append(ValidatorAccumulatedCommissionPrefix, address.MustLengthPrefix(v.Bytes())...) +} + +// GetValidatorSlashEventPrefix creates the prefix key for a validator's slash fractions. +func GetValidatorSlashEventPrefix(v sdk.ValAddress) []byte { + return append(ValidatorSlashEventPrefix, address.MustLengthPrefix(v.Bytes())...) +} + +// GetValidatorSlashEventKeyPrefix creates the prefix key for a validator's slash fraction (ValidatorSlashEventPrefix + height). +func GetValidatorSlashEventKeyPrefix(v sdk.ValAddress, height uint64) []byte { + heightBz := make([]byte, 8) + binary.BigEndian.PutUint64(heightBz, height) + + return append( + ValidatorSlashEventPrefix, + append(address.MustLengthPrefix(v.Bytes()), heightBz...)..., + ) +} + +// GetValidatorSlashEventKey creates the key for a validator's slash fraction. +func GetValidatorSlashEventKey(v sdk.ValAddress, height, period uint64) []byte { + periodBz := make([]byte, 8) + binary.BigEndian.PutUint64(periodBz, period) + prefix := GetValidatorSlashEventKeyPrefix(v, height) + + return append(prefix, periodBz...) +} diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go new file mode 100644 index 00000000..231e86bd --- /dev/null +++ b/x/distribution/types/msg.go @@ -0,0 +1,54 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Verify interface at compile time +var ( + _ sdk.Msg = (*MsgSetWithdrawAddress)(nil) + _ sdk.Msg = (*MsgWithdrawDelegatorReward)(nil) + _ sdk.Msg = (*MsgWithdrawValidatorCommission)(nil) + _ sdk.Msg = (*MsgUpdateParams)(nil) + _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) + _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) +) + +func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { + return &MsgSetWithdrawAddress{ + DelegatorAddress: delAddr.String(), + WithdrawAddress: withdrawAddr.String(), + } +} + +func NewMsgWithdrawDelegatorReward(delAddr, valAddr string) *MsgWithdrawDelegatorReward { + return &MsgWithdrawDelegatorReward{ + DelegatorAddress: delAddr, + ValidatorAddress: valAddr, + } +} + +func NewMsgWithdrawValidatorCommission(valAddr string) *MsgWithdrawValidatorCommission { + return &MsgWithdrawValidatorCommission{ + ValidatorAddress: valAddr, + } +} + +// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and +// a funding amount. +func NewMsgFundCommunityPool(amount sdk.Coins, depositor string) *MsgFundCommunityPool { + return &MsgFundCommunityPool{ + Amount: amount, + Depositor: depositor, + } +} + +// NewMsgDepositValidatorRewardsPool returns a new MsgDepositValidatorRewardsPool +// with a depositor and a funding amount. +func NewMsgDepositValidatorRewardsPool(depositor, valAddr string, amount sdk.Coins) *MsgDepositValidatorRewardsPool { + return &MsgDepositValidatorRewardsPool{ + Amount: amount, + Depositor: depositor, + ValidatorAddress: valAddr, + } +} diff --git a/x/distribution/types/params.go b/x/distribution/types/params.go new file mode 100644 index 00000000..65ac9c77 --- /dev/null +++ b/x/distribution/types/params.go @@ -0,0 +1,48 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" +) + +// DefaultParams returns default distribution parameters +func DefaultParams() Params { + return Params{ + CommunityTax: math.LegacyNewDecWithPrec(2, 2), // 2% + WithdrawAddrEnabled: true, + } +} + +// ValidateBasic performs basic validation on distribution parameters. +func (p Params) ValidateBasic() error { + return validateCommunityTax(p.CommunityTax) +} + +func validateCommunityTax(i interface{}) error { + v, ok := i.(math.LegacyDec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNil() { + return fmt.Errorf("community tax must be not nil") + } + if v.IsNegative() { + return fmt.Errorf("community tax must be positive: %s", v) + } + if v.GT(math.LegacyOneDec()) { + return fmt.Errorf("community tax too large: %s", v) + } + + return nil +} + +func validateWithdrawAddrEnabled(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/x/distribution/types/params_internal_test.go b/x/distribution/types/params_internal_test.go new file mode 100644 index 00000000..21bfd0f1 --- /dev/null +++ b/x/distribution/types/params_internal_test.go @@ -0,0 +1,31 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/math" +) + +func Test_validateAuxFuncs(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + {"wrong type", args{10.5}, true}, + {"empty math.LegacyDec", args{math.LegacyDec{}}, true}, + {"negative", args{math.LegacyNewDec(-1)}, true}, + {"one dec", args{math.LegacyNewDec(1)}, false}, + {"two dec", args{math.LegacyNewDec(2)}, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.wantErr, validateCommunityTax(tt.args.i) != nil) + }) + } +} diff --git a/x/distribution/types/params_legacy.go b/x/distribution/types/params_legacy.go new file mode 100644 index 00000000..4805e8bd --- /dev/null +++ b/x/distribution/types/params_legacy.go @@ -0,0 +1,22 @@ +package types + +import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + +// Parameter keys +var ( + ParamStoreKeyCommunityTax = []byte("communitytax") + ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled") +) + +// Deprecated: ParamKeyTable returns the parameter key table. +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// Deprecated: ParamSetPairs returns the parameter set pairs. +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), + paramtypes.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled), + } +} diff --git a/x/distribution/types/params_test.go b/x/distribution/types/params_test.go new file mode 100644 index 00000000..cab90507 --- /dev/null +++ b/x/distribution/types/params_test.go @@ -0,0 +1,49 @@ +package types_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + "github.com/stretchr/testify/require" + + "github.com/atomone-hub/atomone/x/distribution/types" +) + +func TestParams_ValidateBasic(t *testing.T) { + toDec := sdkmath.LegacyMustNewDecFromStr + + type fields struct { + CommunityTax sdkmath.LegacyDec + BaseProposerReward sdkmath.LegacyDec + BonusProposerReward sdkmath.LegacyDec + WithdrawAddrEnabled bool + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"success", fields{toDec("0.1"), toDec("0"), toDec("0"), false}, false}, + {"negative community tax", fields{toDec("-0.1"), toDec("0"), toDec("0"), false}, true}, + {"negative base proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, + {"negative bonus proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, + {"total sum greater than 1 (must not matter)", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, false}, + {"community tax greater than 1", fields{toDec("1.1"), toDec("0"), toDec("0"), false}, true}, + {"community tax nil", fields{sdkmath.LegacyDec{}, toDec("0"), toDec("0"), false}, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := types.Params{ + CommunityTax: tt.fields.CommunityTax, + WithdrawAddrEnabled: tt.fields.WithdrawAddrEnabled, + } + if err := p.ValidateBasic(); (err != nil) != tt.wantErr { + t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestDefaultParams(t *testing.T) { + require.NoError(t, types.DefaultParams().ValidateBasic()) +} diff --git a/x/distribution/types/querier.go b/x/distribution/types/querier.go new file mode 100644 index 00000000..96bd7afe --- /dev/null +++ b/x/distribution/types/querier.go @@ -0,0 +1,94 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// querier keys +const ( + QueryParams = "params" + QueryValidatorOutstandingRewards = "validator_outstanding_rewards" + QueryValidatorCommission = "validator_commission" + QueryValidatorSlashes = "validator_slashes" + QueryDelegationRewards = "delegation_rewards" + QueryDelegatorTotalRewards = "delegator_total_rewards" + QueryDelegatorValidators = "delegator_validators" + QueryWithdrawAddr = "withdraw_addr" + QueryCommunityPool = "community_pool" +) + +// QueryValidatorOutstandingRewardsParams params for query 'custom/distr/validator_outstanding_rewards' +type QueryValidatorOutstandingRewardsParams struct { + ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"` +} + +// NewQueryValidatorOutstandingRewardsParams creates a new instance of QueryValidatorOutstandingRewardsParams +func NewQueryValidatorOutstandingRewardsParams(validatorAddr sdk.ValAddress) QueryValidatorOutstandingRewardsParams { + return QueryValidatorOutstandingRewardsParams{ + ValidatorAddress: validatorAddr, + } +} + +// QueryValidatorCommissionParams params for query 'custom/distr/validator_commission' +type QueryValidatorCommissionParams struct { + ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"` +} + +// NewQueryValidatorCommissionParams creates a new instance of QueryValidatorCommissionParams +func NewQueryValidatorCommissionParams(validatorAddr sdk.ValAddress) QueryValidatorCommissionParams { + return QueryValidatorCommissionParams{ + ValidatorAddress: validatorAddr, + } +} + +// QueryValidatorSlashesParams params for query 'custom/distr/validator_slashes' +type QueryValidatorSlashesParams struct { + ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"` + StartingHeight uint64 `json:"starting_height" yaml:"starting_height"` + EndingHeight uint64 `json:"ending_height" yaml:"ending_height"` +} + +// NewQueryValidatorSlashesParams creates a new instance of QueryValidatorSlashesParams +func NewQueryValidatorSlashesParams(validatorAddr sdk.ValAddress, startingHeight, endingHeight uint64) QueryValidatorSlashesParams { + return QueryValidatorSlashesParams{ + ValidatorAddress: validatorAddr, + StartingHeight: startingHeight, + EndingHeight: endingHeight, + } +} + +// QueryDelegationRewardsParams params for query 'custom/distr/delegation_rewards' +type QueryDelegationRewardsParams struct { + DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` + ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"` +} + +// NewQueryDelegationRewardsParams creates a new instance of QueryDelegationRewardsParams +func NewQueryDelegationRewardsParams(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryDelegationRewardsParams { + return QueryDelegationRewardsParams{ + DelegatorAddress: delegatorAddr, + ValidatorAddress: validatorAddr, + } +} + +// QueryDelegatorParams params for query 'custom/distr/delegator_total_rewards' and 'custom/distr/delegator_validators' +type QueryDelegatorParams struct { + DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` +} + +// NewQueryDelegatorParams creates a new instance of QueryDelegationRewardsParams +func NewQueryDelegatorParams(delegatorAddr sdk.AccAddress) QueryDelegatorParams { + return QueryDelegatorParams{ + DelegatorAddress: delegatorAddr, + } +} + +// QueryDelegatorWithdrawAddrParams params for query 'custom/distr/withdraw_addr' +type QueryDelegatorWithdrawAddrParams struct { + DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` +} + +// NewQueryDelegatorWithdrawAddrParams creates a new instance of QueryDelegatorWithdrawAddrParams. +func NewQueryDelegatorWithdrawAddrParams(delegatorAddr sdk.AccAddress) QueryDelegatorWithdrawAddrParams { + return QueryDelegatorWithdrawAddrParams{DelegatorAddress: delegatorAddr} +} diff --git a/x/distribution/types/query.go b/x/distribution/types/query.go new file mode 100644 index 00000000..973b038b --- /dev/null +++ b/x/distribution/types/query.go @@ -0,0 +1,37 @@ +package types + +import ( + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// QueryDelegatorTotalRewardsResponse defines the properties of +// QueryDelegatorTotalRewards query's response. +type QueryDelegatorTotalRewardsResponse struct { + Rewards []DelegationDelegatorReward `json:"rewards" yaml:"rewards"` + Total sdk.DecCoins `json:"total" yaml:"total"` +} + +// NewQueryDelegatorTotalRewardsResponse constructs a QueryDelegatorTotalRewardsResponse +func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward, total sdk.DecCoins) QueryDelegatorTotalRewardsResponse { + return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total} +} + +func (res QueryDelegatorTotalRewardsResponse) String() string { + out := "Delegator Total Rewards:\n" + out += " Rewards:" + for _, reward := range res.Rewards { + out += fmt.Sprintf(` + ValidatorAddress: %s + Reward: %s`, reward.ValidatorAddress, reward.Reward) + } + out += fmt.Sprintf("\n Total: %s\n", res.Total) + return strings.TrimSpace(out) +} + +// NewDelegationDelegatorReward constructs a DelegationDelegatorReward. +func NewDelegationDelegatorReward(valAddr string, reward sdk.DecCoins) DelegationDelegatorReward { + return DelegationDelegatorReward{ValidatorAddress: valAddr, Reward: reward} +} diff --git a/x/distribution/types/query.pb.go b/x/distribution/types/query.pb.go new file mode 100644 index 00000000..afed2c65 --- /dev/null +++ b/x/distribution/types/query.pb.go @@ -0,0 +1,4430 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: atomone/distribution/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryValidatorDistributionInfoRequest is the request type for the +// Query/ValidatorDistributionInfo RPC method. +type QueryValidatorDistributionInfoRequest struct { + // validator_address defines the validator address to query for. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *QueryValidatorDistributionInfoRequest) Reset() { *m = QueryValidatorDistributionInfoRequest{} } +func (m *QueryValidatorDistributionInfoRequest) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorDistributionInfoRequest) ProtoMessage() {} +func (*QueryValidatorDistributionInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{2} +} +func (m *QueryValidatorDistributionInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorDistributionInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorDistributionInfoRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorDistributionInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorDistributionInfoRequest.Merge(m, src) +} +func (m *QueryValidatorDistributionInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorDistributionInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorDistributionInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorDistributionInfoRequest proto.InternalMessageInfo + +func (m *QueryValidatorDistributionInfoRequest) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +// QueryValidatorDistributionInfoResponse is the response type for the +// Query/ValidatorDistributionInfo RPC method. +type QueryValidatorDistributionInfoResponse struct { + // operator_address defines the validator operator address. + OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` + // self_bond_rewards defines the self delegations rewards. + SelfBondRewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=self_bond_rewards,json=selfBondRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"self_bond_rewards"` + // commission defines the commission the validator received. + Commission github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=commission,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"commission"` +} + +func (m *QueryValidatorDistributionInfoResponse) Reset() { + *m = QueryValidatorDistributionInfoResponse{} +} +func (m *QueryValidatorDistributionInfoResponse) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorDistributionInfoResponse) ProtoMessage() {} +func (*QueryValidatorDistributionInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{3} +} +func (m *QueryValidatorDistributionInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorDistributionInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorDistributionInfoResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorDistributionInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorDistributionInfoResponse.Merge(m, src) +} +func (m *QueryValidatorDistributionInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorDistributionInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorDistributionInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorDistributionInfoResponse proto.InternalMessageInfo + +func (m *QueryValidatorDistributionInfoResponse) GetOperatorAddress() string { + if m != nil { + return m.OperatorAddress + } + return "" +} + +func (m *QueryValidatorDistributionInfoResponse) GetSelfBondRewards() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.SelfBondRewards + } + return nil +} + +func (m *QueryValidatorDistributionInfoResponse) GetCommission() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Commission + } + return nil +} + +// QueryValidatorOutstandingRewardsRequest is the request type for the +// Query/ValidatorOutstandingRewards RPC method. +type QueryValidatorOutstandingRewardsRequest struct { + // validator_address defines the validator address to query for. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *QueryValidatorOutstandingRewardsRequest) Reset() { + *m = QueryValidatorOutstandingRewardsRequest{} +} +func (m *QueryValidatorOutstandingRewardsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorOutstandingRewardsRequest) ProtoMessage() {} +func (*QueryValidatorOutstandingRewardsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{4} +} +func (m *QueryValidatorOutstandingRewardsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorOutstandingRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorOutstandingRewardsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorOutstandingRewardsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorOutstandingRewardsRequest.Merge(m, src) +} +func (m *QueryValidatorOutstandingRewardsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorOutstandingRewardsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorOutstandingRewardsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorOutstandingRewardsRequest proto.InternalMessageInfo + +func (m *QueryValidatorOutstandingRewardsRequest) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +// QueryValidatorOutstandingRewardsResponse is the response type for the +// Query/ValidatorOutstandingRewards RPC method. +type QueryValidatorOutstandingRewardsResponse struct { + Rewards ValidatorOutstandingRewards `protobuf:"bytes,1,opt,name=rewards,proto3" json:"rewards"` +} + +func (m *QueryValidatorOutstandingRewardsResponse) Reset() { + *m = QueryValidatorOutstandingRewardsResponse{} +} +func (m *QueryValidatorOutstandingRewardsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorOutstandingRewardsResponse) ProtoMessage() {} +func (*QueryValidatorOutstandingRewardsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{5} +} +func (m *QueryValidatorOutstandingRewardsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorOutstandingRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorOutstandingRewardsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorOutstandingRewardsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorOutstandingRewardsResponse.Merge(m, src) +} +func (m *QueryValidatorOutstandingRewardsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorOutstandingRewardsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorOutstandingRewardsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorOutstandingRewardsResponse proto.InternalMessageInfo + +func (m *QueryValidatorOutstandingRewardsResponse) GetRewards() ValidatorOutstandingRewards { + if m != nil { + return m.Rewards + } + return ValidatorOutstandingRewards{} +} + +// QueryValidatorCommissionRequest is the request type for the +// Query/ValidatorCommission RPC method +type QueryValidatorCommissionRequest struct { + // validator_address defines the validator address to query for. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *QueryValidatorCommissionRequest) Reset() { *m = QueryValidatorCommissionRequest{} } +func (m *QueryValidatorCommissionRequest) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorCommissionRequest) ProtoMessage() {} +func (*QueryValidatorCommissionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{6} +} +func (m *QueryValidatorCommissionRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorCommissionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorCommissionRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorCommissionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorCommissionRequest.Merge(m, src) +} +func (m *QueryValidatorCommissionRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorCommissionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorCommissionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorCommissionRequest proto.InternalMessageInfo + +func (m *QueryValidatorCommissionRequest) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +// QueryValidatorCommissionResponse is the response type for the +// Query/ValidatorCommission RPC method +type QueryValidatorCommissionResponse struct { + // commission defines the commission the validator received. + Commission ValidatorAccumulatedCommission `protobuf:"bytes,1,opt,name=commission,proto3" json:"commission"` +} + +func (m *QueryValidatorCommissionResponse) Reset() { *m = QueryValidatorCommissionResponse{} } +func (m *QueryValidatorCommissionResponse) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorCommissionResponse) ProtoMessage() {} +func (*QueryValidatorCommissionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{7} +} +func (m *QueryValidatorCommissionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorCommissionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorCommissionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorCommissionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorCommissionResponse.Merge(m, src) +} +func (m *QueryValidatorCommissionResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorCommissionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorCommissionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorCommissionResponse proto.InternalMessageInfo + +func (m *QueryValidatorCommissionResponse) GetCommission() ValidatorAccumulatedCommission { + if m != nil { + return m.Commission + } + return ValidatorAccumulatedCommission{} +} + +// QueryValidatorSlashesRequest is the request type for the +// Query/ValidatorSlashes RPC method +type QueryValidatorSlashesRequest struct { + // validator_address defines the validator address to query for. + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + // starting_height defines the optional starting height to query the slashes. + StartingHeight uint64 `protobuf:"varint,2,opt,name=starting_height,json=startingHeight,proto3" json:"starting_height,omitempty"` + // starting_height defines the optional ending height to query the slashes. + EndingHeight uint64 `protobuf:"varint,3,opt,name=ending_height,json=endingHeight,proto3" json:"ending_height,omitempty"` + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,4,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryValidatorSlashesRequest) Reset() { *m = QueryValidatorSlashesRequest{} } +func (m *QueryValidatorSlashesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorSlashesRequest) ProtoMessage() {} +func (*QueryValidatorSlashesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{8} +} +func (m *QueryValidatorSlashesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorSlashesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorSlashesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorSlashesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorSlashesRequest.Merge(m, src) +} +func (m *QueryValidatorSlashesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorSlashesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorSlashesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorSlashesRequest proto.InternalMessageInfo + +// QueryValidatorSlashesResponse is the response type for the +// Query/ValidatorSlashes RPC method. +type QueryValidatorSlashesResponse struct { + // slashes defines the slashes the validator received. + Slashes []ValidatorSlashEvent `protobuf:"bytes,1,rep,name=slashes,proto3" json:"slashes"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryValidatorSlashesResponse) Reset() { *m = QueryValidatorSlashesResponse{} } +func (m *QueryValidatorSlashesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorSlashesResponse) ProtoMessage() {} +func (*QueryValidatorSlashesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{9} +} +func (m *QueryValidatorSlashesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorSlashesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorSlashesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorSlashesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorSlashesResponse.Merge(m, src) +} +func (m *QueryValidatorSlashesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorSlashesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorSlashesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorSlashesResponse proto.InternalMessageInfo + +func (m *QueryValidatorSlashesResponse) GetSlashes() []ValidatorSlashEvent { + if m != nil { + return m.Slashes + } + return nil +} + +func (m *QueryValidatorSlashesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryDelegationRewardsRequest is the request type for the +// Query/DelegationRewards RPC method. +type QueryDelegationRewardsRequest struct { + // delegator_address defines the delegator address to query for. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + // validator_address defines the validator address to query for. + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *QueryDelegationRewardsRequest) Reset() { *m = QueryDelegationRewardsRequest{} } +func (m *QueryDelegationRewardsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDelegationRewardsRequest) ProtoMessage() {} +func (*QueryDelegationRewardsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{10} +} +func (m *QueryDelegationRewardsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegationRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegationRewardsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegationRewardsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegationRewardsRequest.Merge(m, src) +} +func (m *QueryDelegationRewardsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegationRewardsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegationRewardsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegationRewardsRequest proto.InternalMessageInfo + +// QueryDelegationRewardsResponse is the response type for the +// Query/DelegationRewards RPC method. +type QueryDelegationRewardsResponse struct { + // rewards defines the rewards accrued by a delegation. + Rewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=rewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"rewards"` +} + +func (m *QueryDelegationRewardsResponse) Reset() { *m = QueryDelegationRewardsResponse{} } +func (m *QueryDelegationRewardsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDelegationRewardsResponse) ProtoMessage() {} +func (*QueryDelegationRewardsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{11} +} +func (m *QueryDelegationRewardsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegationRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegationRewardsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegationRewardsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegationRewardsResponse.Merge(m, src) +} +func (m *QueryDelegationRewardsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegationRewardsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegationRewardsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegationRewardsResponse proto.InternalMessageInfo + +func (m *QueryDelegationRewardsResponse) GetRewards() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Rewards + } + return nil +} + +// QueryDelegationTotalRewardsRequest is the request type for the +// Query/DelegationTotalRewards RPC method. +type QueryDelegationTotalRewardsRequest struct { + // delegator_address defines the delegator address to query for. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` +} + +func (m *QueryDelegationTotalRewardsRequest) Reset() { *m = QueryDelegationTotalRewardsRequest{} } +func (m *QueryDelegationTotalRewardsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDelegationTotalRewardsRequest) ProtoMessage() {} +func (*QueryDelegationTotalRewardsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{12} +} +func (m *QueryDelegationTotalRewardsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegationTotalRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegationTotalRewardsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegationTotalRewardsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegationTotalRewardsRequest.Merge(m, src) +} +func (m *QueryDelegationTotalRewardsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegationTotalRewardsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegationTotalRewardsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegationTotalRewardsRequest proto.InternalMessageInfo + +// QueryDelegationTotalRewardsResponse is the response type for the +// Query/DelegationTotalRewards RPC method. +type QueryDelegationTotalRewardsResponse struct { + // rewards defines all the rewards accrued by a delegator. + Rewards []DelegationDelegatorReward `protobuf:"bytes,1,rep,name=rewards,proto3" json:"rewards"` + // total defines the sum of all the rewards. + Total github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=total,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"total"` +} + +func (m *QueryDelegationTotalRewardsResponse) Reset() { *m = QueryDelegationTotalRewardsResponse{} } +func (m *QueryDelegationTotalRewardsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDelegationTotalRewardsResponse) ProtoMessage() {} +func (*QueryDelegationTotalRewardsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{13} +} +func (m *QueryDelegationTotalRewardsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegationTotalRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegationTotalRewardsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegationTotalRewardsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegationTotalRewardsResponse.Merge(m, src) +} +func (m *QueryDelegationTotalRewardsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegationTotalRewardsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegationTotalRewardsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegationTotalRewardsResponse proto.InternalMessageInfo + +func (m *QueryDelegationTotalRewardsResponse) GetRewards() []DelegationDelegatorReward { + if m != nil { + return m.Rewards + } + return nil +} + +func (m *QueryDelegationTotalRewardsResponse) GetTotal() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Total + } + return nil +} + +// QueryDelegatorValidatorsRequest is the request type for the +// Query/DelegatorValidators RPC method. +type QueryDelegatorValidatorsRequest struct { + // delegator_address defines the delegator address to query for. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` +} + +func (m *QueryDelegatorValidatorsRequest) Reset() { *m = QueryDelegatorValidatorsRequest{} } +func (m *QueryDelegatorValidatorsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDelegatorValidatorsRequest) ProtoMessage() {} +func (*QueryDelegatorValidatorsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{14} +} +func (m *QueryDelegatorValidatorsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegatorValidatorsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegatorValidatorsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegatorValidatorsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegatorValidatorsRequest.Merge(m, src) +} +func (m *QueryDelegatorValidatorsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegatorValidatorsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegatorValidatorsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegatorValidatorsRequest proto.InternalMessageInfo + +// QueryDelegatorValidatorsResponse is the response type for the +// Query/DelegatorValidators RPC method. +type QueryDelegatorValidatorsResponse struct { + // validators defines the validators a delegator is delegating for. + Validators []string `protobuf:"bytes,1,rep,name=validators,proto3" json:"validators,omitempty"` +} + +func (m *QueryDelegatorValidatorsResponse) Reset() { *m = QueryDelegatorValidatorsResponse{} } +func (m *QueryDelegatorValidatorsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDelegatorValidatorsResponse) ProtoMessage() {} +func (*QueryDelegatorValidatorsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{15} +} +func (m *QueryDelegatorValidatorsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegatorValidatorsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegatorValidatorsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegatorValidatorsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegatorValidatorsResponse.Merge(m, src) +} +func (m *QueryDelegatorValidatorsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegatorValidatorsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegatorValidatorsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegatorValidatorsResponse proto.InternalMessageInfo + +// QueryDelegatorWithdrawAddressRequest is the request type for the +// Query/DelegatorWithdrawAddress RPC method. +type QueryDelegatorWithdrawAddressRequest struct { + // delegator_address defines the delegator address to query for. + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` +} + +func (m *QueryDelegatorWithdrawAddressRequest) Reset() { *m = QueryDelegatorWithdrawAddressRequest{} } +func (m *QueryDelegatorWithdrawAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDelegatorWithdrawAddressRequest) ProtoMessage() {} +func (*QueryDelegatorWithdrawAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{16} +} +func (m *QueryDelegatorWithdrawAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegatorWithdrawAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegatorWithdrawAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegatorWithdrawAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegatorWithdrawAddressRequest.Merge(m, src) +} +func (m *QueryDelegatorWithdrawAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegatorWithdrawAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegatorWithdrawAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegatorWithdrawAddressRequest proto.InternalMessageInfo + +// QueryDelegatorWithdrawAddressResponse is the response type for the +// Query/DelegatorWithdrawAddress RPC method. +type QueryDelegatorWithdrawAddressResponse struct { + // withdraw_address defines the delegator address to query for. + WithdrawAddress string `protobuf:"bytes,1,opt,name=withdraw_address,json=withdrawAddress,proto3" json:"withdraw_address,omitempty"` +} + +func (m *QueryDelegatorWithdrawAddressResponse) Reset() { *m = QueryDelegatorWithdrawAddressResponse{} } +func (m *QueryDelegatorWithdrawAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDelegatorWithdrawAddressResponse) ProtoMessage() {} +func (*QueryDelegatorWithdrawAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{17} +} +func (m *QueryDelegatorWithdrawAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegatorWithdrawAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegatorWithdrawAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryDelegatorWithdrawAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegatorWithdrawAddressResponse.Merge(m, src) +} +func (m *QueryDelegatorWithdrawAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegatorWithdrawAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegatorWithdrawAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegatorWithdrawAddressResponse proto.InternalMessageInfo + +// QueryCommunityPoolRequest is the request type for the Query/CommunityPool RPC +// method. +type QueryCommunityPoolRequest struct { +} + +func (m *QueryCommunityPoolRequest) Reset() { *m = QueryCommunityPoolRequest{} } +func (m *QueryCommunityPoolRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCommunityPoolRequest) ProtoMessage() {} +func (*QueryCommunityPoolRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{18} +} +func (m *QueryCommunityPoolRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCommunityPoolRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCommunityPoolRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryCommunityPoolRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCommunityPoolRequest.Merge(m, src) +} +func (m *QueryCommunityPoolRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryCommunityPoolRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCommunityPoolRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCommunityPoolRequest proto.InternalMessageInfo + +// QueryCommunityPoolResponse is the response type for the Query/CommunityPool +// RPC method. +type QueryCommunityPoolResponse struct { + // pool defines community pool's coins. + Pool github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=pool,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"pool"` +} + +func (m *QueryCommunityPoolResponse) Reset() { *m = QueryCommunityPoolResponse{} } +func (m *QueryCommunityPoolResponse) String() string { return proto.CompactTextString(m) } +func (*QueryCommunityPoolResponse) ProtoMessage() {} +func (*QueryCommunityPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0236f797895364c, []int{19} +} +func (m *QueryCommunityPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCommunityPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCommunityPoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryCommunityPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCommunityPoolResponse.Merge(m, src) +} +func (m *QueryCommunityPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryCommunityPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCommunityPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCommunityPoolResponse proto.InternalMessageInfo + +func (m *QueryCommunityPoolResponse) GetPool() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Pool + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "atomone.distribution.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "atomone.distribution.v1beta1.QueryParamsResponse") + proto.RegisterType((*QueryValidatorDistributionInfoRequest)(nil), "atomone.distribution.v1beta1.QueryValidatorDistributionInfoRequest") + proto.RegisterType((*QueryValidatorDistributionInfoResponse)(nil), "atomone.distribution.v1beta1.QueryValidatorDistributionInfoResponse") + proto.RegisterType((*QueryValidatorOutstandingRewardsRequest)(nil), "atomone.distribution.v1beta1.QueryValidatorOutstandingRewardsRequest") + proto.RegisterType((*QueryValidatorOutstandingRewardsResponse)(nil), "atomone.distribution.v1beta1.QueryValidatorOutstandingRewardsResponse") + proto.RegisterType((*QueryValidatorCommissionRequest)(nil), "atomone.distribution.v1beta1.QueryValidatorCommissionRequest") + proto.RegisterType((*QueryValidatorCommissionResponse)(nil), "atomone.distribution.v1beta1.QueryValidatorCommissionResponse") + proto.RegisterType((*QueryValidatorSlashesRequest)(nil), "atomone.distribution.v1beta1.QueryValidatorSlashesRequest") + proto.RegisterType((*QueryValidatorSlashesResponse)(nil), "atomone.distribution.v1beta1.QueryValidatorSlashesResponse") + proto.RegisterType((*QueryDelegationRewardsRequest)(nil), "atomone.distribution.v1beta1.QueryDelegationRewardsRequest") + proto.RegisterType((*QueryDelegationRewardsResponse)(nil), "atomone.distribution.v1beta1.QueryDelegationRewardsResponse") + proto.RegisterType((*QueryDelegationTotalRewardsRequest)(nil), "atomone.distribution.v1beta1.QueryDelegationTotalRewardsRequest") + proto.RegisterType((*QueryDelegationTotalRewardsResponse)(nil), "atomone.distribution.v1beta1.QueryDelegationTotalRewardsResponse") + proto.RegisterType((*QueryDelegatorValidatorsRequest)(nil), "atomone.distribution.v1beta1.QueryDelegatorValidatorsRequest") + proto.RegisterType((*QueryDelegatorValidatorsResponse)(nil), "atomone.distribution.v1beta1.QueryDelegatorValidatorsResponse") + proto.RegisterType((*QueryDelegatorWithdrawAddressRequest)(nil), "atomone.distribution.v1beta1.QueryDelegatorWithdrawAddressRequest") + proto.RegisterType((*QueryDelegatorWithdrawAddressResponse)(nil), "atomone.distribution.v1beta1.QueryDelegatorWithdrawAddressResponse") + proto.RegisterType((*QueryCommunityPoolRequest)(nil), "atomone.distribution.v1beta1.QueryCommunityPoolRequest") + proto.RegisterType((*QueryCommunityPoolResponse)(nil), "atomone.distribution.v1beta1.QueryCommunityPoolResponse") +} + +func init() { + proto.RegisterFile("atomone/distribution/v1beta1/query.proto", fileDescriptor_c0236f797895364c) +} + +var fileDescriptor_c0236f797895364c = []byte{ + // 1278 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x41, 0x6c, 0x1b, 0x45, + 0x14, 0xcd, 0x38, 0x69, 0x4a, 0x7e, 0x29, 0x89, 0xa7, 0x11, 0x72, 0xb6, 0xa9, 0x13, 0x9c, 0xb6, + 0x89, 0x1a, 0xc5, 0x4b, 0x92, 0x43, 0x4b, 0xda, 0x22, 0x62, 0x27, 0x69, 0x11, 0x21, 0x6d, 0xdd, + 0xaa, 0x11, 0x08, 0xd5, 0x5a, 0x7b, 0xb7, 0xeb, 0x05, 0x7b, 0xc7, 0xd9, 0x1d, 0xc7, 0x44, 0x55, + 0x2f, 0x95, 0x90, 0xaa, 0x72, 0x41, 0x70, 0xe3, 0xc4, 0x11, 0x71, 0xe2, 0x50, 0x89, 0x2b, 0xc7, + 0x1e, 0xab, 0x72, 0xc9, 0x09, 0x50, 0x52, 0x09, 0x04, 0x12, 0x88, 0x23, 0xb7, 0xca, 0x33, 0xb3, + 0xf6, 0xae, 0xbd, 0xde, 0xac, 0x6d, 0xf9, 0xd2, 0xc6, 0x7f, 0xff, 0xff, 0xef, 0xbf, 0xff, 0xff, + 0xcc, 0x3e, 0x1b, 0xe6, 0x14, 0x4a, 0x4a, 0xc4, 0xd4, 0x64, 0xd5, 0xb0, 0xa9, 0x65, 0xe4, 0x2a, + 0xd4, 0x20, 0xa6, 0xbc, 0xbb, 0x98, 0xd3, 0xa8, 0xb2, 0x28, 0xef, 0x54, 0x34, 0x6b, 0x2f, 0x59, + 0xb6, 0x08, 0x25, 0x78, 0x52, 0x78, 0x26, 0xdd, 0x9e, 0x49, 0xe1, 0x29, 0x45, 0x95, 0x92, 0x61, + 0x12, 0x99, 0xfd, 0xcb, 0x03, 0x24, 0x39, 0x30, 0xb5, 0x27, 0x0b, 0x0f, 0xb8, 0x90, 0x27, 0x76, + 0x89, 0xd8, 0x72, 0x4e, 0xb1, 0x35, 0x0e, 0x5d, 0xf7, 0x2e, 0x2b, 0xba, 0x61, 0x2a, 0x2e, 0xdf, + 0xb8, 0xdb, 0xd7, 0xf1, 0xca, 0x13, 0xc3, 0x79, 0x3e, 0xc1, 0x9f, 0x67, 0xd9, 0x27, 0x99, 0x7f, + 0x10, 0x8f, 0xc6, 0x75, 0xa2, 0x13, 0x6e, 0xaf, 0xfd, 0x25, 0xac, 0x93, 0x3a, 0x21, 0x7a, 0x51, + 0x93, 0x95, 0xb2, 0x21, 0x2b, 0xa6, 0x49, 0x28, 0x43, 0x13, 0x31, 0x89, 0x71, 0xc0, 0xb7, 0x6a, + 0x05, 0xdd, 0x54, 0x2c, 0xa5, 0x64, 0x67, 0xb4, 0x9d, 0x8a, 0x66, 0xd3, 0xc4, 0x3d, 0x38, 0xe5, + 0xb1, 0xda, 0x65, 0x62, 0xda, 0x1a, 0xbe, 0x06, 0xc3, 0x65, 0x66, 0x89, 0xa1, 0x69, 0x34, 0x77, + 0x62, 0xe9, 0x6c, 0x32, 0xa8, 0x75, 0x49, 0x1e, 0x9d, 0x1a, 0x79, 0xf6, 0xeb, 0xd4, 0xc0, 0xf7, + 0x7f, 0xfc, 0x78, 0x01, 0x65, 0x44, 0x78, 0xa2, 0x0a, 0xe7, 0x58, 0xfe, 0xbb, 0x4a, 0xd1, 0x50, + 0x15, 0x4a, 0xac, 0x35, 0x57, 0xfc, 0xfb, 0xe6, 0x7d, 0x22, 0x0a, 0xc1, 0x5b, 0x10, 0xdd, 0x75, + 0x7c, 0xb2, 0x8a, 0xaa, 0x5a, 0x9a, 0xcd, 0xc1, 0x47, 0x52, 0x6f, 0xbd, 0x78, 0xba, 0x70, 0x46, + 0xf0, 0xaf, 0xe7, 0x59, 0xe5, 0x2e, 0xb7, 0xa9, 0x65, 0x98, 0x7a, 0x66, 0x6c, 0xb7, 0xc9, 0x9e, + 0xf8, 0x27, 0x02, 0xe7, 0x8f, 0x42, 0x16, 0x64, 0x37, 0x61, 0x8c, 0x94, 0x35, 0xab, 0x3b, 0xe4, + 0x51, 0x27, 0x54, 0x98, 0xf1, 0x23, 0x04, 0x51, 0x5b, 0x2b, 0xde, 0xcf, 0xe6, 0x88, 0xa9, 0x66, + 0x2d, 0xad, 0xaa, 0x58, 0xaa, 0x1d, 0x8b, 0x4c, 0x0f, 0xce, 0x9d, 0x58, 0x9a, 0x4c, 0x8a, 0x64, + 0xb5, 0x99, 0xd7, 0xbb, 0xb7, 0xa6, 0xe5, 0xd3, 0xc4, 0x30, 0x53, 0x97, 0x6a, 0xed, 0xfb, 0xe1, + 0xb7, 0xa9, 0x79, 0xdd, 0xa0, 0x85, 0x4a, 0x2e, 0x99, 0x27, 0x25, 0x31, 0x76, 0xf1, 0xdf, 0x82, + 0xad, 0x7e, 0x26, 0xd3, 0xbd, 0xb2, 0x66, 0x3b, 0x31, 0x36, 0xef, 0xf6, 0x68, 0x0d, 0x30, 0x45, + 0x4c, 0x35, 0xc3, 0xe1, 0xf0, 0x0e, 0x40, 0x9e, 0x94, 0x4a, 0x86, 0x6d, 0x1b, 0xc4, 0x8c, 0x0d, + 0x86, 0x00, 0x5f, 0xee, 0x02, 0x3c, 0xe3, 0x02, 0x49, 0xec, 0xc1, 0xac, 0xb7, 0xdf, 0x37, 0x2a, + 0xd4, 0xa6, 0x8a, 0xa9, 0xd6, 0xba, 0xc4, 0xcb, 0xea, 0xd7, 0xac, 0x9f, 0x20, 0x98, 0x3b, 0x1a, + 0x5b, 0x4c, 0xfb, 0x1e, 0x1c, 0x77, 0x86, 0xc2, 0x77, 0xfb, 0x9d, 0xe0, 0xdd, 0x0e, 0xc8, 0xe9, + 0x5e, 0x78, 0x27, 0x69, 0x62, 0x07, 0xa6, 0xbc, 0xb5, 0xa4, 0xeb, 0x3d, 0xea, 0x17, 0xff, 0x2f, + 0x11, 0x4c, 0xb7, 0xc7, 0x14, 0xbc, 0x75, 0xcf, 0x4a, 0x70, 0xea, 0x57, 0x42, 0x52, 0x5f, 0xcd, + 0xe7, 0x2b, 0xa5, 0x4a, 0x51, 0xa1, 0x9a, 0xda, 0xc8, 0xec, 0x66, 0xef, 0x5e, 0x84, 0x27, 0x11, + 0x98, 0xf4, 0x56, 0x73, 0xbb, 0xa8, 0xd8, 0x05, 0xad, 0x5f, 0xe3, 0xc7, 0xb3, 0x30, 0x6a, 0x53, + 0xc5, 0xa2, 0x86, 0xa9, 0x67, 0x0b, 0x9a, 0xa1, 0x17, 0x68, 0x2c, 0x32, 0x8d, 0xe6, 0x86, 0x32, + 0x6f, 0x38, 0xe6, 0xeb, 0xcc, 0x8a, 0x67, 0xe0, 0xa4, 0xc6, 0xe6, 0xe7, 0xb8, 0x0d, 0x32, 0xb7, + 0xd7, 0xb9, 0x51, 0x38, 0x6d, 0x00, 0x34, 0xae, 0xea, 0xd8, 0x10, 0xeb, 0xd3, 0x79, 0xcf, 0xd1, + 0xe1, 0xaf, 0x94, 0xc6, 0xdd, 0xa7, 0x6b, 0x82, 0x59, 0xc6, 0x15, 0xb9, 0x32, 0xf4, 0xf8, 0xbb, + 0xa9, 0x81, 0xc4, 0xcf, 0x08, 0xce, 0xb4, 0x69, 0x86, 0x98, 0xcb, 0x5d, 0x38, 0x6e, 0x73, 0x53, + 0x0c, 0xb1, 0x73, 0xba, 0x18, 0x72, 0x28, 0x2c, 0xd1, 0xfa, 0xae, 0x66, 0x52, 0xcf, 0x1e, 0x8a, + 0x64, 0xf8, 0x9a, 0x87, 0x47, 0x84, 0xf1, 0x98, 0x3d, 0x92, 0x07, 0x2f, 0xca, 0x4d, 0xa4, 0x41, + 0x61, 0x4d, 0x2b, 0x6a, 0x3a, 0xb3, 0x35, 0x9d, 0xe7, 0x75, 0x88, 0xaa, 0xfc, 0x59, 0xcb, 0x40, + 0x63, 0x2f, 0x9e, 0x2e, 0x8c, 0x0b, 0xd0, 0xa6, 0x39, 0xd6, 0x43, 0x9c, 0x39, 0xfa, 0xee, 0x45, + 0xa4, 0xeb, 0xbd, 0x58, 0x79, 0xad, 0x36, 0x81, 0x3f, 0x6b, 0x53, 0xf8, 0x1a, 0x41, 0xbc, 0x1d, + 0x05, 0x31, 0x86, 0xb2, 0xfb, 0x5a, 0xe8, 0xe7, 0x5d, 0x5d, 0xbf, 0x28, 0x2a, 0x90, 0x68, 0xaa, + 0xe9, 0x0e, 0xa1, 0x4a, 0xb1, 0x2f, 0xbd, 0x75, 0xf5, 0xe2, 0x3f, 0x04, 0x33, 0x81, 0xb8, 0xa2, + 0x21, 0x9f, 0x34, 0x37, 0xe4, 0x62, 0xf0, 0x5e, 0x36, 0xd2, 0xad, 0x39, 0xe0, 0x3c, 0xa5, 0xdf, + 0x2d, 0x89, 0x8b, 0x70, 0x8c, 0xd6, 0x50, 0xfb, 0xfc, 0x62, 0xe4, 0x20, 0x09, 0x4b, 0xdc, 0xc9, + 0xf5, 0xca, 0xea, 0x3b, 0xd4, 0xbf, 0x3e, 0x6f, 0x8a, 0x3b, 0xd9, 0x17, 0x53, 0xf4, 0x38, 0x0e, + 0x50, 0xdf, 0x5a, 0xde, 0xe6, 0x91, 0x8c, 0xcb, 0xe2, 0xca, 0x56, 0x85, 0xb3, 0xde, 0x6c, 0xdb, + 0x06, 0x2d, 0xa8, 0x96, 0x52, 0x15, 0xc0, 0x7d, 0xa3, 0xb1, 0x2b, 0x04, 0x5c, 0x7b, 0x60, 0xc1, + 0x25, 0x0d, 0x63, 0x55, 0xf1, 0x28, 0x34, 0xf0, 0x68, 0xd5, 0x9b, 0xcc, 0x85, 0x7b, 0x1a, 0x26, + 0x18, 0x6e, 0xed, 0x7d, 0x53, 0x31, 0x0d, 0xba, 0x77, 0x93, 0x90, 0xa2, 0xa3, 0x5a, 0x1f, 0x23, + 0x90, 0xfc, 0x9e, 0x8a, 0x52, 0x3e, 0x85, 0xa1, 0x32, 0x21, 0xc5, 0x3e, 0x1f, 0x64, 0x86, 0xb1, + 0xb4, 0x1f, 0x85, 0x63, 0xac, 0x14, 0xfc, 0x2d, 0x82, 0x61, 0x2e, 0x84, 0xf1, 0xdb, 0xc1, 0x47, + 0xa5, 0x55, 0x87, 0x4b, 0x8b, 0x1d, 0x44, 0x70, 0x96, 0x89, 0xf9, 0x47, 0xbf, 0xbc, 0xfc, 0x26, + 0x72, 0x0e, 0xcf, 0x38, 0xf5, 0xfa, 0x7e, 0x49, 0xe1, 0x3a, 0x1c, 0xff, 0x8d, 0x60, 0xa2, 0xad, + 0x12, 0xc6, 0xe9, 0x10, 0xe8, 0x47, 0x29, 0x78, 0x69, 0xad, 0xb7, 0x24, 0x82, 0x55, 0x9a, 0xb1, + 0xba, 0x8a, 0x2f, 0x07, 0xb2, 0x6a, 0x9c, 0x11, 0xf9, 0x41, 0xcb, 0x3b, 0xe3, 0x21, 0xfe, 0x22, + 0x02, 0xa7, 0x03, 0x74, 0x1b, 0x5e, 0xef, 0xa4, 0xd4, 0xb6, 0x3a, 0x56, 0xda, 0xe8, 0x35, 0x8d, + 0xe0, 0xbc, 0xcd, 0x38, 0xdf, 0xc2, 0x37, 0x7a, 0xe0, 0x2c, 0x93, 0x46, 0x7e, 0xe7, 0x5b, 0x07, + 0x7e, 0x89, 0xe0, 0x94, 0x8f, 0x26, 0xc4, 0x57, 0x3b, 0x29, 0xbc, 0x45, 0xbf, 0x4a, 0xef, 0x76, + 0x1b, 0x2e, 0xf8, 0x6e, 0x31, 0xbe, 0xd7, 0xf1, 0x46, 0x2f, 0x7c, 0x1b, 0x8a, 0x13, 0xef, 0x23, + 0x18, 0x6b, 0xd6, 0x57, 0x78, 0xa5, 0x93, 0x22, 0xbd, 0x0a, 0x55, 0xba, 0xdc, 0x55, 0xac, 0x60, + 0xf7, 0x01, 0x63, 0xb7, 0x8e, 0xd3, 0xbd, 0xb0, 0x73, 0x54, 0xdc, 0xbf, 0x08, 0xa2, 0x2d, 0xa2, + 0x05, 0x87, 0xa9, 0xaf, 0x9d, 0x5a, 0x93, 0xae, 0x74, 0x17, 0x2c, 0xd8, 0x65, 0x19, 0xbb, 0x8f, + 0xf0, 0x76, 0x20, 0xbb, 0xfa, 0x0b, 0xc5, 0x96, 0x1f, 0xb4, 0xbc, 0x8f, 0x1e, 0xca, 0x62, 0x3f, + 0x7d, 0xcf, 0xee, 0x5f, 0x08, 0xde, 0xf4, 0x97, 0x26, 0xf8, 0xbd, 0x8e, 0x2a, 0xf7, 0x51, 0x53, + 0xd2, 0x6a, 0x0f, 0x19, 0x3a, 0x1a, 0x6f, 0xb8, 0x06, 0xb0, 0x03, 0xea, 0x23, 0x10, 0x42, 0x1d, + 0xd0, 0xf6, 0x62, 0x26, 0xd4, 0x01, 0x0d, 0xd0, 0x25, 0x21, 0x0f, 0xe8, 0x11, 0x1c, 0x1b, 0x1b, + 0x8e, 0xff, 0x47, 0x10, 0x6b, 0x27, 0x20, 0x70, 0xaa, 0x93, 0x62, 0xfd, 0x65, 0x8f, 0x94, 0xee, + 0x29, 0x87, 0x60, 0x7d, 0x87, 0xb1, 0xde, 0xc2, 0x9b, 0xbd, 0xb0, 0x6e, 0xd6, 0x40, 0xf8, 0x27, + 0x04, 0x27, 0x3d, 0x32, 0x05, 0x5f, 0x0c, 0x51, 0xac, 0x9f, 0xec, 0x91, 0x2e, 0x75, 0x1e, 0x28, + 0xa8, 0x2d, 0x33, 0x6a, 0x0b, 0x78, 0x3e, 0x90, 0x5a, 0xde, 0x89, 0xcd, 0xd6, 0xa4, 0x4d, 0xea, + 0xc3, 0x67, 0x07, 0x71, 0xf4, 0xfc, 0x20, 0x8e, 0x7e, 0x3f, 0x88, 0xa3, 0xaf, 0x0e, 0xe3, 0x03, + 0xcf, 0x0f, 0xe3, 0x03, 0xfb, 0x87, 0xf1, 0x81, 0x8f, 0x97, 0x5d, 0x62, 0x49, 0x94, 0xb4, 0x50, + 0xa8, 0xe4, 0xea, 0x3f, 0x97, 0x7e, 0xee, 0xcd, 0xcf, 0xd4, 0x53, 0x6e, 0x98, 0xfd, 0x0e, 0xb9, + 0xfc, 0x2a, 0x00, 0x00, 0xff, 0xff, 0x76, 0x11, 0xce, 0x46, 0xb0, 0x15, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params queries params of the distribution module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // ValidatorDistributionInfo queries validator commission and self-delegation rewards for validator + ValidatorDistributionInfo(ctx context.Context, in *QueryValidatorDistributionInfoRequest, opts ...grpc.CallOption) (*QueryValidatorDistributionInfoResponse, error) + // ValidatorOutstandingRewards queries rewards of a validator address. + ValidatorOutstandingRewards(ctx context.Context, in *QueryValidatorOutstandingRewardsRequest, opts ...grpc.CallOption) (*QueryValidatorOutstandingRewardsResponse, error) + // ValidatorCommission queries accumulated commission for a validator. + ValidatorCommission(ctx context.Context, in *QueryValidatorCommissionRequest, opts ...grpc.CallOption) (*QueryValidatorCommissionResponse, error) + // ValidatorSlashes queries slash events of a validator. + ValidatorSlashes(ctx context.Context, in *QueryValidatorSlashesRequest, opts ...grpc.CallOption) (*QueryValidatorSlashesResponse, error) + // DelegationRewards queries the total rewards accrued by a delegation. + DelegationRewards(ctx context.Context, in *QueryDelegationRewardsRequest, opts ...grpc.CallOption) (*QueryDelegationRewardsResponse, error) + // DelegationTotalRewards queries the total rewards accrued by each + // validator. + DelegationTotalRewards(ctx context.Context, in *QueryDelegationTotalRewardsRequest, opts ...grpc.CallOption) (*QueryDelegationTotalRewardsResponse, error) + // DelegatorValidators queries the validators of a delegator. + DelegatorValidators(ctx context.Context, in *QueryDelegatorValidatorsRequest, opts ...grpc.CallOption) (*QueryDelegatorValidatorsResponse, error) + // DelegatorWithdrawAddress queries withdraw address of a delegator. + DelegatorWithdrawAddress(ctx context.Context, in *QueryDelegatorWithdrawAddressRequest, opts ...grpc.CallOption) (*QueryDelegatorWithdrawAddressResponse, error) + // CommunityPool queries the community pool coins. + // + // WARNING: This query will fail if an external community pool is used. + CommunityPool(ctx context.Context, in *QueryCommunityPoolRequest, opts ...grpc.CallOption) (*QueryCommunityPoolResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ValidatorDistributionInfo(ctx context.Context, in *QueryValidatorDistributionInfoRequest, opts ...grpc.CallOption) (*QueryValidatorDistributionInfoResponse, error) { + out := new(QueryValidatorDistributionInfoResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/ValidatorDistributionInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ValidatorOutstandingRewards(ctx context.Context, in *QueryValidatorOutstandingRewardsRequest, opts ...grpc.CallOption) (*QueryValidatorOutstandingRewardsResponse, error) { + out := new(QueryValidatorOutstandingRewardsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/ValidatorOutstandingRewards", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ValidatorCommission(ctx context.Context, in *QueryValidatorCommissionRequest, opts ...grpc.CallOption) (*QueryValidatorCommissionResponse, error) { + out := new(QueryValidatorCommissionResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/ValidatorCommission", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ValidatorSlashes(ctx context.Context, in *QueryValidatorSlashesRequest, opts ...grpc.CallOption) (*QueryValidatorSlashesResponse, error) { + out := new(QueryValidatorSlashesResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/ValidatorSlashes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DelegationRewards(ctx context.Context, in *QueryDelegationRewardsRequest, opts ...grpc.CallOption) (*QueryDelegationRewardsResponse, error) { + out := new(QueryDelegationRewardsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/DelegationRewards", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DelegationTotalRewards(ctx context.Context, in *QueryDelegationTotalRewardsRequest, opts ...grpc.CallOption) (*QueryDelegationTotalRewardsResponse, error) { + out := new(QueryDelegationTotalRewardsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/DelegationTotalRewards", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DelegatorValidators(ctx context.Context, in *QueryDelegatorValidatorsRequest, opts ...grpc.CallOption) (*QueryDelegatorValidatorsResponse, error) { + out := new(QueryDelegatorValidatorsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/DelegatorValidators", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DelegatorWithdrawAddress(ctx context.Context, in *QueryDelegatorWithdrawAddressRequest, opts ...grpc.CallOption) (*QueryDelegatorWithdrawAddressResponse, error) { + out := new(QueryDelegatorWithdrawAddressResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/DelegatorWithdrawAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) CommunityPool(ctx context.Context, in *QueryCommunityPoolRequest, opts ...grpc.CallOption) (*QueryCommunityPoolResponse, error) { + out := new(QueryCommunityPoolResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Query/CommunityPool", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries params of the distribution module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // ValidatorDistributionInfo queries validator commission and self-delegation rewards for validator + ValidatorDistributionInfo(context.Context, *QueryValidatorDistributionInfoRequest) (*QueryValidatorDistributionInfoResponse, error) + // ValidatorOutstandingRewards queries rewards of a validator address. + ValidatorOutstandingRewards(context.Context, *QueryValidatorOutstandingRewardsRequest) (*QueryValidatorOutstandingRewardsResponse, error) + // ValidatorCommission queries accumulated commission for a validator. + ValidatorCommission(context.Context, *QueryValidatorCommissionRequest) (*QueryValidatorCommissionResponse, error) + // ValidatorSlashes queries slash events of a validator. + ValidatorSlashes(context.Context, *QueryValidatorSlashesRequest) (*QueryValidatorSlashesResponse, error) + // DelegationRewards queries the total rewards accrued by a delegation. + DelegationRewards(context.Context, *QueryDelegationRewardsRequest) (*QueryDelegationRewardsResponse, error) + // DelegationTotalRewards queries the total rewards accrued by each + // validator. + DelegationTotalRewards(context.Context, *QueryDelegationTotalRewardsRequest) (*QueryDelegationTotalRewardsResponse, error) + // DelegatorValidators queries the validators of a delegator. + DelegatorValidators(context.Context, *QueryDelegatorValidatorsRequest) (*QueryDelegatorValidatorsResponse, error) + // DelegatorWithdrawAddress queries withdraw address of a delegator. + DelegatorWithdrawAddress(context.Context, *QueryDelegatorWithdrawAddressRequest) (*QueryDelegatorWithdrawAddressResponse, error) + // CommunityPool queries the community pool coins. + // + // WARNING: This query will fail if an external community pool is used. + CommunityPool(context.Context, *QueryCommunityPoolRequest) (*QueryCommunityPoolResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) ValidatorDistributionInfo(ctx context.Context, req *QueryValidatorDistributionInfoRequest) (*QueryValidatorDistributionInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidatorDistributionInfo not implemented") +} +func (*UnimplementedQueryServer) ValidatorOutstandingRewards(ctx context.Context, req *QueryValidatorOutstandingRewardsRequest) (*QueryValidatorOutstandingRewardsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidatorOutstandingRewards not implemented") +} +func (*UnimplementedQueryServer) ValidatorCommission(ctx context.Context, req *QueryValidatorCommissionRequest) (*QueryValidatorCommissionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidatorCommission not implemented") +} +func (*UnimplementedQueryServer) ValidatorSlashes(ctx context.Context, req *QueryValidatorSlashesRequest) (*QueryValidatorSlashesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidatorSlashes not implemented") +} +func (*UnimplementedQueryServer) DelegationRewards(ctx context.Context, req *QueryDelegationRewardsRequest) (*QueryDelegationRewardsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegationRewards not implemented") +} +func (*UnimplementedQueryServer) DelegationTotalRewards(ctx context.Context, req *QueryDelegationTotalRewardsRequest) (*QueryDelegationTotalRewardsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegationTotalRewards not implemented") +} +func (*UnimplementedQueryServer) DelegatorValidators(ctx context.Context, req *QueryDelegatorValidatorsRequest) (*QueryDelegatorValidatorsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegatorValidators not implemented") +} +func (*UnimplementedQueryServer) DelegatorWithdrawAddress(ctx context.Context, req *QueryDelegatorWithdrawAddressRequest) (*QueryDelegatorWithdrawAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegatorWithdrawAddress not implemented") +} +func (*UnimplementedQueryServer) CommunityPool(ctx context.Context, req *QueryCommunityPoolRequest) (*QueryCommunityPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommunityPool not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ValidatorDistributionInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryValidatorDistributionInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ValidatorDistributionInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/ValidatorDistributionInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ValidatorDistributionInfo(ctx, req.(*QueryValidatorDistributionInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ValidatorOutstandingRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryValidatorOutstandingRewardsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ValidatorOutstandingRewards(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/ValidatorOutstandingRewards", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ValidatorOutstandingRewards(ctx, req.(*QueryValidatorOutstandingRewardsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ValidatorCommission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryValidatorCommissionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ValidatorCommission(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/ValidatorCommission", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ValidatorCommission(ctx, req.(*QueryValidatorCommissionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ValidatorSlashes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryValidatorSlashesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ValidatorSlashes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/ValidatorSlashes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ValidatorSlashes(ctx, req.(*QueryValidatorSlashesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DelegationRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDelegationRewardsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DelegationRewards(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/DelegationRewards", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DelegationRewards(ctx, req.(*QueryDelegationRewardsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DelegationTotalRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDelegationTotalRewardsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DelegationTotalRewards(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/DelegationTotalRewards", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DelegationTotalRewards(ctx, req.(*QueryDelegationTotalRewardsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DelegatorValidators_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDelegatorValidatorsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DelegatorValidators(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/DelegatorValidators", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DelegatorValidators(ctx, req.(*QueryDelegatorValidatorsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DelegatorWithdrawAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDelegatorWithdrawAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DelegatorWithdrawAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/DelegatorWithdrawAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DelegatorWithdrawAddress(ctx, req.(*QueryDelegatorWithdrawAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_CommunityPool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCommunityPoolRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CommunityPool(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Query/CommunityPool", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CommunityPool(ctx, req.(*QueryCommunityPoolRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var Query_serviceDesc = _Query_serviceDesc +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "atomone.distribution.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "ValidatorDistributionInfo", + Handler: _Query_ValidatorDistributionInfo_Handler, + }, + { + MethodName: "ValidatorOutstandingRewards", + Handler: _Query_ValidatorOutstandingRewards_Handler, + }, + { + MethodName: "ValidatorCommission", + Handler: _Query_ValidatorCommission_Handler, + }, + { + MethodName: "ValidatorSlashes", + Handler: _Query_ValidatorSlashes_Handler, + }, + { + MethodName: "DelegationRewards", + Handler: _Query_DelegationRewards_Handler, + }, + { + MethodName: "DelegationTotalRewards", + Handler: _Query_DelegationTotalRewards_Handler, + }, + { + MethodName: "DelegatorValidators", + Handler: _Query_DelegatorValidators_Handler, + }, + { + MethodName: "DelegatorWithdrawAddress", + Handler: _Query_DelegatorWithdrawAddress_Handler, + }, + { + MethodName: "CommunityPool", + Handler: _Query_CommunityPool_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "atomone/distribution/v1beta1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryValidatorDistributionInfoRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorDistributionInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorDistributionInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorDistributionInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorDistributionInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorDistributionInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Commission) > 0 { + for iNdEx := len(m.Commission) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Commission[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.SelfBondRewards) > 0 { + for iNdEx := len(m.SelfBondRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SelfBondRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.OperatorAddress) > 0 { + i -= len(m.OperatorAddress) + copy(dAtA[i:], m.OperatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.OperatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorOutstandingRewardsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorOutstandingRewardsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorOutstandingRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorOutstandingRewardsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorOutstandingRewardsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorOutstandingRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Rewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryValidatorCommissionRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorCommissionRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorCommissionRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorCommissionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorCommissionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorCommissionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Commission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryValidatorSlashesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorSlashesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorSlashesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.EndingHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.EndingHeight)) + i-- + dAtA[i] = 0x18 + } + if m.StartingHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.StartingHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorSlashesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorSlashesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorSlashesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Slashes) > 0 { + for iNdEx := len(m.Slashes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Slashes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegationRewardsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegationRewardsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegationRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegationRewardsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegationRewardsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegationRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Rewards) > 0 { + for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegationTotalRewardsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegationTotalRewardsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegationTotalRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegationTotalRewardsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegationTotalRewardsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegationTotalRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Total) > 0 { + for iNdEx := len(m.Total) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Total[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Rewards) > 0 { + for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegatorValidatorsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegatorValidatorsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegatorValidatorsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegatorValidatorsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegatorValidatorsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegatorValidatorsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Validators[iNdEx]) + copy(dAtA[i:], m.Validators[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Validators[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegatorWithdrawAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegatorWithdrawAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegatorWithdrawAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDelegatorWithdrawAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryDelegatorWithdrawAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegatorWithdrawAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WithdrawAddress) > 0 { + i -= len(m.WithdrawAddress) + copy(dAtA[i:], m.WithdrawAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.WithdrawAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryCommunityPoolRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryCommunityPoolRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCommunityPoolRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryCommunityPoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryCommunityPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCommunityPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Pool) > 0 { + for iNdEx := len(m.Pool) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pool[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryValidatorDistributionInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryValidatorDistributionInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OperatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if len(m.SelfBondRewards) > 0 { + for _, e := range m.SelfBondRewards { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if len(m.Commission) > 0 { + for _, e := range m.Commission { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryValidatorOutstandingRewardsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryValidatorOutstandingRewardsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Rewards.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryValidatorCommissionRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryValidatorCommissionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Commission.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryValidatorSlashesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.StartingHeight != 0 { + n += 1 + sovQuery(uint64(m.StartingHeight)) + } + if m.EndingHeight != 0 { + n += 1 + sovQuery(uint64(m.EndingHeight)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryValidatorSlashesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Slashes) > 0 { + for _, e := range m.Slashes { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDelegationRewardsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDelegationRewardsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Rewards) > 0 { + for _, e := range m.Rewards { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryDelegationTotalRewardsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDelegationTotalRewardsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Rewards) > 0 { + for _, e := range m.Rewards { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if len(m.Total) > 0 { + for _, e := range m.Total { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryDelegatorValidatorsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDelegatorValidatorsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Validators) > 0 { + for _, s := range m.Validators { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryDelegatorWithdrawAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDelegatorWithdrawAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.WithdrawAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryCommunityPoolRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryCommunityPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Pool) > 0 { + for _, e := range m.Pool { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorDistributionInfoRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorDistributionInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorDistributionInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorDistributionInfoResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorDistributionInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorDistributionInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SelfBondRewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SelfBondRewards = append(m.SelfBondRewards, types.DecCoin{}) + if err := m.SelfBondRewards[len(m.SelfBondRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commission = append(m.Commission, types.DecCoin{}) + if err := m.Commission[len(m.Commission)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorOutstandingRewardsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorOutstandingRewardsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorOutstandingRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorOutstandingRewardsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorOutstandingRewardsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorOutstandingRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Rewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorCommissionRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorCommissionRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorCommissionRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorCommissionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorCommissionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorCommissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorSlashesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorSlashesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorSlashesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartingHeight", wireType) + } + m.StartingHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartingHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndingHeight", wireType) + } + m.EndingHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndingHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorSlashesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorSlashesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorSlashesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Slashes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Slashes = append(m.Slashes, ValidatorSlashEvent{}) + if err := m.Slashes[len(m.Slashes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegationRewardsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegationRewardsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegationRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegationRewardsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegationRewardsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegationRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Rewards = append(m.Rewards, types.DecCoin{}) + if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegationTotalRewardsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegationTotalRewardsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegationTotalRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegationTotalRewardsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegationTotalRewardsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegationTotalRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Rewards = append(m.Rewards, DelegationDelegatorReward{}) + if err := m.Rewards[len(m.Rewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Total = append(m.Total, types.DecCoin{}) + if err := m.Total[len(m.Total)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegatorValidatorsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegatorValidatorsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegatorValidatorsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegatorValidatorsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegatorValidatorsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegatorValidatorsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegatorWithdrawAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegatorWithdrawAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegatorWithdrawAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegatorWithdrawAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryDelegatorWithdrawAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegatorWithdrawAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WithdrawAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCommunityPoolRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryCommunityPoolRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCommunityPoolRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCommunityPoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryCommunityPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCommunityPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Pool = append(m.Pool, types.DecCoin{}) + if err := m.Pool[len(m.Pool)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/distribution/types/query.pb.gw.go b/x/distribution/types/query.pb.gw.go new file mode 100644 index 00000000..e1c59289 --- /dev/null +++ b/x/distribution/types/query.pb.gw.go @@ -0,0 +1,1066 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: atomone/distribution/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ValidatorDistributionInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorDistributionInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := client.ValidatorDistributionInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ValidatorDistributionInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorDistributionInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := server.ValidatorDistributionInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ValidatorOutstandingRewards_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorOutstandingRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := client.ValidatorOutstandingRewards(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ValidatorOutstandingRewards_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorOutstandingRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := server.ValidatorOutstandingRewards(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ValidatorCommission_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorCommissionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := client.ValidatorCommission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ValidatorCommission_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorCommissionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := server.ValidatorCommission(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_ValidatorSlashes_0 = &utilities.DoubleArray{Encoding: map[string]int{"validator_address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_ValidatorSlashes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorSlashesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ValidatorSlashes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ValidatorSlashes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ValidatorSlashes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorSlashesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ValidatorSlashes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ValidatorSlashes(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_DelegationRewards_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegationRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := client.DelegationRewards(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DelegationRewards_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegationRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + val, ok = pathParams["validator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_address") + } + + protoReq.ValidatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_address", err) + } + + msg, err := server.DelegationRewards(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_DelegationTotalRewards_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegationTotalRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := client.DelegationTotalRewards(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DelegationTotalRewards_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegationTotalRewardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := server.DelegationTotalRewards(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_DelegatorValidators_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegatorValidatorsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := client.DelegatorValidators(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DelegatorValidators_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegatorValidatorsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := server.DelegatorValidators(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_DelegatorWithdrawAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegatorWithdrawAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := client.DelegatorWithdrawAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DelegatorWithdrawAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegatorWithdrawAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["delegator_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "delegator_address") + } + + protoReq.DelegatorAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "delegator_address", err) + } + + msg, err := server.DelegatorWithdrawAddress(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_CommunityPool_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCommunityPoolRequest + var metadata runtime.ServerMetadata + + msg, err := client.CommunityPool(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_CommunityPool_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCommunityPoolRequest + var metadata runtime.ServerMetadata + + msg, err := server.CommunityPool(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorDistributionInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ValidatorDistributionInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorDistributionInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorOutstandingRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ValidatorOutstandingRewards_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorOutstandingRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorCommission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ValidatorCommission_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorCommission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorSlashes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ValidatorSlashes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorSlashes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegationRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DelegationRewards_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegationRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegationTotalRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DelegationTotalRewards_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegationTotalRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegatorValidators_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DelegatorValidators_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegatorValidators_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegatorWithdrawAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DelegatorWithdrawAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegatorWithdrawAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CommunityPool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_CommunityPool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CommunityPool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorDistributionInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ValidatorDistributionInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorDistributionInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorOutstandingRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ValidatorOutstandingRewards_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorOutstandingRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorCommission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ValidatorCommission_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorCommission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorSlashes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ValidatorSlashes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorSlashes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegationRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DelegationRewards_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegationRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegationTotalRewards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DelegationTotalRewards_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegationTotalRewards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegatorValidators_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DelegatorValidators_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegatorValidators_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DelegatorWithdrawAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DelegatorWithdrawAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegatorWithdrawAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CommunityPool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_CommunityPool_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CommunityPool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "distribution", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ValidatorDistributionInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "distribution", "v1beta1", "validators", "validator_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ValidatorOutstandingRewards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "validators", "validator_address", "outstanding_rewards"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ValidatorCommission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "validators", "validator_address", "commission"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ValidatorSlashes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "validators", "validator_address", "slashes"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DelegationRewards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5, 1, 0, 4, 1, 5, 6}, []string{"cosmos", "distribution", "v1beta1", "delegators", "delegator_address", "rewards", "validator_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DelegationTotalRewards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "delegators", "delegator_address", "rewards"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DelegatorValidators_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "delegators", "delegator_address", "validators"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DelegatorWithdrawAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "distribution", "v1beta1", "delegators", "delegator_address", "withdraw_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_CommunityPool_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "distribution", "v1beta1", "community_pool"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_ValidatorDistributionInfo_0 = runtime.ForwardResponseMessage + + forward_Query_ValidatorOutstandingRewards_0 = runtime.ForwardResponseMessage + + forward_Query_ValidatorCommission_0 = runtime.ForwardResponseMessage + + forward_Query_ValidatorSlashes_0 = runtime.ForwardResponseMessage + + forward_Query_DelegationRewards_0 = runtime.ForwardResponseMessage + + forward_Query_DelegationTotalRewards_0 = runtime.ForwardResponseMessage + + forward_Query_DelegatorValidators_0 = runtime.ForwardResponseMessage + + forward_Query_DelegatorWithdrawAddress_0 = runtime.ForwardResponseMessage + + forward_Query_CommunityPool_0 = runtime.ForwardResponseMessage +) diff --git a/x/distribution/types/tx.pb.go b/x/distribution/types/tx.pb.go new file mode 100644 index 00000000..4b86566b --- /dev/null +++ b/x/distribution/types/tx.pb.go @@ -0,0 +1,3345 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: atomone/distribution/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgSetWithdrawAddress sets the withdraw address for +// a delegator (or validator self-delegation). +type MsgSetWithdrawAddress struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + WithdrawAddress string `protobuf:"bytes,2,opt,name=withdraw_address,json=withdrawAddress,proto3" json:"withdraw_address,omitempty"` +} + +func (m *MsgSetWithdrawAddress) Reset() { *m = MsgSetWithdrawAddress{} } +func (m *MsgSetWithdrawAddress) String() string { return proto.CompactTextString(m) } +func (*MsgSetWithdrawAddress) ProtoMessage() {} +func (*MsgSetWithdrawAddress) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{0} +} +func (m *MsgSetWithdrawAddress) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetWithdrawAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetWithdrawAddress.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSetWithdrawAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetWithdrawAddress.Merge(m, src) +} +func (m *MsgSetWithdrawAddress) XXX_Size() int { + return m.Size() +} +func (m *MsgSetWithdrawAddress) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetWithdrawAddress.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetWithdrawAddress proto.InternalMessageInfo + +// MsgSetWithdrawAddressResponse defines the Msg/SetWithdrawAddress response +// type. +type MsgSetWithdrawAddressResponse struct { +} + +func (m *MsgSetWithdrawAddressResponse) Reset() { *m = MsgSetWithdrawAddressResponse{} } +func (m *MsgSetWithdrawAddressResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSetWithdrawAddressResponse) ProtoMessage() {} +func (*MsgSetWithdrawAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{1} +} +func (m *MsgSetWithdrawAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetWithdrawAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetWithdrawAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSetWithdrawAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetWithdrawAddressResponse.Merge(m, src) +} +func (m *MsgSetWithdrawAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSetWithdrawAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetWithdrawAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetWithdrawAddressResponse proto.InternalMessageInfo + +// MsgWithdrawDelegatorReward represents delegation withdrawal to a delegator +// from a single validator. +type MsgWithdrawDelegatorReward struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *MsgWithdrawDelegatorReward) Reset() { *m = MsgWithdrawDelegatorReward{} } +func (m *MsgWithdrawDelegatorReward) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDelegatorReward) ProtoMessage() {} +func (*MsgWithdrawDelegatorReward) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{2} +} +func (m *MsgWithdrawDelegatorReward) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDelegatorReward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDelegatorReward.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDelegatorReward) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDelegatorReward.Merge(m, src) +} +func (m *MsgWithdrawDelegatorReward) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDelegatorReward) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDelegatorReward.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDelegatorReward proto.InternalMessageInfo + +// MsgWithdrawDelegatorRewardResponse defines the Msg/WithdrawDelegatorReward +// response type. +type MsgWithdrawDelegatorRewardResponse struct { + // Since: cosmos-sdk 0.46 + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *MsgWithdrawDelegatorRewardResponse) Reset() { *m = MsgWithdrawDelegatorRewardResponse{} } +func (m *MsgWithdrawDelegatorRewardResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawDelegatorRewardResponse) ProtoMessage() {} +func (*MsgWithdrawDelegatorRewardResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{3} +} +func (m *MsgWithdrawDelegatorRewardResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawDelegatorRewardResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawDelegatorRewardResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawDelegatorRewardResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawDelegatorRewardResponse.Merge(m, src) +} +func (m *MsgWithdrawDelegatorRewardResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawDelegatorRewardResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawDelegatorRewardResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawDelegatorRewardResponse proto.InternalMessageInfo + +func (m *MsgWithdrawDelegatorRewardResponse) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// MsgWithdrawValidatorCommission withdraws the full commission to the validator +// address. +type MsgWithdrawValidatorCommission struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` +} + +func (m *MsgWithdrawValidatorCommission) Reset() { *m = MsgWithdrawValidatorCommission{} } +func (m *MsgWithdrawValidatorCommission) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawValidatorCommission) ProtoMessage() {} +func (*MsgWithdrawValidatorCommission) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{4} +} +func (m *MsgWithdrawValidatorCommission) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawValidatorCommission) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawValidatorCommission.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawValidatorCommission) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawValidatorCommission.Merge(m, src) +} +func (m *MsgWithdrawValidatorCommission) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawValidatorCommission) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawValidatorCommission.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawValidatorCommission proto.InternalMessageInfo + +// MsgWithdrawValidatorCommissionResponse defines the +// Msg/WithdrawValidatorCommission response type. +type MsgWithdrawValidatorCommissionResponse struct { + // Since: cosmos-sdk 0.46 + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *MsgWithdrawValidatorCommissionResponse) Reset() { + *m = MsgWithdrawValidatorCommissionResponse{} +} +func (m *MsgWithdrawValidatorCommissionResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawValidatorCommissionResponse) ProtoMessage() {} +func (*MsgWithdrawValidatorCommissionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{5} +} +func (m *MsgWithdrawValidatorCommissionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawValidatorCommissionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawValidatorCommissionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawValidatorCommissionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawValidatorCommissionResponse.Merge(m, src) +} +func (m *MsgWithdrawValidatorCommissionResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawValidatorCommissionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawValidatorCommissionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawValidatorCommissionResponse proto.InternalMessageInfo + +func (m *MsgWithdrawValidatorCommissionResponse) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// MsgFundCommunityPool allows an account to directly +// fund the community pool. +type MsgFundCommunityPool struct { + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` + Depositor string `protobuf:"bytes,2,opt,name=depositor,proto3" json:"depositor,omitempty"` +} + +func (m *MsgFundCommunityPool) Reset() { *m = MsgFundCommunityPool{} } +func (m *MsgFundCommunityPool) String() string { return proto.CompactTextString(m) } +func (*MsgFundCommunityPool) ProtoMessage() {} +func (*MsgFundCommunityPool) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{6} +} +func (m *MsgFundCommunityPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFundCommunityPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFundCommunityPool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgFundCommunityPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFundCommunityPool.Merge(m, src) +} +func (m *MsgFundCommunityPool) XXX_Size() int { + return m.Size() +} +func (m *MsgFundCommunityPool) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFundCommunityPool.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFundCommunityPool proto.InternalMessageInfo + +// MsgFundCommunityPoolResponse defines the Msg/FundCommunityPool response type. +type MsgFundCommunityPoolResponse struct { +} + +func (m *MsgFundCommunityPoolResponse) Reset() { *m = MsgFundCommunityPoolResponse{} } +func (m *MsgFundCommunityPoolResponse) String() string { return proto.CompactTextString(m) } +func (*MsgFundCommunityPoolResponse) ProtoMessage() {} +func (*MsgFundCommunityPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{7} +} +func (m *MsgFundCommunityPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFundCommunityPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFundCommunityPoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgFundCommunityPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFundCommunityPoolResponse.Merge(m, src) +} +func (m *MsgFundCommunityPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgFundCommunityPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFundCommunityPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFundCommunityPoolResponse proto.InternalMessageInfo + +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/distribution parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{8} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{9} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +// MsgCommunityPoolSpend defines a message for sending tokens from the community +// pool to another account. This message is typically executed via a governance +// proposal with the governance module being the executing authority. +// +// Since: cosmos-sdk 0.47 +type MsgCommunityPoolSpend struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *MsgCommunityPoolSpend) Reset() { *m = MsgCommunityPoolSpend{} } +func (m *MsgCommunityPoolSpend) String() string { return proto.CompactTextString(m) } +func (*MsgCommunityPoolSpend) ProtoMessage() {} +func (*MsgCommunityPoolSpend) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{10} +} +func (m *MsgCommunityPoolSpend) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommunityPoolSpend) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommunityPoolSpend.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommunityPoolSpend) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommunityPoolSpend.Merge(m, src) +} +func (m *MsgCommunityPoolSpend) XXX_Size() int { + return m.Size() +} +func (m *MsgCommunityPoolSpend) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommunityPoolSpend.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommunityPoolSpend proto.InternalMessageInfo + +func (m *MsgCommunityPoolSpend) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgCommunityPoolSpend) GetRecipient() string { + if m != nil { + return m.Recipient + } + return "" +} + +func (m *MsgCommunityPoolSpend) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// MsgCommunityPoolSpendResponse defines the response to executing a +// MsgCommunityPoolSpend message. +// +// Since: cosmos-sdk 0.47 +type MsgCommunityPoolSpendResponse struct { +} + +func (m *MsgCommunityPoolSpendResponse) Reset() { *m = MsgCommunityPoolSpendResponse{} } +func (m *MsgCommunityPoolSpendResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCommunityPoolSpendResponse) ProtoMessage() {} +func (*MsgCommunityPoolSpendResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{11} +} +func (m *MsgCommunityPoolSpendResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommunityPoolSpendResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommunityPoolSpendResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommunityPoolSpendResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommunityPoolSpendResponse.Merge(m, src) +} +func (m *MsgCommunityPoolSpendResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCommunityPoolSpendResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommunityPoolSpendResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommunityPoolSpendResponse proto.InternalMessageInfo + +// DepositValidatorRewardsPool defines the request structure to provide +// additional rewards to delegators from a specific validator. +// +// Since: cosmos-sdk 0.50 +type MsgDepositValidatorRewardsPool struct { + Depositor string `protobuf:"bytes,1,opt,name=depositor,proto3" json:"depositor,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *MsgDepositValidatorRewardsPool) Reset() { *m = MsgDepositValidatorRewardsPool{} } +func (m *MsgDepositValidatorRewardsPool) String() string { return proto.CompactTextString(m) } +func (*MsgDepositValidatorRewardsPool) ProtoMessage() {} +func (*MsgDepositValidatorRewardsPool) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{12} +} +func (m *MsgDepositValidatorRewardsPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositValidatorRewardsPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositValidatorRewardsPool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDepositValidatorRewardsPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositValidatorRewardsPool.Merge(m, src) +} +func (m *MsgDepositValidatorRewardsPool) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositValidatorRewardsPool) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositValidatorRewardsPool.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositValidatorRewardsPool proto.InternalMessageInfo + +// MsgDepositValidatorRewardsPoolResponse defines the response to executing a +// MsgDepositValidatorRewardsPool message. +// +// Since: cosmos-sdk 0.50 +type MsgDepositValidatorRewardsPoolResponse struct { +} + +func (m *MsgDepositValidatorRewardsPoolResponse) Reset() { + *m = MsgDepositValidatorRewardsPoolResponse{} +} +func (m *MsgDepositValidatorRewardsPoolResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDepositValidatorRewardsPoolResponse) ProtoMessage() {} +func (*MsgDepositValidatorRewardsPoolResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_86cfe63176c8e16c, []int{13} +} +func (m *MsgDepositValidatorRewardsPoolResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositValidatorRewardsPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositValidatorRewardsPoolResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDepositValidatorRewardsPoolResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositValidatorRewardsPoolResponse.Merge(m, src) +} +func (m *MsgDepositValidatorRewardsPoolResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositValidatorRewardsPoolResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositValidatorRewardsPoolResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositValidatorRewardsPoolResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgSetWithdrawAddress)(nil), "atomone.distribution.v1beta1.MsgSetWithdrawAddress") + proto.RegisterType((*MsgSetWithdrawAddressResponse)(nil), "atomone.distribution.v1beta1.MsgSetWithdrawAddressResponse") + proto.RegisterType((*MsgWithdrawDelegatorReward)(nil), "atomone.distribution.v1beta1.MsgWithdrawDelegatorReward") + proto.RegisterType((*MsgWithdrawDelegatorRewardResponse)(nil), "atomone.distribution.v1beta1.MsgWithdrawDelegatorRewardResponse") + proto.RegisterType((*MsgWithdrawValidatorCommission)(nil), "atomone.distribution.v1beta1.MsgWithdrawValidatorCommission") + proto.RegisterType((*MsgWithdrawValidatorCommissionResponse)(nil), "atomone.distribution.v1beta1.MsgWithdrawValidatorCommissionResponse") + proto.RegisterType((*MsgFundCommunityPool)(nil), "atomone.distribution.v1beta1.MsgFundCommunityPool") + proto.RegisterType((*MsgFundCommunityPoolResponse)(nil), "atomone.distribution.v1beta1.MsgFundCommunityPoolResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "atomone.distribution.v1beta1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "atomone.distribution.v1beta1.MsgUpdateParamsResponse") + proto.RegisterType((*MsgCommunityPoolSpend)(nil), "atomone.distribution.v1beta1.MsgCommunityPoolSpend") + proto.RegisterType((*MsgCommunityPoolSpendResponse)(nil), "atomone.distribution.v1beta1.MsgCommunityPoolSpendResponse") + proto.RegisterType((*MsgDepositValidatorRewardsPool)(nil), "atomone.distribution.v1beta1.MsgDepositValidatorRewardsPool") + proto.RegisterType((*MsgDepositValidatorRewardsPoolResponse)(nil), "atomone.distribution.v1beta1.MsgDepositValidatorRewardsPoolResponse") +} + +func init() { + proto.RegisterFile("atomone/distribution/v1beta1/tx.proto", fileDescriptor_86cfe63176c8e16c) +} + +var fileDescriptor_86cfe63176c8e16c = []byte{ + // 939 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0x41, 0x6f, 0xe3, 0x44, + 0x14, 0xce, 0xb4, 0xa2, 0x28, 0xb3, 0x2b, 0xed, 0x26, 0x2a, 0x6a, 0x6b, 0xba, 0xce, 0x62, 0xd8, + 0x12, 0x45, 0x8a, 0xad, 0xa6, 0x02, 0x81, 0xe1, 0xb0, 0xa4, 0xa5, 0x88, 0x43, 0xd0, 0x92, 0x0a, + 0x90, 0xb8, 0x54, 0x4e, 0x3c, 0x38, 0x23, 0x6a, 0x8f, 0xe5, 0x99, 0x24, 0x9b, 0x1b, 0x02, 0x81, + 0x10, 0x27, 0x2e, 0x5c, 0xb8, 0xb0, 0x68, 0x2f, 0x2b, 0x4e, 0x39, 0xec, 0x81, 0x9f, 0xb0, 0x27, + 0xb4, 0xda, 0x13, 0x27, 0x40, 0xa9, 0x50, 0x90, 0xf8, 0x07, 0x1c, 0x10, 0xb2, 0x3d, 0x76, 0xec, + 0xd8, 0xb1, 0xb3, 0x61, 0x45, 0xb9, 0xb4, 0xf1, 0x9b, 0xf7, 0xbe, 0x79, 0xef, 0x9b, 0x6f, 0xde, + 0xb3, 0xe1, 0x0d, 0x8d, 0x11, 0x93, 0x58, 0x48, 0xd1, 0x31, 0x65, 0x0e, 0xee, 0xf4, 0x19, 0x26, + 0x96, 0x32, 0xd8, 0xef, 0x20, 0xa6, 0xed, 0x2b, 0xec, 0xb6, 0x6c, 0x3b, 0x84, 0x91, 0xf2, 0x2e, + 0x77, 0x93, 0xa3, 0x6e, 0x32, 0x77, 0x13, 0x4a, 0x9a, 0x89, 0x2d, 0xa2, 0x78, 0x7f, 0xfd, 0x00, + 0x41, 0xc9, 0xc4, 0x8d, 0xa1, 0xf8, 0x01, 0x62, 0x97, 0x50, 0x93, 0x50, 0xa5, 0xa3, 0x51, 0x14, + 0xfa, 0x75, 0x09, 0x0e, 0xd6, 0xb7, 0xf8, 0xba, 0x49, 0x0d, 0x65, 0xb0, 0xef, 0xfe, 0xe3, 0x0b, + 0x3b, 0xfe, 0xc2, 0xa9, 0xf7, 0xa4, 0xf8, 0x0f, 0x7c, 0x69, 0xd3, 0x20, 0x06, 0xf1, 0xed, 0xee, + 0x2f, 0xdf, 0x2a, 0xfd, 0x09, 0xe0, 0x33, 0x2d, 0x6a, 0x9c, 0x20, 0xf6, 0x01, 0x66, 0x3d, 0xdd, + 0xd1, 0x86, 0x6f, 0xe8, 0xba, 0x83, 0x28, 0x2d, 0xbf, 0x09, 0x4b, 0x3a, 0x3a, 0x43, 0x86, 0xc6, + 0x88, 0x73, 0xaa, 0xf9, 0xc6, 0x6d, 0x70, 0x1d, 0x54, 0x8b, 0xcd, 0xed, 0x47, 0xf7, 0xeb, 0x9b, + 0x1c, 0x9c, 0xbb, 0x9f, 0x30, 0x07, 0x5b, 0x46, 0xfb, 0x6a, 0x18, 0x12, 0xc0, 0x1c, 0xc2, 0xab, + 0x43, 0x8e, 0x1c, 0xa2, 0xac, 0xe5, 0xa0, 0x5c, 0x19, 0xc6, 0x73, 0x51, 0x8f, 0xbf, 0xbc, 0x53, + 0x29, 0xfc, 0x71, 0xa7, 0x52, 0xf8, 0x74, 0x3a, 0xae, 0x25, 0xd3, 0xfa, 0x6a, 0x3a, 0xae, 0x3d, + 0xef, 0x23, 0xd5, 0xa9, 0xfe, 0xb1, 0xd2, 0xa2, 0x46, 0x8b, 0xe8, 0xf8, 0xa3, 0xd1, 0x5c, 0x4d, + 0x52, 0x05, 0x5e, 0x4b, 0x2d, 0xb6, 0x8d, 0xa8, 0x4d, 0x2c, 0x8a, 0xa4, 0xbf, 0x01, 0x14, 0x5a, + 0xd4, 0x08, 0x96, 0x8f, 0x82, 0x9d, 0xda, 0x68, 0xa8, 0x39, 0xfa, 0x93, 0xe2, 0xe4, 0x1d, 0x58, + 0x1a, 0x68, 0x67, 0x58, 0x8f, 0xc1, 0xf8, 0xa4, 0x3c, 0xf7, 0xe8, 0x7e, 0xfd, 0x1a, 0x87, 0x79, + 0x3f, 0xf0, 0x99, 0xc3, 0x1b, 0xcc, 0xd9, 0xd5, 0xb7, 0xf3, 0xe9, 0xd9, 0x8b, 0xd3, 0x33, 0x57, + 0x20, 0x26, 0x96, 0x5f, 0xa1, 0xf4, 0x1d, 0x80, 0xd2, 0x62, 0x02, 0x02, 0x9e, 0xca, 0x23, 0xb8, + 0xa1, 0x99, 0xa4, 0x6f, 0xb1, 0x6d, 0x70, 0x7d, 0xbd, 0x7a, 0xa9, 0xb1, 0x23, 0xf3, 0x9c, 0x5d, + 0xc5, 0x06, 0x57, 0x41, 0x3e, 0x24, 0xd8, 0x6a, 0x1e, 0x3f, 0xf8, 0xa5, 0x52, 0xf8, 0xe1, 0xd7, + 0x4a, 0xd5, 0xc0, 0xac, 0xd7, 0xef, 0xc8, 0x5d, 0x62, 0x72, 0x61, 0x2a, 0x91, 0x9c, 0xd8, 0xc8, + 0x46, 0xd4, 0x0b, 0xa0, 0xdf, 0x4e, 0xc7, 0xb5, 0xcb, 0xee, 0xb6, 0xdd, 0xd1, 0xa9, 0xab, 0x79, + 0x7a, 0x6f, 0x3a, 0xae, 0x81, 0x36, 0xdf, 0x50, 0xfa, 0x11, 0x40, 0x31, 0x92, 0x61, 0x48, 0xd2, + 0x21, 0x31, 0x4d, 0x4c, 0x29, 0x26, 0x56, 0x3a, 0xbf, 0x60, 0x75, 0x7e, 0xe3, 0xf2, 0x4b, 0x40, + 0xa7, 0xc8, 0x2f, 0x92, 0xdd, 0x2c, 0x2f, 0xe9, 0x2e, 0x80, 0x7b, 0xd9, 0xa9, 0xff, 0x1f, 0x08, + 0xfe, 0x7c, 0x0d, 0x6e, 0xb6, 0xa8, 0x71, 0xdc, 0xb7, 0x74, 0x37, 0xb1, 0xbe, 0x85, 0xd9, 0xe8, + 0x16, 0x21, 0x67, 0x17, 0x98, 0x53, 0xf9, 0x65, 0x58, 0xd4, 0x91, 0x4d, 0x28, 0x66, 0xc4, 0xc9, + 0x6d, 0x1f, 0x33, 0x57, 0x55, 0x8d, 0x9e, 0xdc, 0xcc, 0xee, 0x9e, 0x58, 0x25, 0x7e, 0x62, 0x89, + 0x72, 0x25, 0x11, 0xee, 0xa6, 0xd9, 0xc3, 0x5e, 0xf1, 0x13, 0x80, 0x57, 0x5a, 0xd4, 0x78, 0xcf, + 0xd6, 0x35, 0x86, 0x6e, 0x69, 0x8e, 0x66, 0x52, 0x37, 0x4f, 0xad, 0xcf, 0x7a, 0xc4, 0xc1, 0x6c, + 0x94, 0xdb, 0x18, 0x66, 0xae, 0xe5, 0xb7, 0xe0, 0x86, 0xed, 0x21, 0x78, 0xc5, 0x5d, 0x6a, 0xbc, + 0x20, 0x67, 0xcd, 0x18, 0xd9, 0xdf, 0xad, 0x59, 0x74, 0x59, 0xe6, 0x44, 0xf9, 0xe1, 0xaa, 0xea, + 0x15, 0x1a, 0x02, 0xbb, 0x85, 0xbe, 0x18, 0x29, 0x34, 0x36, 0x80, 0xe6, 0x92, 0x97, 0x76, 0xe0, + 0xd6, 0x9c, 0x29, 0xac, 0xf5, 0xee, 0x9a, 0x37, 0x26, 0x62, 0x44, 0x9c, 0xd8, 0xc8, 0xd2, 0x57, + 0xae, 0x78, 0x17, 0x16, 0x1d, 0xd4, 0xc5, 0x36, 0x46, 0x16, 0xf3, 0x4f, 0xb4, 0x3d, 0x33, 0x44, + 0xa4, 0xb6, 0xfe, 0x1f, 0x4b, 0x4d, 0x7d, 0x35, 0xc9, 0xe0, 0xde, 0x3c, 0x83, 0x4a, 0x2a, 0x17, + 0x7c, 0xbc, 0x24, 0x17, 0x42, 0x1a, 0x7f, 0x5f, 0xf3, 0x7a, 0xd7, 0x91, 0xaf, 0xc3, 0xf0, 0xfe, + 0xfb, 0xcd, 0x95, 0x7a, 0x97, 0x2c, 0xa6, 0x74, 0xb0, 0xb4, 0xd2, 0x9f, 0xf4, 0x4c, 0xb9, 0xc8, + 0x13, 0xb8, 0xb9, 0xf8, 0xd2, 0xde, 0x48, 0x3b, 0x89, 0x19, 0x9d, 0x9c, 0x48, 0xa9, 0xea, 0xf5, + 0xd9, 0x0c, 0x9a, 0x83, 0x13, 0x69, 0xfc, 0xf5, 0x34, 0x5c, 0x6f, 0x51, 0xa3, 0xfc, 0x05, 0x80, + 0xe5, 0x94, 0x97, 0xa0, 0x83, 0xec, 0x7b, 0x98, 0xfa, 0x32, 0x21, 0xbc, 0xb6, 0x42, 0x50, 0xd8, + 0xf8, 0xbf, 0x01, 0x70, 0x6b, 0xd1, 0xeb, 0xc7, 0x2b, 0xb9, 0xc0, 0x0b, 0x22, 0x85, 0x9b, 0xab, + 0x46, 0x86, 0x79, 0x7d, 0x0f, 0xe0, 0xb3, 0x59, 0x33, 0xf7, 0xf5, 0xa5, 0x77, 0x48, 0x89, 0x16, + 0x8e, 0xfe, 0x4d, 0x74, 0x98, 0xe3, 0x67, 0x00, 0x96, 0x92, 0x63, 0xab, 0x91, 0x8b, 0x9d, 0x88, + 0x11, 0xd4, 0xc7, 0x8f, 0x09, 0xb3, 0x60, 0xf0, 0x72, 0x6c, 0x26, 0xd4, 0x73, 0xb1, 0xa2, 0xee, + 0xc2, 0x4b, 0x8f, 0xe5, 0x1e, 0xee, 0xea, 0x0a, 0x38, 0xa5, 0x3d, 0xe7, 0x0b, 0x38, 0x19, 0xb4, + 0x84, 0x80, 0x17, 0xf7, 0x38, 0x4f, 0x28, 0x59, 0x0d, 0x2e, 0x5f, 0x28, 0x19, 0xd1, 0x4b, 0x08, + 0x65, 0x89, 0x5b, 0x2f, 0x3c, 0xf5, 0x89, 0xdb, 0x70, 0x9a, 0xef, 0xde, 0x9b, 0x88, 0xe0, 0xc1, + 0x44, 0x04, 0x0f, 0x27, 0x22, 0xf8, 0x6d, 0x22, 0x82, 0xaf, 0xcf, 0xc5, 0xc2, 0xc3, 0x73, 0xb1, + 0xf0, 0xf3, 0xb9, 0x58, 0xf8, 0xf0, 0x20, 0xd2, 0xce, 0xf8, 0xa6, 0xf5, 0x5e, 0xbf, 0x13, 0x7e, + 0xcc, 0xdd, 0x8e, 0x4f, 0x53, 0xaf, 0xbf, 0x75, 0x36, 0xbc, 0xcf, 0xaa, 0x83, 0x7f, 0x02, 0x00, + 0x00, 0xff, 0xff, 0x9c, 0x68, 0xfa, 0x20, 0x4b, 0x0e, 0x00, 0x00, +} + +func (this *MsgSetWithdrawAddressResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgSetWithdrawAddressResponse) + if !ok { + that2, ok := that.(MsgSetWithdrawAddressResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (this *MsgWithdrawDelegatorRewardResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgWithdrawDelegatorRewardResponse) + if !ok { + that2, ok := that.(MsgWithdrawDelegatorRewardResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + return true +} +func (this *MsgWithdrawValidatorCommissionResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgWithdrawValidatorCommissionResponse) + if !ok { + that2, ok := that.(MsgWithdrawValidatorCommissionResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + return true +} +func (this *MsgFundCommunityPoolResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgFundCommunityPoolResponse) + if !ok { + that2, ok := that.(MsgFundCommunityPoolResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (this *MsgUpdateParams) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgUpdateParams) + if !ok { + that2, ok := that.(MsgUpdateParams) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Authority != that1.Authority { + return false + } + if !this.Params.Equal(&that1.Params) { + return false + } + return true +} +func (this *MsgUpdateParamsResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgUpdateParamsResponse) + if !ok { + that2, ok := that.(MsgUpdateParamsResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (this *MsgCommunityPoolSpend) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgCommunityPoolSpend) + if !ok { + that2, ok := that.(MsgCommunityPoolSpend) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Authority != that1.Authority { + return false + } + if this.Recipient != that1.Recipient { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + return true +} +func (this *MsgCommunityPoolSpendResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgCommunityPoolSpendResponse) + if !ok { + that2, ok := that.(MsgCommunityPoolSpendResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (this *MsgDepositValidatorRewardsPoolResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgDepositValidatorRewardsPoolResponse) + if !ok { + that2, ok := that.(MsgDepositValidatorRewardsPoolResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // SetWithdrawAddress defines a method to change the withdraw address + // for a delegator (or validator self-delegation). + SetWithdrawAddress(ctx context.Context, in *MsgSetWithdrawAddress, opts ...grpc.CallOption) (*MsgSetWithdrawAddressResponse, error) + // WithdrawDelegatorReward defines a method to withdraw rewards of delegator + // from a single validator. + WithdrawDelegatorReward(ctx context.Context, in *MsgWithdrawDelegatorReward, opts ...grpc.CallOption) (*MsgWithdrawDelegatorRewardResponse, error) + // WithdrawValidatorCommission defines a method to withdraw the + // full commission to the validator address. + WithdrawValidatorCommission(ctx context.Context, in *MsgWithdrawValidatorCommission, opts ...grpc.CallOption) (*MsgWithdrawValidatorCommissionResponse, error) + // FundCommunityPool defines a method to allow an account to directly + // fund the community pool. + FundCommunityPool(ctx context.Context, in *MsgFundCommunityPool, opts ...grpc.CallOption) (*MsgFundCommunityPoolResponse, error) + // UpdateParams defines a governance operation for updating the x/distribution + // module parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) + // CommunityPoolSpend defines a governance operation for sending tokens from + // the community pool in the x/distribution module to another account, which + // could be the governance module itself. The authority is defined in the + // keeper. + // + // Since: cosmos-sdk 0.47 + CommunityPoolSpend(ctx context.Context, in *MsgCommunityPoolSpend, opts ...grpc.CallOption) (*MsgCommunityPoolSpendResponse, error) + // DepositValidatorRewardsPool defines a method to provide additional rewards + // to delegators to a specific validator. + // + // Since: cosmos-sdk 0.50 + DepositValidatorRewardsPool(ctx context.Context, in *MsgDepositValidatorRewardsPool, opts ...grpc.CallOption) (*MsgDepositValidatorRewardsPoolResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) SetWithdrawAddress(ctx context.Context, in *MsgSetWithdrawAddress, opts ...grpc.CallOption) (*MsgSetWithdrawAddressResponse, error) { + out := new(MsgSetWithdrawAddressResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/SetWithdrawAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) WithdrawDelegatorReward(ctx context.Context, in *MsgWithdrawDelegatorReward, opts ...grpc.CallOption) (*MsgWithdrawDelegatorRewardResponse, error) { + out := new(MsgWithdrawDelegatorRewardResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/WithdrawDelegatorReward", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) WithdrawValidatorCommission(ctx context.Context, in *MsgWithdrawValidatorCommission, opts ...grpc.CallOption) (*MsgWithdrawValidatorCommissionResponse, error) { + out := new(MsgWithdrawValidatorCommissionResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/WithdrawValidatorCommission", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) FundCommunityPool(ctx context.Context, in *MsgFundCommunityPool, opts ...grpc.CallOption) (*MsgFundCommunityPoolResponse, error) { + out := new(MsgFundCommunityPoolResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/FundCommunityPool", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) CommunityPoolSpend(ctx context.Context, in *MsgCommunityPoolSpend, opts ...grpc.CallOption) (*MsgCommunityPoolSpendResponse, error) { + out := new(MsgCommunityPoolSpendResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/CommunityPoolSpend", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DepositValidatorRewardsPool(ctx context.Context, in *MsgDepositValidatorRewardsPool, opts ...grpc.CallOption) (*MsgDepositValidatorRewardsPoolResponse, error) { + out := new(MsgDepositValidatorRewardsPoolResponse) + err := c.cc.Invoke(ctx, "/atomone.distribution.v1beta1.Msg/DepositValidatorRewardsPool", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // SetWithdrawAddress defines a method to change the withdraw address + // for a delegator (or validator self-delegation). + SetWithdrawAddress(context.Context, *MsgSetWithdrawAddress) (*MsgSetWithdrawAddressResponse, error) + // WithdrawDelegatorReward defines a method to withdraw rewards of delegator + // from a single validator. + WithdrawDelegatorReward(context.Context, *MsgWithdrawDelegatorReward) (*MsgWithdrawDelegatorRewardResponse, error) + // WithdrawValidatorCommission defines a method to withdraw the + // full commission to the validator address. + WithdrawValidatorCommission(context.Context, *MsgWithdrawValidatorCommission) (*MsgWithdrawValidatorCommissionResponse, error) + // FundCommunityPool defines a method to allow an account to directly + // fund the community pool. + FundCommunityPool(context.Context, *MsgFundCommunityPool) (*MsgFundCommunityPoolResponse, error) + // UpdateParams defines a governance operation for updating the x/distribution + // module parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) + // CommunityPoolSpend defines a governance operation for sending tokens from + // the community pool in the x/distribution module to another account, which + // could be the governance module itself. The authority is defined in the + // keeper. + // + // Since: cosmos-sdk 0.47 + CommunityPoolSpend(context.Context, *MsgCommunityPoolSpend) (*MsgCommunityPoolSpendResponse, error) + // DepositValidatorRewardsPool defines a method to provide additional rewards + // to delegators to a specific validator. + // + // Since: cosmos-sdk 0.50 + DepositValidatorRewardsPool(context.Context, *MsgDepositValidatorRewardsPool) (*MsgDepositValidatorRewardsPoolResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) SetWithdrawAddress(ctx context.Context, req *MsgSetWithdrawAddress) (*MsgSetWithdrawAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetWithdrawAddress not implemented") +} +func (*UnimplementedMsgServer) WithdrawDelegatorReward(ctx context.Context, req *MsgWithdrawDelegatorReward) (*MsgWithdrawDelegatorRewardResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawDelegatorReward not implemented") +} +func (*UnimplementedMsgServer) WithdrawValidatorCommission(ctx context.Context, req *MsgWithdrawValidatorCommission) (*MsgWithdrawValidatorCommissionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawValidatorCommission not implemented") +} +func (*UnimplementedMsgServer) FundCommunityPool(ctx context.Context, req *MsgFundCommunityPool) (*MsgFundCommunityPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FundCommunityPool not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} +func (*UnimplementedMsgServer) CommunityPoolSpend(ctx context.Context, req *MsgCommunityPoolSpend) (*MsgCommunityPoolSpendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommunityPoolSpend not implemented") +} +func (*UnimplementedMsgServer) DepositValidatorRewardsPool(ctx context.Context, req *MsgDepositValidatorRewardsPool) (*MsgDepositValidatorRewardsPoolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DepositValidatorRewardsPool not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_SetWithdrawAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSetWithdrawAddress) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SetWithdrawAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/SetWithdrawAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SetWithdrawAddress(ctx, req.(*MsgSetWithdrawAddress)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_WithdrawDelegatorReward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawDelegatorReward) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawDelegatorReward(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/WithdrawDelegatorReward", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawDelegatorReward(ctx, req.(*MsgWithdrawDelegatorReward)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_WithdrawValidatorCommission_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawValidatorCommission) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawValidatorCommission(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/WithdrawValidatorCommission", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawValidatorCommission(ctx, req.(*MsgWithdrawValidatorCommission)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_FundCommunityPool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgFundCommunityPool) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).FundCommunityPool(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/FundCommunityPool", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).FundCommunityPool(ctx, req.(*MsgFundCommunityPool)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_CommunityPoolSpend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCommunityPoolSpend) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CommunityPoolSpend(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/CommunityPoolSpend", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CommunityPoolSpend(ctx, req.(*MsgCommunityPoolSpend)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DepositValidatorRewardsPool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDepositValidatorRewardsPool) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).DepositValidatorRewardsPool(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/atomone.distribution.v1beta1.Msg/DepositValidatorRewardsPool", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).DepositValidatorRewardsPool(ctx, req.(*MsgDepositValidatorRewardsPool)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "atomone.distribution.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SetWithdrawAddress", + Handler: _Msg_SetWithdrawAddress_Handler, + }, + { + MethodName: "WithdrawDelegatorReward", + Handler: _Msg_WithdrawDelegatorReward_Handler, + }, + { + MethodName: "WithdrawValidatorCommission", + Handler: _Msg_WithdrawValidatorCommission_Handler, + }, + { + MethodName: "FundCommunityPool", + Handler: _Msg_FundCommunityPool_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + { + MethodName: "CommunityPoolSpend", + Handler: _Msg_CommunityPoolSpend_Handler, + }, + { + MethodName: "DepositValidatorRewardsPool", + Handler: _Msg_DepositValidatorRewardsPool_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "atomone/distribution/v1beta1/tx.proto", +} + +func (m *MsgSetWithdrawAddress) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSetWithdrawAddress) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetWithdrawAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.WithdrawAddress) > 0 { + i -= len(m.WithdrawAddress) + copy(dAtA[i:], m.WithdrawAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.WithdrawAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSetWithdrawAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSetWithdrawAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetWithdrawAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDelegatorReward) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDelegatorReward) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDelegatorReward) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawDelegatorRewardResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawDelegatorRewardResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawDelegatorRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawValidatorCommission) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawValidatorCommission) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawValidatorCommission) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawValidatorCommissionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawValidatorCommissionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawValidatorCommissionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *MsgFundCommunityPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgFundCommunityPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFundCommunityPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Depositor) > 0 { + i -= len(m.Depositor) + copy(dAtA[i:], m.Depositor) + i = encodeVarintTx(dAtA, i, uint64(len(m.Depositor))) + i-- + dAtA[i] = 0x12 + } + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *MsgFundCommunityPoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgFundCommunityPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFundCommunityPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgCommunityPoolSpend) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommunityPoolSpend) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommunityPoolSpend) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Recipient) > 0 { + i -= len(m.Recipient) + copy(dAtA[i:], m.Recipient) + i = encodeVarintTx(dAtA, i, uint64(len(m.Recipient))) + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCommunityPoolSpendResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommunityPoolSpendResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommunityPoolSpendResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDepositValidatorRewardsPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDepositValidatorRewardsPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositValidatorRewardsPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.Depositor) > 0 { + i -= len(m.Depositor) + copy(dAtA[i:], m.Depositor) + i = encodeVarintTx(dAtA, i, uint64(len(m.Depositor))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgDepositValidatorRewardsPoolResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDepositValidatorRewardsPoolResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositValidatorRewardsPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgSetWithdrawAddress) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.WithdrawAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSetWithdrawAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgWithdrawDelegatorReward) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawDelegatorRewardResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgWithdrawValidatorCommission) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawValidatorCommissionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgFundCommunityPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.Depositor) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgFundCommunityPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgCommunityPoolSpend) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Recipient) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgCommunityPoolSpendResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDepositValidatorRewardsPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Depositor) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgDepositValidatorRewardsPoolResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgSetWithdrawAddress) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgSetWithdrawAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetWithdrawAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WithdrawAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetWithdrawAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgSetWithdrawAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetWithdrawAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDelegatorReward) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDelegatorReward: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDelegatorReward: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawDelegatorRewardResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawDelegatorRewardResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawDelegatorRewardResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawValidatorCommission) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawValidatorCommission: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawValidatorCommission: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawValidatorCommissionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawValidatorCommissionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawValidatorCommissionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgFundCommunityPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgFundCommunityPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFundCommunityPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Depositor", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Depositor = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgFundCommunityPoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgFundCommunityPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFundCommunityPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCommunityPoolSpend) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommunityPoolSpend: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommunityPoolSpend: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Recipient = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCommunityPoolSpendResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommunityPoolSpendResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommunityPoolSpendResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDepositValidatorRewardsPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDepositValidatorRewardsPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositValidatorRewardsPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Depositor", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Depositor = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDepositValidatorRewardsPoolResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDepositValidatorRewardsPoolResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositValidatorRewardsPoolResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/distribution/types/validator.go b/x/distribution/types/validator.go new file mode 100644 index 00000000..6f412f43 --- /dev/null +++ b/x/distribution/types/validator.go @@ -0,0 +1,36 @@ +package types + +import ( + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// NewValidatorHistoricalRewards creates a new ValidatorHistoricalRewards +func NewValidatorHistoricalRewards(cumulativeRewardRatio sdk.DecCoins, referenceCount uint32) ValidatorHistoricalRewards { + return ValidatorHistoricalRewards{ + CumulativeRewardRatio: cumulativeRewardRatio, + ReferenceCount: referenceCount, + } +} + +// NewValidatorCurrentRewards creates a new ValidatorCurrentRewards +func NewValidatorCurrentRewards(rewards sdk.DecCoins, period uint64) ValidatorCurrentRewards { + return ValidatorCurrentRewards{ + Rewards: rewards, + Period: period, + } +} + +// InitialValidatorAccumulatedCommission returns the initial accumulated commission (zero) +func InitialValidatorAccumulatedCommission() ValidatorAccumulatedCommission { + return ValidatorAccumulatedCommission{} +} + +// NewValidatorSlashEvent creates a new ValidatorSlashEvent +func NewValidatorSlashEvent(validatorPeriod uint64, fraction sdkmath.LegacyDec) ValidatorSlashEvent { + return ValidatorSlashEvent{ + ValidatorPeriod: validatorPeriod, + Fraction: fraction, + } +} diff --git a/x/gov/client/cli/prompt.go b/x/gov/client/cli/prompt.go index e485a435..dd8bb998 100644 --- a/x/gov/client/cli/prompt.go +++ b/x/gov/client/cli/prompt.go @@ -34,7 +34,7 @@ var suggestedProposalTypes = []proposalType{ }, { Name: "community-pool-spend", - MsgType: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + MsgType: "/atomone.distribution.v1beta1.MsgCommunityPoolSpend", }, { Name: "software-upgrade",