git.delta.rocks / unique-network / refs/commits / 8c2fbfd7d106

difftreelog

source

runtime/common/config/governance/fellowship.rs5.6 KiBsourcehistory
1use pallet_gov_origins::Origin as GovOrigins;2use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};3use sp_runtime::traits::ReplaceWithDefault;45use super::*;6use crate::{7	FellowshipReferenda, Preimage, Runtime, RuntimeCall, RuntimeEvent, Scheduler, Treasury,8};910pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");11pub const DEMOCRACY_TRACK_ID: u16 = 10;1213parameter_types! {14	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();15	pub AlarmInterval: BlockNumber = 1;16	pub SubmissionDeposit: Balance = 1000;17}1819#[cfg(not(feature = "gov-test-timings"))]20use crate::governance_timings::fellowship as fellowship_timings;2122#[cfg(feature = "gov-test-timings")]23pub mod fellowship_timings {24	use super::*;2526	parameter_types! {27		pub UndecidingTimeout: BlockNumber = 35;28	}2930	pub mod track {31		use super::*;3233		pub mod democracy_proposals {34			use super::*;3536			pub const PREPARE_PERIOD: BlockNumber = 3;37			pub const DECISION_PERIOD: BlockNumber = 35;38			pub const CONFIRM_PERIOD: BlockNumber = 3;39			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;40		}41	}42}4344impl pallet_referenda::Config for Runtime {45	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;46	type RuntimeCall = RuntimeCall;47	type RuntimeEvent = RuntimeEvent;48	type Scheduler = Scheduler;49	type Currency = Balances;50	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;51	type CancelOrigin = RootOrAllTechnicalCommittee;52	type KillOrigin = RootOrAllTechnicalCommittee;53	type Slash = Treasury;54	type Votes = pallet_ranked_collective::Votes;55	type Tally = pallet_ranked_collective::TallyOf<Runtime>;56	type SubmissionDeposit = SubmissionDeposit;57	type MaxQueued = ConstU32<100>;58	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;59	type AlarmInterval = AlarmInterval;60	type Tracks = TracksInfo;61	type Preimages = Preimage;62}6364impl RankedConfig for Runtime {65	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;66	type RuntimeEvent = RuntimeEvent;67	type AddOrigin = FellowshipAddOrigin<Self::AccountId>;68	type RemoveOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;69	type ExchangeOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;70	type MemberSwappedHandler = ();71	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;72	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;73	type Polls = FellowshipReferenda;74	type MinRankOfClass = ClassToRankMapper<Self, ()>;75	type VoteWeight = pallet_ranked_collective::Geometric;76}7778pub struct EnsureFellowshipProposition;79impl<O> EnsureOrigin<O> for EnsureFellowshipProposition80where81	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,82{83	type Success = AccountId;8485	fn try_origin(o: O) -> Result<Self::Success, O> {86		o.into().and_then(|o| match o {87			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),88			o => Err(O::from(o)),89		})90	}9192	#[cfg(feature = "runtime-benchmarks")]93	fn try_successful_origin() -> Result<O, ()> {94		Ok(O::from(GovOrigins::FellowshipProposition))95	}96}9798pub type FellowshipAddOrigin<AccountId> = EitherOf<99	EnsureRoot<AccountId>,100	EitherOf<101		MapSuccess<TechnicalCommitteeMember, ReplaceWithDefault<()>>,102		MapSuccess<CouncilMember, ReplaceWithDefault<()>>,103	>,104>;105106pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<107	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,108	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,109>;110111pub struct TracksInfo;112impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {113	type Id = u16;114	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;115	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {116		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(117			DEMOCRACY_TRACK_ID,118			pallet_referenda::TrackInfo {119				name: "democracy_proposals",120				max_deciding: 10,121				decision_deposit: 10 * UNIQUE,122				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,123				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,124				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,125				min_enactment_period:126					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,127				min_approval: pallet_referenda::Curve::LinearDecreasing {128					length: Perbill::from_percent(100),129					floor: Perbill::from_percent(50),130					ceil: Perbill::from_percent(100),131				},132				min_support: pallet_referenda::Curve::LinearDecreasing {133					length: Perbill::from_percent(100),134					floor: Perbill::from_percent(0),135					ceil: Perbill::from_percent(50),136				},137			},138		)];139		&DATA[..]140	}141	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {142		#[cfg(feature = "runtime-benchmarks")]143		{144			// For benchmarks, we enable a root origin.145			// It is important that this is not available in production!146			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();147			if &root == id {148				return Ok(9);149			}150		}151152		match GovOrigins::try_from(id.clone()) {153			Ok(_) => Ok(DEMOCRACY_TRACK_ID),154			_ => Err(()),155		}156	}157}158159pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);160161pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);162163//TODO: Remove the type when it appears in the release.164pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;165166impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>167where168	T: RankedConfig<I>,169	ClassOf<T, I>: Into<Rank>,170{171	fn convert(track_id: ClassOf<T, I>) -> Rank {172		match track_id.into() {173			DEMOCRACY_TRACK_ID => 3,174			other => other,175		}176	}177}