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