Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c5cde02
create enum
Nov 3, 2022
3ab9cd7
logic check
Nov 9, 2022
59958d5
add benchmarks
Nov 14, 2022
9d54b8a
-enum
Nov 18, 2022
8efecfe
Merge branch 'paritytech:master' into ddc-MCF-T1
Nov 19, 2022
f7b0a2d
update
Nov 20, 2022
8931433
bond extra other
Dec 3, 2022
9f83103
update
Dec 4, 2022
9d63fdb
update
Dec 4, 2022
a3718f6
update
Dec 5, 2022
4c6a4e7
cargo fmt
Dec 5, 2022
8207d51
Permissioned
Dec 7, 2022
0401174
Merge branch 'paritytech:master' into ddc-MCF-T1
Dec 7, 2022
a4b6ec2
update
Dec 15, 2022
db9c1b8
cargo fmt
Dec 15, 2022
4d8bc6f
Merge branch 'paritytech:master' into ddc-MCF-T1
Dec 15, 2022
b5eda08
update
Dec 18, 2022
58173e0
Merge branch 'paritytech:master' into ddc-MCF-T1
Jan 2, 2023
b110526
update index
Jan 2, 2023
126bc8d
Merge branch 'paritytech:master' into ddc-MCF-T1
Jan 10, 2023
a45d615
doc update
Jan 26, 2023
ab1e7bb
doc update
Jan 30, 2023
ab064f7
Merge branch 'paritytech:master' into ddc-MCF-T1
Feb 1, 2023
5f25374
cargo fmt
Feb 1, 2023
619e9b9
bond_extra auto compound
Feb 2, 2023
15c286f
bond_extra_other
Feb 7, 2023
1a1479d
Merge branch 'paritytech:master' into ddc-MCF-T1
Feb 7, 2023
b21097b
Merge branch 'paritytech:master' into ddc-MCF-T1
Feb 8, 2023
4ffe8f5
Merge branch 'paritytech:master' into ddc-MCF-T1
Feb 9, 2023
fcd63b2
Apply suggestions from code review
kianenigma Feb 13, 2023
f6254fa
Fixes from kian
kianenigma Feb 13, 2023
ce1ebc9
updates docs & test
Feb 14, 2023
62edda4
Merge remote-tracking branch 'origin/master' into ddc-MCF-T1
Feb 19, 2023
1211229
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
6e4f2b4
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
832281d
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
e242799
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
011d733
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
d9590b1
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
04d6b13
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
b8be98c
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
d8fac0e
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
79f9b7e
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
184d6f2
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
0e0cc6f
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
be3cc5e
Update frame/nomination-pools/src/lib.rs
Feb 20, 2023
768c63d
Update frame/nomination-pools/src/tests.rs
Feb 20, 2023
549a743
fixes + fmt
Feb 20, 2023
e823b43
Merge remote-tracking branch 'origin/master' into ddc-MCF-T1
Feb 21, 2023
1c17bcc
expand ClaimPermissions + add benchmarks
Feb 21, 2023
9b1eb00
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nomination_…
Feb 21, 2023
9996341
tidy up claim payout benches
Feb 21, 2023
6fa711c
fix
Feb 21, 2023
0f9f730
+ test: claim_payout_other_works
Feb 21, 2023
4bdf22a
comments, rename to set_claim_permission
Feb 21, 2023
2965fd9
fix comment
Feb 21, 2023
7c16c8e
remove ClaimPermission on leave pool
Feb 21, 2023
ef63fdf
fix test
Feb 21, 2023
f8cedba
".git/.scripts/commands/fmt/fmt.sh"
Feb 21, 2023
4ac673b
Merge remote-tracking branch 'origin/master' into ddc-MCF-T1
Feb 22, 2023
0ea2309
+ test for ClaimPermissions::remove()
Feb 22, 2023
a39573c
impl can_bond_extra & can_claim_payout
Feb 22, 2023
f7a6568
Merge remote-tracking branch 'origin/master' into ddc-MCF-T1
Feb 22, 2023
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
Prev Previous commit
Next Next commit
update index
  • Loading branch information
doordashcon committed Jan 2, 2023
commit b1105260a42903f79457c6579dca620864c0f429
136 changes: 68 additions & 68 deletions frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,69 +1621,13 @@ pub mod pallet {
Ok(())
}

