Last active
May 27, 2023 16:32
-
-
Save LPX55/255e4f6b630e63bb92c274954b886113 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This gist shows an example on how to use Evmos EVM Extensions to access | |
| x/distribution and x/staking Cosmos SDK modules functionalities from a smart contract |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "overrides": [ | |
| { | |
| "files": "*.sol", | |
| "options": { | |
| "printWidth": 80, | |
| "tabWidth": 4, | |
| "useTabs": false, | |
| "singleQuote": false, | |
| "bracketSpacing": false | |
| } | |
| }, | |
| { | |
| "files": "*.yml", | |
| "options": {} | |
| }, | |
| { | |
| "files": "*.yaml", | |
| "options": {} | |
| }, | |
| { | |
| "files": "*.toml", | |
| "options": {} | |
| }, | |
| { | |
| "files": "*.json", | |
| "options": {} | |
| }, | |
| { | |
| "files": "*.js", | |
| "options": {} | |
| }, | |
| { | |
| "files": "*.ts", | |
| "options": {} | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Evmos EVM Extensions - Simple Staker Example | |
| This is an example of how to create a smart contract that directly calls | |
| the `Staking` and `Distribution` precompiled contracts on Evmos chain - [Simple Staker](./contracts/SimpleStaker.sol) | |
| This smart contract allows the user to: | |
| - Stake tokens | |
| - Withdraw delegation rewards | |
| - Query current delegations | |
| - Query current delegations rewards | |
| The implementation is straightforward and is a good starting point for anyone who wants to create a smart contract that interacts with the Cosmos SDK. | |
| There are a couple of things to keep in mind when using the precompiled contracts: | |
| ## Approvals | |
| Before executing any transaction on the precompiled contracts, | |
| the user interacting with the smart contract must first approve these. | |
| In case of staking transactions, should specify the amount allowed. | |
| The smart contract developer can choose to either separate | |
| the approval and execution of the precompiled contracts transactions | |
| or to combine them into a single transaction. | |
| We have provided convenient constants - `MSG_DELEGATE`, `MSG_UNDELEGATE`, | |
| `MSG_REDELEGATE`, `MSG_CANCEL_UNDELEGATION`, `MSG_SET_WITHDRAWER_ADDRESS`, | |
| `MSG_WITHDRAW_DELEGATOR_REWARD`, `MSG_WITHDRAW_VALIDATOR_COMMISSION` - for easier use. | |
| This is done by calling the `approve` function and will create an authorization grant for the given Cosmos SDK message. | |
| Note that the `approve` method for the `Staking` precompiled is different | |
| than the `Distribution` precompiled. | |
| Use the corresponding method when approving methods for each precompiled | |
| (e.g., use `STAKING_CONTRACT.approve(...)` for staking methods, | |
| and `DISTRIBUTION_CONTRACT.approve(...)` for distribution methods). | |
| The [Simple Staker](./contracts/SimpleStaker.sol) has the function `approveRequiredMethods()` | |
| to perform the necessary approvals. | |
| It approves the required methods for staking tokens (`MSG_DELEGATE`) | |
| and withdraw staking rewards (`MSG_WITHDRAW_DELEGATOR_REWARD`) | |
| ## Allowances | |
| The `Staking` precompile will check if the message sender has enough allowance for the given message type and will | |
| return an error if the transaction exceeds the allowance. | |
| Decreasing the allowance after a successful transaction is not required since we handle it internally. | |
| ## Return Structs | |
| The precompiled contracts provide a set of structs that map to Cosmos SDK message returns types. | |
| These structs can be used as return types for smart contract functions or can be used to add further | |
| logic to your smart contracts. Once a transaction is executed, the return values can be used to verify the transaction | |
| was successful or be as inputs for additional logic. | |
| ## Failed Transactions | |
| The precompiled contracts provide verbose error messages for failed transactions. If a transaction fails, the state | |
| will not be persisted and the transaction will be reverted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: LGPL-v3 | |
| pragma solidity >=0.8.17 .0; | |
| import "./GenericAuthorization.sol" as genericAuth; | |
| import "./Types.sol"; | |
| /// @dev The DistributionI contract's address. | |
| address constant DISTRIBUTION_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000801; | |
| /// @dev Define all the available distribution methods. | |
| string constant MSG_SET_WITHDRAWER_ADDRESS = "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress"; | |
| string constant MSG_WITHDRAW_DELEGATOR_REWARD = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"; | |
| string constant MSG_WITHDRAW_VALIDATOR_COMMISSION = "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"; | |
| /// @dev The DistributionI contract's instance. | |
| DistributionI constant DISTRIBUTION_CONTRACT = DistributionI(DISTRIBUTION_PRECOMPILE_ADDRESS); | |
| struct ValidatorSlashEvent { | |
| uint64 validatorPeriod; | |
| Dec fraction; | |
| } | |
| struct ValidatorDistributionInfo { | |
| string operatorAddress; | |
| DecCoin[] selfBondRewards; | |
| DecCoin[] commission; | |
| } | |
| struct DelegationDelegatorReward { | |
| string validatorAddress; | |
| DecCoin[] reward; | |
| } | |
| /// @author Evmos Team | |
| /// @title Distribution Precompile Contract | |
| /// @dev The interface through which solidity contracts will interact with Distribution | |
| /// @custom:address 0x0000000000000000000000000000000000000801 | |
| interface DistributionI is genericAuth.GenericAuthorizationI { | |
| /// TRANSACTIONS | |
| /// @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); | |
| /// @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 | |
| ); | |
| /// @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 | |
| ); | |
| /// QUERIES | |
| /// @dev Queries validator commission and self-delegation rewards for validator. | |
| /// @param validatorAddress The address of the validator | |
| /// @return distributionInfo The validator's distribution info | |
| function validatorDistributionInfo( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| ValidatorDistributionInfo[] calldata distributionInfo // FIXME: remove unnecessary slice | |
| ); | |
| /// @dev Queries the outstanding rewards of a validator address. | |
| /// @param validatorAddress The address of the validator | |
| /// @return rewards The validator's outstanding rewards | |
| function validatorOutstandingRewards( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata rewards | |
| ); | |
| /// @dev Queries the accumulated commission for a validator. | |
| /// @param validatorAddress The address of the validator | |
| /// @return commission The validator's commission | |
| function validatorCommission( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata commission | |
| ); | |
| /// @dev Queries the slashing events for a validator in a given height interval | |
| /// defined by the starting and ending height. | |
| /// @param validatorAddress The address of the validator | |
| /// @param startingHeight The starting height | |
| /// @param endingHeight The ending height | |
| /// @return slashes The validator's slash events | |
| /// @return pageResponse The pagination response for the query | |
| function validatorSlashes( | |
| string memory validatorAddress, | |
| uint64 startingHeight, | |
| uint64 endingHeight | |
| ) | |
| external | |
| view | |
| returns ( | |
| ValidatorSlashEvent[] calldata slashes, | |
| PageResponse calldata pageResponse | |
| ); | |
| /// @dev Queries the total rewards accrued by a delegation from a specific address to a given validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @return rewards The total rewards accrued by a delegation. | |
| function delegationRewards( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata rewards | |
| ); | |
| /// @dev Queries the total rewards accrued by each validator, that a given | |
| /// address has delegated to. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return rewards The total rewards accrued by each validator for a delegator. | |
| /// @return total The total rewards accrued by a delegator. | |
| function delegationTotalRewards( | |
| address delegatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DelegationDelegatorReward[] calldata rewards, | |
| DecCoin[] calldata total | |
| ); | |
| /// @dev Queries all validators, that a given address has delegated to. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return validators The addresses of all validators, that were delegated to by the given address. | |
| function delegatorValidators( | |
| address delegatorAddress | |
| ) external view returns (string[] calldata validators); | |
| /// @dev Queries the address capable of withdrawing rewards for a given delegator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return withdrawAddress The address capable of withdrawing rewards for the delegator. | |
| function delegatorWithdrawAddress( | |
| address delegatorAddress | |
| ) external view returns (string memory withdrawAddress); | |
| /// @dev SetWithdrawerAddress defines an Event emitted when a new withdrawer address is being set | |
| /// @param caller the caller of the transaction | |
| /// @param withdrawerAddress the newly set withdrawer address | |
| event SetWithdrawerAddress( | |
| address indexed caller, | |
| string withdrawerAddress | |
| ); | |
| /// @dev WithdrawDelegatorRewards defines an Event emitted when rewards from a delegation are withdrawn | |
| /// @param delegatorAddress the address of the delegator | |
| /// @param validatorAddress the address of the validator | |
| /// @param amount the amount being withdrawn from the delegation | |
| event WithdrawDelegatorRewards( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount | |
| ); | |
| /// @dev WithdrawValidatorCommission defines an Event emitted when validator commissions are being withdrawn | |
| /// @param validatorAddress is the address of the validator | |
| /// @param commission is the total commission earned by the validator | |
| event WithdrawValidatorCommission( | |
| string indexed validatorAddress, | |
| uint256 commission | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: LGPL-v3 | |
| pragma solidity >=0.8.17; | |
| import "./Staking.sol"; | |
| import "./Distribution.sol"; | |
| contract SimpleStaker { | |
| /// Methods to approve when calling approveRequiredMethods() | |
| string[] private stakingMethods = [MSG_DELEGATE]; | |
| string[] private distributionMethods = [MSG_WITHDRAW_DELEGATOR_REWARD]; | |
| /// @dev Approves the required transactions for delegation and withdrawal of staking rewards transactions. | |
| /// @dev This creates a Cosmos Authorization Grants for the given methods. | |
| /// @dev This emits an Approval event. | |
| function approveRequiredMethods() public { | |
| bool success = STAKING_CONTRACT.approve( | |
| msg.sender, | |
| type(uint256).max, | |
| stakingMethods | |
| ); | |
| require(success, "Failed to approve delegate method"); | |
| success = DISTRIBUTION_CONTRACT.approve( | |
| msg.sender, | |
| distributionMethods | |
| ); | |
| require(success, "Failed to approve withdraw delegator rewards method"); | |
| } | |
| /// @dev stake a given amount of tokens. Returns the completion time of the staking transaction. | |
| /// @dev This emits an Delegate event. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @param _amount The amount of tokens to stake in aevmos. | |
| /// @return completionTime The completion time of the staking transaction. | |
| function stakeTokens( | |
| string memory _validatorAddr, | |
| uint256 _amount | |
| ) public returns (int64 completionTime) { | |
| return STAKING_CONTRACT.delegate(msg.sender, _validatorAddr, _amount); | |
| } | |
| /// @dev withdraw delegation rewards from the specified validator address | |
| /// @dev This emits an WithdrawDelegatorRewards event. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return amount The amount of Coin withdrawn. | |
| function withdrawRewards( | |
| string memory _validatorAddr | |
| ) public returns (Coin[] memory amount) { | |
| return | |
| DISTRIBUTION_CONTRACT.withdrawDelegatorRewards( | |
| msg.sender, | |
| _validatorAddr | |
| ); | |
| } | |
| /// ================================ | |
| /// QUERIES | |
| /// ================================ | |
| /// @dev Returns the delegation information for a given validator for the msg sender. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return shares and balance. The delegation information for a given validator for the msg sender. | |
| function getDelegation( | |
| string memory _validatorAddr | |
| ) public view returns (uint256 shares, Coin memory balance) { | |
| return STAKING_CONTRACT.delegation(msg.sender, _validatorAddr); | |
| } | |
| /// @dev Returns the delegation rewards for a given validator for the msg sender. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return rewards The delegation rewards corresponding to the msg sender. | |
| function getDelegationRewards( | |
| string memory _validatorAddr | |
| ) public view returns (DecCoin[] memory rewards) { | |
| return | |
| DISTRIBUTION_CONTRACT.delegationRewards(msg.sender, _validatorAddr); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/GenericAuthorization.sol | |
| pragma solidity >=0.8.17; | |
| /// @author Evmos Team | |
| /// @title Authorization Interface | |
| /// @dev The interface through which solidity contracts will interact with smart contract approvals. | |
| interface GenericAuthorizationI { | |
| /// @dev Approves a list of Cosmos or IBC transactions with a specific amount of tokens. | |
| /// @param spender The address which will spend the funds. | |
| /// @param methods The message type URLs of the methods to approve. | |
| /// @return approved Boolean value to indicate if the approval was successful. | |
| function approve( | |
| address spender, | |
| string[] calldata methods | |
| ) external returns (bool approved); | |
| /// @dev This event is emitted when the allowance of a spender is set by a call to the approve method. | |
| /// The value field specifies the new allowance and the methods field holds the information for which methods | |
| /// the approval was set. | |
| /// @param owner The owner of the tokens. | |
| /// @param spender The address which will spend the funds. | |
| /// @param methods The message type URLs of the methods for which the approval is set. | |
| event Approval( | |
| address indexed owner, | |
| address indexed spender, | |
| string[] methods | |
| ); | |
| } | |
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/Types.sol | |
| pragma solidity >=0.8.17; | |
| struct Dec { | |
| uint256 value; | |
| uint8 precision; | |
| } | |
| /// @dev Coin is a struct that represents a token with a denomination and an amount. | |
| struct Coin { | |
| string denom; | |
| uint256 amount; | |
| } | |
| /// @dev DecCoin is a struct that represents a token with a denomination, an amount and a precision. | |
| struct DecCoin { | |
| string denom; | |
| uint256 amount; | |
| uint8 precision; | |
| } | |
| /// @dev PageResponse is a struct that represents a page response. | |
| struct PageResponse { | |
| bytes nextKey; | |
| uint64 total; | |
| } | |
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/Distribution.sol | |
| pragma solidity >=0.8.17 .0; | |
| /// @dev The DistributionI contract's address. | |
| address constant DISTRIBUTION_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000801; | |
| /// @dev Define all the available distribution methods. | |
| string constant MSG_SET_WITHDRAWER_ADDRESS = "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress"; | |
| string constant MSG_WITHDRAW_DELEGATOR_REWARD = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"; | |
| string constant MSG_WITHDRAW_VALIDATOR_COMMISSION = "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"; | |
| /// @dev The DistributionI contract's instance. | |
| DistributionI constant DISTRIBUTION_CONTRACT = DistributionI(DISTRIBUTION_PRECOMPILE_ADDRESS); | |
| struct ValidatorSlashEvent { | |
| uint64 validatorPeriod; | |
| Dec fraction; | |
| } | |
| struct ValidatorDistributionInfo { | |
| string operatorAddress; | |
| DecCoin[] selfBondRewards; | |
| DecCoin[] commission; | |
| } | |
| struct DelegationDelegatorReward { | |
| string validatorAddress; | |
| DecCoin[] reward; | |
| } | |
| /// @author Evmos Team | |
| /// @title Distribution Precompile Contract | |
| /// @dev The interface through which solidity contracts will interact with Distribution | |
| /// @custom:address 0x0000000000000000000000000000000000000801 | |
| interface DistributionI is genericAuth.GenericAuthorizationI { | |
| /// TRANSACTIONS | |
| /// @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); | |
| /// @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 | |
| ); | |
| /// @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 | |
| ); | |
| /// QUERIES | |
| /// @dev Queries validator commission and self-delegation rewards for validator. | |
| /// @param validatorAddress The address of the validator | |
| /// @return distributionInfo The validator's distribution info | |
| function validatorDistributionInfo( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| ValidatorDistributionInfo[] calldata distributionInfo // FIXME: remove unnecessary slice | |
| ); | |
| /// @dev Queries the outstanding rewards of a validator address. | |
| /// @param validatorAddress The address of the validator | |
| /// @return rewards The validator's outstanding rewards | |
| function validatorOutstandingRewards( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata rewards | |
| ); | |
| /// @dev Queries the accumulated commission for a validator. | |
| /// @param validatorAddress The address of the validator | |
| /// @return commission The validator's commission | |
| function validatorCommission( | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata commission | |
| ); | |
| /// @dev Queries the slashing events for a validator in a given height interval | |
| /// defined by the starting and ending height. | |
| /// @param validatorAddress The address of the validator | |
| /// @param startingHeight The starting height | |
| /// @param endingHeight The ending height | |
| /// @return slashes The validator's slash events | |
| /// @return pageResponse The pagination response for the query | |
| function validatorSlashes( | |
| string memory validatorAddress, | |
| uint64 startingHeight, | |
| uint64 endingHeight | |
| ) | |
| external | |
| view | |
| returns ( | |
| ValidatorSlashEvent[] calldata slashes, | |
| PageResponse calldata pageResponse | |
| ); | |
| /// @dev Queries the total rewards accrued by a delegation from a specific address to a given validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @return rewards The total rewards accrued by a delegation. | |
| function delegationRewards( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DecCoin[] calldata rewards | |
| ); | |
| /// @dev Queries the total rewards accrued by each validator, that a given | |
| /// address has delegated to. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return rewards The total rewards accrued by each validator for a delegator. | |
| /// @return total The total rewards accrued by a delegator. | |
| function delegationTotalRewards( | |
| address delegatorAddress | |
| ) | |
| external | |
| view | |
| returns ( | |
| DelegationDelegatorReward[] calldata rewards, | |
| DecCoin[] calldata total | |
| ); | |
| /// @dev Queries all validators, that a given address has delegated to. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return validators The addresses of all validators, that were delegated to by the given address. | |
| function delegatorValidators( | |
| address delegatorAddress | |
| ) external view returns (string[] calldata validators); | |
| /// @dev Queries the address capable of withdrawing rewards for a given delegator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @return withdrawAddress The address capable of withdrawing rewards for the delegator. | |
| function delegatorWithdrawAddress( | |
| address delegatorAddress | |
| ) external view returns (string memory withdrawAddress); | |
| /// @dev SetWithdrawerAddress defines an Event emitted when a new withdrawer address is being set | |
| /// @param caller the caller of the transaction | |
| /// @param withdrawerAddress the newly set withdrawer address | |
| event SetWithdrawerAddress( | |
| address indexed caller, | |
| string withdrawerAddress | |
| ); | |
| /// @dev WithdrawDelegatorRewards defines an Event emitted when rewards from a delegation are withdrawn | |
| /// @param delegatorAddress the address of the delegator | |
| /// @param validatorAddress the address of the validator | |
| /// @param amount the amount being withdrawn from the delegation | |
| event WithdrawDelegatorRewards( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount | |
| ); | |
| /// @dev WithdrawValidatorCommission defines an Event emitted when validator commissions are being withdrawn | |
| /// @param validatorAddress is the address of the validator | |
| /// @param commission is the total commission earned by the validator | |
| event WithdrawValidatorCommission( | |
| string indexed validatorAddress, | |
| uint256 commission | |
| ); | |
| } | |
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/Authorization.sol | |
| pragma solidity >=0.8.17; | |
| /// @author Evmos Team | |
| /// @title Authorization Interface | |
| /// @dev The interface through which solidity contracts will interact with smart contract approvals. | |
| interface AuthorizationI { | |
| /// @dev Approves a list of Cosmos or IBC transactions with a specific amount of tokens. | |
| /// @param spender The address which will spend the funds. | |
| /// @param amount The amount of tokens to be spent. | |
| /// @param methods The message type URLs of the methods to approve. | |
| /// @return approved Boolean value to indicate if the approval was successful. | |
| function approve( | |
| address spender, | |
| uint256 amount, | |
| string[] calldata methods | |
| ) external returns (bool approved); | |
| /// @dev Increase the allowance of a given spender by a specific amount of tokens for IBC | |
| /// transfer methods or staking. | |
| /// @param spender The address which will spend the funds. | |
| /// @param amount The amount of tokens to be spent. | |
| /// @param methods The message type URLs of the methods to approve. | |
| /// @return approved Boolean value to indicate if the approval was successful. | |
| function increaseAllowance( | |
| address spender, | |
| uint256 amount, | |
| string[] calldata methods | |
| ) external returns (bool approved); | |
| /// @dev Decreases the allowance of a given spender by a specific amount of tokens for IBC | |
| /// transfer methods or staking. | |
| /// @param spender The address which will spend the funds. | |
| /// @param amount The amount of tokens to be spent. | |
| /// @param methods The message type URLs of the methods to approve. | |
| /// @return approved Boolean value to indicate if the approval was successful. | |
| function decreaseAllowance( | |
| address spender, | |
| uint256 amount, | |
| string[] calldata methods | |
| ) external returns (bool approved); | |
| /// @dev Returns the remaining number of tokens that spender will be allowed to spend | |
| /// on behalf of the owner through IBC transfer methods or staking. This is zero by default. | |
| /// @param owner The address of the account owning tokens. | |
| /// @param spender The address of the account able to transfer the tokens. | |
| /// @param method The message type URL of the methods for which the approval should be queried. | |
| /// @return remaining The remaining number of tokens available to be spent. | |
| function allowance( | |
| address owner, | |
| address spender, | |
| string calldata method | |
| ) external view returns (uint256 remaining); | |
| /// @dev This event is emitted when the allowance of a spender is set by a call to the approve method. | |
| /// The value field specifies the new allowance and the methods field holds the information for which methods | |
| /// the approval was set. | |
| /// @param owner The owner of the tokens. | |
| /// @param spender The address which will spend the funds. | |
| /// @param methods The message type URLs of the methods for which the approval is set. | |
| /// @param value The amount of tokens approved to be spent. | |
| event Approval( | |
| address indexed owner, | |
| address indexed spender, | |
| string[] methods, | |
| uint256 value | |
| ); | |
| /// @dev This event is emitted when the allowance of a spender is changed by a call to the decrease or increase | |
| /// allowance method. The values field specifies the new allowances and the methods field holds the | |
| /// information for which methods the approval was set. | |
| /// @param owner The owner of the tokens. | |
| /// @param spender The address which will spend the funds. | |
| /// @param methods The message type URLs of the methods for which the approval is set. | |
| /// @param values The amounts of tokens approved to be spent. | |
| event AllowanceChange( | |
| address indexed owner, | |
| address indexed spender, | |
| string[] methods, | |
| uint256[] values | |
| ); | |
| } | |
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/Staking.sol | |
| pragma solidity >=0.8.17; | |
| /// @dev The StakingI contract's address. | |
| address constant STAKING_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000800; | |
| /// @dev The StakingI contract's instance. | |
| StakingI constant STAKING_CONTRACT = StakingI(STAKING_PRECOMPILE_ADDRESS); | |
| /// @dev Define all the available staking methods. | |
| string constant MSG_DELEGATE = "/cosmos.staking.v1beta1.MsgDelegate"; | |
| string constant MSG_UNDELEGATE = "/cosmos.staking.v1beta1.MsgUndelegate"; | |
| string constant MSG_REDELEGATE = "/cosmos.staking.v1beta1.MsgBeginRedelegate"; | |
| string constant MSG_CANCEL_UNDELEGATION = "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation"; | |
| /// @dev Defines the initial commission rates to be used for creating | |
| /// a validator. | |
| struct CommissionRates { | |
| uint256 rate; | |
| uint256 maxRate; | |
| uint256 maxChangeRate; | |
| } | |
| /// @dev Defines commission parameters for a given validator. | |
| struct Commission { | |
| CommissionRates commissionRates; | |
| uint256 updateTime; | |
| } | |
| /// @dev Represents a validator in the staking module. | |
| struct Validator { | |
| string operatorAddress; | |
| string consensusPubkey; | |
| bool jailed; | |
| BondStatus status; | |
| uint256 tokens; | |
| uint256 delegatorShares; | |
| string description; | |
| int64 unbondingHeight; | |
| int64 unbondingTime; | |
| uint256 commission; | |
| uint256 minSelfDelegation; | |
| } | |
| struct RedelegationResponse { | |
| Redelegation redelegation; | |
| RedelegationEntryResponse[] entries; | |
| } | |
| struct Redelegation { | |
| RedelegationEntry[] entries; | |
| } | |
| struct RedelegationEntryResponse { | |
| RedelegationEntry redelegationEntry; | |
| uint256 balance; | |
| } | |
| struct RedelegationEntry { | |
| int64 creationHeight; | |
| int64 completionTime; | |
| uint256 initialBalance; | |
| uint256 sharesDst; | |
| } | |
| struct UnbondingDelegationEntry { | |
| int64 creationHeight; | |
| int64 completionTime; | |
| uint256 initialBalance; | |
| uint256 balance; | |
| } | |
| struct PageRequest { | |
| bytes key; | |
| uint64 offset; | |
| uint64 limit; | |
| bool countTotal; | |
| bool reverse; | |
| } | |
| /// @dev The status of the validator. | |
| enum BondStatus { | |
| Unspecified, | |
| Unbonded, | |
| Unbonding, | |
| Bonded | |
| } | |
| /// @author Evmos Team | |
| /// @title Staking Precompiled Contract | |
| /// @dev The interface through which solidity contracts will interact with staking. | |
| /// We follow this same interface including four-byte function selectors, in the precompile that | |
| /// wraps the pallet. | |
| /// @custom:address 0x0000000000000000000000000000000000000800 | |
| interface StakingI is authorization.AuthorizationI { | |
| /// @dev Defines a method for performing a delegation of coins from a delegator to a validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of the Coin to be delegated to the validator | |
| function delegate( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Defines a method for performing an undelegation from a delegate and a validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount to be undelegated from the validator | |
| /// @return completionTime The time when the undelegation is completed | |
| function undelegate( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Defines a method for performing a redelegation | |
| /// of coins from a delegator and source validator to a destination validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorSrcAddress The validator from which the redelegation is initiated | |
| /// @param validatorDstAddress The validator to which the redelegation is destined | |
| /// @param amount The amount to be redelegated to the validator | |
| /// @return completionTime The time when the redelegation is completed | |
| function redelegate( | |
| address delegatorAddress, | |
| string memory validatorSrcAddress, | |
| string memory validatorDstAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Allows delegators to cancel the unbondingDelegation entry | |
| /// and to delegate back to a previous validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of the Coin | |
| /// @param creationHeight The height at which the unbonding took place | |
| /// @return completionTime The time when the cancellation of the unbonding delegation is completed | |
| function cancelUnbondingDelegation( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount, | |
| uint256 creationHeight | |
| ) external returns (int64 completionTime); | |
| /// @dev Queries the given amount of the bond denomination to a validator. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return shares The amount of shares, that the delegator has received. | |
| /// @return balance The amount in Coin, that the delegator has delegated to the given validator. | |
| function delegation( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) external view returns (uint256 shares, Coin calldata balance); | |
| /// @dev Returns the delegation shares and coins, that are currently | |
| /// unbonding for a given delegator and validator pair. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return entries The delegations that are currently unbonding. | |
| function unbondingDelegation( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) external view returns (UnbondingDelegationEntry[] calldata entries); | |
| /// @dev Queries validator info for a given validator address. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return validators The validator info for the given validator address. | |
| function validator( | |
| string memory validatorAddress | |
| ) | |
| external view returns ( | |
| Validator[] calldata validators | |
| ); | |
| /// @dev Queries all validators that match the given status. | |
| /// @param status Enables to query for validators matching a given status. | |
| /// @param pageRequest Defines an optional pagination for the request. | |
| function validators( | |
| string memory status, | |
| PageRequest calldata pageRequest | |
| ) external view returns ( | |
| Validator[] calldata validators, | |
| PageResponse calldata pageResponse | |
| ); | |
| /// @dev Queries all redelegations from a source to a destination validator for a given delegator. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param srcValidatorAddress Defines the validator address to redelegate from. | |
| /// @param dstValidatorAddress Defines the validator address to redelegate to. | |
| /// @return entries The active redelegations for the given delegator, source and destination validator combination. | |
| function redelegation( | |
| address delegatorAddress, | |
| string memory srcValidatorAddress, | |
| string memory dstValidatorAddress | |
| ) external view returns (RedelegationEntry[] calldata entries); | |
| /// @dev Queries all redelegations from a source to to a destination validator | |
| /// for a given delegator in a specified pagination manner. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param srcValidatorAddress Defines the validator address to redelegate from. | |
| /// @param dstValidatorAddress Defines the validator address to redelegate to. | |
| /// @param pageRequest Defines an optional pagination for the request. | |
| /// @return response Holds the redelegations for the given delegator, source and destination validator combination. | |
| function redelegations( | |
| address delegatorAddress, | |
| string memory srcValidatorAddress, | |
| string memory dstValidatorAddress, | |
| PageRequest calldata pageRequest | |
| ) external view returns (RedelegationResponse calldata response); | |
| /// @dev Delegate defines an Event emitted when a given amount of tokens are delegated from the | |
| /// delegator address to the validator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin being delegated | |
| /// @param newShares The new delegation shares being held | |
| event Delegate( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 newShares | |
| ); | |
| /// @dev Unbond defines an Event emitted when a given amount of tokens are unbonded from the | |
| /// validator address to the delegator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin being unbonded | |
| /// @param completionTime The time at which the unbonding is completed | |
| event Unbond( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 completionTime | |
| ); | |
| /// @dev Redelegate defines an Event emitted when a given amount of tokens are redelegated from | |
| /// the source validator address to the destination validator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorSrcAddress The address of the validator from which the delegation is retracted | |
| /// @param validatorDstAddress The address of the validator to which the delegation is directed | |
| /// @param amount The amount of Coin being redelegated | |
| /// @param completionTime The time at which the redelegation is completed | |
| event Redelegate( | |
| address indexed delegatorAddress, | |
| string indexed validatorSrcAddress, | |
| string indexed validatorDstAddress, | |
| uint256 amount, | |
| uint256 completionTime | |
| ); | |
| /// @dev CancelUnbondingDelegation defines an Event emitted when a given amount of tokens | |
| /// that are in the process of unbonding from the validator address are bonded again. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin that was in the unbonding process which is to be cancelled | |
| /// @param creationHeight The block height at which the unbonding of a delegation was initiated | |
| event CancelUnbondingDelegation( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 creationHeight | |
| ); | |
| } | |
| // File: gist-e259420aec8d85ea2219e4154536ad35/contracts/SimpleStaker.sol | |
| pragma solidity >=0.8.17; | |
| contract SimpleStaker { | |
| /// Methods to approve when calling approveRequiredMethods() | |
| string[] private stakingMethods = [MSG_DELEGATE]; | |
| string[] private distributionMethods = [MSG_WITHDRAW_DELEGATOR_REWARD]; | |
| /// @dev Approves the required transactions for delegation and withdrawal of staking rewards transactions. | |
| /// @dev This creates a Cosmos Authorization Grants for the given methods. | |
| /// @dev This emits an Approval event. | |
| function approveRequiredMethods() public { | |
| bool success = STAKING_CONTRACT.approve( | |
| msg.sender, | |
| type(uint256).max, | |
| stakingMethods | |
| ); | |
| require(success, "Failed to approve delegate method"); | |
| success = DISTRIBUTION_CONTRACT.approve( | |
| msg.sender, | |
| distributionMethods | |
| ); | |
| require(success, "Failed to approve withdraw delegator rewards method"); | |
| } | |
| /// @dev stake a given amount of tokens. Returns the completion time of the staking transaction. | |
| /// @dev This emits an Delegate event. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @param _amount The amount of tokens to stake in aevmos. | |
| /// @return completionTime The completion time of the staking transaction. | |
| function stakeTokens( | |
| string memory _validatorAddr, | |
| uint256 _amount | |
| ) public returns (int64 completionTime) { | |
| return STAKING_CONTRACT.delegate(msg.sender, _validatorAddr, _amount); | |
| } | |
| /// @dev withdraw delegation rewards from the specified validator address | |
| /// @dev This emits an WithdrawDelegatorRewards event. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return amount The amount of Coin withdrawn. | |
| function withdrawRewards( | |
| string memory _validatorAddr | |
| ) public returns (Coin[] memory amount) { | |
| return | |
| DISTRIBUTION_CONTRACT.withdrawDelegatorRewards( | |
| msg.sender, | |
| _validatorAddr | |
| ); | |
| } | |
| /// ================================ | |
| /// QUERIES | |
| /// ================================ | |
| /// @dev Returns the delegation information for a given validator for the msg sender. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return shares and balance. The delegation information for a given validator for the msg sender. | |
| function getDelegation( | |
| string memory _validatorAddr | |
| ) public view returns (uint256 shares, Coin memory balance) { | |
| return STAKING_CONTRACT.delegation(msg.sender, _validatorAddr); | |
| } | |
| /// @dev Returns the delegation rewards for a given validator for the msg sender. | |
| /// @param _validatorAddr The address of the validator. | |
| /// @return rewards The delegation rewards corresponding to the msg sender. | |
| function getDelegationRewards( | |
| string memory _validatorAddr | |
| ) public view returns (DecCoin[] memory rewards) { | |
| return | |
| DISTRIBUTION_CONTRACT.delegationRewards(msg.sender, _validatorAddr); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: LGPL-v3 | |
| pragma solidity >=0.8.17; | |
| import "./Authorization.sol" as authorization; | |
| import "./Types.sol"; | |
| /// @dev The StakingI contract's address. | |
| address constant STAKING_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000800; | |
| /// @dev The StakingI contract's instance. | |
| StakingI constant STAKING_CONTRACT = StakingI(STAKING_PRECOMPILE_ADDRESS); | |
| /// @dev Define all the available staking methods. | |
| string constant MSG_DELEGATE = "/cosmos.staking.v1beta1.MsgDelegate"; | |
| string constant MSG_UNDELEGATE = "/cosmos.staking.v1beta1.MsgUndelegate"; | |
| string constant MSG_REDELEGATE = "/cosmos.staking.v1beta1.MsgBeginRedelegate"; | |
| string constant MSG_CANCEL_UNDELEGATION = "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation"; | |
| /// @dev Defines the initial commission rates to be used for creating | |
| /// a validator. | |
| struct CommissionRates { | |
| uint256 rate; | |
| uint256 maxRate; | |
| uint256 maxChangeRate; | |
| } | |
| /// @dev Defines commission parameters for a given validator. | |
| struct Commission { | |
| CommissionRates commissionRates; | |
| uint256 updateTime; | |
| } | |
| /// @dev Represents a validator in the staking module. | |
| struct Validator { | |
| string operatorAddress; | |
| string consensusPubkey; | |
| bool jailed; | |
| BondStatus status; | |
| uint256 tokens; | |
| uint256 delegatorShares; | |
| string description; | |
| int64 unbondingHeight; | |
| int64 unbondingTime; | |
| uint256 commission; | |
| uint256 minSelfDelegation; | |
| } | |
| struct RedelegationResponse { | |
| Redelegation redelegation; | |
| RedelegationEntryResponse[] entries; | |
| } | |
| struct Redelegation { | |
| RedelegationEntry[] entries; | |
| } | |
| struct RedelegationEntryResponse { | |
| RedelegationEntry redelegationEntry; | |
| uint256 balance; | |
| } | |
| struct RedelegationEntry { | |
| int64 creationHeight; | |
| int64 completionTime; | |
| uint256 initialBalance; | |
| uint256 sharesDst; | |
| } | |
| struct UnbondingDelegationEntry { | |
| int64 creationHeight; | |
| int64 completionTime; | |
| uint256 initialBalance; | |
| uint256 balance; | |
| } | |
| struct PageRequest { | |
| bytes key; | |
| uint64 offset; | |
| uint64 limit; | |
| bool countTotal; | |
| bool reverse; | |
| } | |
| /// @dev The status of the validator. | |
| enum BondStatus { | |
| Unspecified, | |
| Unbonded, | |
| Unbonding, | |
| Bonded | |
| } | |
| /// @author Evmos Team | |
| /// @title Staking Precompiled Contract | |
| /// @dev The interface through which solidity contracts will interact with staking. | |
| /// We follow this same interface including four-byte function selectors, in the precompile that | |
| /// wraps the pallet. | |
| /// @custom:address 0x0000000000000000000000000000000000000800 | |
| interface StakingI is authorization.AuthorizationI { | |
| /// @dev Defines a method for performing a delegation of coins from a delegator to a validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of the Coin to be delegated to the validator | |
| function delegate( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Defines a method for performing an undelegation from a delegate and a validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount to be undelegated from the validator | |
| /// @return completionTime The time when the undelegation is completed | |
| function undelegate( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Defines a method for performing a redelegation | |
| /// of coins from a delegator and source validator to a destination validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorSrcAddress The validator from which the redelegation is initiated | |
| /// @param validatorDstAddress The validator to which the redelegation is destined | |
| /// @param amount The amount to be redelegated to the validator | |
| /// @return completionTime The time when the redelegation is completed | |
| function redelegate( | |
| address delegatorAddress, | |
| string memory validatorSrcAddress, | |
| string memory validatorDstAddress, | |
| uint256 amount | |
| ) external returns (int64 completionTime); | |
| /// @dev Allows delegators to cancel the unbondingDelegation entry | |
| /// and to delegate back to a previous validator. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of the Coin | |
| /// @param creationHeight The height at which the unbonding took place | |
| /// @return completionTime The time when the cancellation of the unbonding delegation is completed | |
| function cancelUnbondingDelegation( | |
| address delegatorAddress, | |
| string memory validatorAddress, | |
| uint256 amount, | |
| uint256 creationHeight | |
| ) external returns (int64 completionTime); | |
| /// @dev Queries the given amount of the bond denomination to a validator. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return shares The amount of shares, that the delegator has received. | |
| /// @return balance The amount in Coin, that the delegator has delegated to the given validator. | |
| function delegation( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) external view returns (uint256 shares, Coin calldata balance); | |
| /// @dev Returns the delegation shares and coins, that are currently | |
| /// unbonding for a given delegator and validator pair. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return entries The delegations that are currently unbonding. | |
| function unbondingDelegation( | |
| address delegatorAddress, | |
| string memory validatorAddress | |
| ) external view returns (UnbondingDelegationEntry[] calldata entries); | |
| /// @dev Queries validator info for a given validator address. | |
| /// @param validatorAddress The address of the validator. | |
| /// @return validators The validator info for the given validator address. | |
| function validator( | |
| string memory validatorAddress | |
| ) | |
| external view returns ( | |
| Validator[] calldata validators | |
| ); | |
| /// @dev Queries all validators that match the given status. | |
| /// @param status Enables to query for validators matching a given status. | |
| /// @param pageRequest Defines an optional pagination for the request. | |
| function validators( | |
| string memory status, | |
| PageRequest calldata pageRequest | |
| ) external view returns ( | |
| Validator[] calldata validators, | |
| PageResponse calldata pageResponse | |
| ); | |
| /// @dev Queries all redelegations from a source to a destination validator for a given delegator. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param srcValidatorAddress Defines the validator address to redelegate from. | |
| /// @param dstValidatorAddress Defines the validator address to redelegate to. | |
| /// @return entries The active redelegations for the given delegator, source and destination validator combination. | |
| function redelegation( | |
| address delegatorAddress, | |
| string memory srcValidatorAddress, | |
| string memory dstValidatorAddress | |
| ) external view returns (RedelegationEntry[] calldata entries); | |
| /// @dev Queries all redelegations from a source to to a destination validator | |
| /// for a given delegator in a specified pagination manner. | |
| /// @param delegatorAddress The address of the delegator. | |
| /// @param srcValidatorAddress Defines the validator address to redelegate from. | |
| /// @param dstValidatorAddress Defines the validator address to redelegate to. | |
| /// @param pageRequest Defines an optional pagination for the request. | |
| /// @return response Holds the redelegations for the given delegator, source and destination validator combination. | |
| function redelegations( | |
| address delegatorAddress, | |
| string memory srcValidatorAddress, | |
| string memory dstValidatorAddress, | |
| PageRequest calldata pageRequest | |
| ) external view returns (RedelegationResponse calldata response); | |
| /// @dev Delegate defines an Event emitted when a given amount of tokens are delegated from the | |
| /// delegator address to the validator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin being delegated | |
| /// @param newShares The new delegation shares being held | |
| event Delegate( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 newShares | |
| ); | |
| /// @dev Unbond defines an Event emitted when a given amount of tokens are unbonded from the | |
| /// validator address to the delegator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin being unbonded | |
| /// @param completionTime The time at which the unbonding is completed | |
| event Unbond( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 completionTime | |
| ); | |
| /// @dev Redelegate defines an Event emitted when a given amount of tokens are redelegated from | |
| /// the source validator address to the destination validator address. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorSrcAddress The address of the validator from which the delegation is retracted | |
| /// @param validatorDstAddress The address of the validator to which the delegation is directed | |
| /// @param amount The amount of Coin being redelegated | |
| /// @param completionTime The time at which the redelegation is completed | |
| event Redelegate( | |
| address indexed delegatorAddress, | |
| string indexed validatorSrcAddress, | |
| string indexed validatorDstAddress, | |
| uint256 amount, | |
| uint256 completionTime | |
| ); | |
| /// @dev CancelUnbondingDelegation defines an Event emitted when a given amount of tokens | |
| /// that are in the process of unbonding from the validator address are bonded again. | |
| /// @param delegatorAddress The address of the delegator | |
| /// @param validatorAddress The address of the validator | |
| /// @param amount The amount of Coin that was in the unbonding process which is to be cancelled | |
| /// @param creationHeight The block height at which the unbonding of a delegation was initiated | |
| event CancelUnbondingDelegation( | |
| address indexed delegatorAddress, | |
| string indexed validatorAddress, | |
| uint256 amount, | |
| uint256 creationHeight | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: LGPL-v3 | |
| pragma solidity >=0.8.17; | |
| struct Dec { | |
| uint256 value; | |
| uint8 precision; | |
| } | |
| /// @dev Coin is a struct that represents a token with a denomination and an amount. | |
| struct Coin { | |
| string denom; | |
| uint256 amount; | |
| } | |
| /// @dev DecCoin is a struct that represents a token with a denomination, an amount and a precision. | |
| struct DecCoin { | |
| string denom; | |
| uint256 amount; | |
| uint8 precision; | |
| } | |
| /// @dev PageResponse is a struct that represents a page response. | |
| struct PageResponse { | |
| bytes nextKey; | |
| uint64 total; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment