github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/README.md (about) 1 --- 2 sidebar_position: 1 3 --- 4 5 # `x/distribution` 6 7 ## Overview 8 9 This _simple_ distribution mechanism describes a functional way to passively 10 distribute rewards between validators and delegators. Note that this mechanism does 11 not distribute funds in as precisely as active reward distribution mechanisms and 12 will therefore be upgraded in the future. 13 14 The mechanism operates as follows. Collected rewards are pooled globally and 15 divided out passively to validators and delegators. Each validator has the 16 opportunity to charge commission to the delegators on the rewards collected on 17 behalf of the delegators. Fees are collected directly into a global reward pool 18 and validator proposer-reward pool. Due to the nature of passive accounting, 19 whenever changes to parameters which affect the rate of reward distribution 20 occurs, withdrawal of rewards must also occur. 21 22 * Whenever withdrawing, one must withdraw the maximum amount they are entitled 23 to, leaving nothing in the pool. 24 * Whenever bonding, unbonding, or re-delegating tokens to an existing account, a 25 full withdrawal of the rewards must occur (as the rules for lazy accounting 26 change). 27 * Whenever a validator chooses to change the commission on rewards, all accumulated 28 commission rewards must be simultaneously withdrawn. 29 30 The above scenarios are covered in `hooks.md`. 31 32 The distribution mechanism outlined herein is used to lazily distribute the 33 following rewards between validators and associated delegators: 34 35 * multi-token fees to be socially distributed 36 * inflated staked asset provisions 37 * validator commission on all rewards earned by their delegators stake 38 39 Fees are pooled within a global pool. The mechanisms used allow for validators 40 and delegators to independently and lazily withdraw their rewards. 41 42 ## Shortcomings 43 44 As a part of the lazy computations, each delegator holds an accumulation term 45 specific to each validator which is used to estimate what their approximate 46 fair portion of tokens held in the global fee pool is owed to them. 47 48 ```text 49 entitlement = delegator-accumulation / all-delegators-accumulation 50 ``` 51 52 Under the circumstance that there was constant and equal flow of incoming 53 reward tokens every block, this distribution mechanism would be equal to the 54 active distribution (distribute individually to all delegators each block). 55 However, this is unrealistic so deviations from the active distribution will 56 occur based on fluctuations of incoming reward tokens as well as timing of 57 reward withdrawal by other delegators. 58 59 If you happen to know that incoming rewards are about to significantly increase, 60 you are incentivized to not withdraw until after this event, increasing the 61 worth of your existing _accum_. See [#2764](https://github.com/cosmos/cosmos-sdk/issues/2764) 62 for further details. 63 64 ## Effect on Staking 65 66 Charging commission on Atom provisions while also allowing for Atom-provisions 67 to be auto-bonded (distributed directly to the validators bonded stake) is 68 problematic within BPoS. Fundamentally, these two mechanisms are mutually 69 exclusive. If both commission and auto-bonding mechanisms are simultaneously 70 applied to the staking-token then the distribution of staking-tokens between 71 any validator and its delegators will change with each block. This then 72 necessitates a calculation for each delegation records for each block - 73 which is considered computationally expensive. 74 75 In conclusion, we can only have Atom commission and unbonded atoms 76 provisions or bonded atom provisions with no Atom commission, and we elect to 77 implement the former. Stakeholders wishing to rebond their provisions may elect 78 to set up a script to periodically withdraw and rebond rewards. 79 80 ## Contents 81 82 * [Concepts](#concepts) 83 * [State](#state) 84 * [FeePool](#feepool) 85 * [Validator Distribution](#validator-distribution) 86 * [Delegation Distribution](#delegation-distribution) 87 * [Params](#params) 88 * [Begin Block](#begin-block) 89 * [Messages](#messages) 90 * [Hooks](#hooks) 91 * [Events](#events) 92 * [Parameters](#parameters) 93 * [Client](#client) 94 * [CLI](#cli) 95 * [gRPC](#grpc) 96 97 ## Concepts 98 99 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. 100 101 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. 102 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. 103 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). 104 105 The commission to the validator is paid when the validator is removed or when the validator requests a withdrawal. 106 The commission is calculated and incremented at every `BeginBlock` operation to update accumulated fee amounts. 107 108 The rewards to a delegator are distributed when the delegation is changed or removed, or a withdrawal is requested. 109 Before rewards are distributed, all slashes to the validator that occurred during the current delegation are applied. 110 111 ### Reference Counting in F1 Fee Distribution 112 113 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. 114 115 Additionally, as slashes change the amount of tokens a delegation will have (but we calculate this lazily, 116 only when a delegator un-delegates), we must calculate rewards in separate periods before / after any slashes 117 which occurred in between when a delegator delegated and when they withdrew their rewards. Thus slashes, like 118 delegations, reference the period which was ended by the slash event. 119 120 All stored historical rewards records for periods which are no longer referenced by any delegations 121 or any slashes can thus be safely removed, as they will never be read (future delegations and future 122 slashes will always reference future periods). This is implemented by tracking a `ReferenceCount` 123 along with each historical reward storage entry. Each time a new object (delegation or slash) 124 is created which might need to reference the historical record, the reference count is incremented. 125 Each time one object which previously needed to reference the historical record is deleted, the reference 126 count is decremented. If the reference count hits zero, the historical record is deleted. 127 128 ## State 129 130 ### FeePool 131 132 All globally tracked parameters for distribution are stored within 133 `FeePool`. Rewards are collected and added to the reward pool and 134 distributed to validators/delegators from here. 135 136 Note that the reward pool holds decimal coins (`DecCoins`) to allow 137 for fractions of coins to be received from operations like inflation. 138 When coins are distributed from the pool they are truncated back to 139 `sdk.Coins` which are non-decimal. 140 141 * FeePool: `0x00 -> ProtocolBuffer(FeePool)` 142 143 ```go 144 // coins with decimal 145 type DecCoins []DecCoin 146 147 type DecCoin struct { 148 Amount math.LegacyDec 149 Denom string 150 } 151 ``` 152 153 ```protobuf reference 154 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/distribution.proto#L116-L123 155 ``` 156 157 ### Validator Distribution 158 159 Validator distribution information for the relevant validator is updated each time: 160 161 1. delegation amount to a validator is updated, 162 2. any delegator withdraws from a validator, or 163 3. the validator withdraws its commission. 164 165 * ValidatorDistInfo: `0x02 | ValOperatorAddrLen (1 byte) | ValOperatorAddr -> ProtocolBuffer(validatorDistribution)` 166 167 ```go 168 type ValidatorDistInfo struct { 169 OperatorAddress sdk.AccAddress 170 SelfBondRewards sdkmath.DecCoins 171 ValidatorCommission types.ValidatorAccumulatedCommission 172 } 173 ``` 174 175 ### Delegation Distribution 176 177 Each delegation distribution only needs to record the height at which it last 178 withdrew fees. Because a delegation must withdraw fees each time it's 179 properties change (aka bonded tokens etc.) its properties will remain constant 180 and the delegator's _accumulation_ factor can be calculated passively knowing 181 only the height of the last withdrawal and its current properties. 182 183 * DelegationDistInfo: `0x02 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValOperatorAddrLen (1 byte) | ValOperatorAddr -> ProtocolBuffer(delegatorDist)` 184 185 ```go 186 type DelegationDistInfo struct { 187 WithdrawalHeight int64 // last time this delegation withdrew rewards 188 } 189 ``` 190 191 ### Params 192 193 The distribution module stores it's params in state with the prefix of `0x09`, 194 it can be updated with governance or the address with authority. 195 196 * Params: `0x09 | ProtocolBuffer(Params)` 197 198 ```protobuf reference 199 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/distribution.proto#L12-L42 200 ``` 201 202 ## Begin Block 203 204 At each `BeginBlock`, all fees received in the previous block are transferred to 205 the distribution `ModuleAccount` account. When a delegator or validator 206 withdraws their rewards, they are taken out of the `ModuleAccount`. During begin 207 block, the different claims on the fees collected are updated as follows: 208 209 * The reserve community tax is charged. 210 * The remainder is distributed proportionally by voting power to all bonded validators 211 212 ### The Distribution Scheme 213 214 See [params](#params) for description of parameters. 215 216 Let `fees` be the total fees collected in the previous block, including 217 inflationary rewards to the stake. All fees are collected in a specific module 218 account during the block. During `BeginBlock`, they are sent to the 219 `"distribution"` `ModuleAccount`. No other sending of tokens occurs. Instead, the 220 rewards each account is entitled to are stored, and withdrawals can be triggered 221 through the messages `FundCommunityPool`, `WithdrawValidatorCommission` and 222 `WithdrawDelegatorReward`. 223 224 #### Reward to the Community Pool 225 226 The community pool gets `community_tax * fees`, plus any remaining dust after 227 validators get their rewards that are always rounded down to the nearest 228 integer value. 229 230 #### Reward To the Validators 231 232 The proposer receives no extra rewards. All fees are distributed among all the 233 bonded validators, including the proposer, in proportion to their consensus power. 234 235 ```text 236 powFrac = validator power / total bonded validator power 237 voteMul = 1 - community_tax 238 ``` 239 240 All validators receive `fees * voteMul * powFrac`. 241 242 #### Rewards to Delegators 243 244 Each validator's rewards are distributed to its delegators. The validator also 245 has a self-delegation that is treated like a regular delegation in 246 distribution calculations. 247 248 The validator sets a commission rate. The commission rate is flexible, but each 249 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. 250 251 The outstanding rewards that the operator is entitled to are stored in 252 `ValidatorAccumulatedCommission`, while the rewards the delegators are entitled 253 to are stored in `ValidatorCurrentRewards`. The [F1 fee distribution scheme](#concepts) is used to calculate the rewards per delegator as they 254 withdraw or update their delegation, and is thus not handled in `BeginBlock`. 255 256 #### Example Distribution 257 258 For this example distribution, the underlying consensus engine selects block proposers in 259 proportion to their power relative to the entire bonded power. 260 261 All validators are equally performant at including pre-commits in their proposed 262 blocks. Then hold `(pre_commits included) / (total bonded validator power)` 263 constant so that the amortized block reward for the validator is `( validator power / total bonded power) * (1 - community tax rate)` of 264 the total rewards. Consequently, the reward for a single delegator is: 265 266 ```text 267 (delegator proportion of the validator power / validator power) * (validator power / total bonded power) 268 * (1 - community tax rate) * (1 - validator commission rate) 269 = (delegator proportion of the validator power / total bonded power) * (1 - 270 community tax rate) * (1 - validator commission rate) 271 ``` 272 273 ## Messages 274 275 ### MsgSetWithdrawAddress 276 277 By default, the withdraw address is the delegator address. To change its withdraw address, a delegator must send a `MsgSetWithdrawAddress` message. 278 Changing the withdraw address is possible only if the parameter `WithdrawAddrEnabled` is set to `true`. 279 280 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. 281 282 Response: 283 284 ```protobuf reference 285 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L49-L60 286 ``` 287 288 ```go 289 func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) error 290 if k.blockedAddrs[withdrawAddr.String()] { 291 fail with "`{withdrawAddr}` is not allowed to receive external funds" 292 } 293 294 if !k.GetWithdrawAddrEnabled(ctx) { 295 fail with `ErrSetWithdrawAddrDisabled` 296 } 297 298 k.SetDelegatorWithdrawAddr(ctx, delegatorAddr, withdrawAddr) 299 ``` 300 301 ### MsgWithdrawDelegatorReward 302 303 A delegator can withdraw its rewards. 304 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. 305 The rewards are sent immediately from the distribution `ModuleAccount` to the withdraw address. 306 Any remainder (truncated decimals) are sent to the community pool. 307 The starting height of the delegation is set to the current validator period, and the reference count for the previous period is decremented. 308 The amount withdrawn is deducted from the `ValidatorOutstandingRewards` variable for the validator. 309 310 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. 311 In basic F1, the total rewards that all the delegators are entitled to between to periods is calculated the following way. 312 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`. 313 Then the rewards for all the delegators for staking between periods `A` and `B` are `(R(B) - R(A)) * total stake`. 314 However, these calculated rewards don't account for slashing. 315 316 Taking the slashes into account requires iteration. 317 Let `F(X)` be the fraction a validator is to be slashed for a slashing event that happened at period `X`. 318 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: 319 320 ```go 321 stake := initial stake 322 rewards := 0 323 previous := A 324 for P in P1, ..., PN`: 325 rewards = (R(P) - previous) * stake 326 stake = stake * F(P) 327 previous = P 328 rewards = rewards + (R(B) - R(PN)) * stake 329 ``` 330 331 The historical rewards are calculated retroactively by playing back all the slashes and then attenuating the delegator's stake at each step. 332 The final calculated stake is equivalent to the actual staked coins in the delegation with a margin of error due to rounding errors. 333 334 Response: 335 336 ```protobuf reference 337 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L66-L77 338 ``` 339 340 ### WithdrawValidatorCommission 341 342 The validator can send the WithdrawValidatorCommission message to withdraw their accumulated commission. 343 The commission is calculated in every block during `BeginBlock`, so no iteration is required to withdraw. 344 The amount withdrawn is deducted from the `ValidatorOutstandingRewards` variable for the validator. 345 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. 346 347 ### FundCommunityPool 348 349 This message sends coins directly from the sender to the community pool. 350 351 The transaction fails if the amount cannot be transferred from the sender to the distribution module account. 352 353 ```go 354 func (k Keeper) FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error { 355 if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { 356 return err 357 } 358 359 feePool, err := k.FeePool.Get(ctx) 360 if err != nil { 361 return err 362 } 363 364 feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) 365 366 if err := k.FeePool.Set(ctx, feePool); err != nil { 367 return err 368 } 369 370 return nil 371 } 372 ``` 373 374 ### Common distribution operations 375 376 These operations take place during many different messages. 377 378 #### Initialize delegation 379 380 Each time a delegation is changed, the rewards are withdrawn and the delegation is reinitialized. 381 Initializing a delegation increments the validator period and keeps track of the starting period of the delegation. 382 383 ```go 384 // initialize starting info for a new delegation 385 func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) { 386 // period has already been incremented - we want to store the period ended by this delegation action 387 previousPeriod := k.GetValidatorCurrentRewards(ctx, val).Period - 1 388 389 // increment reference count for the period we're going to track 390 k.incrementReferenceCount(ctx, val, previousPeriod) 391 392 validator := k.stakingKeeper.Validator(ctx, val) 393 delegation := k.stakingKeeper.Delegation(ctx, del, val) 394 395 // calculate delegation stake in tokens 396 // we don't store directly, so multiply delegation shares * (tokens per share) 397 // note: necessary to truncate so we don't allow withdrawing more rewards than owed 398 stake := validator.TokensFromSharesTruncated(delegation.GetShares()) 399 k.SetDelegatorStartingInfo(ctx, val, del, types.NewDelegatorStartingInfo(previousPeriod, stake, uint64(ctx.BlockHeight()))) 400 } 401 ``` 402 403 ### MsgUpdateParams 404 405 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. 406 407 ```protobuf reference 408 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/distribution/v1beta1/tx.proto#L133-L147 409 ``` 410 411 The message handling can fail if: 412 413 * signer is not the gov module account address. 414 415 ## Hooks 416 417 Available hooks that can be called by and from this module. 418 419 ### Create or modify delegation distribution 420 421 * triggered-by: `staking.MsgDelegate`, `staking.MsgBeginRedelegate`, `staking.MsgUndelegate` 422 423 #### Before 424 425 * The delegation rewards are withdrawn to the withdraw address of the delegator. 426 The rewards include the current period and exclude the starting period. 427 * The validator period is incremented. 428 The validator period is incremented because the validator's power and share distribution might have changed. 429 * The reference count for the delegator's starting period is decremented. 430 431 #### After 432 433 The starting height of the delegation is set to the previous period. 434 Because of the `Before`-hook, this period is the last period for which the delegator was rewarded. 435 436 ### Validator created 437 438 * triggered-by: `staking.MsgCreateValidator` 439 440 When a validator is created, the following validator variables are initialized: 441 442 * Historical rewards 443 * Current accumulated rewards 444 * Accumulated commission 445 * Total outstanding rewards 446 * Period 447 448 By default, all values are set to a `0`, except period, which is set to `1`. 449 450 ### Validator removed 451 452 * triggered-by: `staking.RemoveValidator` 453 454 Outstanding commission is sent to the validator's self-delegation withdrawal address. 455 Remaining delegator rewards get sent to the community fee pool. 456 457 Note: The validator gets removed only when it has no remaining delegations. 458 At that time, all outstanding delegator rewards will have been withdrawn. 459 Any remaining rewards are dust amounts. 460 461 ### Validator is slashed 462 463 * triggered-by: `staking.Slash` 464 * The current validator period reference count is incremented. 465 The reference count is incremented because the slash event has created a reference to it. 466 * The validator period is incremented. 467 * The slash event is stored for later use. 468 The slash event will be referenced when calculating delegator rewards. 469 470 ## Events 471 472 The distribution module emits the following events: 473 474 ### BeginBlocker 475 476 | Type | Attribute Key | Attribute Value | 477 |-----------------|---------------|--------------------| 478 | proposer_reward | validator | {validatorAddress} | 479 | proposer_reward | reward | {proposerReward} | 480 | commission | amount | {commissionAmount} | 481 | commission | validator | {validatorAddress} | 482 | rewards | amount | {rewardAmount} | 483 | rewards | validator | {validatorAddress} | 484 485 ### Handlers 486 487 #### MsgSetWithdrawAddress 488 489 | Type | Attribute Key | Attribute Value | 490 |----------------------|------------------|----------------------| 491 | set_withdraw_address | withdraw_address | {withdrawAddress} | 492 | message | module | distribution | 493 | message | action | set_withdraw_address | 494 | message | sender | {senderAddress} | 495 496 #### MsgWithdrawDelegatorReward 497 498 | Type | Attribute Key | Attribute Value | 499 |---------|---------------|---------------------------| 500 | withdraw_rewards | amount | {rewardAmount} | 501 | withdraw_rewards | validator | {validatorAddress} | 502 | message | module | distribution | 503 | message | action | withdraw_delegator_reward | 504 | message | sender | {senderAddress} | 505 506 #### MsgWithdrawValidatorCommission 507 508 | Type | Attribute Key | Attribute Value | 509 |------------|---------------|-------------------------------| 510 | withdraw_commission | amount | {commissionAmount} | 511 | message | module | distribution | 512 | message | action | withdraw_validator_commission | 513 | message | sender | {senderAddress} | 514 515 ## Parameters 516 517 The distribution module contains the following parameters: 518 519 | Key | Type | Example | 520 | ------------------- | ------------ | -------------------------- | 521 | communitytax | string (dec) | "0.020000000000000000" [0] | 522 | withdrawaddrenabled | bool | true | 523 524 * [0] `communitytax` must be positive and cannot exceed 1.00. 525 * `baseproposerreward` and `bonusproposerreward` were parameters that are deprecated in v0.47 and are not used. 526 527 :::note 528 The reserve pool is the pool of collected funds for use by governance taken via the `CommunityTax`. 529 Currently with the Cosmos SDK, tokens collected by the CommunityTax are accounted for but unspendable. 530 ::: 531 532 ## Client 533 534 ## CLI 535 536 A user can query and interact with the `distribution` module using the CLI. 537 538 #### Query 539 540 The `query` commands allow users to query `distribution` state. 541 542 ```shell 543 simd query distribution --help 544 ``` 545 546 ##### commission 547 548 The `commission` command allows users to query validator commission rewards by address. 549 550 ```shell 551 simd query distribution commission [address] [flags] 552 ``` 553 554 Example: 555 556 ```shell 557 simd query distribution commission cosmosvaloper1... 558 ``` 559 560 Example Output: 561 562 ```yml 563 commission: 564 - amount: "1000000.000000000000000000" 565 denom: stake 566 ``` 567 568 ##### community-pool 569 570 The `community-pool` command allows users to query all coin balances within the community pool. 571 572 ```shell 573 simd query distribution community-pool [flags] 574 ``` 575 576 Example: 577 578 ```shell 579 simd query distribution community-pool 580 ``` 581 582 Example Output: 583 584 ```yml 585 pool: 586 - amount: "1000000.000000000000000000" 587 denom: stake 588 ``` 589 590 ##### params 591 592 The `params` command allows users to query the parameters of the `distribution` module. 593 594 ```shell 595 simd query distribution params [flags] 596 ``` 597 598 Example: 599 600 ```shell 601 simd query distribution params 602 ``` 603 604 Example Output: 605 606 ```yml 607 base_proposer_reward: "0.000000000000000000" 608 bonus_proposer_reward: "0.000000000000000000" 609 community_tax: "0.020000000000000000" 610 withdraw_addr_enabled: true 611 ``` 612 613 ##### rewards 614 615 The `rewards` command allows users to query delegator rewards. Users can optionally include the validator address to query rewards earned from a specific validator. 616 617 ```shell 618 simd query distribution rewards [delegator-addr] [validator-addr] [flags] 619 ``` 620 621 Example: 622 623 ```shell 624 simd query distribution rewards cosmos1... 625 ``` 626 627 Example Output: 628 629 ```yml 630 rewards: 631 - reward: 632 - amount: "1000000.000000000000000000" 633 denom: stake 634 validator_address: cosmosvaloper1.. 635 total: 636 - amount: "1000000.000000000000000000" 637 denom: stake 638 ``` 639 640 ##### slashes 641 642 The `slashes` command allows users to query all slashes for a given block range. 643 644 ```shell 645 simd query distribution slashes [validator] [start-height] [end-height] [flags] 646 ``` 647 648 Example: 649 650 ```shell 651 simd query distribution slashes cosmosvaloper1... 1 1000 652 ``` 653 654 Example Output: 655 656 ```yml 657 pagination: 658 next_key: null 659 total: "0" 660 slashes: 661 - validator_period: 20, 662 fraction: "0.009999999999999999" 663 ``` 664 665 ##### validator-outstanding-rewards 666 667 The `validator-outstanding-rewards` command allows users to query all outstanding (un-withdrawn) rewards for a validator and all their delegations. 668 669 ```shell 670 simd query distribution validator-outstanding-rewards [validator] [flags] 671 ``` 672 673 Example: 674 675 ```shell 676 simd query distribution validator-outstanding-rewards cosmosvaloper1... 677 ``` 678 679 Example Output: 680 681 ```yml 682 rewards: 683 - amount: "1000000.000000000000000000" 684 denom: stake 685 ``` 686 687 ##### validator-distribution-info 688 689 The `validator-distribution-info` command allows users to query validator commission and self-delegation rewards for validator. 690 691 ````shell 692 simd query distribution validator-distribution-info cosmosvaloper1... 693 ``` 694 695 Example Output: 696 697 ```yml 698 commission: 699 - amount: "100000.000000000000000000" 700 denom: stake 701 operator_address: cosmosvaloper1... 702 self_bond_rewards: 703 - amount: "100000.000000000000000000" 704 denom: stake 705 ``` 706 707 #### Transactions 708 709 The `tx` commands allow users to interact with the `distribution` module. 710 711 ```shell 712 simd tx distribution --help 713 ``` 714 715 ##### fund-community-pool 716 717 The `fund-community-pool` command allows users to send funds to the community pool. 718 719 ```shell 720 simd tx distribution fund-community-pool [amount] [flags] 721 ``` 722 723 Example: 724 725 ```shell 726 simd tx distribution fund-community-pool 100stake --from cosmos1... 727 ``` 728 729 ##### set-withdraw-addr 730 731 The `set-withdraw-addr` command allows users to set the withdraw address for rewards associated with a delegator address. 732 733 ```shell 734 simd tx distribution set-withdraw-addr [withdraw-addr] [flags] 735 ``` 736 737 Example: 738 739 ```shell 740 simd tx distribution set-withdraw-addr cosmos1... --from cosmos1... 741 ``` 742 743 ##### withdraw-all-rewards 744 745 The `withdraw-all-rewards` command allows users to withdraw all rewards for a delegator. 746 747 ```shell 748 simd tx distribution withdraw-all-rewards [flags] 749 ``` 750 751 Example: 752 753 ```shell 754 simd tx distribution withdraw-all-rewards --from cosmos1... 755 ``` 756 757 ##### withdraw-rewards 758 759 The `withdraw-rewards` command allows users to withdraw all rewards from a given delegation address, 760 and optionally withdraw validator commission if the delegation address given is a validator operator and the user proves the `--commission` flag. 761 762 ```shell 763 simd tx distribution withdraw-rewards [validator-addr] [flags] 764 ``` 765 766 Example: 767 768 ```shell 769 simd tx distribution withdraw-rewards cosmosvaloper1... --from cosmos1... --commission 770 ``` 771 772 ### gRPC 773 774 A user can query the `distribution` module using gRPC endpoints. 775 776 #### Params 777 778 The `Params` endpoint allows users to query parameters of the `distribution` module. 779 780 Example: 781 782 ```shell 783 grpcurl -plaintext \ 784 localhost:9090 \ 785 cosmos.distribution.v1beta1.Query/Params 786 ``` 787 788 Example Output: 789 790 ```json 791 { 792 "params": { 793 "communityTax": "20000000000000000", 794 "baseProposerReward": "00000000000000000", 795 "bonusProposerReward": "00000000000000000", 796 "withdrawAddrEnabled": true 797 } 798 } 799 ``` 800 801 #### ValidatorDistributionInfo 802 803 The `ValidatorDistributionInfo` queries validator commission and self-delegation rewards for validator. 804 805 Example: 806 807 ```shell 808 grpcurl -plaintext \ 809 -d '{"validator_address":"cosmosvalop1..."}' \ 810 localhost:9090 \ 811 cosmos.distribution.v1beta1.Query/ValidatorDistributionInfo 812 ``` 813 814 Example Output: 815 816 ```json 817 { 818 "commission": { 819 "commission": [ 820 { 821 "denom": "stake", 822 "amount": "1000000000000000" 823 } 824 ] 825 }, 826 "self_bond_rewards": [ 827 { 828 "denom": "stake", 829 "amount": "1000000000000000" 830 } 831 ], 832 "validator_address": "cosmosvalop1..." 833 } 834 ``` 835 836 #### ValidatorOutstandingRewards 837 838 The `ValidatorOutstandingRewards` endpoint allows users to query rewards of a validator address. 839 840 Example: 841 842 ```shell 843 grpcurl -plaintext \ 844 -d '{"validator_address":"cosmosvalop1.."}' \ 845 localhost:9090 \ 846 cosmos.distribution.v1beta1.Query/ValidatorOutstandingRewards 847 ``` 848 849 Example Output: 850 851 ```json 852 { 853 "rewards": { 854 "rewards": [ 855 { 856 "denom": "stake", 857 "amount": "1000000000000000" 858 } 859 ] 860 } 861 } 862 ``` 863 864 #### ValidatorCommission 865 866 The `ValidatorCommission` endpoint allows users to query accumulated commission for a validator. 867 868 Example: 869 870 ```shell 871 grpcurl -plaintext \ 872 -d '{"validator_address":"cosmosvalop1.."}' \ 873 localhost:9090 \ 874 cosmos.distribution.v1beta1.Query/ValidatorCommission 875 ``` 876 877 Example Output: 878 879 ```json 880 { 881 "commission": { 882 "commission": [ 883 { 884 "denom": "stake", 885 "amount": "1000000000000000" 886 } 887 ] 888 } 889 } 890 ``` 891 892 #### ValidatorSlashes 893 894 The `ValidatorSlashes` endpoint allows users to query slash events of a validator. 895 896 Example: 897 898 ```shell 899 grpcurl -plaintext \ 900 -d '{"validator_address":"cosmosvalop1.."}' \ 901 localhost:9090 \ 902 cosmos.distribution.v1beta1.Query/ValidatorSlashes 903 ``` 904 905 Example Output: 906 907 ```json 908 { 909 "slashes": [ 910 { 911 "validator_period": "20", 912 "fraction": "0.009999999999999999" 913 } 914 ], 915 "pagination": { 916 "total": "1" 917 } 918 } 919 ``` 920 921 #### DelegationRewards 922 923 The `DelegationRewards` endpoint allows users to query the total rewards accrued by a delegation. 924 925 Example: 926 927 ```shell 928 grpcurl -plaintext \ 929 -d '{"delegator_address":"cosmos1...","validator_address":"cosmosvalop1..."}' \ 930 localhost:9090 \ 931 cosmos.distribution.v1beta1.Query/DelegationRewards 932 ``` 933 934 Example Output: 935 936 ```json 937 { 938 "rewards": [ 939 { 940 "denom": "stake", 941 "amount": "1000000000000000" 942 } 943 ] 944 } 945 ``` 946 947 #### DelegationTotalRewards 948 949 The `DelegationTotalRewards` endpoint allows users to query the total rewards accrued by each validator. 950 951 Example: 952 953 ```shell 954 grpcurl -plaintext \ 955 -d '{"delegator_address":"cosmos1..."}' \ 956 localhost:9090 \ 957 cosmos.distribution.v1beta1.Query/DelegationTotalRewards 958 ``` 959 960 Example Output: 961 962 ```json 963 { 964 "rewards": [ 965 { 966 "validatorAddress": "cosmosvaloper1...", 967 "reward": [ 968 { 969 "denom": "stake", 970 "amount": "1000000000000000" 971 } 972 ] 973 } 974 ], 975 "total": [ 976 { 977 "denom": "stake", 978 "amount": "1000000000000000" 979 } 980 ] 981 } 982 ``` 983 984 #### DelegatorValidators 985 986 The `DelegatorValidators` endpoint allows users to query all validators for given delegator. 987 988 Example: 989 990 ```shell 991 grpcurl -plaintext \ 992 -d '{"delegator_address":"cosmos1..."}' \ 993 localhost:9090 \ 994 cosmos.distribution.v1beta1.Query/DelegatorValidators 995 ``` 996 997 Example Output: 998 999 ```json 1000 { 1001 "validators": ["cosmosvaloper1..."] 1002 } 1003 ``` 1004 1005 #### DelegatorWithdrawAddress 1006 1007 The `DelegatorWithdrawAddress` endpoint allows users to query the withdraw address of a delegator. 1008 1009 Example: 1010 1011 ```shell 1012 grpcurl -plaintext \ 1013 -d '{"delegator_address":"cosmos1..."}' \ 1014 localhost:9090 \ 1015 cosmos.distribution.v1beta1.Query/DelegatorWithdrawAddress 1016 ``` 1017 1018 Example Output: 1019 1020 ```json 1021 { 1022 "withdrawAddress": "cosmos1..." 1023 } 1024 ``` 1025 1026 #### CommunityPool 1027 1028 The `CommunityPool` endpoint allows users to query the community pool coins. 1029 1030 Example: 1031 1032 ```shell 1033 grpcurl -plaintext \ 1034 localhost:9090 \ 1035 cosmos.distribution.v1beta1.Query/CommunityPool 1036 ``` 1037 1038 Example Output: 1039 1040 ```json 1041 { 1042 "pool": [ 1043 { 1044 "denom": "stake", 1045 "amount": "1000000000000000000" 1046 } 1047 ] 1048 } 1049 ```