Skip to main content

staking

Abstract

The staking precompiled contract acts as a bridge to enable the Stable SDK's x/staking module functionality to be used in an EVM environment.

Contents

  1. Concepts
  2. Configuration
  3. Methods
  4. Events

Concepts

In x/staking module in Stable SDK, bond denom must be registered during chain initialization for staking. Validator and delegator only can use bond denom staking token. In staking precompiled contract, additional checks are made to ensure that the validator or delegator is a caller.

Configuration

Contract address and gas cost is predefined.

Contract Address

  • 0x0000000000000000000000000000000000001001

Methods

createValidator

A validator is created. The validator must be created with an initial delegation from the operator. For potential delegators, validator should offer their information and plan for commission rate. Delegator can choose validator to delegate their own tokens by disclosed information with natural regulation from market mechanism.

CreateValidator is emitted when the validator is successfully registered.

Inputs

NameTypeDescription
descriptionDescriptioninformation of the validator
commissionRatesCommissionRatescommission rate of the staking token rewarded by the validator
minSelfDelegationuint256the minimum self-delegation amount of the validator
validatorAddressaddressthe address of the validator
pubkeystringthe public key of the validator
valueuint256the amount of the staking token initially self-delegated to the validator

Description is a struct with the following fields:

NameTypeDescription
monikerstringname of the validator
identitystringthe identity of the validator
websitestringthe url of the validator's website
securityContactstringsecurity contract information
detailsstringadditional description of the validator

CommissionRates is a struct with the following fields:

NameTypeDescription
rateuint256current commission rate that the validator receives
maxRateuint256the maximum commission rate (cannot be set higher than this)
maxChangeRateuint256the maximium commission rate that validator can change for a day

rate should be set to an appropriate value acceptable to the market.

  • If validator's commission rate is higher, delegator's profit is lower.
  • If validator's commission rate is lower, validator's profit is lower and it makes operation difficult.

Since high maxRate can make delegator concern about unexpected high commission rate by validator, maxRate should be set carefully. maxChangeRate is unchangeable when initialized.

Outputs

NameTypeDescription
successbooltrue if the validator is successfully registered

editValidator

Validator updates its information. Validator only can update information except unchangeable fields such as maxRate and maxChangeRate in CommissionRates struct.

EditValidator is emitted when the validator is successfully updated.

Inputs

NameTypeDescription
descriptionDescriptioninformation of the validator
validatorAddressaddressthe address of the validator
commissionRateint256the commission rate of the staking token rewarded by the validator
minSelfDelegationint256the minimum self-delegation amount of the validator

Outputs

NameTypeDescription
successbooltrue if the validator is successfully updated

delegate

Delegator sets the amount of token to be delegated to the validator.

Delegate is emitted when the delegation is successfully done.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
validatorAddressstringthe address of the validator
amountuint256the amount of the staking token delegated to the validator

Outputs

NameTypeDescription
successbooltrue if the delegation is successfully done

Events

newShares indicates the ownership ratio of the delegator. The shares calculated may vary depending on the time even though the same amount of tokens are delegated.

undelegate

Delegator withdraws the amount of token delegated to the validator.

Unbond is emitted when the undelegation is successfully done.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
validatorAddressstringthe address of the validator
amountuint256the amount of the staking token willing to undelegate from the validator

Outputs

NameTypeDescription
successbooltrue if the undelegation is successfully done

redelegate

Delegator redelegates the amount of token delegated to the validator to another validator.

Redelegate is emitted when the redelegate is successfully done.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
validatorSrcstringthe address of the source validator
validatorDststringthe address of the destination validator
amountuint256the amount of the staking token for redelegation

Outputs

NameTypeDescription
successbooltrue if the redelegate is successfully done

delegation

Returns the delegation information between a delegator and a validator. If there is no delegation found, the shares and balance will be 0.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
validatorAddressstringthe address of the validator

Outputs

NameTypeDescription
sharesuint256the delegated shares
balanceCointhe amount of delegated token and denom

Coin is a struct with the following fields:

NameTypeDescription
denomstringthe denom of the reward
amountuint256the amount of the reward

unbondingDelegation

Returns the unbonding delegation information between a delegator and a validator. If there is no unbonding delegation found, empty UnbondingDelegationOutput will be returned.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
validatorAddressstringthe address of the validator

Outputs

NameTypeDescription
unbondingDelegationUnbondingDelegationOutputthe information of the unbonding delegation

UnbondingDelegationOutput is a struct with the following fields:

NameTypeDescription
validatorAddressstringthe address of the validator
delegatorAddressstringthe address of the delegator
entriesUnbondingDelegationEntry[]the entries of the unbonding delegation

UnbondingDelegationEntry is a struct with the following fields:

