Staking Polaris β
The Cosmos SDK staking module is responsible for managing the delegation, redelegation, and unbonding of tokens in the Cosmos ecosystem. It provides an interface for users to delegate tokens to validators, redelegate tokens from one validator to another, and unbond tokens from validators.Β The module tracks the delegation state, validator information, and unbonding state for each user and validator
The staking module can be used to participate in the consensus process of the Cosmos network by delegating tokens to validators, who are responsible for proposing and validating blocks. Users can also redelegate their tokens to different validators if they wish to change their delegation preferences. Additionally, users can unbond their tokens from validators if they want to withdraw their tokens or stop participating in the consensus process.
The module provides various functions to query validator and delegation information, such as getting a list of all active validators, bonded validator addresses, and delegator validators. It also allows users to perform actions like delegating, undelegating, and redelegating tokens, as well as canceling unbonding delegations.
Note: Link to existing contract ABI's can be found on Github here.
Interface of the staking module's precompiled contract
Functions β
getValAddressFromConsAddress β
Returns the operator address of the validator for the given consensus address.
function getValAddressFromConsAddress(bytes calldata consAddr) external pure returns (address);
function getValAddressFromConsAddress(bytes calldata consAddr) external pure returns (address);
Parameters
Name | Type | Description |
---|---|---|
consAddr | bytes | The consensus address (as bytes) of the validator |
getValidators β
Accepts pagination request (empty == no pagination returned).
Returns a list of all active validators.
function getValidators(Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
function getValidators(Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
getBondedValidators β
Accepts pagination request (empty == no pagination returned).
Returns a list of bonded validator (operator) addresses.
function getBondedValidators(Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
function getBondedValidators(Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
getBondedValidatorsByPower β
Returns a list of bonded validator (operator) addresses, sorted by power (stake) in descending order.
function getBondedValidatorsByPower() external view returns (address[] memory);
function getBondedValidatorsByPower() external view returns (address[] memory);
getValidator β
Returns the validator at the given address.
function getValidator(address validatorAddress) external view returns (Validator memory);
function getValidator(address validatorAddress) external view returns (Validator memory);
Parameters
Name | Type | Description |
---|---|---|
validatorAddress | address | The validator operator address |
getDelegatorValidators β
Accepts pagination request (empty == no pagination returned).
Returns all the validators delegated to by the given delegator.
function getDelegatorValidators(address delegatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
function getDelegatorValidators(address delegatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (Validator[] memory, Cosmos.PageResponse memory);
Parameters
Name | Type | Description |
---|---|---|
delegatorAddress | address | The delegator address to query validators for. |
pagination | Cosmos.PageRequest |
getValidatorDelegations β
Accepts pagination request (empty == no pagination returned).
Returns all the delegations delegated to the given validator.
function getValidatorDelegations(address validatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (Delegation[] memory, Cosmos.PageResponse memory);
function getValidatorDelegations(address validatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (Delegation[] memory, Cosmos.PageResponse memory);
Parameters
Name | Type | Description |
---|---|---|
validatorAddress | address | The validator operator address to query delegations for. |
pagination | Cosmos.PageRequest |
getDelegation β
Returns the amount
of tokens currently delegated by delegatorAddress
to validatorAddress
function getDelegation(address delegatorAddress, address validatorAddress) external view returns (uint256);
function getDelegation(address delegatorAddress, address validatorAddress) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
delegatorAddress | address | The delegator address |
validatorAddress | address | The validator operator address |
getUnbondingDelegation β
Returns a time-ordered list of all UnbondingDelegationEntries between delegatorAddress
and validatorAddress
function getUnbondingDelegation(address delegatorAddress, address validatorAddress)
external
view
returns (UnbondingDelegationEntry[] memory);
function getUnbondingDelegation(address delegatorAddress, address validatorAddress)
external
view
returns (UnbondingDelegationEntry[] memory);
Parameters
Name | Type | Description |
---|---|---|
delegatorAddress | address | The delegator address |
validatorAddress | address | The validator operator address |
getDelegatorUnbondingDelegations β
Accepts pagination request (empty == no pagination returned).
Returns a list of all unbonding delegations for a given delegator
function getDelegatorUnbondingDelegations(address delegatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (UnbondingDelegation[] memory, Cosmos.PageResponse memory);
function getDelegatorUnbondingDelegations(address delegatorAddress, Cosmos.PageRequest calldata pagination)
external
view
returns (UnbondingDelegation[] memory, Cosmos.PageResponse memory);
Parameters
Name | Type | Description |
---|---|---|
delegatorAddress | address | The delegator address |
pagination | Cosmos.PageRequest |
getRedelegations β
Accepts pagination request (empty == no pagination returned).
Returns a list of delegatorAddress
's redelegating bonds from srcValidator
to dstValidator
function getRedelegations(
address delegatorAddress,
address srcValidator,
address dstValidator,
Cosmos.PageRequest calldata pagination
) external view returns (RedelegationEntry[] memory, Cosmos.PageResponse memory);
function getRedelegations(
address delegatorAddress,
address srcValidator,
address dstValidator,
Cosmos.PageRequest calldata pagination
) external view returns (RedelegationEntry[] memory, Cosmos.PageResponse memory);
Parameters
Name | Type | Description |
---|---|---|
delegatorAddress | address | The delegator address |
srcValidator | address | The source validator operator address |
dstValidator | address | The destination validator operator address |
pagination | Cosmos.PageRequest |
delegate β
msg.sender delegates the amount
of tokens to validatorAddress
function delegate(address validatorAddress, uint256 amount) external payable returns (bool);
function delegate(address validatorAddress, uint256 amount) external payable returns (bool);
Parameters
Name | Type | Description |
---|---|---|
validatorAddress | address | The validator operator address |
amount | uint256 | The amount of tokens to delegate |
undelegate β
msg.sender undelegates the amount
of tokens from validatorAddress
function undelegate(address validatorAddress, uint256 amount) external payable returns (bool);
function undelegate(address validatorAddress, uint256 amount) external payable returns (bool);
Parameters
Name | Type | Description |
---|---|---|
validatorAddress | address | The validator operator address |
amount | uint256 | The amount of tokens to undelegate |
beginRedelegate β
msg.sender redelegates the amount
of tokens from srcValidator
to validtorDstAddr
function beginRedelegate(address srcValidator, address dstValidator, uint256 amount) external payable returns (bool);
function beginRedelegate(address srcValidator, address dstValidator, uint256 amount) external payable returns (bool);
Parameters
Name | Type | Description |
---|---|---|
srcValidator | address | The source validator operator address |
dstValidator | address | The destination validator operator address |
amount | uint256 | The amount of tokens to redelegate |
cancelUnbondingDelegation β
Cancels msg.sender's unbonding delegation with validatorAddress
and delegates the amount
of tokens back to validatorAddress
function cancelUnbondingDelegation(address validatorAddress, uint256 amount, int64 creationHeight)
external
payable
returns (bool);
function cancelUnbondingDelegation(address validatorAddress, uint256 amount, int64 creationHeight)
external
payable
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
validatorAddress | address | The validator operator address |
amount | uint256 | The amount of tokens to cancel |
creationHeight | int64 | The height at which the unbonding delegation was created |
Events β
Delegate β
Emitted by the staking module when amount
tokens are delegated to validator
event Delegate(address indexed validator, Cosmos.Coin[] amount);
event Delegate(address indexed validator, Cosmos.Coin[] amount);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator operator address |
amount | Cosmos.Coin[] | The amount of tokens delegated |
Redelegate β
Emitted by the staking module when amount
tokens are redelegated from sourceValidator
to destinationValidator
event Redelegate(address indexed sourceValidator, address indexed destinationValidator, Cosmos.Coin[] amount);
event Redelegate(address indexed sourceValidator, address indexed destinationValidator, Cosmos.Coin[] amount);
Parameters
Name | Type | Description |
---|---|---|
sourceValidator | address | The source validator operator address |
destinationValidator | address | The destination validator operator address |
amount | Cosmos.Coin[] | The amount of tokens redelegated |
CreateValidator β
Emitted by the staking module when amount
tokens are used to create validator
event CreateValidator(address indexed validator, Cosmos.Coin[] amount);
event CreateValidator(address indexed validator, Cosmos.Coin[] amount);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator operator address |
amount | Cosmos.Coin[] | The amount of tokens used to create the validator |
Unbond β
Emitted by the staking module when amount
tokens are unbonded from validator
event Unbond(address indexed validator, Cosmos.Coin[] amount);
event Unbond(address indexed validator, Cosmos.Coin[] amount);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator operator address |
amount | Cosmos.Coin[] | The amount of tokens unbonded |
CancelUnbondingDelegation β
Emitted by the staking module when amount
tokens are canceled from delegator
's unbonding delegation with validator
event CancelUnbondingDelegation(
address indexed validator, address indexed delegator, Cosmos.Coin[] amount, int64 creationHeight
);
event CancelUnbondingDelegation(
address indexed validator, address indexed delegator, Cosmos.Coin[] amount, int64 creationHeight
);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator operator address |
delegator | address | The delegator address |
amount | Cosmos.Coin[] | The amount of tokens canceled |
creationHeight | int64 | The height at which the unbonding delegation was created |
Structs β
Validator β
Represents a validator.
struct Validator {
address operatorAddr;
bytes consAddr;
bool jailed;
string status;
uint256 tokens;
uint256 delegatorShares;
Description description;
int64 unbondingHeight;
string unbondingTime;
Commission commission;
uint256 minSelfDelegation;
int64 unbondingOnHoldRefCount;
uint64[] unbondingIds;
}
struct Validator {
address operatorAddr;
bytes consAddr;
bool jailed;
string status;
uint256 tokens;
uint256 delegatorShares;
Description description;
int64 unbondingHeight;
string unbondingTime;
Commission commission;
uint256 minSelfDelegation;
int64 unbondingOnHoldRefCount;
uint64[] unbondingIds;
}
Commission β
Represents the commission parameters for a given validator.
struct Commission {
CommissionRates commissionRates;
string updateTime;
}
struct Commission {
CommissionRates commissionRates;
string updateTime;
}
CommissionRates β
Represents the initial commission rates to be used for creating a validator.
struct CommissionRates {
uint256 rate;
uint256 maxRate;
uint256 maxChangeRate;
}
struct CommissionRates {
uint256 rate;
uint256 maxRate;
uint256 maxChangeRate;
}
Description β
Represents a validator description.
struct Description {
string moniker;
string identity;
string website;
string securityContact;
string details;
}
struct Description {
string moniker;
string identity;
string website;
string securityContact;
string details;
}
UnbondingDelegationEntry β
Represents one entry of an unbonding delegation
struct UnbondingDelegationEntry {
int64 creationHeight;
string completionTime;
uint256 initialBalance;
uint256 balance;
uint64 unbondingId;
}
struct UnbondingDelegationEntry {
int64 creationHeight;
string completionTime;
uint256 initialBalance;
uint256 balance;
uint64 unbondingId;
}
UnbondingDelegation β
Represents all unbonding bonds of a single delegator with relevant metadata
struct UnbondingDelegation {
address delegatorAddress;
address validatorAddress;
UnbondingDelegationEntry[] entries;
}
struct UnbondingDelegation {
address delegatorAddress;
address validatorAddress;
UnbondingDelegationEntry[] entries;
}
RedelegationEntry β
Represents a redelegation entry with relevant metadata
struct RedelegationEntry {
int64 creationHeight;
string completionTime;
uint256 initialBalance;
uint256 sharesDst;
uint64 unbondingId;
}
struct RedelegationEntry {
int64 creationHeight;
string completionTime;
uint256 initialBalance;
uint256 sharesDst;
uint64 unbondingId;
}
Delegation β
Represents a single delegation.
struct Delegation {
address delegator;
uint256 balance;
uint256 shares;
}
struct Delegation {
address delegator;
uint256 balance;
uint256 shares;
}