pub struct Pallet<T>(_);
Expand description

The pallet implementing the on-chain logic.

Implementations§

Stake funds with a pool. The amount to bond is transferred from the member to the pools account and immediately increases the pools bond.

Note
  • An account can only be a member of a single pool.
  • An account cannot join the same pool multiple times.
  • This call will not dust the member account, so the member must have at least existential deposit + amount in their account.
  • Only a pool with PoolState::Open can be joined

Bond extra more funds from origin into the pool to which they already belong.

Additional funds can come from either the free balance of the account, of from the accumulated rewards, see BondExtra.

Bonding extra funds implies an automatic payout of all pending rewards as well.

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

Unbond up to unbonding_points of the member_account’s funds from the pool. It implicitly collects the rewards one last time, since not doing so would mean some rewards would be forfeited.

Under certain conditions, this call can be dispatched permissionlessly (i.e. by any account).

Conditions for a permissionless dispatch.
  • The pool is blocked and the caller is either the root or state-toggler. This is refereed to as a kick.
  • The pool is destroying and the member is not the depositor.
  • The pool is destroying, the member is the depositor and no other members are in the pool.
Conditions for permissioned dispatch (i.e. the caller is also the

member_account):

  • The caller is not the depositor.
  • The caller is the depositor, the pool is destroying and no other members are in the pool.
Note

If there are too many unlocking chunks to unbond with the pool account, Call::pool_withdraw_unbonded can be called to try and minimize unlocking chunks. If there are too many unlocking chunks, the result of this call will likely be the NoMoreChunks error from the staking system.

Call withdraw_unbonded for the pools account. This call can be made by any account.

This is useful if their are too many unlocking chunks to call unbond, and some 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.

Withdraw unbonded funds from member_account. If no bonded funds can be unbonded, an error is returned.

Under certain conditions, this call can be dispatched permissionlessly (i.e. by any account).

Conditions for a permissionless dispatch
  • The pool is in destroy mode and the target is not the depositor.
  • The target is the depositor and they are the only member in the sub pools.
  • The pool is blocked and the caller is either the root or state-toggler.
Conditions for permissioned dispatch
  • The caller is the target and they are not the depositor.
Note

If the target is the depositor, the pool will be destroyed.

Create a new delegation pool.

Arguments
  • amount - The amount of funds to delegate to the pool. This also acts of a sort of deposit since the pools creator cannot fully unbond funds until the pool is being destroyed.
  • index - A disambiguation index for creating the account. Likely only useful when creating multiple pools in the same extrinsic.
  • root - The account to set as PoolRoles::root.
  • nominator - The account to set as the PoolRoles::nominator.
  • state_toggler - The account to set as the PoolRoles::state_toggler.
Note

In addition to amount, the caller will transfer the existential deposit; so the caller needs at have at least amount + existential_deposit transferrable.

Nominate on behalf of the pool.

The dispatch origin of this call must be signed by the pool nominator or the pool root role.

This directly forward the call to the staking pallet, on behalf of the pool bonded account.

Set a new state for the pool.

If a pool is already in the Destroying state, then under no condition can its state change again.

The dispatch origin of this call must be either:

  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.

Set a new metadata for the pool.

The dispatch origin of this call must be signed by the state toggler, or the root role of the pool.

Update configurations for the nomination pools. The origin for this call must be Root.

Arguments

Update the roles of the pool.

The root is the only entity that can change any of the roles, including itself, excluding the depositor, who can never change.

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.

Chill on behalf of the pool.

The dispatch origin of this call must be signed by the pool nominator or the pool root role, same as Pallet::nominate.

This directly forward the call to the staking pallet, on behalf of the pool bonded account.

Returns the pending rewards for the specified member_account.

In the case of error, None is returned.

Remove everything related to the given bonded pool.

Metadata and all of the sub-pools are also deleted. All accounts are dusted and the leftover of the reward account is returned to the depositor.

Create the main, bonded account of a pool with the given id.

