14
14
// You should have received a copy of the GNU General Public License
15
15
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
17
- use sc_service:: ChainType ;
17
+ use sc_service:: { ChainType , Properties } ;
18
18
use sc_telemetry:: TelemetryEndpoints ;
19
+ use sp_core:: crypto:: Ss58Codec ;
19
20
use sp_core:: { sr25519, Pair , Public } ;
20
21
use sp_runtime:: traits:: { IdentifyAccount , Verify } ;
21
22
use subspace_runtime:: {
22
- AccountId , BalancesConfig , GenesisConfig , Signature , SubspaceConfig , SudoConfig , SystemConfig ,
23
- WASM_BINARY ,
23
+ AccountId , Balance , BalancesConfig , BlockNumber , GenesisConfig , Signature , SubspaceConfig ,
24
+ SudoConfig , SystemConfig , VestingConfig , MILLISECS_PER_BLOCK , SSC , WASM_BINARY ,
24
25
} ;
25
26
26
27
// The URL for the telemetry server.
27
28
const POLKADOT_TELEMETRY_URL : & str = "wss://telemetry.polkadot.io/submit/" ;
28
29
30
+ /// List of accounts which should receive token grants, amounts are specified in SSC.
31
+ const TOKEN_GRANTS : & [ ( & str , u128 ) ] = & [
32
+ (
33
+ "5Dns1SVEeDqnbSm2fVUqHJPCvQFXHVsgiw28uMBwmuaoKFYi" ,
34
+ 3_000_000 ,
35
+ ) ,
36
+ (
37
+ "5DxtHHQL9JGapWCQARYUAWj4yDcwuhg9Hsk5AjhEzuzonVyE" ,
38
+ 1_500_000 ,
39
+ ) ,
40
+ ( "5EHhw9xuQNdwieUkNoucq2YcateoMVJQdN8EZtmRy3roQkVK" , 133_333 ) ,
41
+ ( "5C5qYYCQBnanGNPGwgmv6jiR2MxNPrGnWYLPFEyV1Xdy2P3x" , 178_889 ) ,
42
+ ( "5GBWVfJ253YWVPHzWDTos1nzYZpa9TemP7FpQT9RnxaFN6Sz" , 350_000 ) ,
43
+ ( "5F9tEPid88uAuGbjpyegwkrGdkXXtaQ9sGSWEnYrfVCUCsen" , 111_111 ) ,
44
+ ( "5DkJFCv3cTBsH5y1eFT94DXMxQ3EmVzYojEA88o56mmTKnMp" , 244_444 ) ,
45
+ ( "5G23o1yxWgVNQJuL4Y9UaCftAFvLuMPCRe7BCARxCohjoHc9" , 311_111 ) ,
46
+ ( "5GhHwuJoK1b7uUg5oi8qUXxWHdfgzv6P5CQSdJ3ffrnPRgKM" , 317_378 ) ,
47
+ ( "5EqBwtqrCV427xCtTsxnb9X2Qay39pYmKNk9wD9Kd62jLS97" , 300_000 ) ,
48
+ ( "5D9pNnGCiZ9UqhBQn5n71WFVaRLvZ7znsMvcZ7PHno4zsiYa" , 600_000 ) ,
49
+ ( "5DXfPcXUcP4BG8LBSkJDrfFNApxjWySR6ARfgh3v27hdYr5S" , 430_000 ) ,
50
+ ( "5CXSdDJgzRTj54f9raHN2Z5BNPSMa2ETjqCTUmpaw3ECmwm4" , 330_000 ) ,
51
+ ( "5DqKxL7bQregQmUfFgzTMfRKY4DSvA1KgHuurZWYmxYSCmjY" , 200_000 ) ,
52
+ ( "5CfixiS93yTwHQbzzfn8P2tMxhKXdTx7Jam9htsD7XtiMFtn" , 27_800 ) ,
53
+ ( "5FZe9YzXeEXe7sK5xLR8yCmbU8bPJDTZpNpNbToKvSJBUiEo" , 18_067 ) ,
54
+ ( "5FZwEgsvZz1vpeH7UsskmNmTpbfXvAcojjgVfShgbRqgC1nx" , 27_800 ) ,
55
+ ] ;
56
+
29
57
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
30
58
pub type ChainSpec = sc_service:: GenericChainSpec < GenesisConfig > ;
31
59
@@ -39,11 +67,8 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
39
67
type AccountPublic = <Signature as Verify >:: Signer ;
40
68
41
69
/// Generate an account ID from seed.
42
- pub fn get_account_id_from_seed < TPublic : Public > ( seed : & str ) -> AccountId
43
- where
44
- AccountPublic : From < <TPublic :: Pair as Pair >:: Public > ,
45
- {
46
- AccountPublic :: from ( get_from_seed :: < TPublic > ( seed) ) . into_account ( )
70
+ pub fn get_account_id_from_seed ( seed : & str ) -> AccountId {
71
+ AccountPublic :: from ( get_from_seed :: < sr25519:: Public > ( seed) ) . into_account ( )
47
72
}
48
73
49
74
pub fn testnet_config ( ) -> Result < ChainSpec , String > {
@@ -53,19 +78,59 @@ pub fn testnet_config() -> Result<ChainSpec, String> {
53
78
// ID
54
79
"subspace_test" ,
55
80
ChainType :: Custom ( "Subspace testnet" . to_string ( ) ) ,
56
- // TODO: Provide a way for farmer to start with these accounts
57
81
|| {
58
- testnet_genesis (
82
+ let sudo_account =
83
+ AccountId :: from_ss58check ( "5CXTmJEusve5ixyJufqHThmy4qUrrm6FyLCR7QfE4bbyMTNC" )
84
+ . expect ( "Wrong root account address" ) ;
85
+
86
+ // Pre-funded accounts
87
+ // TODO: Remove these later, this is just for testing
88
+ let mut balances = vec ! [
89
+ ( sudo_account. clone( ) , 1_000 * SSC ) ,
90
+ ( get_account_id_from_seed( "Alice" ) , 1_000 * SSC ) ,
91
+ ( get_account_id_from_seed( "Bob" ) , 1_000 * SSC ) ,
92
+ ] ;
93
+ let vesting_schedules = TOKEN_GRANTS
94
+ . iter ( )
95
+ . flat_map ( |& ( account_address, amount) | {
96
+ let account_id = AccountId :: from_ss58check ( account_address)
97
+ . expect ( "Wrong vesting account address" ) ;
98
+ let amount: Balance = amount * SSC ;
99
+
100
+ // TODO: Adjust start block to real value before mainnet launch
101
+ let start_block = 100_000_000 ;
102
+ let one_month_in_blocks =
103
+ u32:: try_from ( 3600 * 24 * 30 * MILLISECS_PER_BLOCK / 1000 )
104
+ . expect ( "One month of blocks always fits in u32; qed" ) ;
105
+
106
+ // Add balance so it can be locked
107
+ balances. push ( ( account_id. clone ( ) , amount) ) ;
108
+
109
+ [
110
+ // 1/4 of tokens are released after 1 year.
111
+ (
112
+ account_id. clone ( ) ,
113
+ start_block,
114
+ one_month_in_blocks * 12 ,
115
+ 1 ,
116
+ amount / 4 ,
117
+ ) ,
118
+ // 1/48 of tokens are released every month after that for 3 more years.
119
+ (
120
+ account_id,
121
+ start_block + one_month_in_blocks * 12 ,
122
+ one_month_in_blocks,
123
+ 36 ,
124
+ amount / 48 ,
125
+ ) ,
126
+ ]
127
+ } )
128
+ . collect :: < Vec < _ > > ( ) ;
129
+ create_genesis_config (
59
130
WASM_BINARY . expect ( "Wasm binary must be built for testnet" ) ,
60
- // Sudo account
61
- get_account_id_from_seed :: < sr25519:: Public > ( "Alice" ) ,
62
- // Pre-funded accounts
63
- vec ! [
64
- get_account_id_from_seed:: <sr25519:: Public >( "Alice" ) ,
65
- get_account_id_from_seed:: <sr25519:: Public >( "Bob" ) ,
66
- get_account_id_from_seed:: <sr25519:: Public >( "Alice//stash" ) ,
67
- get_account_id_from_seed:: <sr25519:: Public >( "Bob//stash" ) ,
68
- ] ,
131
+ sudo_account,
132
+ balances,
133
+ vesting_schedules,
69
134
)
70
135
} ,
71
136
// Bootnodes
@@ -78,7 +143,16 @@ pub fn testnet_config() -> Result<ChainSpec, String> {
78
143
// Protocol ID
79
144
Some ( "subspace" ) ,
80
145
// Properties
81
- None ,
146
+ Some ( Properties :: from_iter ( [
147
+ (
148
+ "tokenDecimals" . to_string ( ) ,
149
+ serde_json:: to_value ( 18_u8 ) . expect ( "u8 is always serializable; qed" ) ,
150
+ ) ,
151
+ (
152
+ "tokenSymbol" . to_string ( ) ,
153
+ serde_json:: to_value ( "tSSC" ) . expect ( "&str is always serializable; qed" ) ,
154
+ ) ,
155
+ ] ) ) ,
82
156
// Extensions
83
157
None ,
84
158
) )
@@ -95,17 +169,18 @@ pub fn development_config() -> Result<ChainSpec, String> {
95
169
ChainType :: Development ,
96
170
// TODO: Provide a way for farmer to start with these accounts
97
171
|| {
98
- testnet_genesis (
172
+ create_genesis_config (
99
173
wasm_binary,
100
174
// Sudo account
101
- get_account_id_from_seed :: < sr25519 :: Public > ( "Alice" ) ,
175
+ get_account_id_from_seed ( "Alice" ) ,
102
176
// Pre-funded accounts
103
177
vec ! [
104
- get_account_id_from_seed:: <sr25519 :: Public > ( "Alice" ) ,
105
- get_account_id_from_seed:: <sr25519 :: Public > ( "Bob" ) ,
106
- get_account_id_from_seed:: <sr25519 :: Public > ( "Alice//stash" ) ,
107
- get_account_id_from_seed:: <sr25519 :: Public > ( "Bob//stash" ) ,
178
+ ( get_account_id_from_seed( "Alice" ) , 1_000 * SSC ) ,
179
+ ( get_account_id_from_seed( "Bob" ) , 1_000 * SSC ) ,
180
+ ( get_account_id_from_seed( "Alice//stash" ) , 1_000 * SSC ) ,
181
+ ( get_account_id_from_seed( "Bob//stash" ) , 1_000 * SSC ) ,
108
182
] ,
183
+ vec ! [ ] ,
109
184
)
110
185
} ,
111
186
// Bootnodes
@@ -131,25 +206,26 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
131
206
"local_testnet" ,
132
207
ChainType :: Local ,
133
208
|| {
134
- testnet_genesis (
209
+ create_genesis_config (
135
210
wasm_binary,
136
211
// Sudo account
137
- get_account_id_from_seed :: < sr25519 :: Public > ( "Alice" ) ,
212
+ get_account_id_from_seed ( "Alice" ) ,
138
213
// Pre-funded accounts
139
214
vec ! [
140
- get_account_id_from_seed:: <sr25519 :: Public > ( "Alice" ) ,
141
- get_account_id_from_seed:: <sr25519 :: Public > ( "Bob" ) ,
142
- get_account_id_from_seed:: <sr25519 :: Public > ( "Charlie" ) ,
143
- get_account_id_from_seed:: <sr25519 :: Public > ( "Dave" ) ,
144
- get_account_id_from_seed:: <sr25519 :: Public > ( "Eve" ) ,
145
- get_account_id_from_seed:: <sr25519 :: Public > ( "Ferdie" ) ,
146
- get_account_id_from_seed:: <sr25519 :: Public > ( "Alice//stash" ) ,
147
- get_account_id_from_seed:: <sr25519 :: Public > ( "Bob//stash" ) ,
148
- get_account_id_from_seed:: <sr25519 :: Public > ( "Charlie//stash" ) ,
149
- get_account_id_from_seed:: <sr25519 :: Public > ( "Dave//stash" ) ,
150
- get_account_id_from_seed:: <sr25519 :: Public > ( "Eve//stash" ) ,
151
- get_account_id_from_seed:: <sr25519 :: Public > ( "Ferdie//stash" ) ,
215
+ ( get_account_id_from_seed( "Alice" ) , 1_000 * SSC ) ,
216
+ ( get_account_id_from_seed( "Bob" ) , 1_000 * SSC ) ,
217
+ ( get_account_id_from_seed( "Charlie" ) , 1_000 * SSC ) ,
218
+ ( get_account_id_from_seed( "Dave" ) , 1_000 * SSC ) ,
219
+ ( get_account_id_from_seed( "Eve" ) , 1_000 * SSC ) ,
220
+ ( get_account_id_from_seed( "Ferdie" ) , 1_000 * SSC ) ,
221
+ ( get_account_id_from_seed( "Alice//stash" ) , 1_000 * SSC ) ,
222
+ ( get_account_id_from_seed( "Bob//stash" ) , 1_000 * SSC ) ,
223
+ ( get_account_id_from_seed( "Charlie//stash" ) , 1_000 * SSC ) ,
224
+ ( get_account_id_from_seed( "Dave//stash" ) , 1_000 * SSC ) ,
225
+ ( get_account_id_from_seed( "Eve//stash" ) , 1_000 * SSC ) ,
226
+ ( get_account_id_from_seed( "Ferdie//stash" ) , 1_000 * SSC ) ,
152
227
] ,
228
+ vec ! [ ] ,
153
229
)
154
230
} ,
155
231
// Bootnodes
@@ -166,31 +242,27 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
166
242
}
167
243
168
244
/// Configure initial storage state for FRAME modules.
169
- fn testnet_genesis (
245
+ fn create_genesis_config (
170
246
wasm_binary : & [ u8 ] ,
171
- root_key : AccountId ,
172
- endowed_accounts : Vec < AccountId > ,
247
+ sudo_account : AccountId ,
248
+ balances : Vec < ( AccountId , Balance ) > ,
249
+ // who, start, period, period_count, per_period
250
+ vesting : Vec < ( AccountId , BlockNumber , BlockNumber , u32 , Balance ) > ,
173
251
) -> GenesisConfig {
174
252
GenesisConfig {
175
253
system : SystemConfig {
176
254
// Add Wasm runtime to storage.
177
255
code : wasm_binary. to_vec ( ) ,
178
256
changes_trie_config : Default :: default ( ) ,
179
257
} ,
180
- balances : BalancesConfig {
181
- // Configure endowed accounts with initial balance of 1 << 60.
182
- balances : endowed_accounts
183
- . iter ( )
184
- . cloned ( )
185
- . map ( |k| ( k, 1 << 60 ) )
186
- . collect ( ) ,
187
- } ,
258
+ balances : BalancesConfig { balances } ,
188
259
subspace : SubspaceConfig {
189
260
epoch_config : Some ( subspace_runtime:: SUBSPACE_GENESIS_EPOCH_CONFIG ) ,
190
261
} ,
191
262
sudo : SudoConfig {
192
263
// Assign network admin rights.
193
- key : root_key ,
264
+ key : sudo_account ,
194
265
} ,
266
+ vesting : VestingConfig { vesting } ,
195
267
}
196
268
}
0 commit comments