1use 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 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 type AddOrigin = MapSuccess<Self::PromoteOrigin, ReplaceWithDefault<()>>;
329 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 type RemoveOrigin = Self::DemoteOrigin;
345 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 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}