/// Bond pending rewards of `member_account` into the pool they already belong.
///
/// Note: `member_account` must pass `RewardClaim::Permissionless` to `set_reward_claim`,
/// making this call permissionless.
#[pallet::call_index(2)]
#[pallet::weight(
T::WeightInfo::bond_extra_transfer()
.max(T::WeightInfo::bond_extra_reward())
)]
pub fn bond_extra_pending_rewards_other(
origin: OriginFor<T>,
member_account: AccountIdLookupOf<T>,
) -> DispatchResult {
ensure_signed(origin)?;
let member_account = T::Lookup::lookup(member_account)?;
let (mut member, mut bonded_pool, mut reward_pool) =
Self::get_member_with_pools(&member_account)?;

ensure!(
RewardClaimPermission::<T>::get(&member_account) == RewardClaim::Permissionless,
Error::<T>::DoesNotHavePermission
);

reward_pool.update_records(bonded_pool.id, bonded_pool.points)?;
ensure!(!member.active_points().is_zero(), Error::<T>::FullyUnbonding);

let current_reward_counter =
reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?;
let pending_rewards = member.pending_rewards(current_reward_counter)?;

if !pending_rewards.is_zero() {
member.last_recorded_reward_counter = current_reward_counter;
reward_pool.register_claimed_reward(pending_rewards);
}

let points_issued = bonded_pool.try_bond_funds(
&bonded_pool.reward_account(),
pending_rewards,
BondType::Later,
)?;

bonded_pool.ok_to_be_open()?;
member.points = member.points.saturating_add(points_issued);

Self::deposit_event(Event::<T>::Bonded {
member: member_account.clone(),
pool_id: member.pool_id,
bonded: pending_rewards,
joined: false,
});

Self::put_member_with_pools(&member_account, member, bonded_pool, reward_pool);

Ok(())
}

