pub trait StakeStrategy {
    type Balance: Balance;
    type AccountId: Clone + Debug;
    type CoreStaking: StakingInterface<Balance = Self::Balance, AccountId = Self::AccountId>;

Show 23 methods // Required methods fn strategy_type() -> StakeStrategyType; fn transferable_balance( pool_account: Pool<Self::AccountId>, member_account: Member<Self::AccountId> ) -> Self::Balance; fn total_balance( pool_account: Pool<Self::AccountId> ) -> Option<Self::Balance>; fn member_delegation_balance( member_account: Member<Self::AccountId> ) -> Option<Self::Balance>; fn pledge_bond( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, reward_account: &Self::AccountId, amount: Self::Balance, bond_type: BondType ) -> DispatchResult; fn member_withdraw( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, amount: Self::Balance, num_slashing_spans: u32 ) -> DispatchResult; fn dissolve(pool_account: Pool<Self::AccountId>) -> DispatchResult; fn pending_slash(pool_account: Pool<Self::AccountId>) -> Self::Balance; fn member_slash( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, amount: Self::Balance, maybe_reporter: Option<Self::AccountId> ) -> DispatchResult; fn migrate_nominator_to_agent( pool_account: Pool<Self::AccountId>, reward_account: &Self::AccountId ) -> DispatchResult; fn migrate_delegation( pool: Pool<Self::AccountId>, delegator: Member<Self::AccountId>, value: Self::Balance ) -> DispatchResult; // Provided methods fn bonding_duration() -> EraIndex { ... } fn current_era() -> EraIndex { ... } fn minimum_nominator_bond() -> Self::Balance { ... } fn active_stake(pool_account: Pool<Self::AccountId>) -> Self::Balance { ... } fn total_stake(pool_account: Pool<Self::AccountId>) -> Self::Balance { ... } fn pool_strategy(pool_account: Pool<Self::AccountId>) -> StakeStrategyType { ... } fn nominate( pool_account: Pool<Self::AccountId>, validators: Vec<Self::AccountId> ) -> DispatchResult { ... } fn chill(pool_account: Pool<Self::AccountId>) -> DispatchResult { ... } fn unbond( pool_account: Pool<Self::AccountId>, amount: Self::Balance ) -> DispatchResult { ... } fn withdraw_unbonded( pool_account: Pool<Self::AccountId>, num_slashing_spans: u32 ) -> Result<bool, DispatchError> { ... } fn nominations( pool_account: Pool<Self::AccountId> ) -> Option<Vec<Self::AccountId>> { ... } fn remove_as_agent(_pool: Pool<Self::AccountId>) { ... }
}
Expand description

An adapter trait that can support multiple staking strategies.

Depending on which staking strategy we want to use, the staking logic can be slightly different. Refer the two possible strategies currently: TransferStake and DelegateStake for more detail.

Required Associated Types§

source

type Balance: Balance

source

type AccountId: Clone + Debug

source

type CoreStaking: StakingInterface<Balance = Self::Balance, AccountId = Self::AccountId>

Required Methods§

source

fn strategy_type() -> StakeStrategyType

The type of staking strategy of the current adapter.

source

fn transferable_balance( pool_account: Pool<Self::AccountId>, member_account: Member<Self::AccountId> ) -> Self::Balance

Balance that can be transferred from pool account to member.

This is part of the pool balance that can be withdrawn.

source

fn total_balance(pool_account: Pool<Self::AccountId>) -> Option<Self::Balance>

Total balance of the pool including amount that is actively staked.

source

fn member_delegation_balance( member_account: Member<Self::AccountId> ) -> Option<Self::Balance>

Amount of tokens delegated by the member.

source

fn pledge_bond( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, reward_account: &Self::AccountId, amount: Self::Balance, bond_type: BondType ) -> DispatchResult

Pledge amount towards pool_account and update the pool bond. Also see [StakingInterface::bond].

source

