use frame_support::traits::tokens::Balance;
use sp_runtime::{traits::Get, ArithmeticError, DispatchError, DispatchResult};
pub mod base;
pub mod deferred;
pub mod gap;
pub trait RewardMechanism {
type Group;
type Account;
type Currency;
type Balance: Balance;
type MaxCurrencyMovements: Get<u32>;
fn is_ready(group: &Self::Group) -> bool;
fn reward_group(
group: &mut Self::Group,
amount: Self::Balance,
) -> Result<Self::Balance, DispatchError>;
fn deposit_stake(
account: &mut Self::Account,
currency: &mut Self::Currency,
group: &mut Self::Group,
amount: Self::Balance,
) -> DispatchResult;
fn withdraw_stake(
account: &mut Self::Account,
currency: &mut Self::Currency,
group: &mut Self::Group,
amount: Self::Balance,
) -> DispatchResult;
fn compute_reward(
account: &Self::Account,
currency: &Self::Currency,
group: &Self::Group,
) -> Result<Self::Balance, DispatchError>;
fn claim_reward(
account: &mut Self::Account,
currency: &Self::Currency,
group: &Self::Group,
) -> Result<Self::Balance, DispatchError>;
fn move_currency(
currency: &mut Self::Currency,
from_group: &mut Self::Group,
to_group: &mut Self::Group,
) -> Result<(), MoveCurrencyError>;
fn account_stake(account: &Self::Account) -> Self::Balance;
fn group_stake(group: &Self::Group) -> Self::Balance;
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum MoveCurrencyError {
Internal(DispatchError),
MaxMovements,
}
impl From<DispatchError> for MoveCurrencyError {
fn from(e: DispatchError) -> MoveCurrencyError {
Self::Internal(e)
}
}
impl From<ArithmeticError> for MoveCurrencyError {
fn from(e: ArithmeticError) -> MoveCurrencyError {
Self::Internal(DispatchError::Arithmetic(e))
}
}