shiden_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::SHIDEN_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(SHIDEN_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 Shiden 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
40    let balances: Vec<(AccountId, Balance)> = vec![
41        (alice.account_id(), 1_000_000_000_000 * SDN),
42        (bob.account_id(), 1_000_000_000_000 * SDN),
43        (
44            TreasuryPalletId::get().into_account_truncating(),
45            1_000_000_000 * SDN,
46        ),
47    ];
48
49    let slots_per_tier = vec![0, 6, 10, 0];
50    let tier_rank_multipliers: Vec<u32> = vec![0, 24_000, 46_700, 0];
51
52    let authorities = vec![&alice, &bob];
53
54    let config = RuntimeGenesisConfig {
55        system: Default::default(),
56        sudo: SudoConfig {
57            key: Some(alice.account_id()),
58        },
59        parachain_info: ParachainInfoConfig {
60            parachain_id: para_id.into(),
61            ..Default::default()
62        },
63        balances: BalancesConfig {
64            balances,
65            ..Default::default()
66        },
67        vesting: VestingConfig { vesting: vec![] },
68        session: SessionConfig {
69            keys: authorities
70                .iter()
71                .map(|x| {
72                    (
73                        x.account_id(),
74                        x.account_id(),
75                        SessionKeys {
76                            aura: x.pub_key().into(),
77                        },
78                    )
79                })
80                .collect::<Vec<_>>(),
81            ..Default::default()
82        },
83        aura: AuraConfig {
84            authorities: vec![],
85        },
86        aura_ext: Default::default(),
87        collator_selection: CollatorSelectionConfig {
88            desired_candidates: 32,
89            candidacy_bond: 32_000 * SDN,
90            invulnerables: authorities
91                .iter()
92                .map(|x| x.account_id())
93                .collect::<Vec<_>>(),
94        },
95        evm: EVMConfig {
96            // We need _some_ code inserted at the precompile address so that
97            // the evm will actually call the address.
98            accounts: Precompiles::used_addresses_h160()
99                .map(|addr| {
100                    (
101                        addr,
102                        fp_evm::GenesisAccount {
103                            nonce: Default::default(),
104                            balance: Default::default(),
105                            storage: Default::default(),
106                            code: EVM_REVERT_CODE.into(),
107                        },
108                    )
109                })
110                .collect(),
111            ..Default::default()
112        },
113        ethereum: Default::default(),
114        polkadot_xcm: Default::default(),
115        assets: Default::default(),
116        parachain_system: Default::default(),
117        transaction_payment: Default::default(),
118        dapp_staking: DappStakingConfig {
119            reward_portion: vec![
120                Permill::from_percent(0),
121                Permill::from_percent(70),
122                Permill::from_percent(30),
123                Permill::from_percent(0),
124            ],
125            slot_distribution: vec![
126                Permill::from_percent(0),
127                Permill::from_parts(375_000), // 37.5%
128                Permill::from_parts(625_000), // 62.5%
129                Permill::from_percent(0),
130            ],
131            // percentages below are calculated based on a total issuance at the time when dApp staking v3 was revamped (8.6B)
132            tier_thresholds: vec![
133                TierThreshold::FixedPercentage {
134                    required_percentage: Perbill::from_parts(23_200_000), // 2.32%
135                },
136                TierThreshold::FixedPercentage {
137                    required_percentage: Perbill::from_parts(9_300_000), // 0.93%
138                },
139                TierThreshold::FixedPercentage {
140                    required_percentage: Perbill::from_parts(3_500_000), // 0.35%
141                },
142                // Tier 3: unreachable dummy
143                TierThreshold::FixedPercentage {
144                    required_percentage: Perbill::from_parts(0), // 0%
145                },
146            ],
147            slots_per_tier,
148            safeguard: Some(false),
149            tier_rank_multipliers,
150            ..Default::default()
151        },
152        inflation: Default::default(),
153    };
154
155    serde_json::to_value(&config).expect("Could not build genesis config.")
156}