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

            
19
use super::*;
20
use sp_runtime::str_array as s;
21
const fn percent(x: u128) -> sp_arithmetic::FixedI64 {
22
    sp_arithmetic::FixedI64::from_rational(x, 100)
23
}
24
use pallet_referenda::Curve;
25
const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
26
const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(20), percent(50));
27
const TRACKS_DATA: [pallet_referenda::Track<u16, Balance, BlockNumber>; 1] =
28
    [pallet_referenda::Track {
29
        id: 0,
30
        info: pallet_referenda::TrackInfo {
31
            name: s("root"),
32
            max_deciding: 1,
33
            decision_deposit: 500 * GRAND,
34
            prepare_period: 8 * MINUTES,
35
            decision_period: 20 * MINUTES,
36
            confirm_period: 12 * MINUTES,
37
            min_enactment_period: 5 * MINUTES,
38
            min_approval: APP_ROOT,
39
            min_support: SUP_ROOT,
40
        },
41
    }];
42

            
43
pub struct TracksInfo;
44
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
45
    type Id = u16;
46
    type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
47
1
    fn tracks(
48
1
    ) -> impl Iterator<Item = Cow<'static, pallet_referenda::Track<Self::Id, Balance, BlockNumber>>>
49
1
    {
50
1
        TRACKS_DATA.iter().map(Cow::Borrowed)
51
1
    }
52
    fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
53
        if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
54
            match system_origin {
55
                frame_system::RawOrigin::Root => Ok(0),
56
                _ => Err(()),
57
            }
58
        } else {
59
            Err(())
60
        }
61
    }
62
}