From bd6d899fc08c1e58d42c3356ad3291176c92a4fd Mon Sep 17 00:00:00 2001
From: librelois <c@elo.tf>
Date: Sun, 30 Jan 2022 20:33:15 +0100
Subject: [PATCH] feat(runtimes): add pallet atomic swap

---
 Cargo.lock                           | 18 ++++++++++++++++
 runtime/common/src/pallets_config.rs | 28 ++++++++++++++-----------
 runtime/g1/Cargo.toml                |  6 ++++++
 runtime/g1/src/lib.rs                | 31 ++++++++++++++--------------
 runtime/gdev/Cargo.toml              |  6 ++++++
 runtime/gdev/src/lib.rs              | 29 +++++++++++++-------------
 runtime/gtest/Cargo.toml             |  6 ++++++
 runtime/gtest/src/lib.rs             | 31 ++++++++++++++--------------
 8 files changed, 96 insertions(+), 59 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index c0fc162f7..868905f53 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1902,6 +1902,7 @@ dependencies = [
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
  "hex-literal",
+ "pallet-atomic-swap",
  "pallet-authority-discovery",
  "pallet-authority-members",
  "pallet-authorship",
@@ -1958,6 +1959,7 @@ dependencies = [
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
  "hex-literal",
+ "pallet-atomic-swap",
  "pallet-authority-discovery",
  "pallet-authority-members",
  "pallet-authorship",
@@ -2153,6 +2155,7 @@ dependencies = [
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
  "hex-literal",
+ "pallet-atomic-swap",
  "pallet-authority-discovery",
  "pallet-authority-members",
  "pallet-authorship",
@@ -4204,6 +4207,21 @@ dependencies = [
  "stable_deref_trait",
 ]
 
+[[package]]
+name = "pallet-atomic-swap"
+version = "4.0.0-dev"
+source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-01#277da611dd03bc181b094682acf83138e2ea85aa"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
 [[package]]
 name = "pallet-authority-discovery"
 version = "4.0.0-dev"
diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index f24979285..ef3fe5ac2 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -260,6 +260,12 @@ macro_rules! pallets_config {
 
 		// UTILITIES //
 
+		impl pallet_atomic_swap::Config for Runtime {
+			type Event = Event;
+			type SwapAction = pallet_atomic_swap::BalanceSwapAction<AccountId, Balances>;
+			type ProofLimit = frame_support::traits::ConstU32<255>;
+		}
+
 		parameter_types! {
 			// One storage item; key size 32, value size 8; .
 			pub const ProxyDepositBase: Balance = deposit(1, 8);
@@ -283,6 +289,16 @@ macro_rules! pallets_config {
 			type WeightInfo = pallet_proxy::weights::SubstrateWeight<Self>;
 		}
 
+		impl pallet_multisig::Config for Runtime {
+			type Event = Event;
+			type Call = Call;
+			type Currency = Balances;
+			type DepositBase = DepositBase;
+			type DepositFactor = DepositFactor;
+			type MaxSignatories = MaxSignatories;
+			type WeightInfo = pallet_multisig::weights::SubstrateWeight<Self>;
+		}
+
 		impl pallet_utility::Config for Runtime {
 			type Event = Event;
 			type Call = Call;
@@ -399,17 +415,5 @@ macro_rules! pallets_config {
 			type CertRenewablePeriod = SmithCertRenewablePeriod;
 			type ValidityPeriod = SmithValidityPeriod;
 		}
-
-		// MULTISIG //
-
-		impl pallet_multisig::Config for Runtime {
-			type Event = Event;
-			type Call = Call;
-			type Currency = Balances;
-			type DepositBase = DepositBase;
-			type DepositFactor = DepositFactor;
-			type MaxSignatories = MaxSignatories;
-			type WeightInfo = pallet_multisig::weights::SubstrateWeight<Self>;
-		}
 	};
 }
diff --git a/runtime/g1/Cargo.toml b/runtime/g1/Cargo.toml
index 4b4701332..06d0a4fca 100644
--- a/runtime/g1/Cargo.toml
+++ b/runtime/g1/Cargo.toml
@@ -32,6 +32,7 @@ std = [
     'frame-support/std',
     'frame-system-rpc-runtime-api/std',
     'frame-system/std',
+	'pallet-atomic-swap/std',
 	'pallet-authority-discovery/std',
     'pallet-authority-members/std',
     'pallet-babe/std',
@@ -124,6 +125,11 @@ branch = 'duniter-monthly-2022-01'
 optional = true
 version = '0.3.1'
 
+[dependencies.pallet-atomic-swap]
+default-features = false
+git = 'https://github.com/librelois/substrate.git'
+branch = 'duniter-monthly-2022-01'
+
 [dependencies.pallet-authority-discovery]
 default-features = false
 git = 'https://github.com/librelois/substrate.git'
diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs
index 6df027d4c..d6afbed99 100644
--- a/runtime/g1/src/lib.rs
+++ b/runtime/g1/src/lib.rs
@@ -219,27 +219,26 @@ construct_runtime!(
         // Governance stuff.
         Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20,
 
-        // Cunning utilities.
-        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30,
-        Utility: pallet_utility::{Pallet, Call, Event} = 31,
-
-        // Universal dividend.
-        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40,
-        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        // Universal dividend
+        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 30,
+        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 31,
 
         // Web Of Trust
-        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 50,
-        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 51,
-        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
-        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
+        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 40,
+        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
+        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
 
         // Smiths Sub-Wot
-        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 60,
-        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 62,
-        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 63,
+        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
+        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
+        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
 
-        // Multisig dispatch.
-        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 70,
+        // Utilities
+        AtomicSwap: pallet_atomic_swap::{Pallet, Call, Storage, Event<T>} = 60,
+        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 61,
+        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 62,
+        Utility: pallet_utility::{Pallet, Call, Event} = 63,
     }
 );
 
diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml
index ba759bb8d..96e93f929 100644
--- a/runtime/gdev/Cargo.toml
+++ b/runtime/gdev/Cargo.toml
@@ -33,6 +33,7 @@ std = [
     'frame-support/std',
     'frame-system-rpc-runtime-api/std',
     'frame-system/std',
+	'pallet-atomic-swap/std',
 	'pallet-authority-discovery/std',
 	'pallet-authority-members/std',
     'pallet-babe/std',
@@ -127,6 +128,11 @@ branch = 'duniter-monthly-2022-01'
 optional = true
 version = '0.3.1'
 
+[dependencies.pallet-atomic-swap]
+default-features = false
+git = 'https://github.com/librelois/substrate.git'
+branch = 'duniter-monthly-2022-01'
+
 [dependencies.pallet-authority-discovery]
 default-features = false
 git = 'https://github.com/librelois/substrate.git'
diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs
index 8b0e56323..393b5dde2 100644
--- a/runtime/gdev/src/lib.rs
+++ b/runtime/gdev/src/lib.rs
@@ -266,27 +266,26 @@ construct_runtime!(
         // Governance stuff
         Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20,
 
-        // Utilities
-        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30,
-        Utility: pallet_utility::{Pallet, Call, Event} = 31,
-
         // Universal dividend
-        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40,
-        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 30,
+        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 31,
 
         // Web Of Trust
-        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 50,
-        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 51,
-        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
-        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
+        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 40,
+        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
+        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
 
         // Smiths Sub-Wot
-        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 60,
-        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 62,
-        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 63,
+        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
+        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
+        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
 
-        // Multisig dispatch.
-        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 70,
+        // Utilities
+        AtomicSwap: pallet_atomic_swap::{Pallet, Call, Storage, Event<T>} = 60,
+        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 61,
+        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 62,
+        Utility: pallet_utility::{Pallet, Call, Event} = 63,
     }
 );
 
diff --git a/runtime/gtest/Cargo.toml b/runtime/gtest/Cargo.toml
index 248bc42fe..4e559b825 100644
--- a/runtime/gtest/Cargo.toml
+++ b/runtime/gtest/Cargo.toml
@@ -32,6 +32,7 @@ std = [
     'frame-support/std',
     'frame-system-rpc-runtime-api/std',
     'frame-system/std',
+	'pallet-atomic-swap/std',
 	'pallet-authority-discovery/std',
     'pallet-authority-members/std',
     'pallet-babe/std',
@@ -124,6 +125,11 @@ branch = 'duniter-monthly-2022-01'
 optional = true
 version = '0.3.1'
 
+[dependencies.pallet-atomic-swap]
+default-features = false
+git = 'https://github.com/librelois/substrate.git'
+branch = 'duniter-monthly-2022-01'
+
 [dependencies.pallet-authority-discovery]
 default-features = false
 git = 'https://github.com/librelois/substrate.git'
diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs
index 9edf36e92..b13f1c1cd 100644
--- a/runtime/gtest/src/lib.rs
+++ b/runtime/gtest/src/lib.rs
@@ -219,27 +219,26 @@ construct_runtime!(
         // Governance stuff.
         Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20,
 
-        // Cunning utilities.
-        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 30,
-        Utility: pallet_utility::{Pallet, Call, Event} = 31,
-
-        // Universal dividend.
-        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40,
-        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        // Universal dividend
+        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 30,
+        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 31,
 
         // Web Of Trust
-        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 50,
-        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 51,
-        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
-        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
+        Wot: pallet_duniter_wot::<Instance1>::{Pallet} = 40,
+        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,
+        Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
+        Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43,
 
         // Smiths Sub-Wot
-        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 60,
-        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 62,
-        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 63,
+        SmithsSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50,
+        SmithsMembership: pallet_membership::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52,
+        SmithsCert: pallet_certification::<Instance2>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53,
 
-        // Multisig dispatch.
-        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 70,
+        // Utilities
+        AtomicSwap: pallet_atomic_swap::{Pallet, Call, Storage, Event<T>} = 60,
+        Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 61,
+        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 62,
+        Utility: pallet_utility::{Pallet, Call, Event} = 63,
     }
 );
 
-- 
GitLab