fn member_withdraw( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, amount: Self::Balance, num_slashing_spans: u32 ) -> DispatchResult

Withdraw funds from pool account to member account.

source

fn dissolve(pool_account: Pool<Self::AccountId>) -> DispatchResult

Dissolve the pool account.

source

fn pending_slash(pool_account: Pool<Self::AccountId>) -> Self::Balance

Check if there is any pending slash for the pool.

source

fn member_slash( who: Member<Self::AccountId>, pool_account: Pool<Self::AccountId>, amount: Self::Balance, maybe_reporter: Option<Self::AccountId> ) -> DispatchResult

Slash the member account with amount against pending slashes for the pool.

source

fn migrate_nominator_to_agent( pool_account: Pool<Self::AccountId>, reward_account: &Self::AccountId ) -> DispatchResult

Migrate pool account from being a direct nominator to a delegated agent.

This is useful for migrating a pool account from StakeStrategyType::Transfer to StakeStrategyType::Delegate.

source

fn migrate_delegation( pool: Pool<Self::AccountId>, delegator: Member<Self::AccountId>, value: Self::Balance ) -> DispatchResult

Migrate member balance from pool account to member account.

This is useful for a pool account that migrated from StakeStrategyType::Transfer to StakeStrategyType::Delegate. Its members can then migrate their delegated balance back to their account.

Internally, the member funds that are locked in the pool account are transferred back and locked in the member account.

Provided Methods§

source

fn bonding_duration() -> EraIndex

See [StakingInterface::bonding_duration].

source

fn current_era() -> EraIndex

See [StakingInterface::current_era].

source

fn minimum_nominator_bond() -> Self::Balance

See [StakingInterface::minimum_nominator_bond].

source

fn active_stake(pool_account: Pool<Self::AccountId>) -> Self::Balance

See [StakingInterface::active_stake].

source

fn total_stake(pool_account: Pool<Self::AccountId>) -> Self::Balance

See [StakingInterface::total_stake].

source

fn pool_strategy(pool_account: Pool<Self::AccountId>) -> StakeStrategyType

Which strategy the pool account is using.

This can be different from the Self::strategy_type of the adapter if the pool has not migrated to the new strategy yet.

source

fn nominate( pool_account: Pool<Self::AccountId>, validators: Vec<Self::AccountId> ) -> DispatchResult

See [StakingInterface::nominate].

source

fn chill(pool_account: Pool<Self::AccountId>) -> DispatchResult

See [StakingInterface::chill].

source

fn unbond( pool_account: Pool<Self::AccountId>, amount: Self::Balance ) -> DispatchResult

See [StakingInterface::unbond].

source

fn withdraw_unbonded( pool_account: Pool<Self::AccountId>, num_slashing_spans: u32 ) -> Result<bool, DispatchError>

See [StakingInterface::withdraw_unbonded].

source

fn nominations( pool_account: Pool<Self::AccountId> ) -> Option<Vec<Self::AccountId>>

List of validators nominated by the pool account.

source

fn remove_as_agent(_pool: Pool<Self::AccountId>)

Remove the pool account as agent.

Useful for migrating pool account from a delegated agent to a direct nominator. Only used in tests and benchmarks.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Config, Staking: StakingInterface<Balance = BalanceOf<T>, AccountId = T::AccountId>> StakeStrategy for TransferStake<T, Staking>

§

type Balance = <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance

§

type AccountId = <T as Config>::AccountId

§

type CoreStaking = Staking

source§

impl<T: Config, Staking: StakingInterface<Balance = BalanceOf<T>, AccountId = T::AccountId>, Delegation: DelegationInterface<Balance = BalanceOf<T>, AccountId = T::AccountId> + DelegationMigrator<Balance = BalanceOf<T>, AccountId = T::AccountId>> StakeStrategy for DelegateStake<T, Staking, Delegation>

§

type Balance = <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance

§

type AccountId = <T as Config>::AccountId

§

type CoreStaking = Staking