--- /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 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; + type SetMembersOrigin = EnsureRoot; + type MaxProposalWeight = MaxCollectivesProposalWeight; +} + +pub type CouncilCollectiveMembership = pallet_membership::Instance1; +impl pallet_membership::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddOrigin = EnsureRoot; + type RemoveOrigin = EnsureRoot; + type SwapOrigin = EnsureRoot; + type ResetOrigin = EnsureRoot; + type PrimeOrigin = EnsureRoot; + type MembershipInitialized = Council; + type MembershipChanged = Council; + type MaxMembers = CouncilMaxMembers; + type WeightInfo = pallet_membership::weights::SubstrateWeight; +} + +pub type CouncilMember = pallet_collective::EnsureMember; + +pub type OneThirdsCouncil = + pallet_collective::EnsureProportionAtLeast; + +pub type HalfCouncil = + pallet_collective::EnsureProportionAtLeast; + +pub type MoreThanHalfCouncil = + pallet_collective::EnsureProportionMoreThan; + +pub type ThreeFourthsCouncil = EnsureProportionAtLeast; + +pub type AllCouncil = EnsureProportionAtLeast; + +pub type RootOrOneThirdsCouncil = EitherOfDiverse, OneThirdsCouncil>; + +pub type RootOrHalfCouncil = EitherOfDiverse, HalfCouncil>; + +pub type RootOrMoreThanHalfCouncil = EitherOfDiverse, MoreThanHalfCouncil>; + +pub type RootOrThreeFourthsCouncil = EitherOfDiverse, ThreeFourthsCouncil>; + +pub type RootOrAllCouncil = EitherOfDiverse, AllCouncil>; --- /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; + + /// 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, Replace>, + EnsureFellowshipProposition, + >; + + type ExternalOrigin = EnsureNever; + type ExternalMajorityOrigin = EnsureNever; + + /// 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; + 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>; +} --- /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: ::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; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = pallet_ranked_collective::EnsureMember; + type CancelOrigin = RootOrAllTechnicalCommittee; + type KillOrigin = RootOrAllTechnicalCommittee; + type Slash = Treasury; + type Votes = pallet_ranked_collective::Votes; + type Tally = pallet_ranked_collective::TallyOf; + 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; + type RuntimeEvent = RuntimeEvent; + // Promotion is by any of: + // - Council member. + // - Technical committee member. + type PromoteOrigin = FellowshipPromoteDemoteOrigin; + // Demotion is by any of: + // - Council member. + // - Technical committee member. + type DemoteOrigin = FellowshipPromoteDemoteOrigin; + type Polls = FellowshipReferenda; + type MinRankOfClass = ClassToRankMapper; + type VoteWeight = pallet_ranked_collective::Geometric; +} + +pub struct EnsureFellowshipProposition; +impl EnsureOrigin for EnsureFellowshipProposition +where + O: Into> + From, +{ + type Success = AccountId; + + fn try_origin(o: O) -> Result { + 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 { + Ok(O::from(GovOrigins::FellowshipProposition)) + } +} + +pub type FellowshipPromoteDemoteOrigin = EitherOf< + MapSuccess, Replace>>, + MapSuccess>>, +>; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + static DATA: [(u16, pallet_referenda::TrackInfo); 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 { + #[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(PhantomData<(T, I)>); + +//TODO: Remove the type when it appears in the release. +pub type ClassOf = <>::Polls as Polling>>::Class; + +impl Convert, Rank> for ClassToRankMapper +where + T: RankedConfig, + ClassOf: Into, +{ + fn convert(track_id: ClassOf) -> Rank { + match track_id.into() { + DEMOCRACY_TRACK_ID => 3, + other => other, + } + } +} --- /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 . + +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: TryMorph = |r: N::Type| -> Result { + r.checked_sub(&N::get()).ok_or(()) + } where N::Type: CheckedSub; +} + +parameter_types! { + pub MaxCollectivesProposalWeight: Weight = Perbill::from_percent(80) * ::BlockWeights::get().max_block; +} --- /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) * + ::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; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + type WeightInfo = pallet_scheduler::weights::SubstrateWeight; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type Preimages = Preimage; +} --- /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 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; + type SetMembersOrigin = EnsureRoot; + type MaxProposalWeight = MaxCollectivesProposalWeight; +} + +pub type TechnicalCollectiveMembership = pallet_membership::Instance2; +impl pallet_membership::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddOrigin = RootOrMoreThanHalfCouncil; + type RemoveOrigin = RootOrMoreThanHalfCouncil; + type SwapOrigin = RootOrMoreThanHalfCouncil; + type ResetOrigin = EnsureRoot; + type PrimeOrigin = EnsureRoot; + type MembershipInitialized = TechnicalCommittee; + type MembershipChanged = TechnicalCommittee; + type MaxMembers = TechnicalMaxMembers; + type WeightInfo = pallet_membership::weights::SubstrateWeight; +} + +pub type TechnicalCommitteeMember = pallet_collective::EnsureMember; + +pub type RootOrTechnicalCommitteeMember = + EitherOfDiverse, TechnicalCommitteeMember>; + +pub type AllTechnicalCommittee = + pallet_collective::EnsureProportionAtLeast; + +pub type RootOrAllTechnicalCommittee = + EitherOfDiverse, AllTechnicalCommittee>; --- 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; --- 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<::AccountId>; --- 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 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; - type SetMembersOrigin = EnsureRoot; - type MaxProposalWeight = MaxCollectivesProposalWeight; -} - -pub type CouncilCollectiveMembership = pallet_membership::Instance1; -impl pallet_membership::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type AddOrigin = EnsureRoot; - type RemoveOrigin = EnsureRoot; - type SwapOrigin = EnsureRoot; - type ResetOrigin = EnsureRoot; - type PrimeOrigin = EnsureRoot; - type MembershipInitialized = Council; - type MembershipChanged = Council; - type MaxMembers = CouncilMaxMembers; - type WeightInfo = pallet_membership::weights::SubstrateWeight; -} - -pub type CouncilMember = pallet_collective::EnsureMember; - -pub type OneThirdsCouncil = - pallet_collective::EnsureProportionAtLeast; - -pub type HalfCouncil = - pallet_collective::EnsureProportionAtLeast; - -pub type MoreThanHalfCouncil = - pallet_collective::EnsureProportionMoreThan; - -pub type ThreeFourthsCouncil = EnsureProportionAtLeast; - -pub type AllCouncil = EnsureProportionAtLeast; - -pub type RootOrOneThirdsCouncil = EitherOfDiverse, OneThirdsCouncil>; - -pub type RootOrHalfCouncil = EitherOfDiverse, HalfCouncil>; - -pub type RootOrMoreThanHalfCouncil = EitherOfDiverse, MoreThanHalfCouncil>; - -pub type RootOrThreeFourthsCouncil = EitherOfDiverse, ThreeFourthsCouncil>; - -pub type RootOrAllCouncil = EitherOfDiverse, AllCouncil>; --- 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; - - /// 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, Replace>, - EnsureFellowshipProposition, - >; - - type ExternalOrigin = EnsureNever; - type ExternalMajorityOrigin = EnsureNever; - - /// 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; - 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>; -} --- 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: ::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; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type Scheduler = Scheduler; - type Currency = Balances; - type SubmitOrigin = pallet_ranked_collective::EnsureMember; - type CancelOrigin = RootOrAllTechnicalCommittee; - type KillOrigin = RootOrAllTechnicalCommittee; - type Slash = Treasury; - type Votes = pallet_ranked_collective::Votes; - type Tally = pallet_ranked_collective::TallyOf; - 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; - type RuntimeEvent = RuntimeEvent; - // Promotion is by any of: - // - Council member. - // - Technical committee member. - type PromoteOrigin = FellowshipPromoteDemoteOrigin; - // Demotion is by any of: - // - Council member. - // - Technical committee member. - type DemoteOrigin = FellowshipPromoteDemoteOrigin; - type Polls = FellowshipReferenda; - type MinRankOfClass = ClassToRankMapper; - type VoteWeight = pallet_ranked_collective::Geometric; -} - -pub struct EnsureFellowshipProposition; -impl EnsureOrigin for EnsureFellowshipProposition -where - O: Into> + From, -{ - type Success = AccountId; - - fn try_origin(o: O) -> Result { - 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 { - Ok(O::from(GovOrigins::FellowshipProposition)) - } -} - -pub type FellowshipPromoteDemoteOrigin = EitherOf< - MapSuccess, Replace>>, - MapSuccess>>, ->; - -pub struct TracksInfo; -impl pallet_referenda::TracksInfo for TracksInfo { - type Id = u16; - type RuntimeOrigin = ::PalletsOrigin; - fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { - static DATA: [(u16, pallet_referenda::TrackInfo); 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 { - #[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(PhantomData<(T, I)>); - -//TODO: Remove the type when it appears in the release. -pub type ClassOf = <>::Polls as Polling>>::Class; - -impl Convert, Rank> for ClassToRankMapper -where - T: RankedConfig, - ClassOf: Into, -{ - fn convert(track_id: ClassOf) -> Rank { - match track_id.into() { - DEMOCRACY_TRACK_ID => 3, - other => other, - } - } -} --- 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 . - -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: TryMorph = |r: N::Type| -> Result { - r.checked_sub(&N::get()).ok_or(()) - } where N::Type: CheckedSub; -} - -parameter_types! { - pub MaxCollectivesProposalWeight: Weight = Perbill::from_percent(80) * ::BlockWeights::get().max_block; -} --- 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) * - ::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; - type MaxScheduledPerBlock = MaxScheduledPerBlock; - type WeightInfo = pallet_scheduler::weights::SubstrateWeight; - type OriginPrivilegeCmp = EqualPrivilegeOnly; - type Preimages = Preimage; -} --- 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 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; - type SetMembersOrigin = EnsureRoot; - type MaxProposalWeight = MaxCollectivesProposalWeight; -} - -pub type TechnicalCollectiveMembership = pallet_membership::Instance2; -impl pallet_membership::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type AddOrigin = RootOrMoreThanHalfCouncil; - type RemoveOrigin = RootOrMoreThanHalfCouncil; - type SwapOrigin = RootOrMoreThanHalfCouncil; - type ResetOrigin = EnsureRoot; - type PrimeOrigin = EnsureRoot; - type MembershipInitialized = TechnicalCommittee; - type MembershipChanged = TechnicalCommittee; - type MaxMembers = TechnicalMaxMembers; - type WeightInfo = pallet_membership::weights::SubstrateWeight; -} - -pub type TechnicalCommitteeMember = pallet_collective::EnsureMember; - -pub type RootOrTechnicalCommitteeMember = - EitherOfDiverse, TechnicalCommitteeMember>; - -pub type AllTechnicalCommittee = - pallet_collective::EnsureProportionAtLeast; - -pub type RootOrAllTechnicalCommittee = - EitherOfDiverse, AllTechnicalCommittee>; --- 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; --- a/runtime/common/config/xcm/mod.rs +++ b/runtime/common/config/xcm/mod.rs @@ -50,7 +50,7 @@ pub use nativeassets as xcm_assets; #[cfg(feature = "governance")] -use crate::runtime_common::config::pallets::governance; +use crate::runtime_common::config::governance; use xcm_assets::{AssetTransactor, IsReserve, Trader};