/// A bonded member can use this to claim their payout based on the rewards that the pool
/// has accumulated since their last claimed payout (OR since joining if this is there first
/// time claiming rewards). The payout will be transferred to the member's account.
///
/// The member will earn rewards pro rata based on the members stake vs the sum of the
/// members in the pools stake. Rewards do not "expire".
#[pallet::call_index(3)]
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::claim_payout())]
pub fn claim_payout(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -1726,7 +1670,7 @@ pub mod pallet {
/// are available). However, it may not be possible to release the current unlocking chunks,
/// in which case, the result of this call will likely be the `NoMoreChunks` error from the
/// staking system.
#[pallet::call_index(4)]
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::unbond())]
pub fn unbond(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1803,7 +1747,7 @@ pub mod pallet {
/// can be cleared by withdrawing. In the case there are too many unlocking chunks, the user
/// would probably see an error like `NoMoreChunks` emitted from the staking system when
/// they attempt to unbond.
#[pallet::call_index(5)]
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::pool_withdraw_unbonded(*num_slashing_spans))]
pub fn pool_withdraw_unbonded(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1838,7 +1782,7 @@ pub mod pallet {
/// # Note
///
/// If the target is the depositor, the pool will be destroyed.
#[pallet::call_index(6)]
#[pallet::call_index(5)]
#[pallet::weight(
T::WeightInfo::withdraw_unbonded_kill(*num_slashing_spans)
)]
Expand Down Expand Up @@ -1960,7 +1904,7 @@ pub mod pallet {
///
/// In addition to `amount`, the caller will transfer the existential deposit; so the caller
/// needs at have at least `amount + existential_deposit` transferrable.
#[pallet::call_index(7)]
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::create())]
pub fn create(
origin: OriginFor<T>,
Expand All @@ -1985,7 +1929,7 @@ pub mod pallet {
///
/// same as `create` with the inclusion of
/// * `pool_id` - `A valid PoolId.
#[pallet::call_index(8)]
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::create())]
pub fn create_with_pool_id(
origin: OriginFor<T>,
Expand All @@ -2010,7 +1954,7 @@ pub mod pallet {
///
/// This directly forward the call to the staking pallet, on behalf of the pool bonded
/// account.
#[pallet::call_index(9)]
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::nominate(validators.len() as u32))]
pub fn nominate(
origin: OriginFor<T>,
Expand All @@ -2033,7 +1977,7 @@ pub mod pallet {
/// 1. signed by the state toggler, or the root role of the pool,
/// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and
/// then the state of the pool can be permissionlessly changed to `Destroying`.
#[pallet::call_index(10)]
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::set_state())]
pub fn set_state(
origin: OriginFor<T>,
Expand Down Expand Up @@ -2062,7 +2006,7 @@ pub mod pallet {
///
/// The dispatch origin of this call must be signed by the state toggler, or the root role
/// of the pool.
#[pallet::call_index(11)]
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::set_metadata(metadata.len() as u32))]
pub fn set_metadata(
origin: OriginFor<T>,
Expand Down Expand Up @@ -2094,7 +2038,7 @@ pub mod pallet {
/// * `max_pools` - Set [`MaxPools`].
/// * `max_members` - Set [`MaxPoolMembers`].
/// * `max_members_per_pool` - Set [`MaxPoolMembersPerPool`].
#[pallet::call_index(12)]
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::set_configs())]
pub fn set_configs(
origin: OriginFor<T>,
Expand Down Expand Up @@ -2131,7 +2075,7 @@ pub mod pallet {
///
/// It emits an event, notifying UIs of the role change. This event is quite relevant to
/// most pool members and they should be informed of changes to pool roles.
#[pallet::call_index(13)]
#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::update_roles())]
pub fn update_roles(
origin: OriginFor<T>,
Expand Down Expand Up @@ -2184,7 +2128,7 @@ pub mod pallet {
///
/// This directly forward the call to the staking pallet, on behalf of the pool bonded
/// account.
#[pallet::call_index(14)]
#[pallet::call_index(13)]
#[pallet::weight(T::WeightInfo::chill())]
pub fn chill(origin: OriginFor<T>, pool_id: PoolId) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -2193,6 +2137,62 @@ pub mod pallet {
T::Staking::chill(&bonded_pool.bonded_account())
}

/// Bond pending rewards of `member_account` into the pool they already belong.
///
/// Note: `member_account` must pass `RewardClaim::Permissionless` to `set_reward_claim`,
/// making this call permissionless.
#[pallet::call_index(14)]
#[pallet::weight(
T::WeightInfo::bond_extra_transfer()
.max(T::WeightInfo::bond_extra_reward())
)]
pub fn bond_extra_pending_rewards_other(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have asked this before, but can't this be one transaction with the existing bond_extra? and even if we want to keep them separate, shan't they share most of the internal code?

Copy link
Contributor Author

@Doordashcon Doordashcon Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does share most of the internal code of bond_extra, it excludes transferring pending rewards to the member from the do_reward_payout helper function and instead transfers the pending reward directly to the bounding account from try_bound_fund and increment the points accordingly.

Copy link
Contributor Author

@Doordashcon Doordashcon Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kianenigma Yes an extra parameter other: Option<AccountId> can be added to bond_extra then the claimed rewards will be bonded for the account specified in other.

origin: OriginFor<T>,
member_account: AccountIdLookupOf<T>,
) -> DispatchResult {
ensure_signed(origin)?;
let member_account = T::Lookup::lookup(member_account)?;
let (mut member, mut bonded_pool, mut reward_pool) =
Self::get_member_with_pools(&member_account)?;

ensure!(
RewardClaimPermission::<T>::get(&member_account) == RewardClaim::Permissionless,
Error::<T>::DoesNotHavePermission
);

reward_pool.update_records(bonded_pool.id, bonded_pool.points)?;
ensure!(!member.active_points().is_zero(), Error::<T>::FullyUnbonding);

let current_reward_counter =
reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?;
let pending_rewards = member.pending_rewards(current_reward_counter)?;

if !pending_rewards.is_zero() {
member.last_recorded_reward_counter = current_reward_counter;
reward_pool.register_claimed_reward(pending_rewards);
}

let points_issued = bonded_pool.try_bond_funds(
&bonded_pool.reward_account(),
pending_rewards,
BondType::Later,
)?;

bonded_pool.ok_to_be_open()?;
member.points = member.points.saturating_add(points_issued);

Self::deposit_event(Event::<T>::Bonded {
member: member_account.clone(),
pool_id: member.pool_id,
bonded: pending_rewards,
joined: false,
});

Self::put_member_with_pools(&member_account, member, bonded_pool, reward_pool);

Ok(())
}

/// Set reward claim permission.
///
/// # Arguments
Expand Down