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::{
21    dapp_staking::FIXED_TIER_SLOTS_ARGS, evm::EVM_REVERT_CODE, genesis::GenesisAccount,
22    parachain::ASTAR_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(ASTAR_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 Astar 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    let charlie = GenesisAccount::<sr25519::Public>::from_seed("Charlie");
43    let dave = GenesisAccount::<sr25519::Public>::from_seed("Dave");
44    let eve = GenesisAccount::<sr25519::Public>::from_seed("Eve");
45
46    let authorities = vec![&alice, &bob];
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            ]
59            .iter(),
60        )
61        .map(|x| (x.clone(), 1_000_000_000 * ASTR))
62        .collect::<Vec<_>>();
63
64    let slots_per_tier = vec![0, 6, 10, 0];
65    let tier_rank_multipliers: Vec<u32> = vec![0, 24_000, 46_700, 0];
66
67    let config = RuntimeGenesisConfig {
68        system: Default::default(),
69        #[cfg(feature = "astar-sudo")]
70        sudo: SudoConfig {
71            key: Some(alice.account_id()),
72        },
73        parachain_info: ParachainInfoConfig {
74            parachain_id: para_id.into(),
75            ..Default::default()
76        },
77        balances: BalancesConfig {
78            balances,
79            ..Default::default()
80        },
81        vesting: VestingConfig { vesting: vec![] },
82        session: SessionConfig {
83            keys: authorities
84                .iter()
85                .map(|x| {
86                    (
87                        x.account_id(),
88                        x.account_id(),
89                        SessionKeys {
90                            aura: x.pub_key().into(),
91                        },
92                    )
93                })
94                .collect::<Vec<_>>(),
95            ..Default::default()
96        },
97        aura: AuraConfig {
98            authorities: vec![],
99        },
100        aura_ext: Default::default(),
101        collator_selection: CollatorSelectionConfig {
102            desired_candidates: 32,
103            candidacy_bond: 3_200_000 * ASTR,
104            invulnerables: authorities
105                .iter()
106                .map(|x| x.account_id())
107                .collect::<Vec<_>>(),
108        },
109        evm: EVMConfig {
110            // We need _some_ code inserted at the precompile address so that
111            // the evm will actually call the address.
112            accounts: Precompiles::used_addresses_h160()
113                .map(|addr| {
114                    (
115                        addr,
116                        fp_evm::GenesisAccount {
117                            nonce: Default::default(),
118                            balance: Default::default(),
119                            storage: Default::default(),
120                            code: EVM_REVERT_CODE.into(),
121                        },
122                    )
123                })
124                .collect(),
125            ..Default::default()
126        },
127        ethereum: Default::default(),
128        polkadot_xcm: Default::default(),
129        assets: Default::default(),
130        parachain_system: Default::default(),
131        transaction_payment: Default::default(),
132        dapp_staking: DappStakingConfig {
133            reward_portion: vec![
134                Permill::from_percent(0),
135                Permill::from_percent(70),
136                Permill::from_percent(30),
137                Permill::from_percent(0),
138            ],
139            slot_distribution: vec![
140                Permill::from_percent(0),
141                Permill::from_parts(375_000), // 37.5%
142                Permill::from_parts(625_000), // 62.5%
143                Permill::from_percent(0),
144            ],
145            // percentages below are calculated based on a total issuance at the time when dApp staking v3 was revamped (8.6B)
146            tier_thresholds: vec![
147                TierThreshold::FixedPercentage {
148                    required_percentage: Perbill::from_parts(23_200_000), // 2.32%
149                },
150                TierThreshold::FixedPercentage {
151                    required_percentage: Perbill::from_parts(9_300_000), // 0.93%
152                },
153                TierThreshold::FixedPercentage {
154                    required_percentage: Perbill::from_parts(3_500_000), // 0.35%
155                },
156                // Tier 3: unreachable dummy
157                TierThreshold::FixedPercentage {
158                    required_percentage: Perbill::from_parts(0), // 0%
159                },
160            ],
161            slots_per_tier,
162            slot_number_args: FIXED_TIER_SLOTS_ARGS,
163            safeguard: Some(false),
164            tier_rank_multipliers,
165            ..Default::default()
166        },
167        inflation: Default::default(),
168        oracle_membership: OracleMembershipConfig {
169            members: vec![alice.account_id(), bob.account_id()]
170                .try_into()
171                .expect("Assumption is that at least two members will be allowed."),
172            ..Default::default()
173        },
174        price_aggregator: PriceAggregatorConfig {
175            circular_buffer: vec![CurrencyAmount::from_rational(5, 10)]
176                .try_into()
177                .expect("Must work since buffer should have at least a single value."),
178        },
179        council_membership: CouncilMembershipConfig {
180            members: accounts
181                .clone()
182                .try_into()
183                .expect("Should support at least 5 members."),
184            phantom: Default::default(),
185        },
186        technical_committee_membership: TechnicalCommitteeMembershipConfig {
187            members: accounts[..3]
188                .to_vec()
189                .try_into()
190                .expect("Should support at least 3 members."),
191            phantom: Default::default(),
192        },
193        community_council_membership: CommunityCouncilMembershipConfig {
194            members: accounts
195                .try_into()
196                .expect("Should support at least 5 members."),
197            phantom: Default::default(),
198        },
199        council: Default::default(),
200        technical_committee: Default::default(),
201        community_council: Default::default(),
202        democracy: Default::default(),
203        treasury: Default::default(),
204        community_treasury: Default::default(),
205        safe_mode: Default::default(),
206        tx_pause: Default::default(),
207    };
208
209    serde_json::to_value(&config).expect("Could not build genesis config.")
210}