Skip to content

Commit c754a6f

Browse files
wilwadeclaireclark1JoeCap08055
authored
Capacity Pallet Documentation Improvements (#1997)
# Goal The goal of this PR is to improve the documentation of the Pallets and make that documentation be able to be used on docs.frequency.xyz. Part of frequency-chain/docs#59 # Discussion - Capacity Pallet Readme --------- Co-authored-by: V. Claire Olmstead <[email protected]> Co-authored-by: Joe Caputo <[email protected]>
1 parent 358ac19 commit c754a6f

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

pallets/capacity/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Capacity Pallet
2+
3+
The Capacity Pallet manages the staking and balances for Capacity, an alternative payment system on Frequency.
4+
5+
## Summary
6+
7+
Capacity is an alternative to paying with tokens for a limited set of calls.
8+
These Capacity eligible extrinsics are noted in each pallet's documentation with "Capacity" in the Payment column of the extrinsics section.
9+
Tokens can be staked to generate Capacity for a targeted Provider.
10+
The generated Capacity renews each [Epoch](#capacity-epoch).
11+
[Learn more about Capacity](https://docs.frequency.xyz/Tokenomics/ProviderIncentives.html#capacity-model).
12+
13+
### Staking & Unstaking
14+
Currently, the token to Capacity ratio is 50:1.
15+
For example, for a 5 token stake, a Provider would receive 0.1 Capacity.
16+
Staking and unstaking affect available Capacity immediately.
17+
18+
### Capacity Epoch
19+
20+
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.
21+
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.
22+
The duration of a Capacity Epoch is determined by Governance, and is currently set to 7200 blocks.
23+
With the current average block time of approximately 12 seconds, one Capacity Epoch lasts around 24 hours on Mainnet.
24+
25+
### Thaw Period
26+
27+
After unstaking, the tokens will still be frozen for a set amount of time before they are unencumbered and able to be transferred.
28+
The `UnstakingThawPeriod` constant defines the number of Epochs that must pass before the tokens may be reclaimed for any use via `withdrawUnstaked()`.
29+
Currently it is set to 30 Epochs or ~30 days after unstaking.
30+
31+
### Actions
32+
33+
The Capacity Pallet provides for:
34+
35+
- Staking to receive Capacity
36+
- Unstaking & Thaw Period
37+
- Capacity Epoch management
38+
39+
## Interactions
40+
41+
### Extrinsics
42+
43+
| Name/Description | Caller | Payment | Key Events | Runtime Added |
44+
| -------------------------------- | ------------- | ------- | ------------------------------------------------------------------------------------------------------------- | ------------- |
45+
| `stake`<br />Lock tokens to grant Capacity to a Provider | Token Account | Tokens | [`Staked`](https://frequency-chain.github.io/frequency/pallet_capacity/pallet/enum.Event.html#variant.Staked) | 1 |
46+
| `unstake`<br />Begin the process of unlocking tokens by unstaking currently staked tokens | Token Account | Tokens | [`UnStaked`](https://frequency-chain.github.io/frequency/pallet_capacity/pallet/enum.Event.html#variant.UnStaked) | 1 |
47+
| `withdraw_unstaked`<br />Complete the process of unlocking tokens staked by releasing locks on expired unlock chunks | Token Account | Tokens | [`StakeWithdrawn`](https://frequency-chain.github.io/frequency/pallet_capacity/pallet/enum.Event.html#variant.StakeWithdrawn) | 1 |
48+
49+
See [Rust Docs](https://frequency-chain.github.io/frequency/pallet_capacity/pallet/struct.Pallet.html) for more details.
50+
51+
### State Queries
52+
53+
| Name | Description | Query | Runtime Added |
54+
| --------- | ------------------- | ------------------------ | ------------- |
55+
| Get Capacity Ledger | Returns the Capacity balance details for a Provider's MSA Id | `capacityLedger` | 1 |
56+
| Get Current Epoch | Returns the current Capacity Epoch number | `currentEpoch` | 1 |
57+
| Get Current Epoch Info | Returns information about the current Capacity Epoch such as the starting block number | `currentEpochInfo` | 1 |
58+
| Get Staking Account Ledger | Returns information about an account's current staking details | `stakingAccountLedger` | 1 |
59+
| Staking Target Ledger | Returns information about an account's current staking details for a specific target Provider MSA Id | `stakingTargetLedger` | 1 |
60+
| Get Unstake Information | Returns the information about an account's current unstaking details and the unlocking chunks | `unstakeUnlocks` | 1 |
61+
62+
63+
See the [Rust Docs](https://frequency-chain.github.io/frequency/pallet_capacity/pallet/storage_types/index.html) for additional state queries and details.

pallets/capacity/src/lib.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
1-
//! # Capacity Pallet
2-
//! The Capacity pallet provides functionality for staking tokens to the Frequency network.
1+
//! Managages staking to the network for Capacity
32
//!
3+
//! ## Quick Links
44
//! - [Configuration: `Config`](Config)
55
//! - [Extrinsics: `Call`](Call)
66
//! - [Event Enum: `Event`](Event)
77
//! - [Error Enum: `Error`](Error)
8+
#![doc = include_str!("../README.md")]
89
//!
9-
//! ## Overview
10-
//! Capacity is a refillable resource that can be used to make transactions on the network.
11-
//! Tokens may be staked to the network targeting a provider MSA account to which the network will grant Capacity.
10+
//! ## Lazy Capacity Refill
1211
//!
13-
//! The network generates Capacity based on a Capacity-generating function that considers usage and network congestion.
14-
//! When token is staked, the targeted provider MSA receives the Capacity generated.
15-
//!
16-
//! This Capacity can be used to pay for transactions given that the key used to pay for those transactions have a minimum balance
17-
//! of the existential deposit.
18-
//!
19-
//! The staked amount may be increased, targeting either the same or a different target to receive the newly generated Capacity.
20-
//! As a result, every time the network is staked to, the staked tokens are locked until unstaked.
21-
//!
22-
//! Unstaking schedules some amount of token to be unlocked. Any amount up to the total staked amount may
23-
//! be unstaked, however, there is a a limit on how many concurrently scheduled unstaking requests can exist.
24-
//! After scheduling tokens to be unlocked, they must undergo a thaw period before being withdrawn.
25-
//!
26-
//! After thawing, the tokens may be withdrawn using the withdraw_unstaked extrinsic.
27-
//! On success, the tokens are unlocked and free up space to submit more unstaking request.
28-
//!
29-
//! The Capacity pallet provides functions for:
30-
//!
31-
//! - staking and, updating,
32-
//!
33-
//! ## Terminology
34-
//! * **Capacity:** A refillable and non-transferable resource that can be used to pay for transactions on the network.
35-
//! * **Staker:** An account that stakes tokens to the Frequency network in exchange for Capacity.
36-
//! * **Target** A provider MSA account that receives Capacity.
37-
//! * **Epoch Period:** The length of an epoch in blocks, used for replenishment and thawing.
38-
//! * **Replenishable:** The ability of a provider MSA account to be refilled with Capacity after an epoch period.
12+
//! Capacity is refilled on an as needed basis.
13+
//! Thus, the provider's capacity balance retains the information of the last epoch.
14+
//! 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.
15+
//! Thus, the first use of Capacity in an Epoch will update the last Epoch number to match the current Epoch.
16+
//! If a provider does not use any Capacity in an Epoch, the provider's capacity balance information is never updated for that Epoch.
3917
//!
4018
// Substrate macros are tripping the clippy::expect_used lint.
4119
#![allow(clippy::expect_used)]

0 commit comments

Comments
 (0)