-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathgenesis_config.rs
204 lines (193 loc) · 7.8 KB
/
genesis_config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// This file is part of Astar.
// Copyright (C) Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.
use crate::*;
use astar_primitives::{evm::EVM_REVERT_CODE, genesis::GenesisAccount, parachain::SHIBUYA_ID};
/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
let genesis = match id.try_into() {
Ok("development") => default_config(SHIBUYA_ID),
_ => return None,
};
Some(
serde_json::to_string(&genesis)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
/// Get the default genesis config for the Shibuya runtime.
pub fn default_config(para_id: u32) -> serde_json::Value {
let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
let bob = GenesisAccount::<sr25519::Public>::from_seed("Bob");
let charlie = GenesisAccount::<sr25519::Public>::from_seed("Charlie");
let dave = GenesisAccount::<sr25519::Public>::from_seed("Dave");
let eve = GenesisAccount::<sr25519::Public>::from_seed("Eve");
let balances: Vec<(AccountId, Balance)> = vec![
(alice.account_id(), 1_000_000_000 * SBY),
(bob.account_id(), 1_000_000_000 * SBY),
(
TreasuryPalletId::get().into_account_truncating(),
1_000_000_000 * SBY,
),
(
CommunityTreasuryPalletId::get().into_account_truncating(),
1_000_000_000 * SBY,
),
];
let authorities = vec![&alice, &bob];
let accounts = vec![&alice, &bob, &charlie, &dave, &eve]
.iter()
.map(|x| x.account_id())
.collect::<Vec<_>>();
let config = RuntimeGenesisConfig {
system: Default::default(),
sudo: SudoConfig {
key: Some(alice.account_id()),
},
parachain_info: ParachainInfoConfig {
parachain_id: para_id.into(),
..Default::default()
},
balances: BalancesConfig { balances },
vesting: VestingConfig { vesting: vec![] },
session: SessionConfig {
keys: authorities
.iter()
.map(|x| {
(
x.account_id(),
x.account_id(),
SessionKeys {
aura: x.pub_key().into(),
},
)
})
.collect::<Vec<_>>(),
},
aura: AuraConfig {
authorities: vec![],
},
aura_ext: Default::default(),
collator_selection: CollatorSelectionConfig {
desired_candidates: 32,
candidacy_bond: 32_000 * SBY,
invulnerables: authorities
.iter()
.map(|x| x.account_id())
.collect::<Vec<_>>(),
},
evm: EVMConfig {
// We need _some_ code inserted at the precompile address so that
// the evm will actually call the address.
accounts: Precompiles::used_addresses_h160()
.map(|addr| {
(
addr,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: EVM_REVERT_CODE.into(),
},
)
})
.collect(),
..Default::default()
},
evm_chain_id: EVMChainIdConfig {
chain_id: 0x51,
..Default::default()
},
ethereum: Default::default(),
polkadot_xcm: Default::default(),
assets: Default::default(),
parachain_system: Default::default(),
transaction_payment: Default::default(),
dapp_staking: DappStakingConfig {
reward_portion: vec![
Permill::from_percent(40),
Permill::from_percent(30),
Permill::from_percent(20),
Permill::from_percent(10),
],
slot_distribution: vec![
Permill::from_percent(10),
Permill::from_percent(20),
Permill::from_percent(30),
Permill::from_percent(40),
],
// percentages below are calulated based on a total issuance at the time when dApp staking v3 was launched (147M)
tier_thresholds: vec![
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(20_000), // 0.0020%
minimum_required_percentage: Perbill::from_parts(17_000), // 0.0017%
},
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(13_000), // 0.0013%
minimum_required_percentage: Perbill::from_parts(10_000), // 0.0010%
},
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(5_400), // 0.00054%
minimum_required_percentage: Perbill::from_parts(3_400), // 0.00034%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(1_400), // 0.00014%
},
],
slots_per_tier: vec![10, 20, 30, 40],
safeguard: Some(false),
..Default::default()
},
inflation: Default::default(),
oracle_membership: OracleMembershipConfig {
members: vec![alice.account_id(), bob.account_id()]
.try_into()
.expect("Assumption is that at least two members will be allowed."),
..Default::default()
},
price_aggregator: PriceAggregatorConfig {
circular_buffer: vec![CurrencyAmount::from_rational(5, 10)]
.try_into()
.expect("Must work since buffer should have at least a single value."),
},
council_membership: CouncilMembershipConfig {
members: accounts
.clone()
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
technical_committee_membership: TechnicalCommitteeMembershipConfig {
members: accounts[..3]
.to_vec()
.try_into()
.expect("Should support at least 3 members."),
phantom: Default::default(),
},
community_council_membership: CommunityCouncilMembershipConfig {
members: accounts
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
council: Default::default(),
technical_committee: Default::default(),
community_council: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
};
serde_json::to_value(&config).expect("Could not build genesis config.")
}