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: Agent<Self::AccountId>) -> Option<Self::Balance>;
fn agent_transferable_balance(
agent: Agent<Self::AccountId>
) -> Option<Self::Balance>;
fn delegator_balance(
delegator: Delegator<Self::AccountId>
) -> Option<Self::Balance>;
fn register_agent(
agent: Agent<Self::AccountId>,
reward_account: &Self::AccountId
) -> DispatchResult;
fn remove_agent(agent: Agent<Self::AccountId>) -> DispatchResult;
fn delegate(
delegator: Delegator<Self::AccountId>,
agent: Agent<Self::AccountId>,
amount: Self::Balance
) -> DispatchResult;
fn withdraw_delegation(
delegator: Delegator<Self::AccountId>,
agent: Agent<Self::AccountId>,
amount: Self::Balance,
num_slashing_spans: u32
) -> DispatchResult;
fn pending_slash(agent: Agent<Self::AccountId>) -> Option<Self::Balance>;
fn delegator_slash(
agent: Agent<Self::AccountId>,
delegator: Delegator<Self::AccountId>,
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>
) -> DispatchResult;
}
Expand description
Trait to provide delegation functionality for stakers.
Required Associated Types§
Required Methods§
sourcefn agent_balance(agent: Agent<Self::AccountId>) -> Option<Self::Balance>
fn agent_balance(agent: Agent<Self::AccountId>) -> Option<Self::Balance>
Returns effective balance of the Agent
account. None
if not an Agent
.
This takes into account any pending slashes to Agent
against the delegated balance.
sourcefn agent_transferable_balance(
agent: Agent<Self::AccountId>
) -> Option<Self::Balance>
fn agent_transferable_balance( agent: Agent<Self::AccountId> ) -> Option<Self::Balance>
Returns the total amount of funds that is unbonded and can be withdrawn from the Agent
account. None
if not an Agent
.
sourcefn delegator_balance(
delegator: Delegator<Self::AccountId>
) -> Option<Self::Balance>
fn delegator_balance( delegator: Delegator<Self::AccountId> ) -> Option<Self::Balance>
Returns the total amount of funds delegated. None
if not a Delegator
.
sourcefn register_agent(
agent: Agent<Self::AccountId>,
reward_account: &Self::AccountId
) -> DispatchResult
fn register_agent( agent: Agent<Self::AccountId>, reward_account: &Self::AccountId ) -> DispatchResult
Register Agent
such that it can accept delegation.
sourcefn remove_agent(agent: Agent<Self::AccountId>) -> DispatchResult
fn remove_agent(agent: Agent<Self::AccountId>) -> DispatchResult
Removes Agent
registration.
This should only be allowed if the agent has no staked funds.
sourcefn delegate(
delegator: Delegator<Self::AccountId>,
agent: Agent<Self::AccountId>,
amount: Self::Balance
) -> DispatchResult
fn delegate( delegator: Delegator<Self::AccountId>, agent: Agent<Self::AccountId>, amount: Self::Balance ) -> DispatchResult
Add delegation to the Agent
.
sourcefn withdraw_delegation(
delegator: Delegator<Self::AccountId>,
agent: Agent<Self::AccountId>,
amount: Self::Balance,
num_slashing_spans: u32
) -> DispatchResult
fn withdraw_delegation( delegator: Delegator<Self::AccountId>, agent: 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 pending_slash(agent: Agent<Self::AccountId>) -> Option<Self::Balance>
fn pending_slash(agent: Agent<Self::AccountId>) -> Option<Self::Balance>
Returns pending slashes posted to the Agent
account. None if not an Agent
.
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: Agent<Self::AccountId>,
delegator: Delegator<Self::AccountId>,
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>
) -> DispatchResult
fn delegator_slash( agent: Agent<Self::AccountId>, delegator: 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.