Create the reward account of a pool with the given id.

Ensure the correctness of the state of this pallet.

This should be valid before or after each state transition of this pallet.

Invariants:

First, let’s consider pools:

  • BondedPools and RewardPools must all have the EXACT SAME key-set.
  • SubPoolsStorage must be a subset of the above superset.
  • Metadata keys must be a subset of the above superset.
  • the count of the above set must be less than MaxPools.

Then, considering members as well:

  • each BondedPool.member_counter must be:
    • correct (compared to actual count of member who have .pool_id this pool)
    • less than MaxPoolMembersPerPool.
  • each member.pool_id must correspond to an existing BondedPool.id (which implies the existence of the reward pool as well).
  • count of all members must be less than MaxPoolMembers.

Then, considering unbonding members:

for each pool:

  • sum of the balance that’s tracked in all unbonding pools must be the same as the unbonded balance of the main account, as reported by the staking interface.
  • sum of the balance that’s tracked in all unbonding pools, plus the bonded balance of the main account should be less than or qual to the total balance of the main account.
Sanity check level

To cater for tests that want to escape parts of these checks, this function is split into multiple levels, where the higher the level, the more checks we performs. So, try_state(255) is the strongest sanity check, and 0 performs no checks.

Fully unbond the shares of member, when executed from origin.

This is useful for backwards compatibility with the majority of tests that only deal with full unbonding, not partial unbonding.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the current storage version as supported by the pallet.
Returns the on-chain storage version of the pallet as stored in the storage.
Run integrity test. Read more
The block is being finalized. Implement to have something happen.
This will be run when the block is being finalized (before on_finalize). Implement to have something happen using the remaining weight. Will not fire if the remaining weight is 0. Return the weight used, the hook will subtract it from current weight used and pass the result to the next on_idle hook if it exists. Read more
The block is being initialized. Implement to have something happen. Read more
Perform a module upgrade. Read more
Execute the sanity checks of this pallet, per block. Read more
Execute some pre-checks prior to a runtime upgrade. Read more
Execute some post-checks after a runtime upgrade. Read more
Implementing this function on a module allows you to perform long-running tasks that make (by default) validators generate transactions that feed results of those long-running computations back on chain. Read more
Run integrity test. Read more
This function is being called after every block import (when fully synced). Read more
The block is being finalized. Implement to have something happen. Read more
Something that should happen at genesis.
The block is being finalized. Implement to have something happen in case there is leftover weight. Check the passed remaining_weight to make sure it is high enough to allow for your pallet’s extra computation. Read more
The block is being initialized. Implement to have something happen. Read more
Perform a module upgrade. Read more
Execute some pre-checks prior to a runtime upgrade. Read more
Execute some post-checks after a runtime upgrade. Read more
A hook for any operations to perform when a staker is slashed. Read more
Index of the pallet as configured in the runtime.
Name of the pallet as configured in the runtime.
Name of the Rust module containing the pallet.
Version of the crate containing the pallet.
The number of pallets’ information that this type represents. Read more
All of the pallets’ information that this type represents.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert from a value of T into an equivalent instance of Option<Self>. Read more
Consume self to return Some equivalent value of Option<T>. Read more
Converts self into T using Into<T>. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more
Compare self to key and return true if they are equal.
Causes self to use its Binary implementation when Debug-formatted. Read more
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted. Read more
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more
Formats each item in a sequence. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Cast reference.
Cast reference.
Cast mutable reference.
Cast mutable reference.

Get a reference to the inner from the outer.

Get a mutable reference to the inner from the outer.

Generate a storage key unique to this runtime upgrade. Read more
Get temporary storage data written by Self::set_temp_storage. Read more
Write some temporary data to a specific storage that can be read (potentially in post-upgrade hook) via Self::get_temp_storage. Read more
Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
Convert from a value of T into an equivalent instance of Self. Read more
Consume self to return an equivalent value of T. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The counterpart to unchecked_from.
Consume self to return an equivalent value of T.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more