referrerpolicy=no-referrer-when-downgrade

rococo_runtime/governance/
fellowship.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17//! Elements of governance concerning the Rococo Fellowship.
18
19use alloc::borrow::Cow;
20use frame_support::traits::{MapSuccess, TryMapSuccess};
21use pallet_referenda::{Track, TrackInfo};
22use sp_runtime::{
23	str_array as s,
24	traits::{CheckedReduceBy, ConstU16, Replace, ReplaceWithDefault},
25};
26
27use super::*;
28use crate::{CENTS, DAYS};
29
30parameter_types! {
31	pub const AlarmInterval: BlockNumber = 1;
32	pub const SubmissionDeposit: Balance = 0;
33	pub const UndecidingTimeout: BlockNumber = 7 * DAYS;
34}
35
36pub struct TracksInfo;
37impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
38	type Id = u16;
39	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
40
41	fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, Balance, BlockNumber>>> {
42		static DATA: [Track<u16, Balance, BlockNumber>; 10] = [
43			Track {
44				id: 0u16,
45				info: TrackInfo {
46					name: s("candidates"),
47					max_deciding: 10,
48					decision_deposit: 100 * 3 * CENTS,
49					prepare_period: 30 * MINUTES,
50					decision_period: 7 * DAYS,
51					confirm_period: 30 * MINUTES,
52					min_enactment_period: 1 * MINUTES,
53					min_approval: pallet_referenda::Curve::LinearDecreasing {
54						length: Perbill::from_percent(100),
55						floor: Perbill::from_percent(50),
56						ceil: Perbill::from_percent(100),
57					},
58					min_support: pallet_referenda::Curve::LinearDecreasing {
59						length: Perbill::from_percent(100),
60						floor: Perbill::from_percent(0),
61						ceil: Perbill::from_percent(50),
62					},
63				},
64			},
65			Track {
66				id: 1u16,
67				info: TrackInfo {
68					name: s("members"),
69					max_deciding: 10,
70					decision_deposit: 10 * 3 * CENTS,
71					prepare_period: 30 * MINUTES,
72					decision_period: 7 * DAYS,
73					confirm_period: 30 * MINUTES,
74					min_enactment_period: 1 * MINUTES,
75					min_approval: pallet_referenda::Curve::LinearDecreasing {
76						length: Perbill::from_percent(100),
77						floor: Perbill::from_percent(50),
78						ceil: Perbill::from_percent(100),
79					},
80					min_support: pallet_referenda::Curve::LinearDecreasing {
81						length: Perbill::from_percent(100),
82						floor: Perbill::from_percent(0),
83						ceil: Perbill::from_percent(50),
84					},
85				},
86			},
87			Track {
88				id: 2u16,
89				info: TrackInfo {
90					name: s("proficients"),
91					max_deciding: 10,
92					decision_deposit: 10 * 3 * CENTS,
93					prepare_period: 30 * MINUTES,
94					decision_period: 7 * DAYS,
95					confirm_period: 30 * MINUTES,
96					min_enactment_period: 1 * MINUTES,
97					min_approval: pallet_referenda::Curve::LinearDecreasing {
98						length: Perbill::from_percent(100),
99						floor: Perbill::from_percent(50),
100						ceil: Perbill::from_percent(100),
101					},
102					min_support: pallet_referenda::Curve::LinearDecreasing {
103						length: Perbill::from_percent(100),
104						floor: Perbill::from_percent(0),
105						ceil: Perbill::from_percent(50),
106					},
107				},
108			},
109			Track {
110				id: 3u16,
111				info: TrackInfo {
112					name: s("fellows"),
113					max_deciding: 10,
114					decision_deposit: 10 * 3 * CENTS,
115					prepare_period: 30 * MINUTES,
116					decision_period: 7 * DAYS,
117					confirm_period: 30 * MINUTES,
118					min_enactment_period: 1 * MINUTES,
119					min_approval: pallet_referenda::Curve::LinearDecreasing {
120						length: Perbill::from_percent(100),
121						floor: Perbill::from_percent(50),
122						ceil: Perbill::from_percent(100),
123					},
124					min_support: pallet_referenda::Curve::LinearDecreasing {
125						length: Perbill::from_percent(100),
126						floor: Perbill::from_percent(0),
127						ceil: Perbill::from_percent(50),
128					},
129				},
130			},
131			Track {
132				id: 4u16,
133				info: TrackInfo {
134					name: s("senior fellows"),
135					max_deciding: 10,
136					decision_deposit: 10 * 3 * CENTS,
137					prepare_period: 30 * MINUTES,
138					decision_period: 7 * DAYS,
139					confirm_period: 30 * MINUTES,
140					min_enactment_period: 1 * MINUTES,
141					min_approval: pallet_referenda::Curve::LinearDecreasing {
142						length: Perbill::from_percent(100),
143						floor: Perbill::from_percent(50),
144						ceil: Perbill::from_percent(100),
145					},
146					min_support: pallet_referenda::Curve::LinearDecreasing {
147						length: Perbill::from_percent(100),
148						floor: Perbill::from_percent(0),
149						ceil: Perbill::from_percent(50),
150					},
151				},
152			},
153			Track {
154				id: 5u16,
155				info: TrackInfo {
156					name: s("experts"),
157					max_deciding: 10,
158					decision_deposit: 1 * 3 * CENTS,
159					prepare_period: 30 * MINUTES,
160					decision_period: 7 * DAYS,
161					confirm_period: 30 * MINUTES,
162					min_enactment_period: 1 * MINUTES,
163					min_approval: pallet_referenda::Curve::LinearDecreasing {
164						length: Perbill::from_percent(100),
165						floor: Perbill::from_percent(50),
166						ceil: Perbill::from_percent(100),
167					},
168					min_support: pallet_referenda::Curve::LinearDecreasing {
169						length: Perbill::from_percent(100),
170						floor: Perbill::from_percent(0),
171						ceil: Perbill::from_percent(50),
172					},
173				},
174			},
175			Track {
176				id: 6u16,
177				info: TrackInfo {
178					name: s("senior experts"),
179					max_deciding: 10,
180					decision_deposit: 1 * 3 * CENTS,
181					prepare_period: 30 * MINUTES,
182					decision_period: 7 * DAYS,
183					confirm_period: 30 * MINUTES,
184					min_enactment_period: 1 * MINUTES,
185					min_approval: pallet_referenda::Curve::LinearDecreasing {
186						length: Perbill::from_percent(100),
187						floor: Perbill::from_percent(50),
188						ceil: Perbill::from_percent(100),
189					},
190					min_support: pallet_referenda::Curve::LinearDecreasing {
191						length: Perbill::from_percent(100),
192						floor: Perbill::from_percent(0),
193						ceil: Perbill::from_percent(50),
194					},
195				},
196			},
197			Track {
198				id: 7u16,
199				info: TrackInfo {
200					name: s("masters"),
201					max_deciding: 10,
202					decision_deposit: 1 * 3 * CENTS,
203					prepare_period: 30 * MINUTES,
204					decision_period: 7 * DAYS,
205					confirm_period: 30 * MINUTES,
206					min_enactment_period: 1 * MINUTES,
207					min_approval: pallet_referenda::Curve::LinearDecreasing {
208						length: Perbill::from_percent(100),
209						floor: Perbill::from_percent(50),
210						ceil: Perbill::from_percent(100),
211					},
212					min_support: pallet_referenda::Curve::LinearDecreasing {
213						length: Perbill::from_percent(100),
214						floor: Perbill::from_percent(0),
215						ceil: Perbill::from_percent(50),
216					},
217				},
218			},
219			Track {
220				id: 8u16,
221				info: TrackInfo {
222					name: s("senior masters"),
223					max_deciding: 10,
224					decision_deposit: 1 * 3 * CENTS,
225					prepare_period: 30 * MINUTES,
226					decision_period: 7 * DAYS,
227					confirm_period: 30 * MINUTES,
228					min_enactment_period: 1 * MINUTES,
229					min_approval: pallet_referenda::Curve::LinearDecreasing {
230						length: Perbill::from_percent(100),
231						floor: Perbill::from_percent(50),
232						ceil: Perbill::from_percent(100),
233					},
234					min_support: pallet_referenda::Curve::LinearDecreasing {
235						length: Perbill::from_percent(100),
236						floor: Perbill::from_percent(0),
237						ceil: Perbill::from_percent(50),
238					},
239				},
240			},
241			Track {
242				id: 9u16,
243				info: TrackInfo {
244					name: s("grand masters"),
245					max_deciding: 10,
246					decision_deposit: 1 * 3 * CENTS,
247					prepare_period: 30 * MINUTES,
248					decision_period: 7 * DAYS,
249					confirm_period: 30 * MINUTES,
250					min_enactment_period: 1 * MINUTES,
251					min_approval: pallet_referenda::Curve::LinearDecreasing {
252						length: Perbill::from_percent(100),
253						floor: Perbill::from_percent(50),
254						ceil: Perbill::from_percent(100),
255					},
256					min_support: pallet_referenda::Curve::LinearDecreasing {
257						length: Perbill::from_percent(100),
258						floor: Perbill::from_percent(0),
259						ceil: Perbill::from_percent(50),
260					},
261				},
262			},
263		];
264		DATA.iter().map(Cow::Borrowed)
265	}
266	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
267		use super::origins::Origin;
268
269		#[cfg(feature = "runtime-benchmarks")]
270		{
271			// For benchmarks, we enable a root origin.
272			// It is important that this is not available in production!
273			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
274			if &root == id {
275				return Ok(9)
276			}
277		}
278
279		match Origin::try_from(id.clone()) {
280			Ok(Origin::FellowshipInitiates) => Ok(0),
281			Ok(Origin::Fellowship1Dan) => Ok(1),
282			Ok(Origin::Fellowship2Dan) => Ok(2),
283			Ok(Origin::Fellowship3Dan) | Ok(Origin::Fellows) => Ok(3),
284			Ok(Origin::Fellowship4Dan) => Ok(4),
285			Ok(Origin::Fellowship5Dan) | Ok(Origin::FellowshipExperts) => Ok(5),
286			Ok(Origin::Fellowship6Dan) => Ok(6),
287			Ok(Origin::Fellowship7Dan | Origin::FellowshipMasters) => Ok(7),
288			Ok(Origin::Fellowship8Dan) => Ok(8),
289			Ok(Origin::Fellowship9Dan) => Ok(9),
290			_ => Err(()),
291		}
292	}
293}
294
295pub type FellowshipReferendaInstance = pallet_referenda::Instance2;
296
297impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
298	type WeightInfo = weights::pallet_referenda_fellowship_referenda::WeightInfo<Self>;
299	type RuntimeCall = RuntimeCall;
300	type RuntimeEvent = RuntimeEvent;
301	type Scheduler = Scheduler;
302	type Currency = Balances;
303	type SubmitOrigin =
304		pallet_ranked_collective::EnsureMember<Runtime, FellowshipCollectiveInstance, 1>;
305	type CancelOrigin = FellowshipExperts;
306	type KillOrigin = FellowshipMasters;
307	type Slash = Treasury;
308	type Votes = pallet_ranked_collective::Votes;
309	type Tally = pallet_ranked_collective::TallyOf<Runtime, FellowshipCollectiveInstance>;
310	type SubmissionDeposit = SubmissionDeposit;
311	type MaxQueued = ConstU32<100>;
312	type UndecidingTimeout = UndecidingTimeout;
313	type AlarmInterval = AlarmInterval;
314	type Tracks = TracksInfo;
315	type Preimages = Preimage;
316	type BlockNumberProvider = System;
317}
318
319pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;
320
321impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime {
322	type WeightInfo = weights::pallet_ranked_collective::WeightInfo<Self>;
323	type RuntimeEvent = RuntimeEvent;
324	// Adding is by any of:
325	// - Root.
326	// - the FellowshipAdmin origin.
327	// - a Fellowship origin.
328	type AddOrigin = MapSuccess<Self::PromoteOrigin, ReplaceWithDefault<()>>;
329	// Promotion is by any of:
330	// - Root can demote arbitrarily.
331	// - the FellowshipAdmin origin (i.e. token holder referendum);
332	// - a vote by the rank *above* the new rank.
333	type PromoteOrigin = EitherOf<
334		frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
335		EitherOf<
336			MapSuccess<FellowshipAdmin, Replace<ConstU16<9>>>,
337			TryMapSuccess<origins::EnsureFellowship, CheckedReduceBy<ConstU16<1>>>,
338		>,
339	>;
340	// Removing is by any of:
341	// - Root can remove arbitrarily.
342	// - the FellowshipAdmin origin (i.e. token holder referendum);
343	// - a vote by the rank two above the current rank.
344	type RemoveOrigin = Self::DemoteOrigin;
345	// Demotion is by any of:
346	// - Root can demote arbitrarily.
347	// - the FellowshipAdmin origin (i.e. token holder referendum);
348	// - a vote by the rank two above the current rank.
349	type DemoteOrigin = EitherOf<
350		frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
351		EitherOf<
352			MapSuccess<FellowshipAdmin, Replace<ConstU16<9>>>,
353			TryMapSuccess<origins::EnsureFellowship, CheckedReduceBy<ConstU16<2>>>,
354		>,
355	>;
356	// Exchange is by any of:
357	// - Root can exchange arbitrarily.
358	// - the Fellows origin;
359	type ExchangeOrigin =
360		EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Fellows>;
361	type Polls = FellowshipReferenda;
362	type MinRankOfClass = sp_runtime::traits::Identity;
363	type MemberSwappedHandler = ();
364	type VoteWeight = pallet_ranked_collective::Geometric;
365	type MaxMemberCount = ();
366	#[cfg(feature = "runtime-benchmarks")]
367	type BenchmarkSetup = ();
368}