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