git.delta.rocks / unique-network / refs/commits / bce2cc1e9ab8

difftreelog

source

runtime/common/config/governance/fellowship.rs5.3 KiBsourcehistory
1use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};2use super::*;3use pallet_gov_origins::Origin as GovOrigins;4use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};56pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");7pub const DEMOCRACY_TRACK_ID: u16 = 10;89parameter_types! {10	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();11	pub AlarmInterval: BlockNumber = 1;12	pub SubmissionDeposit: Balance = 1000;13}1415#[cfg(not(feature = "gov-test-timings"))]16use crate::governance_timings::fellowship as fellowship_timings;1718#[cfg(feature = "gov-test-timings")]19pub mod fellowship_timings {20	use super::*;2122	parameter_types! {23		pub UndecidingTimeout: BlockNumber = 35;24	}2526	pub mod track {27		use super::*;2829		pub mod democracy_proposals {30			use super::*;3132			pub const PREPARE_PERIOD: BlockNumber = 3;33			pub const DECISION_PERIOD: BlockNumber = 35;34			pub const CONFIRM_PERIOD: BlockNumber = 3;35			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;36		}37	}38}3940impl pallet_referenda::Config for Runtime {41	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;42	type RuntimeCall = RuntimeCall;43	type RuntimeEvent = RuntimeEvent;44	type Scheduler = Scheduler;45	type Currency = Balances;46	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;47	type CancelOrigin = RootOrAllTechnicalCommittee;48	type KillOrigin = RootOrAllTechnicalCommittee;49	type Slash = Treasury;50	type Votes = pallet_ranked_collective::Votes;51	type Tally = pallet_ranked_collective::TallyOf<Runtime>;52	type SubmissionDeposit = SubmissionDeposit;53	type MaxQueued = ConstU32<100>;54	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;55	type AlarmInterval = AlarmInterval;56	type Tracks = TracksInfo;57	type Preimages = Preimage;58}5960impl RankedConfig for Runtime {61	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;62	type RuntimeEvent = RuntimeEvent;63	// Promotion is by any of:64	// - Council member.65	// - Technical committee member.66	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;67	// Demotion is by any of:68	// - Council member.69	// - Technical committee member.70	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;71	type Polls = FellowshipReferenda;72	type MinRankOfClass = ClassToRankMapper<Self, ()>;73	type VoteWeight = pallet_ranked_collective::Geometric;74}7576pub struct EnsureFellowshipProposition;77impl<O> EnsureOrigin<O> for EnsureFellowshipProposition78where79	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,80{81	type Success = AccountId;8283	fn try_origin(o: O) -> Result<Self::Success, O> {84		o.into().and_then(|o| match o {85			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),86			o => Err(O::from(o)),87		})88	}8990	#[cfg(feature = "runtime-benchmarks")]91	fn try_successful_origin() -> Result<O, ()> {92		Ok(O::from(GovOrigins::FellowshipProposition))93	}94}9596pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<97	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,98	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,99>;100101pub struct TracksInfo;102impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {103	type Id = u16;104	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;105	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {106		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(107			DEMOCRACY_TRACK_ID,108			pallet_referenda::TrackInfo {109				name: "democracy_proposals",110				max_deciding: 10,111				decision_deposit: 10 * UNIQUE,112				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,113				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,114				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,115				min_enactment_period:116					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,117				min_approval: pallet_referenda::Curve::LinearDecreasing {118					length: Perbill::from_percent(100),119					floor: Perbill::from_percent(50),120					ceil: Perbill::from_percent(100),121				},122				min_support: pallet_referenda::Curve::LinearDecreasing {123					length: Perbill::from_percent(100),124					floor: Perbill::from_percent(0),125					ceil: Perbill::from_percent(50),126				},127			},128		)];129		&DATA[..]130	}131	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {132		#[cfg(feature = "runtime-benchmarks")]133		{134			// For benchmarks, we enable a root origin.135			// It is important that this is not available in production!136			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();137			if &root == id {138				return Ok(9);139			}140		}141142		match GovOrigins::try_from(id.clone()) {143			Ok(_) => Ok(DEMOCRACY_TRACK_ID),144			_ => Err(()),145		}146	}147}148149pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);150151pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);152153//TODO: Remove the type when it appears in the release.154pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;155156impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>157where158	T: RankedConfig<I>,159	ClassOf<T, I>: Into<Rank>,160{161	fn convert(track_id: ClassOf<T, I>) -> Rank {162		match track_id.into() {163			DEMOCRACY_TRACK_ID => 3,164			other => other,165		}166	}167}