referrerpolicy=no-referrer-when-downgrade

westend_runtime/governance/
tracks.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//! Track configurations for governance.
18
19use super::*;
20
21use alloc::borrow::Cow;
22use sp_runtime::str_array as s;
23
24const fn percent(x: i32) -> sp_arithmetic::FixedI64 {
25	sp_arithmetic::FixedI64::from_rational(x as u128, 100)
26}
27use pallet_referenda::Curve;
28const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
29const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
30const APP_STAKING_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
31const SUP_STAKING_ADMIN: Curve =
32	Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
33const APP_TREASURER: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
34const SUP_TREASURER: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
35const APP_FELLOWSHIP_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
36const SUP_FELLOWSHIP_ADMIN: Curve =
37	Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
38const APP_GENERAL_ADMIN: Curve =
39	Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
40const SUP_GENERAL_ADMIN: Curve =
41	Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50));
42const APP_AUCTION_ADMIN: Curve =
43	Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
44const SUP_AUCTION_ADMIN: Curve =
45	Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50));
46const APP_LEASE_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
47const SUP_LEASE_ADMIN: Curve = Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
48const APP_REFERENDUM_CANCELLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
49const SUP_REFERENDUM_CANCELLER: Curve =
50	Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
51const APP_REFERENDUM_KILLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
52const SUP_REFERENDUM_KILLER: Curve =
53	Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
54const APP_SMALL_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
55const SUP_SMALL_TIPPER: Curve = Curve::make_reciprocal(1, 28, percent(4), percent(0), percent(50));
56const APP_BIG_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
57const SUP_BIG_TIPPER: Curve = Curve::make_reciprocal(8, 28, percent(1), percent(0), percent(50));
58const APP_SMALL_SPENDER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
59const SUP_SMALL_SPENDER: Curve =
60	Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
61const APP_MEDIUM_SPENDER: Curve = Curve::make_linear(23, 28, percent(50), percent(100));
62const SUP_MEDIUM_SPENDER: Curve =
63	Curve::make_reciprocal(16, 28, percent(1), percent(0), percent(50));
64const APP_BIG_SPENDER: Curve = Curve::make_linear(28, 28, percent(50), percent(100));
65const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percent(0), percent(50));
66const APP_WHITELISTED_CALLER: Curve =
67	Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
68const SUP_WHITELISTED_CALLER: Curve =
69	Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));
70
71const TRACKS_DATA: [pallet_referenda::Track<u16, Balance, BlockNumber>; 15] = [
72	pallet_referenda::Track {
73		id: 0,
74		info: pallet_referenda::TrackInfo {
75			name: s("root"),
76			max_deciding: 1,
77			decision_deposit: 100 * GRAND,
78			prepare_period: 8 * MINUTES,
79			decision_period: 20 * MINUTES,
80			confirm_period: 12 * MINUTES,
81			min_enactment_period: 5 * MINUTES,
82			min_approval: APP_ROOT,
83			min_support: SUP_ROOT,
84		},
85	},
86	pallet_referenda::Track {
87		id: 1,
88		info: pallet_referenda::TrackInfo {
89			name: s("whitelisted_caller"),
90			max_deciding: 100,
91			decision_deposit: 10 * GRAND,
92			prepare_period: 6 * MINUTES,
93			decision_period: 20 * MINUTES,
94			confirm_period: 4 * MINUTES,
95			min_enactment_period: 3 * MINUTES,
96			min_approval: APP_WHITELISTED_CALLER,
97			min_support: SUP_WHITELISTED_CALLER,
98		},
99	},
100	pallet_referenda::Track {
101		id: 10,
102		info: pallet_referenda::TrackInfo {
103			name: s("staking_admin"),
104			max_deciding: 10,
105			decision_deposit: 5 * GRAND,
106			prepare_period: 8 * MINUTES,
107			decision_period: 20 * MINUTES,
108			confirm_period: 8 * MINUTES,
109			min_enactment_period: 3 * MINUTES,
110			min_approval: APP_STAKING_ADMIN,
111			min_support: SUP_STAKING_ADMIN,
112		},
113	},
114	pallet_referenda::Track {
115		id: 11,
116		info: pallet_referenda::TrackInfo {
117			name: s("treasurer"),
118			max_deciding: 10,
119			decision_deposit: 1 * GRAND,
120			prepare_period: 8 * MINUTES,
121			decision_period: 20 * MINUTES,
122			confirm_period: 8 * MINUTES,
123			min_enactment_period: 5 * MINUTES,
124			min_approval: APP_TREASURER,
125			min_support: SUP_TREASURER,
126		},
127	},
128	pallet_referenda::Track {
129		id: 12,
130		info: pallet_referenda::TrackInfo {
131			name: s("lease_admin"),
132			max_deciding: 10,
133			decision_deposit: 5 * GRAND,
134			prepare_period: 8 * MINUTES,
135			decision_period: 20 * MINUTES,
136			confirm_period: 8 * MINUTES,
137			min_enactment_period: 3 * MINUTES,
138			min_approval: APP_LEASE_ADMIN,
139			min_support: SUP_LEASE_ADMIN,
140		},
141	},
142	pallet_referenda::Track {
143		id: 13,
144		info: pallet_referenda::TrackInfo {
145			name: s("fellowship_admin"),
146			max_deciding: 10,
147			decision_deposit: 5 * GRAND,
148			prepare_period: 8 * MINUTES,
149			decision_period: 20 * MINUTES,
150			confirm_period: 8 * MINUTES,
151			min_enactment_period: 3 * MINUTES,
152			min_approval: APP_FELLOWSHIP_ADMIN,
153			min_support: SUP_FELLOWSHIP_ADMIN,
154		},
155	},
156	pallet_referenda::Track {
157		id: 14,
158		info: pallet_referenda::TrackInfo {
159			name: s("general_admin"),
160			max_deciding: 10,
161			decision_deposit: 5 * GRAND,
162			prepare_period: 8 * MINUTES,
163			decision_period: 20 * MINUTES,
164			confirm_period: 8 * MINUTES,
165			min_enactment_period: 3 * MINUTES,
166			min_approval: APP_GENERAL_ADMIN,
167			min_support: SUP_GENERAL_ADMIN,
168		},
169	},
170	pallet_referenda::Track {
171		id: 15,
172		info: pallet_referenda::TrackInfo {
173			name: s("auction_admin"),
174			max_deciding: 10,
175			decision_deposit: 5 * GRAND,
176			prepare_period: 8 * MINUTES,
177			decision_period: 20 * MINUTES,
178			confirm_period: 8 * MINUTES,
179			min_enactment_period: 3 * MINUTES,
180			min_approval: APP_AUCTION_ADMIN,
181			min_support: SUP_AUCTION_ADMIN,
182		},
183	},
184	pallet_referenda::Track {
185		id: 20,
186		info: pallet_referenda::TrackInfo {
187			name: s("referendum_canceller"),
188			max_deciding: 1_000,
189			decision_deposit: 10 * GRAND,
190			prepare_period: 8 * MINUTES,
191			decision_period: 14 * MINUTES,
192			confirm_period: 8 * MINUTES,
193			min_enactment_period: 3 * MINUTES,
194			min_approval: APP_REFERENDUM_CANCELLER,
195			min_support: SUP_REFERENDUM_CANCELLER,
196		},
197	},
198	pallet_referenda::Track {
199		id: 21,
200		info: pallet_referenda::TrackInfo {
201			name: s("referendum_killer"),
202			max_deciding: 1_000,
203			decision_deposit: 50 * GRAND,
204			prepare_period: 8 * MINUTES,
205			decision_period: 20 * MINUTES,
206			confirm_period: 8 * MINUTES,
207			min_enactment_period: 3 * MINUTES,
208			min_approval: APP_REFERENDUM_KILLER,
209			min_support: SUP_REFERENDUM_KILLER,
210		},
211	},
212	pallet_referenda::Track {
213		id: 30,
214		info: pallet_referenda::TrackInfo {
215			name: s("small_tipper"),
216			max_deciding: 200,
217			decision_deposit: 1 * 3 * CENTS,
218			prepare_period: 1 * MINUTES,
219			decision_period: 14 * MINUTES,
220			confirm_period: 4 * MINUTES,
221			min_enactment_period: 1 * MINUTES,
222			min_approval: APP_SMALL_TIPPER,
223			min_support: SUP_SMALL_TIPPER,
224		},
225	},
226	pallet_referenda::Track {
227		id: 31,
228		info: pallet_referenda::TrackInfo {
229			name: s("big_tipper"),
230			max_deciding: 100,
231			decision_deposit: 10 * 3 * CENTS,
232			prepare_period: 4 * MINUTES,
233			decision_period: 14 * MINUTES,
234			confirm_period: 12 * MINUTES,
235			min_enactment_period: 3 * MINUTES,
236			min_approval: APP_BIG_TIPPER,
237			min_support: SUP_BIG_TIPPER,
238		},
239	},
240	pallet_referenda::Track {
241		id: 32,
242		info: pallet_referenda::TrackInfo {
243			name: s("small_spender"),
244			max_deciding: 50,
245			decision_deposit: 100 * 3 * CENTS,
246			prepare_period: 10 * MINUTES,
247			decision_period: 20 * MINUTES,
248			confirm_period: 10 * MINUTES,
249			min_enactment_period: 5 * MINUTES,
250			min_approval: APP_SMALL_SPENDER,
251			min_support: SUP_SMALL_SPENDER,
252		},
253	},
254	pallet_referenda::Track {
255		id: 33,
256		info: pallet_referenda::TrackInfo {
257			name: s("medium_spender"),
258			max_deciding: 50,
259			decision_deposit: 200 * 3 * CENTS,
260			prepare_period: 10 * MINUTES,
261			decision_period: 20 * MINUTES,
262			confirm_period: 12 * MINUTES,
263			min_enactment_period: 5 * MINUTES,
264			min_approval: APP_MEDIUM_SPENDER,
265			min_support: SUP_MEDIUM_SPENDER,
266		},
267	},
268	pallet_referenda::Track {
269		id: 34,
270		info: pallet_referenda::TrackInfo {
271			name: s("big_spender"),
272			max_deciding: 50,
273			decision_deposit: 400 * 3 * CENTS,
274			prepare_period: 10 * MINUTES,
275			decision_period: 20 * MINUTES,
276			confirm_period: 14 * MINUTES,
277			min_enactment_period: 5 * MINUTES,
278			min_approval: APP_BIG_SPENDER,
279			min_support: SUP_BIG_SPENDER,
280		},
281	},
282];
283
284pub struct TracksInfo;
285impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
286	type Id = u16;
287	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
288
289	fn tracks(
290	) -> impl Iterator<Item = Cow<'static, pallet_referenda::Track<Self::Id, Balance, BlockNumber>>>
291	{
292		TRACKS_DATA.iter().map(Cow::Borrowed)
293	}
294	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
295		if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
296			match system_origin {
297				frame_system::RawOrigin::Root => Ok(0),
298				_ => Err(()),
299			}
300		} else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) {
301			match custom_origin {
302				origins::Origin::WhitelistedCaller => Ok(1),
303				// General admin
304				origins::Origin::StakingAdmin => Ok(10),
305				origins::Origin::Treasurer => Ok(11),
306				origins::Origin::LeaseAdmin => Ok(12),
307				origins::Origin::FellowshipAdmin => Ok(13),
308				origins::Origin::GeneralAdmin => Ok(14),
309				origins::Origin::AuctionAdmin => Ok(15),
310				// Referendum admins
311				origins::Origin::ReferendumCanceller => Ok(20),
312				origins::Origin::ReferendumKiller => Ok(21),
313				// Limited treasury spenders
314				origins::Origin::SmallTipper => Ok(30),
315				origins::Origin::BigTipper => Ok(31),
316				origins::Origin::SmallSpender => Ok(32),
317				origins::Origin::MediumSpender => Ok(33),
318				origins::Origin::BigSpender => Ok(34),
319				_ => Err(()),
320			}
321		} else {
322			Err(())
323		}
324	}
325}