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