1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use super::*;
use sp_arithmetic::traits::BaseArithmetic;
use sp_std::marker::PhantomData;

/// Get the amount of staking per Era in a module in the Plasm Network.
pub trait ComputeEraWithParam<EraIndex> {
    type Param;
    fn compute(era: &EraIndex) -> Self::Param;
}

pub struct DefaultForDappsStaking<T: Trait> {
    _phantom: PhantomData<T>,
}
impl<T: Trait> ComputeEraWithParam<EraIndex> for DefaultForDappsStaking<T> {
    type Param = BalanceOf<T>;
    fn compute(_era: &EraIndex) -> BalanceOf<T> {
        0.into()
    }
}

/// The reward is allocated from the total supply of tokens,
/// the time for Era, the amount of staking for Security, and the amount of staking for Dapps.
pub trait ComputeTotalPayout<ValidatorParam, DappsParam> {
    fn compute<N, M>(
        total_tokens: N,
        era_duration: M,
        for_security_parm: ValidatorParam,
        for_dapps_param: DappsParam,
    ) -> (N, N)
    where
        N: BaseArithmetic + num_traits::sign::Unsigned + Clone + From<u32>,
        M: BaseArithmetic + Clone + From<u32>;
}

/// Returns the next validator candidate.
pub trait MaybeValidators<EraIndex, AccountId> {
    fn compute(current_era: EraIndex) -> Option<Vec<AccountId>>;
}

/// Get the era for validator and dapps staking module.
pub trait EraFinder<EraIndex, SessionIndex, Moment> {
    /// The current era index.
    ///
    /// This is the latest planned era, depending on how session module queues the validator
    /// set, it might be active or not.
    fn current() -> Option<EraIndex>;

    /// The active era information, it holds index and start.
    ///
    /// The active era is the era currently rewarded.
    /// Validator set of this era must be equal to `SessionInterface::validators`.
    fn active() -> Option<ActiveEraInfo<Moment>>;

    /// The session index at which the era start for the last `HISTORY_DEPTH` eras
    fn start_session_index(era: &EraIndex) -> Option<SessionIndex>;
}

/// Get the security rewards for validator module.
pub trait ForSecurityEraRewardFinder<Balance> {
    fn get(era: &EraIndex) -> Option<Balance>;
}

/// Get the dapps rewards for dapps staking module.
pub trait ForDappsEraRewardFinder<Balance> {
    fn get(era: &EraIndex) -> Option<Balance>;
}

/// Get the history depth
pub trait HistoryDepthFinder {
    fn get() -> u32;
}