Currency Imbalances

pallets/currency-imbalances Try on playground View on GitHub

Imbalance is used when tokens are burned or minted. In order to execute imbalance implement the OnUnbalancedtrait. In this pallet a specific amount of funds will be slashed from an account and award a specific amount of funds to said specific account.

Slash funds

#[weight = 10_000]
pub fn slash_funds(origin, to_punish: T::AccountId, collateral: BalanceOf<T>) {
    let _ = ensure_signed(origin)?;

    let imbalance = T::Currency::slash_reserved(&to_punish, collateral).0;
    T::Slash::on_unbalanced(imbalance);

    let now = <frame_system::Module<T>>::block_number();
    Self::deposit_event(RawEvent::SlashFunds(to_punish, collateral, now));
}

Reward funds

#[weight = 10_000]
pub fn reward_funds(origin, to_reward: T::AccountId, reward: BalanceOf<T>) {
    let _ = ensure_signed(origin)?;

    let mut total_imbalance = <PositiveImbalanceOf<T>>::zero();

    let r = T::Currency::deposit_into_existing(&to_reward, reward).ok();
    total_imbalance.maybe_subsume(r);
    T::Reward::on_unbalanced(total_imbalance);

    let now = <frame_system::Module<T>>::block_number();
    Self::deposit_event(RawEvent::RewardFunds(to_reward, reward, now));
}