From f357c9ec08ef1b815ac7ec294d7c5a169eb84828 Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Tue, 13 Jun 2023 13:00:00 +0200
Subject: [PATCH] add DustHandle

---
 runtime/common/src/pallets_config.rs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index cebb892c4..043b8c675 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -147,7 +147,7 @@ macro_rules! pallets_config {
             type ReserveIdentifier = [u8; 8];
             /// The type for recording an account's balance.
             type Balance = Balance;
-            type DustRemoval = (); // TODO Treasury;
+            type DustRemoval = HandleDust;
             type ExistentialDeposit = ExistentialDeposit;
             type AccountStore = Account;
 			type HoldIdentifier = ();
@@ -159,6 +159,18 @@ macro_rules! pallets_config {
             type WeightInfo = common_runtime::weights::pallet_balances::WeightInfo<Runtime>;
         }
 
+        // Take Dust from Balances and put it in the Treasury pot
+        use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
+        use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Imbalance;
+        pub struct HandleDust;
+        type CreditOf = frame_support::traits::tokens::fungible::Credit<AccountId, Balances>;
+        impl frame_support::traits::OnUnbalanced<CreditOf> for HandleDust {
+            fn on_nonzero_unbalanced(amount: CreditOf) {
+                let imbalance = NegativeImbalance::new(amount.peek());
+                Balances::resolve_creating(&Treasury::account_id(), imbalance);
+            }
+        }
+
         pub struct HandleFees;
         type NegativeImbalance = <Balances as frame_support::traits::Currency<AccountId>>::NegativeImbalance;
         impl frame_support::traits::OnUnbalanced<NegativeImbalance> for HandleFees {
-- 
GitLab