Skip to content

Commit 391f963

Browse files
committed
Design documents first versions
updates to design docs to use a capacity rewards interface Prototypes, make check working refinements to design doc Implement Staking Reward Eras basics (#1589) Implement the basic functionality of tracking and rotating Reward Era. Closes #1567 Does not include anything to do with the Reward Pool. Feat/staking rewards rewards provider #1572 (#1598) The goal of this PR is to implement a really basic version of the StakingRewardsProvider in the Capacity pallet and in the test mock, neither of which is actively used. Closes #1572 Does not include anything to do with setting and storing RewardPoolInfo when each new Era starts. change staking target extrinsic, closes #1570 (#1623) comments, capacity boost fn added to StakingRewardsProvider trait * Refactor staking type to go in StakingTargetDetails * Make some functions pass by reference (performance) * fix broken tests & calls use capacity_boost and StakingType to adjust capacity generation, add/adjust tests * Check from/to aren't the same when retargeting * Performance: move non-db checks to top when retargeting * Lots more tests * Fix a bug where we weren't setting the staking type on a retarget * Remove staking type from StakingAccountDetails * Fix broken tests from last commit Feat/reward pool history (#1710) Closes #1710 Feat/split stake extrinsic #1699 (#1717) The goal of this PR is to split the `stake` extrinsic into two: `stake` and `provider_boost` Closes #1707 Feat/split storage #1726 (#1744) The goal of this PR is to split up storage of boosting and maximized staking accounts, as well as store retarget history separately, which can store retargeting events for any type of staking. Closes #1726 fix e2e tests, correction to implementation design doc initialize storage for ProviderBoost on runtime upgrade Set ProviderBoost capacity generated and fix tests (#1947) * set the amount of capacity generated by a provider boost to the final amount, 50% of what is generated by MaximizedCapacity staking. * Also Fixes some tests broken from the last rebase with main. Closes #1569 Update reward pool on `provider_boost` or `unstake` #1699 (#1948) The goal of this PR is to update the StakingRewardPool on a `provider_boost` or `unstake` extrinsic call. Closes #1699 Implement rewards calculation formula #1941 (#1956) The goal of this PR is to implement (but not really use yet) the chosen formula for calculation of a reward in a single Provider Boost Reward Era. Closes #1941 updates after rebase upsert staking history #1699 (#1963) The goal of this PR is to add and use storage for individual staking history so that rewards can be calculated and paid out. Benchmarks run to update capacity weights. Relates to #1699 Chores/update capacity benchmarks #1949 (#1966) The goal of this PR is to update the benchmark for `on_initialize` to include the weight when a new RewardEra must be created. Closes #1949 Feat/check unclaimed rewards 1969 (#1972) The goal of this PR is to implement `list_unclaimed_rewards`, and also one that is lighter weight, `has_unclaimed_rewards`, which returns a `bool` and which `unstake` extrinsic uses. Unstake now fails if there are any unclaimed rewards. Closes #1969 Closes #1578 Feat/reward pool refactor #1976 (#2005) The goal of this PR is to implement a "chunk" version of the overall reward pool history to reduce read/write load and hence weight for transactions and `on_initialize` when a new `RewardEra` needs to start. Part of #1976 Co-authored-by: Wil Wade <[email protected]> Revise Provider Boost implementation design doc #2016 (#2020) The goal of this PR is to review and update the implementation design doc in light of the chosen economic model, and to reflect some changes in behavior. Review of the design doc also fed back into the code itself. Some code is no longer needed. Closes #2016 Co-authored-by: Aramik <[email protected]> E2e for new extrinsics (#2067) The goal of this PR is to add some e2e tests for the `provider_boost` extrinsic, and update the `change_staking_target` extrinsic after a rebase with main. Refactor reward era (#2069) The goal of this PR is primarily to pull RewardEra out of the Capacity Config and make it the same type everywhere. `claim_staking_rewards` extrinsic (#2080) Closes #1970 Capacity runtime api with list_unclaimed_rewards endpoint (#2088) The goal of this PR is to implement a capacity runtime api for the `list_unclaimed_rewards` endpoint. Closes #1698 Update Capacity README address the lint failure. updates after rebase with main Remove TODO since it's already been addressed. Add a minor test case to unstaking tests Add new extrinsics to Capacity README
1 parent bbac770 commit 391f963

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5058
-1773
lines changed

Cargo.lock

Lines changed: 938 additions & 1276 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ benchmarks-multi:
198198
benchmarks-multi-local:
199199
./scripts/run_benchmarks.sh -t bench-dev $(PALLETS)
200200

201-
benchmarks-capacity:
202-
./scripts/run_benchmark.sh -p capacity
203-
204201
.PHONY: docs
205202
docs:
206203
RUSTC_BOOTSTRAP=1 RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --no-deps --workspace --features frequency

common/primitives/src/capacity.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use crate::msa::MessageSourceId;
22
use frame_support::traits::tokens::Balance;
3+
use scale_info::TypeInfo;
4+
use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug};
35
use sp_runtime::DispatchError;
46

7+
/// The type of a Reward Era
8+
pub type RewardEra = u32;
9+
510
/// A trait for checking that a target MSA can be staked to.
611
pub trait TargetValidator {
712
/// Checks if an MSA is a valid target.
@@ -15,19 +20,24 @@ impl TargetValidator for () {
1520
}
1621
}
1722

