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

            
21
const fn percent(x: u128) -> sp_arithmetic::FixedI64 {
22
    sp_arithmetic::FixedI64::from_rational(x, 100)
23
}
24
use pallet_referenda::{Curve, Track};
25
use runtime_common::prod_or_fast;
26
use sp_runtime::str_array as s;
27
const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
28
const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
29
const APP_WHITELISTED_CALLER: Curve =
30
    Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
31
const SUP_WHITELISTED_CALLER: Curve =
32
    Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));
33

            
34
const TRACKS_DATA: [pallet_referenda::Track<u16, Balance, BlockNumber>; 2] = [
35
    pallet_referenda::Track {
36
        id: 0,
37
        info: pallet_referenda::TrackInfo {
38
            name: s("root"),
39
            max_deciding: 1,
40
            decision_deposit: 500 * GRAND,
41
            prepare_period: prod_or_fast!(1 * DAYS, 8 * MINUTES),
42
            decision_period: prod_or_fast!(14 * DAYS, 20 * MINUTES),
43
            confirm_period: prod_or_fast!(1 * DAYS, 12 * MINUTES),
44
            min_enactment_period: prod_or_fast!(1 * DAYS, 5 * MINUTES),
45
            min_approval: APP_ROOT,
46
            min_support: SUP_ROOT,
47
        },
48
    },
49
    pallet_referenda::Track {
50
        id: 1,
51
        info: pallet_referenda::TrackInfo {
52
            name: s("whitelisted_caller"),
53
            max_deciding: 100,
54
            decision_deposit: 10 * GRAND,
55
            prepare_period: 10 * MINUTES,
56
            decision_period: 14 * DAYS,
57
            confirm_period: 10 * MINUTES,
58
            min_enactment_period: 30 * MINUTES,
59
            min_approval: APP_WHITELISTED_CALLER,
60
            min_support: SUP_WHITELISTED_CALLER,
61
        },
62
    },
63
];
64

            
65
pub struct TracksInfo;
66
#[allow(unreachable_patterns)]
67
// Allow unreachable patterns for potentially future origin tracks
68
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
69
    type Id = u16;
70
    type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
71
28
    fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, Balance, BlockNumber, 25>>> {
72
28
        TRACKS_DATA.iter().map(Cow::Borrowed)
73
28
    }
74
3
    fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
75
3
        if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
76
1
            match system_origin {
77
1
                frame_system::RawOrigin::Root => Ok(0),
78
                _ => Err(()),
79
            }
80
2
        } else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) {
81
2
            match custom_origin {
82
2
                origins::Origin::WhitelistedCaller => Ok(1),
83
                _ => Err(()),
84
            }
85
        } else {
86
            Err(())
87
        }
88
3
    }
89
}