Trait staking::RewardsApi

pub trait RewardsApi<PoolId, StakeId, Balance>where
    Balance: Saturating + PartialOrd<Balance> + Copy,{
    type CurrencyId;

    // Required methods
    fn reward_currencies_len(pool_id: &PoolId) -> u32;
    fn distribute_reward(
        pool_id: &PoolId,
        currency_id: Self::CurrencyId,
        amount: Balance
    ) -> Result<(), DispatchError>;
    fn compute_reward(
        pool_id: &PoolId,
        stake_id: &StakeId,
        currency_id: Self::CurrencyId
    ) -> Result<Balance, DispatchError>;
    fn withdraw_reward(
        pool_id: &PoolId,
        stake_id: &StakeId,
        currency_id: Self::CurrencyId
    ) -> Result<Balance, DispatchError>;
    fn deposit_stake(
        pool_id: &PoolId,
        stake_id: &StakeId,
        amount: Balance
    ) -> Result<(), DispatchError>;
    fn withdraw_stake(
        pool_id: &PoolId,
        stake_id: &StakeId,
        amount: Balance
    ) -> Result<(), DispatchError>;
    fn get_total_stake(pool_id: &PoolId) -> Result<Balance, DispatchError>;
    fn get_stake(
        pool_id: &PoolId,
        stake_id: &StakeId
    ) -> Result<Balance, DispatchError>;

    // Provided methods
    fn withdraw_all_stake(
        pool_id: &PoolId,
        stake_id: &StakeId
    ) -> Result<Balance, DispatchError> { ... }
    fn set_stake(
        pool_id: &PoolId,
        stake_id: &StakeId,
        amount: Balance
    ) -> Result<(), DispatchError> { ... }
}

Required Associated Types§

Required Methods§

fn reward_currencies_len(pool_id: &PoolId) -> u32

fn distribute_reward( pool_id: &PoolId, currency_id: Self::CurrencyId, amount: Balance ) -> Result<(), DispatchError>

Distribute the amount to all participants OR error if zero total stake.

fn compute_reward( pool_id: &PoolId, stake_id: &StakeId, currency_id: Self::CurrencyId ) -> Result<Balance, DispatchError>

Compute the expected reward for the stake_id.

fn withdraw_reward( pool_id: &PoolId, stake_id: &StakeId, currency_id: Self::CurrencyId ) -> Result<Balance, DispatchError>

Withdraw all rewards from the stake_id.

fn deposit_stake( pool_id: &PoolId, stake_id: &StakeId, amount: Balance ) -> Result<(), DispatchError>

Deposit stake for an account.

fn withdraw_stake( pool_id: &PoolId, stake_id: &StakeId, amount: Balance ) -> Result<(), DispatchError>

Withdraw stake for an account.

fn get_total_stake(pool_id: &PoolId) -> Result<Balance, DispatchError>

Return the stake associated with the pool_id.

fn get_stake( pool_id: &PoolId, stake_id: &StakeId ) -> Result<Balance, DispatchError>

Return the stake associated with the stake_id.

Provided Methods§

fn withdraw_all_stake( pool_id: &PoolId, stake_id: &StakeId ) -> Result<Balance, DispatchError>

Withdraw all stake for an account.

fn set_stake( pool_id: &PoolId, stake_id: &StakeId, amount: Balance ) -> Result<(), DispatchError>

Set the stake to amount for stake_id regardless of its current stake.

Implementations on Foreign Types§

§

impl<PoolId, StakeId, Balance> RewardsApi<PoolId, StakeId, Balance> for ()where Balance: Saturating + PartialOrd<Balance> + Default + Copy,

§

type CurrencyId = ()

§

fn reward_currencies_len(_: &PoolId) -> u32

§

fn distribute_reward( _: &PoolId, _: <() as RewardsApi<PoolId, StakeId, Balance>>::CurrencyId, _: Balance ) -> Result<(), DispatchError>

§

fn compute_reward( _: &PoolId, _: &StakeId, _: <() as RewardsApi<PoolId, StakeId, Balance>>::CurrencyId ) -> Result<Balance, DispatchError>

§

fn withdraw_reward( _: &PoolId, _: &StakeId, _: <() as RewardsApi<PoolId, StakeId, Balance>>::CurrencyId ) -> Result<Balance, DispatchError>

§

fn get_total_stake(_: &PoolId) -> Result<Balance, DispatchError>

§

fn get_stake(_: &PoolId, _: &StakeId) -> Result<Balance, DispatchError>

§

fn deposit_stake( _: &PoolId, _: &StakeId, _: Balance ) -> Result<(), DispatchError>

§

fn withdraw_stake( _: &PoolId, _: &StakeId, _: Balance ) -> Result<(), DispatchError>

Implementors§

source§

impl<T, Balance> RewardsApi<(Option<<T as Config>::Nonce>, VaultId<<T as Config>::AccountId, <T as Config>::CurrencyId>), <T as Config>::AccountId, Balance> for staking::pallet::Pallet<T>where T: Config, Balance: BalanceToFixedPoint<<T as Config>::SignedFixedPoint> + Saturating + PartialOrd + Copy, <T::SignedFixedPoint as FixedPointNumber>::Inner: TryInto<Balance>,

§

impl<T, I, Balance> RewardsApi<<T as Config<I>>::PoolId, <T as Config<I>>::StakeId, Balance> for Pallet<T, I>where T: Config<I>, I: 'static, Balance: BalanceToFixedPoint<<T as Config<I>>::SignedFixedPoint> + Saturating + PartialOrd<Balance> + Copy, <<T as Config<I>>::SignedFixedPoint as FixedPointNumber>::Inner: TryInto<Balance>,

§

type CurrencyId = <T as Config<I>>::CurrencyId