1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use {
18
    crate as container_chain_template_simple_runtime,
19
    crate::{
20
        dynamic_params::SEPOLIA_ETH_TESTNET_CHAIN_ID, AccountId, MaintenanceModeConfig,
21
        MigrationsConfig, PolkadotXcmConfig,
22
    },
23
    alloc::{vec, vec::Vec},
24
    cumulus_primitives_core::ParaId,
25
    cumulus_primitives_core::{GlobalConsensus, Junctions::X1, Location, NetworkId},
26
    sp_keyring::Sr25519Keyring,
27
};
28

            
29
/// Orcherstrator's parachain id
30
pub const ORCHESTRATOR: ParaId = ParaId::new(1000);
31

            
32
pub fn local(
33
    endowed_accounts: Vec<AccountId>,
34
    id: ParaId,
35
    root_key: AccountId,
36
) -> serde_json::Value {
37
    testnet_genesis(endowed_accounts, id, root_key)
38
}
39

            
40
2
pub fn development(
41
2
    endowed_accounts: Vec<AccountId>,
42
2
    id: ParaId,
43
2
    root_key: AccountId,
44
2
) -> serde_json::Value {
45
2
    testnet_genesis(endowed_accounts, id, root_key)
46
2
}
47

            
48
2
fn testnet_genesis(
49
2
    endowed_accounts: Vec<AccountId>,
50
2
    id: ParaId,
51
2
    root_key: AccountId,
52
2
) -> serde_json::Value {
53
2
    let g = container_chain_template_simple_runtime::RuntimeGenesisConfig {
54
        balances: container_chain_template_simple_runtime::BalancesConfig {
55
2
            balances: endowed_accounts
56
2
                .iter()
57
2
                .cloned()
58
24
                .map(|k| (k, 1 << 60))
59
2
                .collect(),
60
2
            ..Default::default()
61
        },
62
2
        parachain_info: container_chain_template_simple_runtime::ParachainInfoConfig {
63
2
            parachain_id: id,
64
2
            ..Default::default()
65
2
        },
66
2
        parachain_system: Default::default(),
67
2
        sudo: container_chain_template_simple_runtime::SudoConfig {
68
2
            key: Some(root_key.clone()),
69
2
        },
70
2
        authorities_noting: container_chain_template_simple_runtime::AuthoritiesNotingConfig {
71
2
            orchestrator_para_id: ORCHESTRATOR,
72
2
            ..Default::default()
73
2
        },
74
2
        migrations: MigrationsConfig::default(),
75
2
        maintenance_mode: MaintenanceModeConfig {
76
2
            start_in_maintenance_mode: false,
77
2
            ..Default::default()
78
2
        },
79
2
        foreign_assets_creator: pallet_foreign_asset_creator::GenesisConfig {
80
2
            // foreign_asset, asset_id, admin, is_sufficient, min_balance
81
2
            assets: vec![
82
2
                // TANSSI
83
2
                (
84
2
                    Location::parent(), // native token of parent chain (orchestrator)
85
2
                    0xffff,             // TANSSI local asset id
86
2
                    root_key.clone(),
87
2
                    true,
88
2
                    1,
89
2
                ),
90
2
                // ETH
91
2
                (
92
2
                    Location {
93
2
                        parents: 2,
94
2
                        interior: X1([GlobalConsensus(NetworkId::Ethereum {
95
2
                            chain_id: SEPOLIA_ETH_TESTNET_CHAIN_ID,
96
2
                        })]
97
2
                        .into()),
98
2
                    },
99
2
                    0xfffe, // ETH local asset id
100
2
                    root_key,
101
2
                    true,
102
2
                    1,
103
2
                ),
104
2
            ],
105
2
        },
106
        // This should initialize it to whatever we have set in the pallet
107
2
        polkadot_xcm: PolkadotXcmConfig::default(),
108
2
        transaction_payment: Default::default(),
109
2
        tx_pause: Default::default(),
110
2
        system: Default::default(),
111
    };
112

            
113
2
    serde_json::to_value(g).unwrap()
114
2
}
115

            
116
/// Get pre-funded accounts
117
2
pub fn pre_funded_accounts() -> Vec<AccountId> {
118
2
    Sr25519Keyring::well_known()
119
24
        .map(|k| k.to_account_id())
120
2
        .collect()
121
2
}