Skip to content

Commit b3ef46a

Browse files
committed
refinements to design doc
1 parent 6acaf3c commit b3ef46a

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

designdocs/capacity_staking_rewards_implementation.md

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ This document outlines how to implement the Staking for Rewards feature describe
2020
1. **Capacity**: the non-transferrable utility token which can be used only to pay for certain Frequency transactions.
2121
1. **Account**: a Frequency System Account controlled by a private key and addressed by a public key, having at least a minimum balance (currently 0.01 FRQCY).
2222
1. **Stake** (verb): to lock some amount of a token against transfer for a period of time in exchange for some reward.
23-
1. **RewardEra**: the time period (TBD in blocks or Capacity Epochs) that Staking Rewards are based upon.
23+
1. **RewardEra**: the time period (TBD in blocks or Capacity Epochs) that Staking Rewards are based upon. RewardEra is to distinguish it easily from Substrate's staking pallet Era.
2424
1. **Staking Reward**: a per-RewardEra share of a staking reward pool of FRQCY tokens for a given staking account.
2525
1. **Reward Pool**: a fixed amount of FRQCY that can be minted for rewards each RewardEra and distributed to stakers.
2626

2727
## Staking Token Rewards
2828

2929
### StakingAccountDetails updates
30-
We add a new field, `last_rewarded_at`, to keep track of the last time rewards were claimed for this Staking Account.
30+
New fields are added. The field `last_rewarded_at` is to keep track of the last time rewards were claimed for this Staking Account.
3131
MaximumCapacity staking accounts MUST always have the value `None` for `last_rewarded_at`. This should be the default value also.
3232
`MaximumCapacity` is also the default value for `staking_type` and should map to 0.
33+
Finally, `stake_change_unlocking`, a BoundedVec is added which tracks the chunks of when a staking account has changed targets for some amount of funds.
3334
```rust
3435
pub struct StakingAccountDetails {
3536
pub active: BalanceOf<T>,
@@ -46,7 +47,7 @@ pub struct StakingAccountDetails {
4647
```
4748

4849
**Unstaking thaw period**
49-
We change the thaw period to begin at the first block of next Epoch instead of immediately.
50+
Changes the thaw period to begin at the first block of next RewardEra instead of immediately.
5051

5152
### Changes to extrinsics
5253
```rust
@@ -125,9 +126,7 @@ pub trait StakingRewardsProvider {
125126
}
126127
```
127128

128-
The number of blocks for which Rewards from a RewardPool applies is called a `RewardEra`; this is to distinguish it from `Era` in the Substrate staking pallet; this way automatic imports don't accidentally pull in the wrong thing.
129-
130-
### NEW: storage items, Config, Errors and related types
129+
### NEW: StakingType enum
131130
```rust
132131
pub enum StakingType {
133132
/// Staking account targets Providers for capacity only, no token reward
@@ -136,7 +135,10 @@ pub enum StakingType {
136135
/// and token for the account holder
137136
Rewards,
138137
}
138+
```
139139

140+
### NEW: Config items
141+
```rust
140142
pub trait Config: frame_system::Config {
141143
// ...
142144

@@ -159,25 +161,35 @@ pub trait Config: frame_system::Config {
159161

160162
type RewardsProvider: StakingRewardsProvider;
161163
};
164+
```
162165

166+
### NEW: RewardPoolInfo
167+
This is the necessary information about the reward pool for a given Reward Era and how it's stored.
168+
```rust
163169
pub struct RewardPoolInfo<T: Config> {
164170
/// the total staked for rewards in the associated RewardEra
165171
total_staked_token: BalanceOf<T>,
166172
/// the remaining rewards balance to be claimed
167173
unclaimed_balance: BalanceOf<T>
168174
}
169-
170175
#[pallet::storage]
171176
#[pallet::getter(fn get_reward_pool_for_era)]
172177
/// Reward Pool history
173178
pub type StakingRewardPool<T: Config> = <StorageMap<_, Twox64Concat, RewardEra, RewardPoolInfo<T>;
179+
```
174180

181+
#### NEW: CurrentEra
182+
Incremented, like CurrentEpoch, tracks the current RewardEra number.
183+
```rust
175184
#[pallet::storage]
176185
#[pallet::whitelist_storage]
177186
#[pallet::getter(fn get_current_era)]
178187
/// Similar to CurrentEpoch
179188
pub type CurrentEra<T:Config> = StorageValue<_, T::RewardEra, ValueQuery>;
189+
```
180190

