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;7677 #[cfg(feature = "runtime-benchmarks")]78 type BenchmarkSetup = ();79}8081pub struct EnsureFellowshipProposition;82impl<O> EnsureOrigin<O> for EnsureFellowshipProposition83where84 O: Into<Result<GovOrigins, O>> + From<GovOrigins>,85{86 type Success = AccountId;8788 fn try_origin(o: O) -> Result<Self::Success, O> {89 o.into().and_then(|o| match o {90 GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),91 o => Err(O::from(o)),92 })93 }9495 #[cfg(feature = "runtime-benchmarks")]96 fn try_successful_origin() -> Result<O, ()> {97 Ok(O::from(GovOrigins::FellowshipProposition))98 }99}100101pub type FellowshipAddOrigin<AccountId> = EitherOf<102 EnsureRoot<AccountId>,103 EitherOf<104 MapSuccess<TechnicalCommitteeMember, ReplaceWithDefault<()>>,105 MapSuccess<CouncilMember, ReplaceWithDefault<()>>,106 >,107>;108109pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<110 MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,111 MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,112>;113114pub struct TracksInfo;115impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {116 type Id = u16;117 type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;118 fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {119 static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(120 DEMOCRACY_TRACK_ID,121 pallet_referenda::TrackInfo {122 name: "democracy_proposals",123 max_deciding: 10,124 decision_deposit: 10 * UNIQUE,125 prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,126 decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,127 confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,128 min_enactment_period:129 fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,130 min_approval: pallet_referenda::Curve::LinearDecreasing {131 length: Perbill::from_percent(100),132 floor: Perbill::from_percent(50),133 ceil: Perbill::from_percent(100),134 },135 min_support: pallet_referenda::Curve::LinearDecreasing {136 length: Perbill::from_percent(100),137 floor: Perbill::from_percent(0),138 ceil: Perbill::from_percent(50),139 },140 },141 )];142 &DATA[..]143 }144 fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {145 #[cfg(feature = "runtime-benchmarks")]146 {147 148 149 let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();150 if &root == id {151 return Ok(9);152 }153 }154155 match GovOrigins::try_from(id.clone()) {156 Ok(_) => Ok(DEMOCRACY_TRACK_ID),157 _ => Err(()),158 }159 }160}161162pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);163164pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);165166167pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;168169impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>170where171 T: RankedConfig<I>,172 ClassOf<T, I>: Into<Rank>,173{174 fn convert(track_id: ClassOf<T, I>) -> Rank {175 match track_id.into() {176 DEMOCRACY_TRACK_ID => 3,177 other => other,178 }179 }180}