Distribution

Solidity Interface & ABIarrow-up-right

Distribution.sol serves as an interface for Solidity contracts to interact with Cosmos SDK distribution. This offers convenience to developers, as they are not required to understand the implementation intricacies of the x/distribution module within the Cosmos SDK. Instead, they can utilize distribution functions through the familiar Ethereum interface.

Interface Distribution.solarrow-up-right

Transactionsarrow-up-right

  • setWithdrawAddress

    /// @dev Change the address, that can withdraw the rewards of a delegator.
    /// Note that this address cannot be a module account.
    /// @param delegatorAddress The address of the delegator
    /// @param withdrawerAddress The address that will be capable of withdrawing rewards for
    /// the given delegator address
    function setWithdrawAddress(
        address delegatorAddress,
        string memory withdrawerAddress
    ) external returns (bool success);
  • withdrawDelegatorRewards

    /// @dev Withdraw the rewards of a delegator from a validator
    /// @param delegatorAddress The address of the delegator
    /// @param validatorAddress The address of the validator
    /// @return amount The amount of Coin withdrawn
    function withdrawDelegatorRewards(
        address delegatorAddress,
        string memory validatorAddress
    )
    external
    returns (
        Coin[] calldata amount
    );
  • withdrawValidatorCommission

    /// @dev Withdraws the rewards commission of a validator.
    /// @param validatorAddress The address of the validator
    /// @return amount The amount of Coin withdrawn
    function withdrawValidatorCommission(
        string memory validatorAddress
    )
    external
    returns (
        Coin[] calldata amount
    );

  • validatorDistribution

  • validatorOutstandingRewards

  • validatorCommission

  • validatorSlashes

  • delegationRewards

  • delegationTotalRewards

  • delegatorValidators

  • delegatorWithdrawAddress

    delegatorWithdrawAddress queries withdraw address of a delegator

Each of the transactions emits its corresponding event. These are:

  • SetWithdrawerAddress

  • WithdrawDelegatorRewards

  • WithdrawValidatorCommission

Utilize the Solidity Interface​:

Here are examples demonstrating interaction with this Solidity interface from your smart contracts. Ensure to import the precompiled interface, such as:

Set Withdraw Address:

The changeWithdrawAddress function enables a user to set a new withdraw address in the Cosmos x/distribution module. To ensure the success of this transaction, ensure that the user has previously approved the MSG_SET_WITHDRAWER_ADDRESS message.

Withdraw staking rewardsarrow-up-right

The withdrawStakingRewards function permits a user to withdraw their rewards associated with a specified validator. To execute this transaction successfully, ensure that the user has previously approved the MSG_WITHDRAW_DELEGATOR_REWARD message.

Withdraw validator commissionarrow-up-right

If the user operates a validator, they can withdraw the corresponding commission through a smart contract. A function similar to withdrawCommission can be utilized for this purpose. To ensure the transaction's success, the user must have previously approved the MSG_WITHDRAW_VALIDATOR_COMMISSION message.

Similar to transactions, smart contracts can utilize query methods, which are read-only. Examples include the getDelegationRewards and getValidatorCommission functions, which retrieve information for the specified validator address.

Last updated