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

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;

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

Reward funds

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();

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