NameTypeDescription
creationHeightuint64the creation height of the entry
completionTimeuint64the completion time of the entry
initialBalanceCointhe initial balance of the entry
balanceCointhe balance of the entry

validator

Returns the validator information. If there is no validator found, empty ValidatorOutput will be returned.

Inputs

NameTypeDescription
validatorAddressaddressthe address of the validator

Outputs

NameTypeDescription
validatorValidatorthe information of the validator

Validator is a struct with the following fields:

NameTypeDescription
operatorAddressstringthe address of the validator
consensusPubkeystringthe public key of the validator
jailedboolwhether the validator is jailed or not
statusint32the status of the validator
tokensuint256the amount of the staking token delegated to the validator
delegatorSharesuint256the amount of the delegation shares
descriptionstringthe description of the validator
unbondingHeightint64the height at which the validator is unbonding
unbondingTimeint64the time at which the validator is unbonding
commissionuint256the commission rate of the staking token rewarded by the validator
minSelfDelegationuint256the minimum self-delegation amount of the validator

validators

Returns all validators matched with the status. If there is no validator found, empty ValidatorsOutput will be returned.

Status, declared in x/staking module, can be one of the following:

  • 0 : "BOND_STATUS_UNSPECIFIED", unspecified status
  • 1 : "BOND_STATUS_UNBONDING", validator is unbonding
  • 2 : "BOND_STATUS_UNBONDED", validator is unbonded
  • 3 : "BOND_STATUS_BONDED", validator is bonded

Inputs

NameTypeDescription
statusstringthe status of the validator
pageRequestPageReqrequest for pagination

PageReq is a struct with the following fields:

NameTypeDescription
keybytesthe key of the page
offsetint64the offset of the page
limitint64the limit of the page
countTotalboolwhether to count the total number of results or not
reverseboolwhether to reverse the results or not

Outputs

NameTypeDescription
validatorsValidator[]the arrays of the validators
pageResponsePageRespresponse for pagination

PageResp is a struct with the following fields:

NameTypeDescription
nextKeybytesthe next key of the page
totaluint64the total number of the results

redelegation

Returns the redelegation information of delegator, source validator and destination validator. If there is no redelegation found, empty RedelegationOutput will be returned.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
srcValidatorAddressstringthe address of the source validator
dstValidatorAddressstringthe address of the destination validator

Outputs

NameTypeDescription
redelegationRedelegationOutputthe information of the redelegation

RedelegationOutput is a struct with the following fields:

NameTypeDescription
delegatorAddressstringthe address of the delegator
validatorSrcAddressstringthe address of the source validator
validatorDstAddressstringthe address of the destination validator
entriesRedelegationEntry[]the entries of the redelegation

RedelegationEntry is a struct with the following fields:

NameTypeDescription
creationHeightuint64the creation height of the entry
completionTimeuint64the completion time of the entry
initialBalanceCointhe initial balance of the entry
balanceCointhe balance of the entry

redelegations

Returns all redelegations of delegator, source validator and destination validator. If there is no redelegation found, empty RedelegationResponse and PageResp will be returned.

Inputs

NameTypeDescription
delegatorAddressaddressthe address of the delegator
srcValidatorAddressstringthe address of the source validator
dstValidatorAddressstringthe address of the destination validator
pageRequestPageReqrequest for pagination

Outputs

NameTypeDescription
responseRedelegationResponse[]the information of the redelegations
pageResponsePageRespresponse for pagination

Events

CreateValidator

NameTypeIndexedDescription
valiAddraddressYthe address of the validator
valueuint256Nthe amount of the staking token initially self-delegated to the validator

EditValidator

NameTypeIndexedDescription
valiAddraddressYthe address of the validator
commissionRateint256Nthe updated commission rate of the staking token rewarded by the validator
minSelfDelegationint256Nthe updated minimum self-delegation amount of the validator

Delegate

NameTypeIndexedDescription
delegatorAddraddressYthe address of the delegator
validatorAddrstringYthe address of the validator
amountuint256Nthe amount of the staking token delegated to the validator
newSharesuint256Nthe amount of the delegation shares after the delegation

Unbond

NameTypeIndexedDescription
delegatorAddraddressYthe address of the delegator
validatorAddrstringYthe address of the validator
amountuint256Nthe amount of the staking token undelegated from the validator
completionTimeuint256Nthe completion time of the undelegation

Redelegate

NameTypeIndexedDescription
delegatorAddraddressYthe address of the delegator
validatorSrcAddressstringYthe address of the source validator
validatorDstAddressstringYthe address of the destination validator
amountuint256Nthe amount of the staking token for redelegation
completionTimeuint256Nthe completion time of the redelegate