local_runtime/
genesis_config.rs

1// This file is part of Astar.
2
3// Copyright (C) Stake Technologies Pte.Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6// Astar is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// Astar is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with Astar. If not, see <http://www.gnu.org/licenses/>.
18
19use crate::*;
20use astar_primitives::{
21    evm::EVM_REVERT_CODE,
22    genesis::{get_from_seed, GenesisAccount},
23};
24use sp_core::crypto::Ss58Codec;
25
26/// Provides the JSON representation of predefined genesis config for given `id`.
27pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
28    let genesis = match id.as_str() {
29        "development" => default_config(),
30        _ => return None,
31    };
32    Some(
33        serde_json::to_string(&genesis)
34            .expect("serialization to json is expected to work. qed.")
35            .into_bytes(),
36    )
37}
38
39/// Get the default genesis config for the local runtime.
40pub fn default_config() -> serde_json::Value {
41    let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
42    let bob = GenesisAccount::<sr25519::Public>::from_seed("Bob");
43    let charlie = GenesisAccount::<sr25519::Public>::from_seed("Charlie");
44    let dave = GenesisAccount::<sr25519::Public>::from_seed("Dave");
45    let eve = GenesisAccount::<sr25519::Public>::from_seed("Eve");
46
47    let accounts = vec![&alice, &bob, &charlie, &dave, &eve]
48        .iter()
49        .map(|x| x.account_id())
50        .collect::<Vec<_>>();
51
52    let balances = accounts
53        .iter()
54        .chain(
55            vec![
56                TreasuryPalletId::get().into_account_truncating(),
57                CommunityTreasuryPalletId::get().into_account_truncating(),
58                // Private key: 0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391
59                // H160 public address: 0xaaafB3972B05630fCceE866eC69CdADd9baC2771
60                AccountId::from_ss58check("5FQedkNQcF2fJPwkB6Z1ZcMgGti4vcJQNs6x85YPv3VhjBBT")
61                    .expect("Invalid SS58 address"),
62            ]
63            .iter(),
64        )
65        .map(|x| (x.clone(), 1_000_000_000 * AST))
66        .collect::<Vec<_>>();
67
68    let config = RuntimeGenesisConfig {
69        system: Default::default(),
70        sudo: SudoConfig {
71            key: Some(alice.account_id()),
72        },
73        balances: BalancesConfig {
74            balances,
75            ..Default::default()
76        },
77        vesting: VestingConfig { vesting: vec![] },
78        aura: AuraConfig {
79            authorities: vec![get_from_seed::<AuraId>("Alice")],
80        },
81        grandpa: GrandpaConfig {
82            authorities: vec![(get_from_seed::<GrandpaId>("Alice"), 1)],
83            ..Default::default()
84        },
85        evm: EVMConfig {
86            // We need _some_ code inserted at the precompile address so that
87            // the evm will actually call the address.
88            accounts: Precompiles::used_addresses_h160()
89                .map(|addr| {
90                    (
91                        addr,
92                        fp_evm::GenesisAccount {
93                            nonce: Default::default(),
94                            balance: Default::default(),
95                            storage: Default::default(),
96                            code: EVM_REVERT_CODE.into(),
97                        },
98                    )
99                })
100                .collect(),
101            ..Default::default()
102        },
103        ethereum: Default::default(),
104        assets: Default::default(),
105        transaction_payment: Default::default(),
106        dapp_staking: DappStakingConfig {
107            reward_portion: vec![
108                Permill::from_percent(40),
109                Permill::from_percent(30),
110                Permill::from_percent(20),
111                Permill::from_percent(10),
112            ],
113            slot_distribution: vec![
114                Permill::from_percent(10),
115                Permill::from_percent(20),
116                Permill::from_percent(30),
117                Permill::from_percent(40),
118            ],
119            tier_thresholds: vec![
120                TierThreshold::DynamicPercentage {
121                    percentage: Perbill::from_parts(35_700_000), // 3.57%
122                    minimum_required_percentage: Perbill::from_parts(23_800_000), // 2.38%
123                    maximum_possible_percentage: Perbill::from_percent(100),
124                },
125                TierThreshold::DynamicPercentage {
126                    percentage: Perbill::from_parts(8_900_000), // 0.89%
127                    minimum_required_percentage: Perbill::from_parts(6_000_000), // 0.6%
128                    maximum_possible_percentage: Perbill::from_percent(100),
129                },
130                TierThreshold::DynamicPercentage {
131                    percentage: Perbill::from_parts(23_800_000), // 2.38%
132                    minimum_required_percentage: Perbill::from_parts(17_900_000), // 1.79%
133                    maximum_possible_percentage: Perbill::from_percent(100),
134                },
135                TierThreshold::FixedPercentage {
136                    required_percentage: Perbill::from_parts(600_000), // 0.06%
137                },
138            ],
139            slots_per_tier: vec![10, 20, 30, 40],
140            safeguard: Some(false),
141            ..Default::default()
142        },
143        inflation: InflationConfig {
144            params: InflationParameters {
145                max_inflation_rate: Perquintill::from_percent(7),
146                treasury_part: Perquintill::from_percent(5),
147                collators_part: Perquintill::from_percent(3),
148                dapps_part: Perquintill::from_percent(20),
149                base_stakers_part: Perquintill::from_percent(25),
150                adjustable_stakers_part: Perquintill::from_percent(35),
151                bonus_part: Perquintill::from_percent(12),
152                ideal_staking_rate: Perquintill::from_percent(50),
153                decay_rate: Perquintill::one(),
154            },
155            ..Default::default()
156        },
157        council_membership: CouncilMembershipConfig {
158            members: accounts
159                .clone()
160                .try_into()
161                .expect("Should support at least 5 members."),
162            phantom: Default::default(),
163        },
164        technical_committee_membership: TechnicalCommitteeMembershipConfig {
165            members: accounts[..3]
166                .to_vec()
167                .try_into()
168                .expect("Should support at least 3 members."),
169            phantom: Default::default(),
170        },
171        community_council_membership: CommunityCouncilMembershipConfig {
172            members: accounts
173                .try_into()
174                .expect("Should support at least 5 members."),
175            phantom: Default::default(),
176        },
177        council: Default::default(),
178        technical_committee: Default::default(),
179        community_council: Default::default(),
180        democracy: Default::default(),
181        treasury: Default::default(),
182        community_treasury: Default::default(),
183        safe_mode: Default::default(),
184        tx_pause: Default::default(),
185    };
186
187    serde_json::to_value(&config).expect("Could not build genesis config.")
188}