-
Notifications
You must be signed in to change notification settings - Fork 2.7k
permissionless bond_extra in nomination pools
#12608
Changes from 3 commits
c5cde02
3ab9cd7
59958d5
9d54b8a
8efecfe
f7b0a2d
8931433
9f83103
9d63fdb
a3718f6
4c6a4e7
8207d51
0401174
a4b6ec2
db9c1b8
4d8bc6f
b5eda08
58173e0
b110526
126bc8d
a45d615
ab1e7bb
ab064f7
5f25374
619e9b9
15c286f
1a1479d
b21097b
4ffe8f5
fcd63b2
f6254fa
ce1ebc9
62edda4
1211229
6e4f2b4
832281d
e242799
011d733
d9590b1
04d6b13
b8be98c
d8fac0e
79f9b7e
184d6f2
0e0cc6f
be3cc5e
768c63d
549a743
e823b43
1c17bcc
9b1eb00
9996341
6fa711c
0f9f730
4bdf22a
2965fd9
7c16c8e
ef63fdf
f8cedba
4ac673b
0ea2309
a39573c
f7a6568
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1276,6 +1276,10 @@ pub mod pallet { | |
| pub type ReversePoolIdLookup<T: Config> = | ||
| CountedStorageMap<_, Twox64Concat, T::AccountId, PoolId, OptionQuery>; | ||
|
|
||
| /// Member decision for operator claimable reward action. | ||
| #[pallet::storage] | ||
| pub type ClaimableAction<T: Config> = StorageMap<_, Twox64Concat, T::AccountId, bool, ValueQuery>; | ||
|
|
||
| #[pallet::genesis_config] | ||
| pub struct GenesisConfig<T: Config> { | ||
| pub min_join_bond: BalanceOf<T>, | ||
|
|
@@ -1433,6 +1437,8 @@ pub mod pallet { | |
| PoolIdInUse, | ||
| /// Pool id provided is not correct/usable. | ||
| InvalidPoolId, | ||
| /// The caller is not the operator for this pool. | ||
| NotRoot, | ||
| } | ||
|
|
||
| #[derive(Encode, Decode, PartialEq, TypeInfo, frame_support::PalletError, RuntimeDebug)] | ||
|
|
@@ -1566,6 +1572,61 @@ pub mod pallet { | |
| Ok(()) | ||
| } | ||
|
|
||
| // TODO: Update weight info | ||
| // Investigate adding helper function to remove code duplication. | ||
| #[pallet::weight( | ||
| T::WeightInfo::bond_extra_transfer() | ||
| .max(T::WeightInfo::bond_extra_reward()) | ||
| )] | ||
| #[transactional] | ||
| pub fn root_bond_extra( | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| origin: OriginFor<T>, | ||
| member_account: AccountIdLookupOf<T>, | ||
| ) -> DispatchResult { | ||
| let who = 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!(bonded_pool.is_root(&who), Error::<T>::NotRoot); | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ensure!(ClaimableAction::<T>::get(&member_account), Error::<T>::DoesNotHavePermission); | ||
|
|
||
| // IMPORTANT: reward pool records must be updated with the old points. why? | ||
| reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; | ||
rossbulat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // A member who has no skin in the game anymore cannot claim any rewards. | ||
| 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(pending_rewards)?; | ||
| 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. | ||
|
|
@@ -2079,6 +2140,19 @@ pub mod pallet { | |
| ensure!(bonded_pool.can_nominate(&who), Error::<T>::NotNominator); | ||
| T::Staking::chill(&bonded_pool.bonded_account()) | ||
| } | ||
|
|
||
| // TODO: For when the pool member leaves or is kiked out, clear storage. | ||
| // Update weight info | ||
| #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] | ||
| pub fn set_claimable_action(origin: OriginFor<T>, action: bool) -> DispatchResult { | ||
|
||
| let who = ensure_signed(origin)?; | ||
|
|
||
| ensure!(PoolMembers::<T>::contains_key(&who), Error::<T>::PoolMemberNotFound); | ||
| <ClaimableAction::<T>>::mutate(who, |delegate| { | ||
| *delegate = action; | ||
| }); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[pallet::hooks] | ||
|
|
@@ -2265,7 +2339,7 @@ impl<T: Config> Pallet<T> { | |
| // We check for zero above | ||
| .div(current_points) | ||
| } | ||
|
|
||
| // TODO: Investigate logic here to add conditional event emission on different account types. | ||
| /// If the member has some rewards, transfer a payout from the reward pool to the member. | ||
| // Emits events and potentially modifies pool state if any arithmetic saturates, but does | ||
| // not persist any of the mutable inputs to storage. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.