18-
/// A trait for Non-transferable asset.
23+
/// A trait for Non-transferable asset
1924
pub trait Nontransferable {
2025
/// Scalar type for representing balance of an account.
2126
type Balance: Balance;
2227

23-
/// The balance Capacity for an MSA account.
28+
/// The balance Capacity for an MSA.
2429
fn balance(msa_id: MessageSourceId) -> Self::Balance;
2530

26-
/// Reduce Capacity of an MSA account by amount.
27-
fn deduct(msa_id: MessageSourceId, amount: Self::Balance) -> Result<(), DispatchError>;
31+
/// Reduce Capacity of an MSA by amount.
32+
fn deduct(msa_id: MessageSourceId, capacity_amount: Self::Balance)
33+
-> Result<(), DispatchError>;
2834

29-
/// Increase Capacity of an MSA account by an amount.
30-
fn deposit(msa_id: MessageSourceId, amount: Self::Balance) -> Result<(), DispatchError>;
35+
/// Increase Staked Token + Capacity amounts of an MSA. (unused)
36+
fn deposit(
37+
msa_id: MessageSourceId,
38+
token_amount: Self::Balance,
39+
capacity_amount: Self::Balance,
40+
) -> Result<(), DispatchError>;
3141
}
3242

3343
/// A trait for replenishing Capacity.
@@ -47,3 +57,22 @@ pub trait Replenishable {
4757
/// Checks if an account can be replenished.
4858
fn can_replenish(msa_id: MessageSourceId) -> bool;
4959
}
60+
61+
/// Result of checking a Boost History item to see if it's eligible for a reward.
62+
#[derive(
63+
Copy, Clone, Default, Encode, Eq, Decode, RuntimeDebug, MaxEncodedLen, PartialEq, TypeInfo,
64+
)]
65+
66+
pub struct UnclaimedRewardInfo<Balance, BlockNumber> {
67+
/// The Reward Era for which this reward was earned
68+
pub reward_era: RewardEra,
69+
/// When this reward expires, i.e. can no longer be claimed
70+
pub expires_at_block: BlockNumber,
71+
/// The total staked in this era as of the current block
72+
pub staked_amount: Balance,
73+
/// The amount staked in this era that is eligible for rewards. Does not count additional amounts
74+
/// staked in this era.
75+
pub eligible_amount: Balance,
76+
/// The amount in token of the reward (only if it can be calculated using only on chain data)
77+
pub earned_amount: Balance,
78+
}

designdocs/capacity.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Stakes some amount of tokens to the network and generates Capacity.
117117
///
118118
/// - Returns Error::InsufficientBalance if the sender does not have free balance amount needed to stake.
119119
/// - Returns Error::InvalidTarget if attempting to stake to an invalid target.
120-
/// - Returns Error::InsufficientStakingAmount if attempting to stake an amount below the minimum amount.
120+
/// - Returns Error::StakingAmountBelowMinimum if attempting to stake an amount below the minimum amount.
121121
/// - Returns Error::BalanceTooLowtoStake if the sender does not have
122122
/// free balance amount > MinimumTokenBalance after staking.
123123
pub fn stake(origin: OriginFor<T>, target: MessageSourceId, amount: BalanceOf<T>) -> DispatchResult {}
@@ -211,7 +211,7 @@ pub enum Error<T> {
211211
/// Capacity is not available for the given MSA.
212212
InsufficientBalance,
213213
/// Staker is attempting to stake an amount below the minimum amount.
214-
InsufficientStakingAmount,
214+
StakingAmountBelowMinimum,
215215
/// Staker is attempting to stake a zero amount.
216216
ZeroAmountNotAllowed,
217217
/// Origin has no Staking Account
@@ -825,7 +825,7 @@ Note that Capacity transactions do not get refunded for overcharges.
825825

826826
## Non-goals
827827

828-
Staking rewards and re-staking are left for another design document.
828+
Rewards and re-staking are left for another design document.
829829

830830
## Benefits and Risk
831831

designdocs/capacity_staking_rewards.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

designdocs/provider_boosting_economic_model.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ This document does not:
6666

6767
### Formula
6868

69-
The Provider Boost reward in FRQCY tokens for a given Era <i>e</i> is
69+
The Provider Boost reward in FRQCY tokens for a given Era <i>e</i> is a simple interest model, with the following formula:
7070

7171
R = <i>min</i>(R<sub>era</sub>*L<sub>u</sub>/L<sub>T</sub>, L<sub>u</sub>*P<sub>max</sub>)
7272

73-
Put into words, if the pool of Rewards per Era is R<sub>era</sub> FRQCY, then the Reward amount in FRQCY earned by a given Provider Booster will be proportional to how much they've locked for Provider Boosting out of the total, OR P<sub>max</sub> times the amount locked, whichever is less.
73+
Put into words, if the pool of Rewards per Era is
74+
75+
R<sub>era</sub> FRQCY, then the Reward amount in FRQCY earned by a given Provider Booster will be proportional to how much they've locked for Provider Boosting out of the total OR P<sub>max</sub> times the amount locked, whichever is less.
7476

7577
Put another way, there is a fixed number of tokens to be rewarded each Era (R<sub>era</sub>), split up according to each Provider Boost account holder's percentage of the locked total. However, the reward return each Era for every individual account (P<sub>max</sub>) is capped at some rate, for example, 10%.
7678

@@ -93,4 +95,4 @@ Rewards are not prorated; they are calculated only for balances held for an enti
9395
- Provider Boost Rewards are not minted until they are explicitly <i>claimed</i> by the Provider Boost account holder, by calling a non-free extrinsic.
9496
- Rewards must be claimed within a certain number of Provider Boost Eras.
9597
- When claimed, all available, unexpired Rewards for each previous Era are minted and transferred to the same account that locked them.
96-
- **Is there a cap on how much can be claimed at once?**
98+
- Currently there is no cap on how much can be claimed at once.

0 commit comments

Comments
 (0)