Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider Boosting implementation #1694

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ac64e47
some words
shannonwells Apr 8, 2023
8f9b426
Design documents first versions
shannonwells Apr 11, 2023
042c7c7
updates to design docs to use a capacity rewards interface
shannonwells May 23, 2023
82ea1b8
make check and make test working
shannonwells Jun 1, 2023
0dbcb90
remove economic model design doc until further notice
shannonwells Jun 2, 2023
076c6ff
Implement Staking Reward Eras basics (#1589)
shannonwells Jun 7, 2023
e871a27
Feat/staking rewards rewards provider #1572 (#1598)
shannonwells Jun 14, 2023
7cfc638
change staking target extrinsic, closes #1570 (#1623)
shannonwells Jul 7, 2023
4e6465b
comments, capacity boost fn added to StakingRewardsProvider trait
shannonwells Oct 2, 2023
928dc4c
* Refactor staking type to go in StakingTargetDetails
shannonwells Oct 3, 2023
71b51d8
use capacity_boost and StakingType to adjust capacity generation, add…
shannonwells Oct 4, 2023
e6c22e8
* Check from/to aren't the same when retargeting
shannonwells Oct 5, 2023
699471d
Feat/reward pool history (#1710)
shannonwells Oct 16, 2023
4a29295
Feat/split stake extrinsic #1699 (#1717)
shannonwells Oct 17, 2023
ef48e8e
Feat/split storage #1726 (#1744)
shannonwells Oct 30, 2023
318c4ce
fix e2e tests, correction to implementation design doc
shannonwells Oct 30, 2023
169e0a4
updates after rebase
shannonwells Dec 12, 2023
1414262
initialize storage for ProviderBoost on runtime upgrade
shannonwells Apr 19, 2024
cd0e239
Set ProviderBoost capacity generated and fix tests (#1947)
shannonwells Apr 23, 2024
85d1d90
Update reward pool on `provider_boost` or `unstake` #1699 (#1948)
shannonwells Apr 25, 2024
b2360de
Implement rewards calculation formula #1941 (#1956)
shannonwells May 3, 2024
fb7c153
updates after rebase
shannonwells May 6, 2024
5354673
upsert staking history #1699 (#1963)
shannonwells May 8, 2024
b94bd78
Chores/update capacity benchmarks #1949 (#1966)
shannonwells May 13, 2024
863e26a
Feat/check unclaimed rewards 1969 (#1972)
shannonwells May 21, 2024
69f5198
updates after rebase with m ain
shannonwells May 22, 2024
869cb1a
restore undone merge from bad rebase
shannonwells May 23, 2024
b9466a8
Feat/reward pool refactor #1976 (#2005)
shannonwells Jun 10, 2024
078d412
Revise Provider Boost implementation design doc #2016 (#2020)
shannonwells Jun 12, 2024
07599e9
E2e for new extrinsics (#2067)
shannonwells Jul 12, 2024
0b35226
Refactor reward era (#2069)
shannonwells Jul 12, 2024
6ed6217
`claim_staking_rewards` extrinsic (#2080)
shannonwells Jul 18, 2024
f70d1aa
updates after rebase
shannonwells Jul 18, 2024
6a2a150
Capacity runtime api with list_unclaimed_rewards endpoint (#2088)
shannonwells Jul 19, 2024
233496b
cleanup for audit & review
shannonwells Jul 20, 2024
fe94fcf
please the linter
shannonwells Jul 22, 2024
ae0236b
Update Capacity README and please the linter
shannonwells Jul 22, 2024
ffb5a7f
address the lint failure. updates after rebase with main
shannonwells Jul 23, 2024
78ee1ca
Remove TODO since it's already been addressed.
shannonwells Jul 23, 2024
8e26370
Merge branch 'main' into feat/capacity-staking-rewards-impl
wilwade Jul 30, 2024
276fbf1
Bump Spec Version
wilwade Jul 30, 2024
4cf9e2f
Fix e2e funding sources
wilwade Jul 30, 2024
c842471
Update other spec version
wilwade Jul 30, 2024
bc111d7
e2e test formatting
wilwade Jul 30, 2024
2d8cc0f
Merge remote-tracking branch 'origin/main' into feat/capacity-staking…
wilwade Jul 30, 2024
b7bed08
Merge remote-tracking branch 'origin/main' into feat/capacity-staking…
wilwade Jul 31, 2024
5ee47ab
Merge remote-tracking branch 'origin/main' into feat/capacity-staking…
wilwade Aug 2, 2024
c68a698
Formatting
wilwade Aug 2, 2024
5b7b213
Fix cargo deny
wilwade Aug 2, 2024
29e68c4
Merge branch 'main' into feat/capacity-staking-rewards-impl
wilwade Aug 2, 2024
b45c8c2
Bug fix capacity e2e test (#2110)
wilwade Aug 2, 2024
35dc097
Update e2e/capacity/change_staking_target.test.ts
shannonwells Aug 5, 2024
9ec30fb
Setup genesis with the correct `CurrentEraInfo`
wilwade Aug 5, 2024
40f3910
Fix Typo in e2e test
wilwade Aug 5, 2024
65df923
Boosting: removed added getters (#2112)
aramikm Aug 5, 2024
556fe38
Merge remote-tracking branch 'origin/main' into feat/capacity-staking…
wilwade Aug 5, 2024
2223e4a
check error name and clarify test names
shannonwells Aug 5, 2024
6d94da0
Formatting fixes
wilwade Aug 5, 2024
14271c8
Fixing passkey test
wilwade Aug 5, 2024
eb68e65
booster: feedback 1 (#2114)
aramikm Aug 6, 2024
3480405
some minor refactoring
aramikm Aug 6, 2024
56df16d
Make RewardEras zero-indexed (#2115)
shannonwells Aug 6, 2024
c2bef19
adding more checks
aramikm Aug 6, 2024
abe5066
* New alias for ChunkIndex = u32
shannonwells Aug 6, 2024
e3ae518
[Capacity] MinimumStakingAmount is not enforced if a stake already ex…
mattheworris Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ benchmarks-multi:
benchmarks-multi-local:
./scripts/run_benchmarks.sh -t bench-dev $(PALLETS)

benchmarks-capacity:
./scripts/run_benchmark.sh -p capacity

.PHONY: docs
docs:
RUSTC_BOOTSTRAP=1 RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --no-deps --features frequency
Expand Down
41 changes: 35 additions & 6 deletions common/primitives/src/capacity.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::msa::MessageSourceId;
use frame_support::traits::tokens::Balance;
use scale_info::TypeInfo;
use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug};
use sp_runtime::DispatchError;

/// The type of a Reward Era
pub type RewardEra = u32;

/// A trait for checking that a target MSA can be staked to.
pub trait TargetValidator {
/// Checks if an MSA is a valid target.
Expand All @@ -15,19 +20,24 @@ impl TargetValidator for () {
}
}

/// A trait for Non-transferable asset.
/// A trait for Non-transferable asset
pub trait Nontransferable {
/// Scalar type for representing balance of an account.
type Balance: Balance;

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

/// Reduce Capacity of an MSA account by amount.
fn deduct(msa_id: MessageSourceId, amount: Self::Balance) -> Result<(), DispatchError>;
/// Reduce Capacity of an MSA by amount.
fn deduct(msa_id: MessageSourceId, capacity_amount: Self::Balance)
-> Result<(), DispatchError>;

/// Increase Capacity of an MSA account by an amount.
fn deposit(msa_id: MessageSourceId, amount: Self::Balance) -> Result<(), DispatchError>;
/// Increase Staked Token + Capacity amounts of an MSA. (unused)
fn deposit(
msa_id: MessageSourceId,
token_amount: Self::Balance,
capacity_amount: Self::Balance,
) -> Result<(), DispatchError>;
}

/// A trait for replenishing Capacity.
Expand All @@ -47,3 +57,22 @@ pub trait Replenishable {
/// Checks if an account can be replenished.
fn can_replenish(msa_id: MessageSourceId) -> bool;
}

/// Result of checking a Boost History item to see if it's eligible for a reward.
#[derive(
Copy, Clone, Default, Encode, Eq, Decode, RuntimeDebug, MaxEncodedLen, PartialEq, TypeInfo,
)]

pub struct UnclaimedRewardInfo<Balance, BlockNumber> {
/// The Reward Era for which this reward was earned
pub reward_era: RewardEra,
/// When this reward expires, i.e. can no longer be claimed
pub expires_at_block: BlockNumber,
/// The total staked in this era as of the current block
pub staked_amount: Balance,
/// The amount staked in this era that is eligible for rewards. Does not count additional amounts
/// staked in this era.
pub eligible_amount: Balance,
/// The amount in token of the reward (only if it can be calculated using only on chain data)
pub earned_amount: Balance,
}
6 changes: 3 additions & 3 deletions designdocs/capacity.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Stakes some amount of tokens to the network and generates Capacity.
///
/// - Returns Error::InsufficientBalance if the sender does not have free balance amount needed to stake.
/// - Returns Error::InvalidTarget if attempting to stake to an invalid target.
/// - Returns Error::InsufficientStakingAmount if attempting to stake an amount below the minimum amount.
/// - Returns Error::StakingAmountBelowMinimum if attempting to stake an amount below the minimum amount.
/// - Returns Error::BalanceTooLowtoStake if the sender does not have
/// free balance amount > MinimumTokenBalance after staking.
pub fn stake(origin: OriginFor<T>, target: MessageSourceId, amount: BalanceOf<T>) -> DispatchResult {}
Expand Down Expand Up @@ -211,7 +211,7 @@ pub enum Error<T> {
/// Capacity is not available for the given MSA.
InsufficientBalance,
/// Staker is attempting to stake an amount below the minimum amount.
InsufficientStakingAmount,
StakingAmountBelowMinimum,
/// Staker is attempting to stake a zero amount.
ZeroAmountNotAllowed,
/// Origin has no Staking Account
Expand Down Expand Up @@ -828,7 +828,7 @@ Note that Capacity transactions do not get refunded for overcharges.

## Non-goals

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

## Benefits and Risk

Expand Down
8 changes: 5 additions & 3 deletions designdocs/provider_boosting_economic_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ This document does not:

### Formula

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

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

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.
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.

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%.

Expand All @@ -93,4 +95,4 @@ Rewards are not prorated; they are calculated only for balances held for an enti
- 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.
- Rewards must be claimed within a certain number of Provider Boost Eras.
- When claimed, all available, unexpired Rewards for each previous Era are minted and transferred to the same account that locked them.
- **Is there a cap on how much can be claimed at once?**
- Currently there is no cap on how much can be claimed at once.
Loading