191+
#### NEW: Error enums
192+
```rust
181193
pub enum Error<T> {
182194
/// ...
183195
/// Staker tried to change StakingType on an existing account
@@ -189,42 +201,42 @@ pub enum Error<T> {
189201
}
190202
```
191203

192-
### New extrinsics
193-
1. *claim_staking_reward*
204+
### NEW Extrinsics
205+
1. *claim_staking_reward*, first version
194206
a. `claim_staking_reward(origin,proof,payload)`
195-
```rust
196-
/// TBD whether this is the form for claiming rewards. This could be the form if calculations are
197-
/// done off chain and submitted for validation.
198-
/// Validates the reward claim. If validated, mints token and transfers to Origin.
199-
/// Errors:
200-
/// - NotAStakingAccount: if Origin does not own the StakingRewardDetails in the claim.
201-
/// - StakingRewardClaimInvalid: if validation of calculation fails
202-
/// - IneligibleForPayoutInEraRange: if rewards were already paid out in the provided RewardEra range
203-
/// - EraOutOfRange: if one or both of the StakingRewardClaim eras are invalid
204-
/// `proof` - the Merkle proof for the reward claim
205-
#[pallet::call_index(n)]
206-
pub fn claim_staking_reward(
207-
origin: OriginFor<T>,
208-
proof: Hash,
209-
payload: StakingRewardClaim<T>
210-
);
211-
```
212-
b. `claim_staking_reward(origin, from_era, to_era)`
213-
```rust
214-
/// An alternative, depending on staking reward economic model. This could be the form if calculations are done on chain.
215-
/// from_era: if None, since last_reward_claimed_at
216-
/// to_era: if None, to CurrentEra - 1
217-
/// Errors:
218-
/// - NotAStakingAccount: if Origin does not own the StakingRewardDetails in the claim.
219-
/// - IneligibleForPayoutInEraRange: if rewards were already paid out in the provided RewardEra range
220-
/// - EraOutOfRange: if one or both of the eras specified are invalid
221-
#[pallet::call_index(n)]
222-
pub fn claim_staking_reward(
223-
origin: OriginFor<T>,
224-
from_era: Option<T::RewardEra>,
225-
to_era: Option<T::RewardEra>
226-
);
227-
```
207+
```rust
208+
/// TBD whether this is the form for claiming rewards. This could be the form if calculations are
209+
/// done off chain and submitted for validation.
210+
/// Validates the reward claim. If validated, mints token and transfers to Origin.
211+
/// Errors:
212+
/// - NotAStakingAccount: if Origin does not own the StakingRewardDetails in the claim.
213+
/// - StakingRewardClaimInvalid: if validation of calculation fails
214+
/// - IneligibleForPayoutInEraRange: if rewards were already paid out in the provided RewardEra range
215+
/// - EraOutOfRange: if one or both of the StakingRewardClaim eras are invalid
216+
/// `proof` - the Merkle proof for the reward claim
217+
#[pallet::call_index(n)]
218+
pub fn claim_staking_reward(
219+
origin: OriginFor<T>,
220+
proof: Hash,
221+
payload: StakingRewardClaim<T>
222+
);
223+
```
224+
b. *claim_staking_reward*, alternate version
225+
```rust
226+
/// An alternative, depending on staking reward economic model. This could be the form if calculations are done on chain.
227+
/// from_era: if None, since last_reward_claimed_at
228+
/// to_era: if None, to CurrentEra - 1
229+
/// Errors:
230+
/// - NotAStakingAccount: if Origin does not own the StakingRewardDetails in the claim.
231+
/// - IneligibleForPayoutInEraRange: if rewards were already paid out in the provided RewardEra range
232+
/// - EraOutOfRange: if one or both of the eras specified are invalid
233+
#[pallet::call_index(n)]
234+
pub fn claim_staking_reward(
235+
origin: OriginFor<T>,
236+
from_era: Option<T::RewardEra>,
237+
to_era: Option<T::RewardEra>
238+
);
239+
```
228240

229241
2. **change_staking_target(origin, from, to, amount)**
230242
```rust
@@ -248,7 +260,8 @@ pub fn change_staking_target(
248260
);
249261
```
250262

251-
### RPC
263+
### NEW RPC
264+
There are no custom RPCs for the Capacity pallet, so that work will need to be done.
252265
```rust
253266
/// RPC access to the pallet function by the same name
254267
pub fn payout_eligible(account_id: AccountId) -> bool;

0 commit comments

Comments
 (0)