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