Crate pallet_capacity

source ·
Expand description

Managages staking to the network for Capacity

Capacity Pallet

The Capacity Pallet manages the staking and balances for Capacity, an alternative payment system on Frequency.

Summary

Capacity is an alternative to paying with tokens for a limited set of calls. These Capacity eligible extrinsics are noted in each pallet’s documentation with “Capacity” in the Payment column of the extrinsics section. Tokens can be staked to generate Capacity for a targeted Provider. The generated Capacity renews each Epoch. Learn more about Capacity.

Staking & Unstaking

Currently, the token to Capacity ratio is 50:1. For example, for a 5 token stake, a Provider would receive 0.1 Capacity. Staking and unstaking affect available Capacity immediately.

Capacity Epoch

A Capacity Epoch is a period consisting of a specific number of blocks, during which a Provider’s utilization of network Capacity is capped at the amount of generated Capacity targeted to that Provider. At the start of each new Epoch, the available Capacity is renewed for each Provider, regardless of how much they consumed in the prior Epoch. The duration of a Capacity Epoch is determined by Governance, and is currently set to 7200 blocks. With the current average block time of approximately 12 seconds, one Capacity Epoch lasts around 24 hours on Mainnet.

Thaw Period

After unstaking, the tokens will still be frozen for a set amount of time before they are unencumbered and able to be transferred. The UnstakingThawPeriod constant defines the number of Epochs that must pass before the tokens may be reclaimed for any use via withdrawUnstaked(). Currently it is set to 30 Epochs or ~30 days after unstaking.

Actions

The Capacity Pallet provides for:

  • Staking to receive Capacity
  • Unstaking & Thaw Period
  • Capacity Epoch management

Interactions

Extrinsics

Name/DescriptionCallerPaymentKey EventsRuntime Added
change_staking_target
Change the target of a stake from one Provider to the other.
Token AccountTokensStakingTargetChanged1
claim_staking_rewards
Mint and pay out eligible staking rewards from Provider Boosting.
Token AccountTokensProviderBoostRewardClaimed1
provider_boost
Lock tokens to grant Capacity to a Provider and earn token Rewards
Token AccountTokensProviderBoosted1
stake
Lock tokens to grant Capacity to a Provider
Token AccountTokensStaked1
unstake
Begin the process of unlocking tokens by unstaking currently staked tokens
Token AccountTokensUnStaked1
withdraw_unstaked
Complete the process of unlocking tokens staked by releasing locks on expired unlock chunks
Token AccountTokensStakeWithdrawn1

See Rust Docs for more details.

State Queries

NameDescriptionQueryRuntime Added
Get Capacity LedgerReturns the Capacity balance details for a Provider’s MSA IdcapacityLedger1
Get Current EpochReturns the current Capacity Epoch numbercurrentEpoch1
Get Current Epoch InfoReturns information about the current Capacity Epoch such as the starting block numbercurrentEpochInfo1
Current Era InfoReturns the index of the current era and the block when it startedcurrentEraInfo1
Current Era Provider Boost TotalReturns the total amount of token staked this Reward Era, as of the current blockcurrentProviderBoostTotal1
Provider Boost HistoriesReturns the ProviderBoostHistory stored for the provided AccountIdproviderBoostHistories1
Provider Boost Reward PoolReturns the Provider Boost Reward Pool Chunk at the given indexproviderBoostRewardBools1
RetargetsReturns the count of retargets and what era was the last retarget, for the provided AccountId.retargets1
Get Staking Account LedgerReturns information about an account’s current staking detailsstakingAccountLedger1
Staking Target LedgerReturns information about an account’s current staking details for a specific target Provider MSA IdstakingTargetLedger1
Get Unstake InformationReturns the information about an account’s current unstaking details and the unlocking chunksunstakeUnlocks1

RPCs

Custom RPCs are not enabled for this pallet. The following RuntimeAPI functions may be accessed by making a state call, for example:

    const encodedAddr = api.registry.createType('AccountId32', booster.address);  // where booster is a polkadot/keyring Keypair type
    let result = await api.rcp.state.call('CapacityRuntimeApi_list_unclaimed_rewards', encodedAddr);
    const decodedResult: Vec<UnclaimedRewardInfo> = api.registry.createType('Vec<UnclaimedRewardInfo>', result);
NameDescriptionQueryRuntime Added
List unclaimed rewardsReturns a list of UnclaimedRewardInfo for the provided AccountId.CapacityRuntimeApi_list_unclaimed_rewards1

See the Rust Docs for additional state queries and details.

Lazy Capacity Refill

Capacity is refilled on an as needed basis. Thus, the provider’s capacity balance retains the information of the last epoch. Upon use, if the last Epoch is less than the current Epoch, the balance is assumed to be the maximum as the reload “has” happened. Thus, the first use of Capacity in an Epoch will update the last Epoch number to match the current Epoch. If a provider does not use any Capacity in an Epoch, the provider’s capacity balance information is never updated for that Epoch.

Re-exports

Modules

  • storage migrations
  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
  • Types for the Capacity Pallet
  • Autogenerated weights for pallet_capacity

Structs

  • Result of checking a Boost History item to see if it’s eligible for a reward.

Traits

Functions

  • Wraps PREFIX and POSTFIX around a Vec<u8> Returns PREFIX ++ data ++ POSTFIX

Type Aliases

  • Some way of identifying an account on the chain. We intentionally make it equivalent to the public key of our transaction signing scheme.
  • Balance is a generic type for the balance of an account.
  • An index to a block.
  • Message Source Id or msaId is the unique identifier for Message Source Accounts
  • The type of a Reward Era