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

claim staking rewards 1747 | will be split up into multiple PRs #2065

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2ad8209
some words
shannonwells Apr 8, 2023
3eefdbd
Design documents first versions
shannonwells Apr 11, 2023
8823fa9
updates to design docs to use a capacity rewards interface
shannonwells May 23, 2023
8055a21
make check and make test working
shannonwells Jun 1, 2023
6e940d2
remove economic model design doc until further notice
shannonwells Jun 2, 2023
385bfad
Implement Staking Reward Eras basics (#1589)
shannonwells Jun 7, 2023
36e8645
Feat/staking rewards rewards provider #1572 (#1598)
shannonwells Jun 14, 2023
fbb8848
change staking target extrinsic, closes #1570 (#1623)
shannonwells Jul 7, 2023
e27b5ce
comments, capacity boost fn added to StakingRewardsProvider trait
shannonwells Oct 2, 2023
b62de39
* Refactor staking type to go in StakingTargetDetails
shannonwells Oct 3, 2023
b85157e
use capacity_boost and StakingType to adjust capacity generation, add…
shannonwells Oct 4, 2023
e81063f
* Check from/to aren't the same when retargeting
shannonwells Oct 5, 2023
cb443e2
Feat/reward pool history (#1710)
shannonwells Oct 16, 2023
30d1522
Feat/split stake extrinsic #1699 (#1717)
shannonwells Oct 17, 2023
95eb6cf
Feat/split storage #1726 (#1744)
shannonwells Oct 30, 2023
7ba6785
fix e2e tests, correction to implementation design doc
shannonwells Oct 30, 2023
a727c05
updates after rebase
shannonwells Dec 12, 2023
4f33f4b
initialize storage for ProviderBoost on runtime upgrade
shannonwells Apr 19, 2024
c8e30fd
Set ProviderBoost capacity generated and fix tests (#1947)
shannonwells Apr 23, 2024
781cb36
Update reward pool on `provider_boost` or `unstake` #1699 (#1948)
shannonwells Apr 25, 2024
e29dc41
Implement rewards calculation formula #1941 (#1956)
shannonwells May 3, 2024
fbeb483
updates after rebase
shannonwells May 6, 2024
4dd521c
upsert staking history #1699 (#1963)
shannonwells May 8, 2024
5a5e523
Chores/update capacity benchmarks #1949 (#1966)
shannonwells May 13, 2024
8c9e13b
Feat/check unclaimed rewards 1969 (#1972)
shannonwells May 21, 2024
1b8c062
updates after rebase with m ain
shannonwells May 22, 2024
4e461d7
restore undone merge from bad rebase
shannonwells May 23, 2024
81eebe8
Feat/reward pool refactor #1976 (#2005)
shannonwells Jun 10, 2024
da640fd
Revise Provider Boost implementation design doc #2016 (#2020)
shannonwells Jun 12, 2024
4bd088d
E2e for new extrinsics (#2067)
shannonwells Jul 12, 2024
75602c6
Refactor reward era (#2069)
shannonwells Jul 12, 2024
acf73fb
change staking target extrinsic, closes #1570 (#1623)
shannonwells Jul 7, 2023
ac815f9
error test passing
shannonwells Jun 13, 2024
4a5459d
claim_staking_rewards passes all tests
shannonwells Jun 17, 2024
8d91801
capacity with only runtime-api passing make check
shannonwells Jun 25, 2024
7d2c1e6
updates after rebase
shannonwells Jun 25, 2024
2e58950
updates after rebase
shannonwells Jun 25, 2024
be8af51
runtime api working w/ make start and make e2e tests
shannonwells Jun 27, 2024
76fa929
e2e tests running but 1 is still failing
shannonwells Jun 28, 2024
b211a0e
* Fixes to e2e tests
shannonwells Jul 3, 2024
d741059
fix build issue
shannonwells Jul 9, 2024
137daeb
runtime-api test working
shannonwells Jul 10, 2024
e384c64
updates after rebase, still one failing test
shannonwells Jul 12, 2024
14651a2
* more updates after rebase to get tests working
shannonwells Jul 15, 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
13 changes: 13 additions & 0 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 @@ -194,9 +194,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,
)]
#[scale_info(skip_type_params(T))]
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
Loading