1use super::Origin;
19use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, DOLLARS, HOURS};
20use sp_runtime::{str_array as s, Perbill};
21use sp_std::borrow::Cow;
22
23pub type TrackId = u16;
25
26pub mod constants {
28 use super::TrackId;
29
30 pub const AMBASSADOR_TIER_1: TrackId = 1;
31 pub const AMBASSADOR_TIER_2: TrackId = 2;
32 pub const SENIOR_AMBASSADOR_TIER_3: TrackId = 3;
33 pub const SENIOR_AMBASSADOR_TIER_4: TrackId = 4;
34 pub const HEAD_AMBASSADOR_TIER_5: TrackId = 5;
35 pub const HEAD_AMBASSADOR_TIER_6: TrackId = 6;
36 pub const HEAD_AMBASSADOR_TIER_7: TrackId = 7;
37 pub const MASTER_AMBASSADOR_TIER_8: TrackId = 8;
38 pub const MASTER_AMBASSADOR_TIER_9: TrackId = 9;
39}
40
41pub struct TracksInfo;
43
44impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
46 type Id = TrackId;
47
48 type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
49
50 fn tracks(
52 ) -> impl Iterator<Item = Cow<'static, pallet_referenda::Track<Self::Id, Balance, BlockNumber>>>
53 {
54 static DATA: [pallet_referenda::Track<TrackId, Balance, BlockNumber>; 9] = [
55 pallet_referenda::Track {
56 id: constants::AMBASSADOR_TIER_1,
57 info: pallet_referenda::TrackInfo {
58 name: s("ambassador tier 1"),
59 max_deciding: 10,
60 decision_deposit: 5 * DOLLARS,
61 prepare_period: 24 * HOURS,
62 decision_period: 1 * DAYS,
63 confirm_period: 24 * HOURS,
64 min_enactment_period: 1 * HOURS,
65 min_approval: pallet_referenda::Curve::LinearDecreasing {
66 length: Perbill::from_percent(100),
67 floor: Perbill::from_percent(50),
68 ceil: Perbill::from_percent(100),
69 },
70 min_support: pallet_referenda::Curve::LinearDecreasing {
71 length: Perbill::from_percent(100),
72 floor: Perbill::from_percent(10),
73 ceil: Perbill::from_percent(50),
74 },
75 },
76 },
77 pallet_referenda::Track {
78 id: constants::AMBASSADOR_TIER_2,
79 info: pallet_referenda::TrackInfo {
80 name: s("ambassador tier 2"),
81 max_deciding: 10,
82 decision_deposit: 5 * DOLLARS,
83 prepare_period: 24 * HOURS,
84 decision_period: 1 * DAYS,
85 confirm_period: 24 * HOURS,
86 min_enactment_period: 1 * HOURS,
87 min_approval: pallet_referenda::Curve::LinearDecreasing {
88 length: Perbill::from_percent(100),
89 floor: Perbill::from_percent(50),
90 ceil: Perbill::from_percent(100),
91 },
92 min_support: pallet_referenda::Curve::LinearDecreasing {
93 length: Perbill::from_percent(100),
94 floor: Perbill::from_percent(10),
95 ceil: Perbill::from_percent(50),
96 },
97 },
98 },
99 pallet_referenda::Track {
100 id: constants::SENIOR_AMBASSADOR_TIER_3,
101 info: pallet_referenda::TrackInfo {
102 name: s("senior ambassador tier 3"),
103 max_deciding: 10,
104 decision_deposit: 5 * DOLLARS,
105 prepare_period: 24 * HOURS,
106 decision_period: 1 * DAYS,
107 confirm_period: 24 * HOURS,
108 min_enactment_period: 1 * HOURS,
109 min_approval: pallet_referenda::Curve::LinearDecreasing {
110 length: Perbill::from_percent(100),
111 floor: Perbill::from_percent(50),
112 ceil: Perbill::from_percent(100),
113 },
114 min_support: pallet_referenda::Curve::LinearDecreasing {
115 length: Perbill::from_percent(100),
116 floor: Perbill::from_percent(10),
117 ceil: Perbill::from_percent(50),
118 },
119 },
120 },
121 pallet_referenda::Track {
122 id: constants::SENIOR_AMBASSADOR_TIER_4,
123 info: pallet_referenda::TrackInfo {
124 name: s("senior ambassador tier 4"),
125 max_deciding: 10,
126 decision_deposit: 5 * DOLLARS,
127 prepare_period: 24 * HOURS,
128 decision_period: 1 * DAYS,
129 confirm_period: 24 * HOURS,
130 min_enactment_period: 1 * HOURS,
131 min_approval: pallet_referenda::Curve::LinearDecreasing {
132 length: Perbill::from_percent(100),
133 floor: Perbill::from_percent(50),
134 ceil: Perbill::from_percent(100),
135 },
136 min_support: pallet_referenda::Curve::LinearDecreasing {
137 length: Perbill::from_percent(100),
138 floor: Perbill::from_percent(10),
139 ceil: Perbill::from_percent(50),
140 },
141 },
142 },
143 pallet_referenda::Track {
144 id: constants::HEAD_AMBASSADOR_TIER_5,
145 info: pallet_referenda::TrackInfo {
146 name: s("head ambassador tier 5"),
147 max_deciding: 10,
148 decision_deposit: 5 * DOLLARS,
149 prepare_period: 24 * HOURS,
150 decision_period: 1 * DAYS,
151 confirm_period: 24 * HOURS,
152 min_enactment_period: 1 * HOURS,
153 min_approval: pallet_referenda::Curve::LinearDecreasing {
154 length: Perbill::from_percent(100),
155 floor: Perbill::from_percent(50),
156 ceil: Perbill::from_percent(100),
157 },
158 min_support: pallet_referenda::Curve::LinearDecreasing {
159 length: Perbill::from_percent(100),
160 floor: Perbill::from_percent(10),
161 ceil: Perbill::from_percent(50),
162 },
163 },
164 },
165 pallet_referenda::Track {
166 id: constants::HEAD_AMBASSADOR_TIER_6,
167 info: pallet_referenda::TrackInfo {
168 name: s("head ambassador tier 6"),
169 max_deciding: 10,
170 decision_deposit: 5 * DOLLARS,
171 prepare_period: 24 * HOURS,
172 decision_period: 1 * DAYS,
173 confirm_period: 24 * HOURS,
174 min_enactment_period: 1 * HOURS,
175 min_approval: pallet_referenda::Curve::LinearDecreasing {
176 length: Perbill::from_percent(100),
177 floor: Perbill::from_percent(50),
178 ceil: Perbill::from_percent(100),
179 },
180 min_support: pallet_referenda::Curve::LinearDecreasing {
181 length: Perbill::from_percent(100),
182 floor: Perbill::from_percent(10),
183 ceil: Perbill::from_percent(50),
184 },
185 },
186 },
187 pallet_referenda::Track {
188 id: constants::HEAD_AMBASSADOR_TIER_7,
189 info: pallet_referenda::TrackInfo {
190 name: s("head ambassador tier 7"),
191 max_deciding: 10,
192 decision_deposit: 5 * DOLLARS,
193 prepare_period: 24 * HOURS,
194 decision_period: 1 * DAYS,
195 confirm_period: 24 * HOURS,
196 min_enactment_period: 1 * HOURS,
197 min_approval: pallet_referenda::Curve::LinearDecreasing {
198 length: Perbill::from_percent(100),
199 floor: Perbill::from_percent(50),
200 ceil: Perbill::from_percent(100),
201 },
202 min_support: pallet_referenda::Curve::LinearDecreasing {
203 length: Perbill::from_percent(100),
204 floor: Perbill::from_percent(10),
205 ceil: Perbill::from_percent(50),
206 },
207 },
208 },
209 pallet_referenda::Track {
210 id: constants::MASTER_AMBASSADOR_TIER_8,
211 info: pallet_referenda::TrackInfo {
212 name: s("master ambassador tier 8"),
213 max_deciding: 10,
214 decision_deposit: 5 * DOLLARS,
215 prepare_period: 24 * HOURS,
216 decision_period: 1 * DAYS,
217 confirm_period: 24 * HOURS,
218 min_enactment_period: 1 * HOURS,
219 min_approval: pallet_referenda::Curve::LinearDecreasing {
220 length: Perbill::from_percent(100),
221 floor: Perbill::from_percent(50),
222 ceil: Perbill::from_percent(100),
223 },
224 min_support: pallet_referenda::Curve::LinearDecreasing {
225 length: Perbill::from_percent(100),
226 floor: Perbill::from_percent(10),
227 ceil: Perbill::from_percent(50),
228 },
229 },
230 },
231 pallet_referenda::Track {
232 id: constants::MASTER_AMBASSADOR_TIER_9,
233 info: pallet_referenda::TrackInfo {
234 name: s("master ambassador tier 9"),
235 max_deciding: 10,
236 decision_deposit: 5 * DOLLARS,
237 prepare_period: 24 * HOURS,
238 decision_period: 1 * DAYS,
239 confirm_period: 24 * HOURS,
240 min_enactment_period: 1 * HOURS,
241 min_approval: pallet_referenda::Curve::LinearDecreasing {
242 length: Perbill::from_percent(100),
243 floor: Perbill::from_percent(50),
244 ceil: Perbill::from_percent(100),
245 },
246 min_support: pallet_referenda::Curve::LinearDecreasing {
247 length: Perbill::from_percent(100),
248 floor: Perbill::from_percent(10),
249 ceil: Perbill::from_percent(50),
250 },
251 },
252 },
253 ];
254 DATA.iter().map(Cow::Borrowed)
255 }
256
257 fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
259 #[cfg(feature = "runtime-benchmarks")]
260 {
261 let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
264 if &root == id {
265 return Ok(constants::MASTER_AMBASSADOR_TIER_9)
266 }
267 }
268
269 match Origin::try_from(id.clone()) {
270 Ok(Origin::Ambassadors) => Ok(constants::AMBASSADOR_TIER_1),
271 Ok(Origin::AmbassadorsTier2) => Ok(constants::AMBASSADOR_TIER_2),
272 Ok(Origin::SeniorAmbassadors) => Ok(constants::SENIOR_AMBASSADOR_TIER_3),
273 Ok(Origin::SeniorAmbassadorsTier4) => Ok(constants::SENIOR_AMBASSADOR_TIER_4),
274 Ok(Origin::HeadAmbassadors) => Ok(constants::HEAD_AMBASSADOR_TIER_5),
275 Ok(Origin::HeadAmbassadorsTier6) => Ok(constants::HEAD_AMBASSADOR_TIER_6),
276 Ok(Origin::HeadAmbassadorsTier7) => Ok(constants::HEAD_AMBASSADOR_TIER_7),
277 Ok(Origin::MasterAmbassadors) => Ok(constants::MASTER_AMBASSADOR_TIER_8),
278 Ok(Origin::MasterAmbassadorsTier9) => Ok(constants::MASTER_AMBASSADOR_TIER_9),
279 _ => Err(()),
280 }
281 }
282}