referrerpolicy=no-referrer-when-downgrade

asset_hub_rococo_runtime/
genesis_config_presets.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! # Asset Hub Rococo Runtime genesis config presets
17
18use crate::{
19	xcm_config::{bridging::to_westend::WestendNetwork, UniversalLocation},
20	*,
21};
22use alloc::{vec, vec::Vec};
23use cumulus_primitives_core::ParaId;
24use frame_support::build_struct_json_patch;
25use hex_literal::hex;
26use parachains_common::{AccountId, AuraId};
27use sp_core::crypto::UncheckedInto;
28use sp_genesis_builder::PresetId;
29use sp_keyring::Sr25519Keyring;
30use testnet_parachains_constants::rococo::{currency::UNITS as ROC, xcm_version::SAFE_XCM_VERSION};
31use xcm::latest::prelude::*;
32use xcm_builder::GlobalConsensusConvertsFor;
33use xcm_executor::traits::ConvertLocation;
34
35const ASSET_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get();
36
37fn asset_hub_rococo_genesis(
38	invulnerables: Vec<(AccountId, AuraId)>,
39	endowed_accounts: Vec<AccountId>,
40	endowment: Balance,
41	id: ParaId,
42	foreign_assets: Vec<(Location, AccountId, Balance)>,
43	foreign_assets_endowed_accounts: Vec<(Location, AccountId, Balance)>,
44) -> serde_json::Value {
45	build_struct_json_patch!(RuntimeGenesisConfig {
46		balances: BalancesConfig {
47			balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
48		},
49		parachain_info: ParachainInfoConfig { parachain_id: id },
50		collator_selection: CollatorSelectionConfig {
51			invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
52			candidacy_bond: ASSET_HUB_ROCOCO_ED * 16,
53		},
54		session: SessionConfig {
55			keys: invulnerables
56				.into_iter()
57				.map(|(acc, aura)| {
58					(
59						acc.clone(),          // account id
60						acc,                  // validator id
61						SessionKeys { aura }, // session keys
62					)
63				})
64				.collect(),
65		},
66		polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
67		foreign_assets: ForeignAssetsConfig {
68			assets: foreign_assets
69				.into_iter()
70				.map(|asset| (asset.0.try_into().unwrap(), asset.1, false, asset.2))
71				.collect(),
72			accounts: foreign_assets_endowed_accounts
73				.into_iter()
74				.map(|asset| (asset.0.try_into().unwrap(), asset.1, asset.2))
75				.collect(),
76			..Default::default()
77		},
78	})
79}
80
81/// Encapsulates names of predefined presets.
82mod preset_names {
83	pub const PRESET_GENESIS: &str = "genesis";
84}
85
86/// Provides the JSON representation of predefined genesis config for given `id`.
87pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
88	use preset_names::*;
89	let patch = match id.as_ref() {
90		PRESET_GENESIS => asset_hub_rococo_genesis(
91			// initial collators.
92			vec![
93				// E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG
94				(
95					hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608").into(),
96					hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608")
97						.unchecked_into(),
98				),
99				// G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri
100				(
101					hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944").into(),
102					hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944")
103						.unchecked_into(),
104				),
105				// G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c
106				(
107					hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948").into(),
108					hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948")
109						.unchecked_into(),
110				),
111				// GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt
112				(
113					hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f").into(),
114					hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f")
115						.unchecked_into(),
116				),
117			],
118			Vec::new(),
119			ASSET_HUB_ROCOCO_ED * 524_288,
120			1000.into(),
121			vec![],
122			vec![],
123		),
124		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET =>
125			asset_hub_rococo_genesis(
126				// initial collators.
127				vec![
128					(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
129					(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
130				],
131				Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(),
132				testnet_parachains_constants::rococo::currency::UNITS * 1_000_000,
133				1000.into(),
134				vec![
135			// bridged WND
136			(
137				Location::new(2, [GlobalConsensus(WestendNetwork::get())]),
138				GlobalConsensusConvertsFor::<UniversalLocation, AccountId>::convert_location(
139					&Location { parents: 2, interior: [GlobalConsensus(WestendNetwork::get())].into() },
140				)
141				.unwrap(),
142				10_000_000,
143			),
144			],
145				vec![
146					// bridged WND to Bob
147					(
148						Location::new(2, [GlobalConsensus(WestendNetwork::get())]),
149						Sr25519Keyring::Bob.to_account_id(),
150						10_000_000 * 4096 * 4096,
151					),
152				],
153			),
154		sp_genesis_builder::DEV_RUNTIME_PRESET => asset_hub_rococo_genesis(
155			// initial collators.
156			vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())],
157			vec![
158				Sr25519Keyring::Alice.to_account_id(),
159				Sr25519Keyring::Bob.to_account_id(),
160				Sr25519Keyring::AliceStash.to_account_id(),
161				Sr25519Keyring::BobStash.to_account_id(),
162			],
163			ROC * 1_000_000,
164			1000.into(),
165			vec![],
166			vec![],
167		),
168		_ => return None,
169	};
170
171	Some(
172		serde_json::to_string(&patch)
173			.expect("serialization to json is expected to work. qed.")
174			.into_bytes(),
175	)
176}
177
178/// List of supported presets.
179pub fn preset_names() -> Vec<PresetId> {
180	use preset_names::*;
181	vec![
182		PresetId::from(PRESET_GENESIS),
183		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
184		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
185	]
186}