git.delta.rocks / unique-network / refs/commits / 3e9a8d1b2326

difftreelog

Merge pull request #976 from UniqueNetwork/fix/governance-setup-inconsistencies

Yaroslav Bolyukin2023-09-02parents: #a17eff7 #42448e1.patch.diff
in: master

16 files changed

addedruntime/common/config/governance/council.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/council.rs
@@ -0,0 +1,71 @@
+use super::*;
+
+parameter_types! {
+	pub CouncilMaxProposals: u32 = 100;
+	pub CouncilMaxMembers: u32 = 100;
+}
+
+#[cfg(not(feature = "test-env"))]
+use crate::governance_timings::council as council_timings;
+
+#[cfg(feature = "test-env")]
+pub mod council_timings {
+	use super::*;
+
+	parameter_types! {
+		pub CouncilMotionDuration: BlockNumber = 35;
+	}
+}
+
+pub type CouncilCollective = pallet_collective::Instance1;
+impl pallet_collective::Config<CouncilCollective> for Runtime {
+	type RuntimeOrigin = RuntimeOrigin;
+	type Proposal = RuntimeCall;
+	type RuntimeEvent = RuntimeEvent;
+	type MotionDuration = council_timings::CouncilMotionDuration;
+	type MaxProposals = CouncilMaxProposals;
+	type MaxMembers = CouncilMaxMembers;
+	type DefaultVote = pallet_collective::PrimeDefaultVote;
+	type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
+	type SetMembersOrigin = EnsureRoot<AccountId>;
+	type MaxProposalWeight = MaxCollectivesProposalWeight;
+}
+
+pub type CouncilCollectiveMembership = pallet_membership::Instance1;
+impl pallet_membership::Config<CouncilCollectiveMembership> for Runtime {
+	type RuntimeEvent = RuntimeEvent;
+	type AddOrigin = EnsureRoot<AccountId>;
+	type RemoveOrigin = EnsureRoot<AccountId>;
+	type SwapOrigin = EnsureRoot<AccountId>;
+	type ResetOrigin = EnsureRoot<AccountId>;
+	type PrimeOrigin = EnsureRoot<AccountId>;
+	type MembershipInitialized = Council;
+	type MembershipChanged = Council;
+	type MaxMembers = CouncilMaxMembers;
+	type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
+}
+
+pub type CouncilMember = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
+
+pub type OneThirdsCouncil =
+	pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 3>;
+
+pub type HalfCouncil =
+	pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
+
+pub type MoreThanHalfCouncil =
+	pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>;
+
+pub type ThreeFourthsCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>;
+
+pub type AllCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
+
+pub type RootOrOneThirdsCouncil = EitherOfDiverse<EnsureRoot<AccountId>, OneThirdsCouncil>;
+
+pub type RootOrHalfCouncil = EitherOfDiverse<EnsureRoot<AccountId>, HalfCouncil>;
+
+pub type RootOrMoreThanHalfCouncil = EitherOfDiverse<EnsureRoot<AccountId>, MoreThanHalfCouncil>;
+
+pub type RootOrThreeFourthsCouncil = EitherOfDiverse<EnsureRoot<AccountId>, ThreeFourthsCouncil>;
+
+pub type RootOrAllCouncil = EitherOfDiverse<EnsureRoot<AccountId>, AllCouncil>;
addedruntime/common/config/governance/democracy.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/democracy.rs
@@ -0,0 +1,102 @@
+use super::*;
+
+parameter_types! {
+	pub MinimumDeposit: Balance = 0;
+	pub InstantAllowed: bool = false;
+	pub MaxVotes: u32 = 100;
+	pub MaxProposals: u32 = 100;
+}
+
+#[cfg(not(feature = "test-env"))]
+use crate::governance_timings::democracy as democracy_timings;
+
+#[cfg(feature = "test-env")]
+pub mod democracy_timings {
+	use super::*;
+
+	parameter_types! {
+		pub LaunchPeriod: BlockNumber = 35;
+		pub VotingPeriod: BlockNumber = 35;
+		pub FastTrackVotingPeriod: BlockNumber = 5;
+		pub EnactmentPeriod: BlockNumber = 40;
+		pub CooloffPeriod: BlockNumber = 35;
+	}
+}
+
+impl pallet_democracy::Config for Runtime {
+	type RuntimeEvent = RuntimeEvent;
+	type Currency = Balances;
+	type Slash = Treasury;
+	type Scheduler = Scheduler;
+	type PalletsOrigin = OriginCaller;
+	type Preimages = Preimage;
+	type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
+
+	/// The period between a proposal being approved and enacted.
+	type EnactmentPeriod = democracy_timings::EnactmentPeriod;
+
+	/// The minimum period of vote locking.
+	type VoteLockingPeriod = democracy_timings::EnactmentPeriod;
+
+	/// How often new public referenda are launched.
+	type LaunchPeriod = democracy_timings::LaunchPeriod;
+
+	/// How long the referendum will last.
+	type VotingPeriod = democracy_timings::VotingPeriod;
+
+	/// The minimum amount to be used as a deposit for the Fellowship referendum proposal.
+	type MinimumDeposit = MinimumDeposit;
+
+	type SubmitOrigin = EitherOf<
+		MapSuccess<EnsureRoot<Self::AccountId>, Replace<fellowship::FellowshipAccountId>>,
+		EnsureFellowshipProposition,
+	>;
+
+	type ExternalOrigin = EnsureNever<Self::AccountId>;
+	type ExternalMajorityOrigin = EnsureNever<Self::AccountId>;
+
+	/// Root (for the initial referendums)
+	/// or >50% of council can have the next scheduled referendum be a straight default-carries
+	/// (NTB) vote (SuperMajorityAgainst).
+	type ExternalDefaultOrigin = RootOrMoreThanHalfCouncil;
+
+	/// A unanimous technical committee can have an ExternalMajority/ExternalDefault vote
+	/// be tabled immediately and with a shorter voting/enactment period.
+	type FastTrackOrigin = RootOrAllTechnicalCommittee;
+
+	/// Origin from which the next referendum may be tabled to vote immediately and asynchronously.
+	/// Can set a faster voting period.
+	type InstantOrigin = EnsureNever<Self::AccountId>;
+	type InstantAllowed = InstantAllowed;
+
+	/// Minimum voting period allowed for a fast-track referendum.
+	type FastTrackVotingPeriod = democracy_timings::FastTrackVotingPeriod;
+
+	/// To cancel a proposal which has been passed, the technical committee must be unanimous or
+	/// Root must agree.
+	type CancellationOrigin = RootOrAllTechnicalCommittee;
+
+	/// To cancel a proposal before it has been passed, the technical committee must be unanimous or
+	/// Root must agree.
+	type CancelProposalOrigin = RootOrAllTechnicalCommittee;
+
+	/// A unanimous council or Root can blacklist a proposal permanently.
+	type BlacklistOrigin = RootOrAllCouncil;
+
+	// Any single technical committee member may veto a coming council proposal, however they can
+	// only do it once and it lasts only for the cooloff period.
+	type VetoOrigin = TechnicalCommitteeMember;
+	type CooloffPeriod = democracy_timings::CooloffPeriod;
+
+	/// The maximum number of votes for an account
+	type MaxVotes = MaxVotes;
+
+	/// The maximum number of public proposals that can exist at any time.
+	type MaxProposals = MaxProposals;
+
+	/// The maximum number of deposits a public proposal may have at any time.
+	type MaxDeposits = ConstU32<100>;
+
+	/// The maximum number of items that can be blacklisted.
+	type MaxBlacklisted = ConstU32<100>;
+}
addedruntime/common/config/governance/fellowship.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/fellowship.rs
@@ -0,0 +1,167 @@
+use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};
+use super::*;
+use pallet_gov_origins::Origin as GovOrigins;
+use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};
+
+pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");
+pub const DEMOCRACY_TRACK_ID: u16 = 10;
+
+parameter_types! {
+	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();
+	pub AlarmInterval: BlockNumber = 1;
+	pub SubmissionDeposit: Balance = 1000;
+}
+
+#[cfg(not(feature = "test-env"))]
+use crate::governance_timings::fellowship as fellowship_timings;
+
+#[cfg(feature = "test-env")]
+pub mod fellowship_timings {
+	use super::*;
+
+	parameter_types! {
+		pub UndecidingTimeout: BlockNumber = 35;
+	}
+
+	pub mod track {
+		use super::*;
+
+		pub mod democracy_proposals {
+			use super::*;
+
+			pub const PREPARE_PERIOD: BlockNumber = 3;
+			pub const DECISION_PERIOD: BlockNumber = 35;
+			pub const CONFIRM_PERIOD: BlockNumber = 3;
+			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;
+		}
+	}
+}
+
+impl pallet_referenda::Config for Runtime {
+	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
+	type RuntimeCall = RuntimeCall;
+	type RuntimeEvent = RuntimeEvent;
+	type Scheduler = Scheduler;
+	type Currency = Balances;
+	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;
+	type CancelOrigin = RootOrAllTechnicalCommittee;
+	type KillOrigin = RootOrAllTechnicalCommittee;
+	type Slash = Treasury;
+	type Votes = pallet_ranked_collective::Votes;
+	type Tally = pallet_ranked_collective::TallyOf<Runtime>;
+	type SubmissionDeposit = SubmissionDeposit;
+	type MaxQueued = ConstU32<100>;
+	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;
+	type AlarmInterval = AlarmInterval;
+	type Tracks = TracksInfo;
+	type Preimages = Preimage;
+}
+
+impl RankedConfig for Runtime {
+	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;
+	type RuntimeEvent = RuntimeEvent;
+	// Promotion is by any of:
+	// - Council member.
+	// - Technical committee member.
+	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;
+	// Demotion is by any of:
+	// - Council member.
+	// - Technical committee member.
+	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;
+	type Polls = FellowshipReferenda;
+	type MinRankOfClass = ClassToRankMapper<Self, ()>;
+	type VoteWeight = pallet_ranked_collective::Geometric;
+}
+
+pub struct EnsureFellowshipProposition;
+impl<O> EnsureOrigin<O> for EnsureFellowshipProposition
+where
+	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,
+{
+	type Success = AccountId;
+
+	fn try_origin(o: O) -> Result<Self::Success, O> {
+		o.into().and_then(|o| match o {
+			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),
+			o => Err(O::from(o)),
+		})
+	}
+
+	#[cfg(feature = "runtime-benchmarks")]
+	fn try_successful_origin() -> Result<O, ()> {
+		Ok(O::from(GovOrigins::FellowshipProposition))
+	}
+}
+
+pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<
+	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,
+	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,
+>;
+
+pub struct TracksInfo;
+impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
+	type Id = u16;
+	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
+	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
+		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(
+			DEMOCRACY_TRACK_ID,
+			pallet_referenda::TrackInfo {
+				name: "democracy_proposals",
+				max_deciding: 10,
+				decision_deposit: 10 * UNIQUE,
+				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,
+				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,
+				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,
+				min_enactment_period:
+					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,
+				min_approval: pallet_referenda::Curve::LinearDecreasing {
+					length: Perbill::from_percent(100),
+					floor: Perbill::from_percent(50),
+					ceil: Perbill::from_percent(100),
+				},
+				min_support: pallet_referenda::Curve::LinearDecreasing {
+					length: Perbill::from_percent(100),
+					floor: Perbill::from_percent(0),
+					ceil: Perbill::from_percent(50),
+				},
+			},
+		)];
+		&DATA[..]
+	}
+	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
+		#[cfg(feature = "runtime-benchmarks")]
+		{
+			// For benchmarks, we enable a root origin.
+			// It is important that this is not available in production!
+			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
+			if &root == id {
+				return Ok(9);
+			}
+		}
+
+		match GovOrigins::try_from(id.clone()) {
+			Ok(_) => Ok(DEMOCRACY_TRACK_ID),
+			_ => Err(()),
+		}
+	}
+}
+
+pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
+
+pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);
+
+//TODO: Remove the type when it appears in the release.
+pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;
+
+impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>
+where
+	T: RankedConfig<I>,
+	ClassOf<T, I>: Into<Rank>,
+{
+	fn convert(track_id: ClassOf<T, I>) -> Rank {
+		match track_id.into() {
+			DEMOCRACY_TRACK_ID => 3,
+			other => other,
+		}
+	}
+}
addedruntime/common/config/governance/mod.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/mod.rs
@@ -0,0 +1,68 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+use frame_support::{
+	PalletId, parameter_types,
+	traits::{
+		EnsureOrigin, EqualPrivilegeOnly, EitherOfDiverse, EitherOf, MapSuccess, ConstU16, Polling,
+	},
+	weights::Weight,
+	pallet_prelude::*,
+};
+use frame_system::{EnsureRoot, EnsureNever};
+use sp_runtime::{
+	Perbill,
+	traits::{AccountIdConversion, ConstU32, Replace, CheckedSub, Convert},
+	morph_types,
+};
+use crate::{
+	Runtime, RuntimeOrigin, RuntimeEvent, RuntimeCall, OriginCaller, Preimage, Balances, Treasury,
+	Scheduler, Council, TechnicalCommittee,
+};
+pub use up_common::{
+	constants::{UNIQUE, DAYS, HOURS, MINUTES, CENTIUNIQUE},
+	types::{AccountId, Balance, BlockNumber},
+};
+use pallet_collective::EnsureProportionAtLeast;
+
+pub mod council;
+pub use council::*;
+
+pub mod democracy;
+pub use democracy::*;
+
+pub mod technical_committee;
+pub use technical_committee::*;
+
+pub mod fellowship;
+pub use fellowship::*;
+
+pub mod scheduler;
+pub use scheduler::*;
+
+impl pallet_gov_origins::Config for Runtime {}
+
+morph_types! {
+	/// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for
+	/// underflow.
+	pub type CheckedReduceBy<N: TypedGet>: TryMorph = |r: N::Type| -> Result<N::Type, ()> {
+		r.checked_sub(&N::get()).ok_or(())
+	} where N::Type: CheckedSub;
+}
+
+parameter_types! {
+	pub MaxCollectivesProposalWeight: Weight = Perbill::from_percent(80) * <Runtime as frame_system::Config>::BlockWeights::get().max_block;
+}
addedruntime/common/config/governance/scheduler.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/scheduler.rs
@@ -0,0 +1,24 @@
+use up_common::constants::{MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
+
+use super::*;
+
+parameter_types! {
+	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
+		<Runtime as frame_system::Config>::BlockWeights::get()
+		.per_class.get(frame_support::pallet_prelude::DispatchClass::Normal).max_total
+		.unwrap_or(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
+	pub MaxScheduledPerBlock: u32 = 50;
+}
+
+impl pallet_scheduler::Config for Runtime {
+	type RuntimeOrigin = RuntimeOrigin;
+	type RuntimeEvent = RuntimeEvent;
+	type PalletsOrigin = OriginCaller;
+	type RuntimeCall = RuntimeCall;
+	type MaximumWeight = MaximumSchedulerWeight;
+	type ScheduleOrigin = EnsureRoot<AccountId>;
+	type MaxScheduledPerBlock = MaxScheduledPerBlock;
+	type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
+	type OriginPrivilegeCmp = EqualPrivilegeOnly;
+	type Preimages = Preimage;
+}
addedruntime/common/config/governance/technical_committee.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/governance/technical_committee.rs
@@ -0,0 +1,57 @@
+use super::*;
+
+parameter_types! {
+	pub TechnicalMaxProposals: u32 = 100;
+	pub TechnicalMaxMembers: u32 = 100;
+}
+
+#[cfg(not(feature = "test-env"))]
+use crate::governance_timings::technical_committee as technical_committee_timings;
+
+#[cfg(feature = "test-env")]
+pub mod technical_committee_timings {
+	use super::*;
+
+	parameter_types! {
+		pub TechnicalMotionDuration: BlockNumber = 35;
+	}
+}
+
+pub type TechnicalCollective = pallet_collective::Instance2;
+impl pallet_collective::Config<TechnicalCollective> for Runtime {
+	type RuntimeOrigin = RuntimeOrigin;
+	type Proposal = RuntimeCall;
+	type RuntimeEvent = RuntimeEvent;
+	type MotionDuration = technical_committee_timings::TechnicalMotionDuration;
+	type MaxProposals = TechnicalMaxProposals;
+	type MaxMembers = TechnicalMaxMembers;
+	type DefaultVote = pallet_collective::PrimeDefaultVote;
+	type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
+	type SetMembersOrigin = EnsureRoot<AccountId>;
+	type MaxProposalWeight = MaxCollectivesProposalWeight;
+}
+
+pub type TechnicalCollectiveMembership = pallet_membership::Instance2;
+impl pallet_membership::Config<TechnicalCollectiveMembership> for Runtime {
+	type RuntimeEvent = RuntimeEvent;
+	type AddOrigin = RootOrMoreThanHalfCouncil;
+	type RemoveOrigin = RootOrMoreThanHalfCouncil;
+	type SwapOrigin = RootOrMoreThanHalfCouncil;
+	type ResetOrigin = EnsureRoot<AccountId>;
+	type PrimeOrigin = EnsureRoot<AccountId>;
+	type MembershipInitialized = TechnicalCommittee;
+	type MembershipChanged = TechnicalCommittee;
+	type MaxMembers = TechnicalMaxMembers;
+	type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
+}
+
+pub type TechnicalCommitteeMember = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
+
+pub type RootOrTechnicalCommitteeMember =
+	EitherOfDiverse<EnsureRoot<AccountId>, TechnicalCommitteeMember>;
+
+pub type AllTechnicalCommittee =
+	pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
+
+pub type RootOrAllTechnicalCommittee =
+	EitherOfDiverse<EnsureRoot<AccountId>, AllTechnicalCommittee>;
modifiedruntime/common/config/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/mod.rs
+++ b/runtime/common/config/mod.rs
@@ -22,5 +22,8 @@
 pub mod substrate;
 pub mod xcm;
 
+#[cfg(feature = "governance")]
+pub mod governance;
+
 #[cfg(feature = "test-env")]
 pub mod test_pallets;
modifiedruntime/common/config/pallets/collator_selection.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/collator_selection.rs
+++ b/runtime/common/config/pallets/collator_selection.rs
@@ -22,7 +22,7 @@
 };
 
 #[cfg(feature = "governance")]
-use crate::config::pallets::governance;
+use crate::config::governance;
 
 #[cfg(not(feature = "governance"))]
 use frame_system::EnsureRoot;
@@ -85,10 +85,10 @@
 	type SubAccountDeposit = SubAccountDeposit;
 
 	#[cfg(feature = "governance")]
-	type RegistrarOrigin = governance::RootOrAllTechnicalCommittee;
+	type RegistrarOrigin = governance::RootOrTechnicalCommitteeMember;
 
 	#[cfg(feature = "governance")]
-	type ForceOrigin = governance::RootOrAllTechnicalCommittee;
+	type ForceOrigin = governance::RootOrTechnicalCommitteeMember;
 
 	#[cfg(not(feature = "governance"))]
 	type RegistrarOrigin = EnsureRoot<<Self as frame_system::Config>::AccountId>;
deletedruntime/common/config/pallets/governance/council.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/council.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-use super::*;
-
-parameter_types! {
-	pub CouncilMaxProposals: u32 = 100;
-	pub CouncilMaxMembers: u32 = 100;
-}
-
-#[cfg(not(feature = "test-env"))]
-use crate::governance_timings::council as council_timings;
-
-#[cfg(feature = "test-env")]
-pub mod council_timings {
-	use super::*;
-
-	parameter_types! {
-		pub CouncilMotionDuration: BlockNumber = 35;
-	}
-}
-
-pub type CouncilCollective = pallet_collective::Instance1;
-impl pallet_collective::Config<CouncilCollective> for Runtime {
-	type RuntimeOrigin = RuntimeOrigin;
-	type Proposal = RuntimeCall;
-	type RuntimeEvent = RuntimeEvent;
-	type MotionDuration = council_timings::CouncilMotionDuration;
-	type MaxProposals = CouncilMaxProposals;
-	type MaxMembers = CouncilMaxMembers;
-	type DefaultVote = pallet_collective::PrimeDefaultVote;
-	type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
-	type SetMembersOrigin = EnsureRoot<AccountId>;
-	type MaxProposalWeight = MaxCollectivesProposalWeight;
-}
-
-pub type CouncilCollectiveMembership = pallet_membership::Instance1;
-impl pallet_membership::Config<CouncilCollectiveMembership> for Runtime {
-	type RuntimeEvent = RuntimeEvent;
-	type AddOrigin = EnsureRoot<AccountId>;
-	type RemoveOrigin = EnsureRoot<AccountId>;
-	type SwapOrigin = EnsureRoot<AccountId>;
-	type ResetOrigin = EnsureRoot<AccountId>;
-	type PrimeOrigin = EnsureRoot<AccountId>;
-	type MembershipInitialized = Council;
-	type MembershipChanged = Council;
-	type MaxMembers = CouncilMaxMembers;
-	type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
-}
-
-pub type CouncilMember = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
-
-pub type OneThirdsCouncil =
-	pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 3>;
-
-pub type HalfCouncil =
-	pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
-
-pub type MoreThanHalfCouncil =
-	pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>;
-
-pub type ThreeFourthsCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>;
-
-pub type AllCouncil = EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
-
-pub type RootOrOneThirdsCouncil = EitherOfDiverse<EnsureRoot<AccountId>, OneThirdsCouncil>;
-
-pub type RootOrHalfCouncil = EitherOfDiverse<EnsureRoot<AccountId>, HalfCouncil>;
-
-pub type RootOrMoreThanHalfCouncil = EitherOfDiverse<EnsureRoot<AccountId>, MoreThanHalfCouncil>;
-
-pub type RootOrThreeFourthsCouncil = EitherOfDiverse<EnsureRoot<AccountId>, ThreeFourthsCouncil>;
-
-pub type RootOrAllCouncil = EitherOfDiverse<EnsureRoot<AccountId>, AllCouncil>;
deletedruntime/common/config/pallets/governance/democracy.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/democracy.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-use super::*;
-
-parameter_types! {
-	pub MinimumDeposit: Balance = 0;
-	pub InstantAllowed: bool = false;
-	pub MaxVotes: u32 = 100;
-	pub MaxProposals: u32 = 100;
-}
-
-#[cfg(not(feature = "test-env"))]
-use crate::governance_timings::democracy as democracy_timings;
-
-#[cfg(feature = "test-env")]
-pub mod democracy_timings {
-	use super::*;
-
-	parameter_types! {
-		pub LaunchPeriod: BlockNumber = 35;
-		pub VotingPeriod: BlockNumber = 35;
-		pub FastTrackVotingPeriod: BlockNumber = 5;
-		pub EnactmentPeriod: BlockNumber = 40;
-		pub CooloffPeriod: BlockNumber = 35;
-	}
-}
-
-impl pallet_democracy::Config for Runtime {
-	type RuntimeEvent = RuntimeEvent;
-	type Currency = Balances;
-	type Slash = Treasury;
-	type Scheduler = Scheduler;
-	type PalletsOrigin = OriginCaller;
-	type Preimages = Preimage;
-	type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
-
-	/// The period between a proposal being approved and enacted.
-	type EnactmentPeriod = democracy_timings::EnactmentPeriod;
-
-	/// The minimum period of vote locking.
-	type VoteLockingPeriod = democracy_timings::EnactmentPeriod;
-
-	/// How often new public referenda are launched.
-	type LaunchPeriod = democracy_timings::LaunchPeriod;
-
-	/// How long the referendum will last.
-	type VotingPeriod = democracy_timings::VotingPeriod;
-
-	/// The minimum amount to be used as a deposit for the Fellowship referendum proposal.
-	type MinimumDeposit = MinimumDeposit;
-
-	type SubmitOrigin = EitherOf<
-		MapSuccess<EnsureRoot<Self::AccountId>, Replace<fellowship::FellowshipAccountId>>,
-		EnsureFellowshipProposition,
-	>;
-
-	type ExternalOrigin = EnsureNever<Self::AccountId>;
-	type ExternalMajorityOrigin = EnsureNever<Self::AccountId>;
-
-	/// Root (for the initial referendums)
-	/// or >50% of council can have the next scheduled referendum be a straight default-carries
-	/// (NTB) vote (SuperMajorityAgainst).
-	type ExternalDefaultOrigin = RootOrMoreThanHalfCouncil;
-
-	/// A unanimous technical committee can have an ExternalMajority/ExternalDefault vote
-	/// be tabled immediately and with a shorter voting/enactment period.
-	type FastTrackOrigin = RootOrAllTechnicalCommittee;
-
-	/// Origin from which the next referendum may be tabled to vote immediately and asynchronously.
-	/// Can set a faster voting period.
-	type InstantOrigin = EnsureNever<Self::AccountId>;
-	type InstantAllowed = InstantAllowed;
-
-	/// Minimum voting period allowed for a fast-track referendum.
-	type FastTrackVotingPeriod = democracy_timings::FastTrackVotingPeriod;
-
-	/// A single technical committee member can cancel a proposal which has been passed.
-	type CancellationOrigin = RootOrAllTechnicalCommittee;
-
-	/// To cancel a proposal before it has been passed, the technical committee must be unanimous or
-	/// Root must agree.
-	type CancelProposalOrigin = RootOrAllTechnicalCommittee;
-
-	/// A unanimous council or Root can blacklist a proposal permanently.
-	type BlacklistOrigin = RootOrAllCouncil;
-
-	// Any single technical committee member may veto a coming council proposal, however they can
-	// only do it once and it lasts only for the cooloff period.
-	type VetoOrigin = TechnicalCommitteeMember;
-	type CooloffPeriod = democracy_timings::CooloffPeriod;
-
-	/// The maximum number of votes for an account
-	type MaxVotes = MaxVotes;
-
-	/// The maximum number of public proposals that can exist at any time.
-	type MaxProposals = MaxProposals;
-
-	/// The maximum number of deposits a public proposal may have at any time.
-	type MaxDeposits = ConstU32<100>;
-
-	/// The maximum number of items that can be blacklisted.
-	type MaxBlacklisted = ConstU32<100>;
-}
deletedruntime/common/config/pallets/governance/fellowship.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/fellowship.rs
+++ /dev/null
@@ -1,167 +0,0 @@
-use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};
-use super::*;
-use pallet_gov_origins::Origin as GovOrigins;
-use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};
-
-pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");
-pub const DEMOCRACY_TRACK_ID: u16 = 10;
-
-parameter_types! {
-	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();
-	pub AlarmInterval: BlockNumber = 1;
-	pub SubmissionDeposit: Balance = 1000;
-}
-
-#[cfg(not(feature = "test-env"))]
-use crate::governance_timings::fellowship as fellowship_timings;
-
-#[cfg(feature = "test-env")]
-pub mod fellowship_timings {
-	use super::*;
-
-	parameter_types! {
-		pub UndecidingTimeout: BlockNumber = 35;
-	}
-
-	pub mod track {
-		use super::*;
-
-		pub mod democracy_proposals {
-			use super::*;
-
-			pub const PREPARE_PERIOD: BlockNumber = 3;
-			pub const DECISION_PERIOD: BlockNumber = 35;
-			pub const CONFIRM_PERIOD: BlockNumber = 3;
-			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;
-		}
-	}
-}
-
-impl pallet_referenda::Config for Runtime {
-	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
-	type RuntimeCall = RuntimeCall;
-	type RuntimeEvent = RuntimeEvent;
-	type Scheduler = Scheduler;
-	type Currency = Balances;
-	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;
-	type CancelOrigin = RootOrAllTechnicalCommittee;
-	type KillOrigin = RootOrAllTechnicalCommittee;
-	type Slash = Treasury;
-	type Votes = pallet_ranked_collective::Votes;
-	type Tally = pallet_ranked_collective::TallyOf<Runtime>;
-	type SubmissionDeposit = SubmissionDeposit;
-	type MaxQueued = ConstU32<100>;
-	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;
-	type AlarmInterval = AlarmInterval;
-	type Tracks = TracksInfo;
-	type Preimages = Preimage;
-}
-
-impl RankedConfig for Runtime {
-	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;
-	type RuntimeEvent = RuntimeEvent;
-	// Promotion is by any of:
-	// - Council member.
-	// - Technical committee member.
-	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;
-	// Demotion is by any of:
-	// - Council member.
-	// - Technical committee member.
-	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;
-	type Polls = FellowshipReferenda;
-	type MinRankOfClass = ClassToRankMapper<Self, ()>;
-	type VoteWeight = pallet_ranked_collective::Geometric;
-}
-
-pub struct EnsureFellowshipProposition;
-impl<O> EnsureOrigin<O> for EnsureFellowshipProposition
-where
-	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,
-{
-	type Success = AccountId;
-
-	fn try_origin(o: O) -> Result<Self::Success, O> {
-		o.into().and_then(|o| match o {
-			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),
-			o => Err(O::from(o)),
-		})
-	}
-
-	#[cfg(feature = "runtime-benchmarks")]
-	fn try_successful_origin() -> Result<O, ()> {
-		Ok(O::from(GovOrigins::FellowshipProposition))
-	}
-}
-
-pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<
-	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,
-	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,
->;
-
-pub struct TracksInfo;
-impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
-	type Id = u16;
-	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
-	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
-		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(
-			DEMOCRACY_TRACK_ID,
-			pallet_referenda::TrackInfo {
-				name: "democracy_proposals",
-				max_deciding: 10,
-				decision_deposit: 10 * UNIQUE,
-				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,
-				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,
-				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,
-				min_enactment_period:
-					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,
-				min_approval: pallet_referenda::Curve::LinearDecreasing {
-					length: Perbill::from_percent(100),
-					floor: Perbill::from_percent(50),
-					ceil: Perbill::from_percent(100),
-				},
-				min_support: pallet_referenda::Curve::LinearDecreasing {
-					length: Perbill::from_percent(100),
-					floor: Perbill::from_percent(0),
-					ceil: Perbill::from_percent(50),
-				},
-			},
-		)];
-		&DATA[..]
-	}
-	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
-		#[cfg(feature = "runtime-benchmarks")]
-		{
-			// For benchmarks, we enable a root origin.
-			// It is important that this is not available in production!
-			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
-			if &root == id {
-				return Ok(9);
-			}
-		}
-
-		match GovOrigins::try_from(id.clone()) {
-			Ok(_) => Ok(DEMOCRACY_TRACK_ID),
-			_ => Err(()),
-		}
-	}
-}
-
-pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
-
-pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);
-
-//TODO: Remove the type when it appears in the release.
-pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;
-
-impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>
-where
-	T: RankedConfig<I>,
-	ClassOf<T, I>: Into<Rank>,
-{
-	fn convert(track_id: ClassOf<T, I>) -> Rank {
-		match track_id.into() {
-			DEMOCRACY_TRACK_ID => 3,
-			other => other,
-		}
-	}
-}
deletedruntime/common/config/pallets/governance/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/mod.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-use frame_support::{
-	PalletId, parameter_types,
-	traits::{
-		EnsureOrigin, EqualPrivilegeOnly, EitherOfDiverse, EitherOf, MapSuccess, ConstU16, Polling,
-	},
-	weights::Weight,
-	pallet_prelude::*,
-};
-use frame_system::{EnsureRoot, EnsureNever};
-use sp_runtime::{
-	Perbill,
-	traits::{AccountIdConversion, ConstU32, Replace, CheckedSub, Convert},
-	morph_types,
-};
-use crate::{
-	Runtime, RuntimeOrigin, RuntimeEvent, RuntimeCall, OriginCaller, Preimage, Balances, Treasury,
-	Scheduler, Council, TechnicalCommittee,
-};
-pub use up_common::{
-	constants::{UNIQUE, DAYS, HOURS, MINUTES, CENTIUNIQUE},
-	types::{AccountId, Balance, BlockNumber},
-};
-use pallet_collective::EnsureProportionAtLeast;
-
-pub mod council;
-pub use council::*;
-
-pub mod democracy;
-pub use democracy::*;
-
-pub mod technical_committee;
-pub use technical_committee::*;
-
-pub mod fellowship;
-pub use fellowship::*;
-
-pub mod scheduler;
-pub use scheduler::*;
-
-impl pallet_gov_origins::Config for Runtime {}
-
-morph_types! {
-	/// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for
-	/// underflow.
-	pub type CheckedReduceBy<N: TypedGet>: TryMorph = |r: N::Type| -> Result<N::Type, ()> {
-		r.checked_sub(&N::get()).ok_or(())
-	} where N::Type: CheckedSub;
-}
-
-parameter_types! {
-	pub MaxCollectivesProposalWeight: Weight = Perbill::from_percent(80) * <Runtime as frame_system::Config>::BlockWeights::get().max_block;
-}
deletedruntime/common/config/pallets/governance/scheduler.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/scheduler.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-use up_common::constants::{MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
-
-use super::*;
-
-parameter_types! {
-	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
-		<Runtime as frame_system::Config>::BlockWeights::get()
-		.per_class.get(frame_support::pallet_prelude::DispatchClass::Normal).max_total
-		.unwrap_or(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
-	pub MaxScheduledPerBlock: u32 = 50;
-}
-
-impl pallet_scheduler::Config for Runtime {
-	type RuntimeOrigin = RuntimeOrigin;
-	type RuntimeEvent = RuntimeEvent;
-	type PalletsOrigin = OriginCaller;
-	type RuntimeCall = RuntimeCall;
-	type MaximumWeight = MaximumSchedulerWeight;
-	type ScheduleOrigin = EnsureRoot<AccountId>;
-	type MaxScheduledPerBlock = MaxScheduledPerBlock;
-	type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
-	type OriginPrivilegeCmp = EqualPrivilegeOnly;
-	type Preimages = Preimage;
-}
deletedruntime/common/config/pallets/governance/technical_committee.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/governance/technical_committee.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use super::*;
-
-parameter_types! {
-	pub TechnicalMaxProposals: u32 = 100;
-	pub TechnicalMaxMembers: u32 = 100;
-}
-
-#[cfg(not(feature = "test-env"))]
-use crate::governance_timings::technical_committee as technical_committee_timings;
-
-#[cfg(feature = "test-env")]
-pub mod technical_committee_timings {
-	use super::*;
-
-	parameter_types! {
-		pub TechnicalMotionDuration: BlockNumber = 35;
-	}
-}
-
-pub type TechnicalCollective = pallet_collective::Instance2;
-impl pallet_collective::Config<TechnicalCollective> for Runtime {
-	type RuntimeOrigin = RuntimeOrigin;
-	type Proposal = RuntimeCall;
-	type RuntimeEvent = RuntimeEvent;
-	type MotionDuration = technical_committee_timings::TechnicalMotionDuration;
-	type MaxProposals = TechnicalMaxProposals;
-	type MaxMembers = TechnicalMaxMembers;
-	type DefaultVote = pallet_collective::PrimeDefaultVote;
-	type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
-	type SetMembersOrigin = EnsureRoot<AccountId>;
-	type MaxProposalWeight = MaxCollectivesProposalWeight;
-}
-
-pub type TechnicalCollectiveMembership = pallet_membership::Instance2;
-impl pallet_membership::Config<TechnicalCollectiveMembership> for Runtime {
-	type RuntimeEvent = RuntimeEvent;
-	type AddOrigin = RootOrMoreThanHalfCouncil;
-	type RemoveOrigin = RootOrMoreThanHalfCouncil;
-	type SwapOrigin = RootOrMoreThanHalfCouncil;
-	type ResetOrigin = EnsureRoot<AccountId>;
-	type PrimeOrigin = EnsureRoot<AccountId>;
-	type MembershipInitialized = TechnicalCommittee;
-	type MembershipChanged = TechnicalCommittee;
-	type MaxMembers = TechnicalMaxMembers;
-	type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
-}
-
-pub type TechnicalCommitteeMember = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
-
-pub type RootOrTechnicalCommitteeMember =
-	EitherOfDiverse<EnsureRoot<AccountId>, TechnicalCommitteeMember>;
-
-pub type AllTechnicalCommittee =
-	pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
-
-pub type RootOrAllTechnicalCommittee =
-	EitherOfDiverse<EnsureRoot<AccountId>, AllTechnicalCommittee>;
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -36,6 +36,9 @@
 };
 use sp_arithmetic::Perbill;
 
+#[cfg(feature = "governance")]
+use crate::runtime_common::config::governance;
+
 #[cfg(feature = "unique-scheduler")]
 pub mod scheduler;
 
@@ -50,9 +53,6 @@
 
 #[cfg(feature = "preimage")]
 pub mod preimage;
-
-#[cfg(feature = "governance")]
-pub mod governance;
 
 parameter_types! {
 	pub const CollectionCreationPrice: Balance = 2 * UNIQUE;
modifiedruntime/common/config/xcm/mod.rsdiffbeforeafterboth
before · runtime/common/config/xcm/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError},19	parameter_types,20};21use frame_system::EnsureRoot;22use pallet_xcm::XcmPassthrough;23use polkadot_parachain::primitives::Sibling;24use xcm::latest::{prelude::*, Weight, MultiLocation};25use xcm::v3::Instruction;26use xcm_builder::{27	AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, RelayChainAsNative,28	SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,29	SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,30};31use xcm_executor::{XcmExecutor, traits::ShouldExecute};32use sp_std::marker::PhantomData;33use crate::{34	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm,35	XcmpQueue, xcm_barrier::Barrier, RelayNetwork, AllPalletsWithSystem, Balances,36};3738use up_common::types::AccountId;3940#[cfg(feature = "foreign-assets")]41pub mod foreignassets;4243#[cfg(not(feature = "foreign-assets"))]44pub mod nativeassets;4546#[cfg(feature = "foreign-assets")]47pub use foreignassets as xcm_assets;4849#[cfg(not(feature = "foreign-assets"))]50pub use nativeassets as xcm_assets;5152#[cfg(feature = "governance")]53use crate::runtime_common::config::pallets::governance;5455use xcm_assets::{AssetTransactor, IsReserve, Trader};5657parameter_types! {58	pub const RelayLocation: MultiLocation = MultiLocation::parent();59	pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();60	pub UniversalLocation: InteriorMultiLocation = (61		GlobalConsensus(crate::RelayNetwork::get()),62		Parachain(ParachainInfo::get().into()),63	).into();64	pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6566	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.67	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); // ?68	pub const MaxInstructions: u32 = 100;69}7071/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used72/// when determining ownership of accounts for asset transacting and when attempting to use XCM73/// `Transact` in order to determine the dispatch Origin.74pub type LocationToAccountId = (75	// The parent (Relay-chain) origin converts to the default `AccountId`.76	ParentIsPreset<AccountId>,77	// Sibling parachain origins convert to AccountId via the `ParaId::into`.78	SiblingParachainConvertsVia<Sibling, AccountId>,79	// Straight up local `AccountId32` origins just alias directly to `AccountId`.80	AccountId32Aliases<RelayNetwork, AccountId>,81);8283/// No local origins on this chain are allowed to dispatch XCM sends/executions.84pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);8586/// The means for routing XCM messages which are not for local execution into the right message87/// queues.88pub type XcmRouter = (89	// Two routers - use UMP to communicate with the relay chain:90	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,91	// ..and XCMP to communicate with the sibling chains.92	XcmpQueue,93);9495/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,96/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can97/// biases the kind of local `Origin` it will become.98pub type XcmOriginToTransactDispatchOrigin = (99	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location100	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for101	// foreign chains who want to have a local sovereign account on this chain which they control.102	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,103	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when104	// recognised.105	RelayChainAsNative<RelayOrigin, RuntimeOrigin>,106	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when107	// recognised.108	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,109	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a110	// transaction from the Root origin.111	ParentAsSuperuser<RuntimeOrigin>,112	// Native signed account converter; this just converts an `AccountId32` origin into a normal113	// `Origin::Signed` origin of the same 32-byte value.114	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,115	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.116	XcmPassthrough<RuntimeOrigin>,117);118119pub trait TryPass {120	fn try_pass<Call>(121		origin: &MultiLocation,122		message: &mut [Instruction<Call>],123	) -> Result<(), ProcessMessageError>;124}125126#[impl_trait_for_tuples::impl_for_tuples(30)]127impl TryPass for Tuple {128	fn try_pass<Call>(129		origin: &MultiLocation,130		message: &mut [Instruction<Call>],131	) -> Result<(), ProcessMessageError> {132		for_tuples!( #(133			Tuple::try_pass(origin, message)?;134		)* );135136		Ok(())137	}138}139140/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.141/// If it passes the Deny, and matches one of the Allow cases then it is let through.142pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)143where144	Deny: TryPass,145	Allow: ShouldExecute;146147impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>148where149	Deny: TryPass,150	Allow: ShouldExecute,151{152	fn should_execute<Call>(153		origin: &MultiLocation,154		message: &mut [Instruction<Call>],155		max_weight: Weight,156		weight_credit: &mut Weight,157	) -> Result<(), ProcessMessageError> {158		Deny::try_pass(origin, message)?;159		Allow::should_execute(origin, message, max_weight, weight_credit)160	}161}162163pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;164165pub struct XcmExecutorConfig<T>(PhantomData<T>);166impl<T> xcm_executor::Config for XcmExecutorConfig<T>167where168	T: pallet_configuration::Config,169{170	type RuntimeCall = RuntimeCall;171	type XcmSender = XcmRouter;172	// How to withdraw and deposit an asset.173	type AssetTransactor = AssetTransactor;174	type OriginConverter = XcmOriginToTransactDispatchOrigin;175	type IsReserve = IsReserve;176	type IsTeleporter = (); // Teleportation is disabled177	type UniversalLocation = UniversalLocation;178	type Barrier = Barrier;179	type Weigher = Weigher;180	type Trader = Trader<T>;181	type ResponseHandler = PolkadotXcm;182	type SubscriptionService = PolkadotXcm;183	type PalletInstancesInfo = AllPalletsWithSystem;184	type MaxAssetsIntoHolding = ConstU32<8>;185186	type AssetTrap = PolkadotXcm;187	type AssetClaims = PolkadotXcm;188	type AssetLocker = ();189	type AssetExchanger = ();190	type FeeManager = ();191	type MessageExporter = ();192	type UniversalAliases = Nothing;193	type CallDispatcher = RuntimeCall;194195	// Deny all XCM Transacts.196	type SafeCallFilter = Nothing;197}198199#[cfg(feature = "runtime-benchmarks")]200parameter_types! {201	pub ReachableDest: Option<MultiLocation> = Some(Parent.into());202}203204impl pallet_xcm::Config for Runtime {205	type RuntimeEvent = RuntimeEvent;206	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;207	type XcmRouter = XcmRouter;208	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;209	type XcmExecuteFilter = Everything;210	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;211	type XcmTeleportFilter = Everything;212	type XcmReserveTransferFilter = Everything;213	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;214	type RuntimeOrigin = RuntimeOrigin;215	type RuntimeCall = RuntimeCall;216	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;217	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;218	type UniversalLocation = UniversalLocation;219	type Currency = Balances;220	type CurrencyMatcher = ();221	type TrustedLockers = ();222	type SovereignAccountOf = LocationToAccountId;223	type MaxLockers = ConstU32<8>;224	type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;225	type AdminOrigin = EnsureRoot<AccountId>;226	type MaxRemoteLockConsumers = ConstU32<0>;227	type RemoteLockConsumerIdentifier = ();228	#[cfg(feature = "runtime-benchmarks")]229	type ReachableDest = ReachableDest;230}231232impl cumulus_pallet_xcm::Config for Runtime {233	type RuntimeEvent = RuntimeEvent;234	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;235}236237impl cumulus_pallet_xcmp_queue::Config for Runtime {238	type WeightInfo = ();239	type RuntimeEvent = RuntimeEvent;240	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;241	type ChannelInfo = ParachainSystem;242	type VersionWrapper = PolkadotXcm;243	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;244245	#[cfg(feature = "governance")]246	type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;247248	#[cfg(not(feature = "governance"))]249	type ControllerOrigin = frame_system::EnsureRoot<AccountId>;250251	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;252	type PriceForSiblingDelivery = ();253}254255impl cumulus_pallet_dmp_queue::Config for Runtime {256	type RuntimeEvent = RuntimeEvent;257	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;258	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;259}
after · runtime/common/config/xcm/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError},19	parameter_types,20};21use frame_system::EnsureRoot;22use pallet_xcm::XcmPassthrough;23use polkadot_parachain::primitives::Sibling;24use xcm::latest::{prelude::*, Weight, MultiLocation};25use xcm::v3::Instruction;26use xcm_builder::{27	AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, RelayChainAsNative,28	SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,29	SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,30};31use xcm_executor::{XcmExecutor, traits::ShouldExecute};32use sp_std::marker::PhantomData;33use crate::{34	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm,35	XcmpQueue, xcm_barrier::Barrier, RelayNetwork, AllPalletsWithSystem, Balances,36};3738use up_common::types::AccountId;3940#[cfg(feature = "foreign-assets")]41pub mod foreignassets;4243#[cfg(not(feature = "foreign-assets"))]44pub mod nativeassets;4546#[cfg(feature = "foreign-assets")]47pub use foreignassets as xcm_assets;4849#[cfg(not(feature = "foreign-assets"))]50pub use nativeassets as xcm_assets;5152#[cfg(feature = "governance")]53use crate::runtime_common::config::governance;5455use xcm_assets::{AssetTransactor, IsReserve, Trader};5657parameter_types! {58	pub const RelayLocation: MultiLocation = MultiLocation::parent();59	pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();60	pub UniversalLocation: InteriorMultiLocation = (61		GlobalConsensus(crate::RelayNetwork::get()),62		Parachain(ParachainInfo::get().into()),63	).into();64	pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6566	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.67	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); // ?68	pub const MaxInstructions: u32 = 100;69}7071/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used72/// when determining ownership of accounts for asset transacting and when attempting to use XCM73/// `Transact` in order to determine the dispatch Origin.74pub type LocationToAccountId = (75	// The parent (Relay-chain) origin converts to the default `AccountId`.76	ParentIsPreset<AccountId>,77	// Sibling parachain origins convert to AccountId via the `ParaId::into`.78	SiblingParachainConvertsVia<Sibling, AccountId>,79	// Straight up local `AccountId32` origins just alias directly to `AccountId`.80	AccountId32Aliases<RelayNetwork, AccountId>,81);8283/// No local origins on this chain are allowed to dispatch XCM sends/executions.84pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);8586/// The means for routing XCM messages which are not for local execution into the right message87/// queues.88pub type XcmRouter = (89	// Two routers - use UMP to communicate with the relay chain:90	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,91	// ..and XCMP to communicate with the sibling chains.92	XcmpQueue,93);9495/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,96/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can97/// biases the kind of local `Origin` it will become.98pub type XcmOriginToTransactDispatchOrigin = (99	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location100	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for101	// foreign chains who want to have a local sovereign account on this chain which they control.102	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,103	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when104	// recognised.105	RelayChainAsNative<RelayOrigin, RuntimeOrigin>,106	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when107	// recognised.108	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,109	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a110	// transaction from the Root origin.111	ParentAsSuperuser<RuntimeOrigin>,112	// Native signed account converter; this just converts an `AccountId32` origin into a normal113	// `Origin::Signed` origin of the same 32-byte value.114	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,115	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.116	XcmPassthrough<RuntimeOrigin>,117);118119pub trait TryPass {120	fn try_pass<Call>(121		origin: &MultiLocation,122		message: &mut [Instruction<Call>],123	) -> Result<(), ProcessMessageError>;124}125126#[impl_trait_for_tuples::impl_for_tuples(30)]127impl TryPass for Tuple {128	fn try_pass<Call>(129		origin: &MultiLocation,130		message: &mut [Instruction<Call>],131	) -> Result<(), ProcessMessageError> {132		for_tuples!( #(133			Tuple::try_pass(origin, message)?;134		)* );135136		Ok(())137	}138}139140/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.141/// If it passes the Deny, and matches one of the Allow cases then it is let through.142pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)143where144	Deny: TryPass,145	Allow: ShouldExecute;146147impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>148where149	Deny: TryPass,150	Allow: ShouldExecute,151{152	fn should_execute<Call>(153		origin: &MultiLocation,154		message: &mut [Instruction<Call>],155		max_weight: Weight,156		weight_credit: &mut Weight,157	) -> Result<(), ProcessMessageError> {158		Deny::try_pass(origin, message)?;159		Allow::should_execute(origin, message, max_weight, weight_credit)160	}161}162163pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;164165pub struct XcmExecutorConfig<T>(PhantomData<T>);166impl<T> xcm_executor::Config for XcmExecutorConfig<T>167where168	T: pallet_configuration::Config,169{170	type RuntimeCall = RuntimeCall;171	type XcmSender = XcmRouter;172	// How to withdraw and deposit an asset.173	type AssetTransactor = AssetTransactor;174	type OriginConverter = XcmOriginToTransactDispatchOrigin;175	type IsReserve = IsReserve;176	type IsTeleporter = (); // Teleportation is disabled177	type UniversalLocation = UniversalLocation;178	type Barrier = Barrier;179	type Weigher = Weigher;180	type Trader = Trader<T>;181	type ResponseHandler = PolkadotXcm;182	type SubscriptionService = PolkadotXcm;183	type PalletInstancesInfo = AllPalletsWithSystem;184	type MaxAssetsIntoHolding = ConstU32<8>;185186	type AssetTrap = PolkadotXcm;187	type AssetClaims = PolkadotXcm;188	type AssetLocker = ();189	type AssetExchanger = ();190	type FeeManager = ();191	type MessageExporter = ();192	type UniversalAliases = Nothing;193	type CallDispatcher = RuntimeCall;194195	// Deny all XCM Transacts.196	type SafeCallFilter = Nothing;197}198199#[cfg(feature = "runtime-benchmarks")]200parameter_types! {201	pub ReachableDest: Option<MultiLocation> = Some(Parent.into());202}203204impl pallet_xcm::Config for Runtime {205	type RuntimeEvent = RuntimeEvent;206	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;207	type XcmRouter = XcmRouter;208	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;209	type XcmExecuteFilter = Everything;210	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;211	type XcmTeleportFilter = Everything;212	type XcmReserveTransferFilter = Everything;213	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;214	type RuntimeOrigin = RuntimeOrigin;215	type RuntimeCall = RuntimeCall;216	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;217	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;218	type UniversalLocation = UniversalLocation;219	type Currency = Balances;220	type CurrencyMatcher = ();221	type TrustedLockers = ();222	type SovereignAccountOf = LocationToAccountId;223	type MaxLockers = ConstU32<8>;224	type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;225	type AdminOrigin = EnsureRoot<AccountId>;226	type MaxRemoteLockConsumers = ConstU32<0>;227	type RemoteLockConsumerIdentifier = ();228	#[cfg(feature = "runtime-benchmarks")]229	type ReachableDest = ReachableDest;230}231232impl cumulus_pallet_xcm::Config for Runtime {233	type RuntimeEvent = RuntimeEvent;234	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;235}236237impl cumulus_pallet_xcmp_queue::Config for Runtime {238	type WeightInfo = ();239	type RuntimeEvent = RuntimeEvent;240	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;241	type ChannelInfo = ParachainSystem;242	type VersionWrapper = PolkadotXcm;243	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;244245	#[cfg(feature = "governance")]246	type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;247248	#[cfg(not(feature = "governance"))]249	type ControllerOrigin = frame_system::EnsureRoot<AccountId>;250251	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;252	type PriceForSiblingDelivery = ();253}254255impl cumulus_pallet_dmp_queue::Config for Runtime {256	type RuntimeEvent = RuntimeEvent;257	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;258	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;259}