Trait sp_staking::DelegationInterface
source · pub trait DelegationInterface {
type Balance: Sub<Output = Self::Balance> + Ord + PartialEq + Default + Copy + MaxEncodedLen + FullCodec + TypeInfo + Saturating;
type AccountId: Clone + Debug;
// Required methods
fn agent_balance(agent: &Self::AccountId) -> Self::Balance;
fn delegator_balance(delegator: &Self::AccountId) -> Self::Balance;
fn delegate(
delegator: &Self::AccountId,
agent: &Self::AccountId,
reward_account: &Self::AccountId,
amount: Self::Balance,
) -> DispatchResult;
fn delegate_extra(
delegator: &Self::AccountId,
agent: &Self::AccountId,
amount: Self::Balance,
) -> DispatchResult;
fn withdraw_delegation(
delegator: &Self::AccountId,
agent: &Self::AccountId,
amount: Self::Balance,
num_slashing_spans: u32,
) -> DispatchResult;
fn has_pending_slash(agent: &Self::AccountId) -> bool;
fn delegator_slash(
agent: &Self::AccountId,
delegator: &Self::AccountId,
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>,
) -> DispatchResult;
}
Expand description
Trait to provide delegation functionality for stakers.
Introduces two new terms to the staking system:
Delegator
: An account that delegates funds to anAgent
.Agent
: An account that receives delegated funds fromDelegators
. It can then use these funds to participate in the staking system. It can never use its own funds to stake. They (virtually bond)StakingUnchecked::virtual_bond
into the staking system and can also be termed asVirtual Nominators
.
The Agent
is responsible for managing rewards and slashing for all the Delegators
that
have delegated funds to it.
Required Associated Types§
Required Methods§
sourcefn agent_balance(agent: &Self::AccountId) -> Self::Balance
fn agent_balance(agent: &Self::AccountId) -> Self::Balance
Effective balance of the Agent
account.
This takes into account any pending slashes to Agent
.
sourcefn delegator_balance(delegator: &Self::AccountId) -> Self::Balance
fn delegator_balance(delegator: &Self::AccountId) -> Self::Balance
Returns the total amount of funds delegated by a delegator
.
sourcefn delegate(
delegator: &Self::AccountId,
agent: &Self::AccountId,
reward_account: &Self::AccountId,
amount: Self::Balance,
) -> DispatchResult
fn delegate( delegator: &Self::AccountId, agent: &Self::AccountId, reward_account: &Self::AccountId, amount: Self::Balance, ) -> DispatchResult
Delegate funds to Agent
.
Only used for the initial delegation. Use Self::delegate_extra
to add more delegation.
sourcefn delegate_extra(
delegator: &Self::AccountId,
agent: &Self::AccountId,
amount: Self::Balance,
) -> DispatchResult
fn delegate_extra( delegator: &Self::AccountId, agent: &Self::AccountId, amount: Self::Balance, ) -> DispatchResult
Add more delegation to the Agent
.
If this is the first delegation, use Self::delegate
instead.
sourcefn withdraw_delegation(
delegator: &Self::AccountId,
agent: &Self::AccountId,
amount: Self::Balance,
num_slashing_spans: u32,
) -> DispatchResult
fn withdraw_delegation( delegator: &Self::AccountId, agent: &Self::AccountId, amount: Self::Balance, num_slashing_spans: u32, ) -> DispatchResult
Withdraw or revoke delegation to Agent
.
If there are Agent
funds upto amount
available to withdraw, then those funds would
be released to the delegator
sourcefn has_pending_slash(agent: &Self::AccountId) -> bool
fn has_pending_slash(agent: &Self::AccountId) -> bool
Returns true if there are pending slashes posted to the Agent
account.
Slashes to Agent
account are not immediate and are applied lazily. Since Agent
has an unbounded number of delegators, immediate slashing is not possible.
sourcefn delegator_slash(
agent: &Self::AccountId,
delegator: &Self::AccountId,
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>,
) -> DispatchResult
fn delegator_slash( agent: &Self::AccountId, delegator: &Self::AccountId, value: Self::Balance, maybe_reporter: Option<Self::AccountId>, ) -> DispatchResult
Apply a pending slash to an Agent
by slashing value
from delegator
.
A reporter may be provided (if one exists) in order for the implementor to reward them, if applicable.