astar_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::{evm::EVM_REVERT_CODE, genesis::GenesisAccount, parachain::ASTAR_ID};
21
22/// Provides the JSON representation of predefined genesis config for given `id`.
23pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
24    let genesis = match id.as_str() {
25        "development" => default_config(ASTAR_ID),
26        _ => return None,
27    };
28    Some(
29        serde_json::to_string(&genesis)
30            .expect("serialization to json is expected to work. qed.")
31            .into_bytes(),
32    )
33}
34
35/// Get the default genesis config for the Astar runtime.
36pub fn default_config(para_id: u32) -> serde_json::Value {
37    let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
38    let bob = GenesisAccount::<sr25519::Public>::from_seed("Bob");
39    let charlie = GenesisAccount::<sr25519::Public>::from_seed("Charlie");
40    let dave = GenesisAccount::<sr25519::Public>::from_seed("Dave");
41    let eve = GenesisAccount::<sr25519::Public>::from_seed("Eve");
42
43    let authorities = vec![&alice, &bob];
44    let accounts = vec![&alice, &bob, &charlie, &dave, &eve]
45        .iter()
46        .map(|x| x.account_id())
47        .collect::<Vec<_>>();
48
49    let balances = accounts
50        .iter()
51        .chain(
52            vec![
53                TreasuryPalletId::get().into_account_truncating(),
54                CommunityTreasuryPalletId::get().into_account_truncating(),
55            ]
56            .iter(),
57        )
58        .map(|x| (x.clone(), 1_000_000_000 * ASTR))
59        .collect::<Vec<_>>();
60
61    let slots_per_tier = vec![0, 6, 10, 0];
62    let tier_rank_multipliers: Vec<u32> = vec![0, 24_000, 46_700, 0];
63
64    let config = RuntimeGenesisConfig {
65        system: Default::default(),
66        #[cfg(feature = "astar-sudo")]
67        sudo: SudoConfig {
68            key: Some(alice.account_id()),
69        },
70        parachain_info: ParachainInfoConfig {
71            parachain_id: para_id.into(),
72            ..Default::default()
73        },
74        balances: BalancesConfig {
75            balances,
76            ..Default::default()
77        },
78        vesting: VestingConfig { vesting: vec![] },
79        session: SessionConfig {
80            keys: authorities
81                .iter()
82                .map(|x| {
83                    (
84                        x.account_id(),
85                        x.account_id(),
86                        SessionKeys {
87                            aura: x.pub_key().into(),
88                        },
89                    )
90                })
91                .collect::<Vec<_>>(),
92            ..Default::default()
93        },
94        aura: AuraConfig {
95            authorities: vec![],
96        },
97        aura_ext: Default::default(),
98        collator_selection: CollatorSelectionConfig {
99            desired_candidates: 32,
100            candidacy_bond: 3_200_000 * ASTR,
101            invulnerables: authorities
102                .iter()
103                .map(|x| x.account_id())
104                .collect::<Vec<_>>(),
105        },
106        evm: EVMConfig {
107            // We need _some_ code inserted at the precompile address so that
108            // the evm will actually call the address.
109            accounts: Precompiles::used_addresses_h160()
110                .map(|addr| {
111                    (
112                        addr,
113                        fp_evm::GenesisAccount {
114                            nonce: Default::default(),
115                            balance: Default::default(),
116                            storage: Default::default(),
117                            code: EVM_REVERT_CODE.into(),
118                        },
119                    )
120                })
121                .collect(),
122            ..Default::default()
123        },
124        ethereum: Default::default(),
125        polkadot_xcm: Default::default(),
126        assets: Default::default(),
127        parachain_system: Default::default(),
128        transaction_payment: Default::default(),
129        dapp_staking: DappStakingConfig {
130            reward_portion: vec![
131                Permill::from_percent(0),
132                Permill::from_percent(70),
133                Permill::from_percent(30),
134                Permill::from_percent(0),
135            ],
136            slot_distribution: vec![
137                Permill::from_percent(0),
138                Permill::from_parts(375_000), // 37.5%
139                Permill::from_parts(625_000), // 62.5%
140                Permill::from_percent(0),
141            ],
142            // percentages below are calculated based on a total issuance at the time when dApp staking v3 was revamped (8.6B)
143            tier_thresholds: vec![
144                TierThreshold::FixedPercentage {
145                    required_percentage: Perbill::from_parts(23_200_000), // 2.32%
146                },
147                TierThreshold::FixedPercentage {
148                    required_percentage: Perbill::from_parts(9_300_000), // 0.93%
149                },
150                TierThreshold::FixedPercentage {
151                    required_percentage: Perbill::from_parts(3_500_000), // 0.35%
152                },
153                // Tier 3: unreachable dummy
154                TierThreshold::FixedPercentage {
155                    required_percentage: Perbill::from_parts(0), // 0%
156                },
157            ],
158            slots_per_tier,
159            safeguard: Some(false),
160            tier_rank_multipliers,
161            ..Default::default()
162        },
163        inflation: Default::default(),
164
165        council_membership: CouncilMembershipConfig {
166            members: accounts
167                .clone()
168                .try_into()
169                .expect("Should support at least 5 members."),
170            phantom: Default::default(),
171        },
172        technical_committee_membership: TechnicalCommitteeMembershipConfig {
173            members: accounts[..3]
174                .to_vec()
175                .try_into()
176                .expect("Should support at least 3 members."),
177            phantom: Default::default(),
178        },
179        community_council_membership: CommunityCouncilMembershipConfig {
180            members: accounts
181                .try_into()
182                .expect("Should support at least 5 members."),
183            phantom: Default::default(),
184        },
185        council: Default::default(),
186        technical_committee: Default::default(),
187        community_council: Default::default(),
188        democracy: Default::default(),
189        treasury: Default::default(),
190        community_treasury: Default::default(),
191        safe_mode: Default::default(),
192        tx_pause: Default::default(),
193    };
194
195    serde_json::to_value(&config).expect("Could not build genesis config.")
196}