1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16
#![cfg_attr(not(feature = "std"), no_std)]
17

            
18
use frame_support::traits::{fungible::Credit, tokens::imbalance::ResolveTo, OnUnbalanced};
19
use pallet_balances::NegativeImbalance;
20
#[cfg(feature = "runtime-benchmarks")]
21
pub mod benchmarking;
22
pub mod migrations;
23
pub mod processors;
24

            
25
pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
26
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
27
where
28
    R: pallet_balances::Config + pallet_treasury::Config + frame_system::Config,
29
    pallet_treasury::NegativeImbalanceOf<R>: From<NegativeImbalance<R>>,
30
{
31
    // this seems to be called for substrate-based transactions
32
2538
    fn on_unbalanceds(
33
2538
        mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
34
2538
    ) {
35
2538
        if let Some(fees) = fees_then_tips.next() {
36
            // 100% of fees & tips goes to the treasury.
37
2538
            ResolveTo::<pallet_treasury::TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(fees);
38

            
39
2538
            if let Some(tip) = fees_then_tips.next() {
40
2538
                ResolveTo::<pallet_treasury::TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(tip);
41
2538
            }
42
        }
43
2538
    }
44

            
45
    fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) {
46
        // 100% goes to the treasury
47
        ResolveTo::<pallet_treasury::TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(amount);
48
    }
49
}