1use pallet_gov_origins::Origin as GovOrigins;2use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};34use super::*;5use crate::{6 FellowshipReferenda, Preimage, Runtime, RuntimeCall, RuntimeEvent, Scheduler, Treasury,7};89pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");10pub const DEMOCRACY_TRACK_ID: u16 = 10;1112parameter_types! {13 pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();14 pub AlarmInterval: BlockNumber = 1;15 pub SubmissionDeposit: Balance = 1000;16}1718#[cfg(not(feature = "gov-test-timings"))]19use crate::governance_timings::fellowship as fellowship_timings;2021#[cfg(feature = "gov-test-timings")]22pub mod fellowship_timings {23 use super::*;2425 parameter_types! {26 pub UndecidingTimeout: BlockNumber = 35;27 }2829 pub mod track {30 use super::*;3132 pub mod democracy_proposals {33 use super::*;3435 pub const PREPARE_PERIOD: BlockNumber = 3;36 pub const DECISION_PERIOD: BlockNumber = 35;37 pub const CONFIRM_PERIOD: BlockNumber = 3;38 pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;39 }40 }41}4243impl pallet_referenda::Config for Runtime {44 type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;45 type RuntimeCall = RuntimeCall;46 type RuntimeEvent = RuntimeEvent;47 type Scheduler = Scheduler;48 type Currency = Balances;49 type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;50 type CancelOrigin = RootOrAllTechnicalCommittee;51 type KillOrigin = RootOrAllTechnicalCommittee;52 type Slash = Treasury;53 type Votes = pallet_ranked_collective::Votes;54 type Tally = pallet_ranked_collective::TallyOf<Runtime>;55 type SubmissionDeposit = SubmissionDeposit;56 type MaxQueued = ConstU32<100>;57 type UndecidingTimeout = fellowship_timings::UndecidingTimeout;58 type AlarmInterval = AlarmInterval;59 type Tracks = TracksInfo;60 type Preimages = Preimage;61}6263impl RankedConfig for Runtime {64 type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;65 type RuntimeEvent = RuntimeEvent;66 67 68 69 type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;70 71 72 73 type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;74 type Polls = FellowshipReferenda;75 type MinRankOfClass = ClassToRankMapper<Self, ()>;76 type VoteWeight = pallet_ranked_collective::Geometric;77}7879pub struct EnsureFellowshipProposition;80impl<O> EnsureOrigin<O> for EnsureFellowshipProposition81where82 O: Into<Result<GovOrigins, O>> + From<GovOrigins>,83{84 type Success = AccountId;8586 fn try_origin(o: O) -> Result<Self::Success, O> {87 o.into().and_then(|o| match o {88 GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),89 o => Err(O::from(o)),90 })91 }9293 #[cfg(feature = "runtime-benchmarks")]94 fn try_successful_origin() -> Result<O, ()> {95 Ok(O::from(GovOrigins::FellowshipProposition))96 }97}9899pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<100 MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,101 MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,102>;103104pub struct TracksInfo;105impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {106 type Id = u16;107 type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;108 fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {109 static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(110 DEMOCRACY_TRACK_ID,111 pallet_referenda::TrackInfo {112 name: "democracy_proposals",113 max_deciding: 10,114 decision_deposit: 10 * UNIQUE,115 prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,116 decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,117 confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,118 min_enactment_period:119 fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,120 min_approval: pallet_referenda::Curve::LinearDecreasing {121 length: Perbill::from_percent(100),122 floor: Perbill::from_percent(50),123 ceil: Perbill::from_percent(100),124 },125 min_support: pallet_referenda::Curve::LinearDecreasing {126 length: Perbill::from_percent(100),127 floor: Perbill::from_percent(0),128 ceil: Perbill::from_percent(50),129 },130 },131 )];132 &DATA[..]133 }134 fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {135 #[cfg(feature = "runtime-benchmarks")]136 {137 138 139 let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();140 if &root == id {141 return Ok(9);142 }143 }144145 match GovOrigins::try_from(id.clone()) {146 Ok(_) => Ok(DEMOCRACY_TRACK_ID),147 _ => Err(()),148 }149 }150}151152pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);153154pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);155156157pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;158159impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>160where161 T: RankedConfig<I>,162 ClassOf<T, I>: Into<Rank>,163{164 fn convert(track_id: ClassOf<T, I>) -> Rank {165 match track_id.into() {166 DEMOCRACY_TRACK_ID => 3,167 other => other,168 }169 }170}