@@ -205,14 +205,9 @@ pub(crate) async fn bench_process_command(
205
205
let ( owner_signer, owner) =
206
206
config. signer_or_default ( arg_matches, "owner" , wallet_manager) ;
207
207
signers. push ( owner_signer) ;
208
- let from = pubkey_of_signer ( arg_matches, "from" , wallet_manager)
209
- . unwrap ( )
210
- . unwrap_or_else ( || {
211
- get_associated_token_address_with_program_id ( & owner, & token, & config. program_id )
212
- } ) ;
213
-
208
+ let from = pubkey_of_signer ( arg_matches, "from" , wallet_manager) . unwrap ( ) ;
214
209
command_deposit_into_or_withdraw_from (
215
- config, signers, & token, n, & owner, ui_amount, & from, true ,
210
+ config, signers, & token, n, & owner, ui_amount, from, true ,
216
211
)
217
212
. await ?;
218
213
}
@@ -225,14 +220,9 @@ pub(crate) async fn bench_process_command(
225
220
let ( owner_signer, owner) =
226
221
config. signer_or_default ( arg_matches, "owner" , wallet_manager) ;
227
222
signers. push ( owner_signer) ;
228
- let to = pubkey_of_signer ( arg_matches, "to" , wallet_manager)
229
- . unwrap ( )
230
- . unwrap_or_else ( || {
231
- get_associated_token_address_with_program_id ( & owner, & token, & config. program_id )
232
- } ) ;
233
-
223
+ let to = pubkey_of_signer ( arg_matches, "to" , wallet_manager) . unwrap ( ) ;
234
224
command_deposit_into_or_withdraw_from (
235
- config, signers, & token, n, & owner, ui_amount, & to, false ,
225
+ config, signers, & token, n, & owner, ui_amount, to, false ,
236
226
)
237
227
. await ?;
238
228
}
@@ -266,15 +256,18 @@ fn get_token_addresses_with_seed(
266
256
. collect ( )
267
257
}
268
258
269
- async fn is_valid_token ( rpc_client : & RpcClient , token : & Pubkey ) -> Result < ( ) , Error > {
259
+ async fn get_valid_mint_program_id (
260
+ rpc_client : & RpcClient ,
261
+ token : & Pubkey ,
262
+ ) -> Result < Pubkey , Error > {
270
263
let mint_account = rpc_client
271
- . get_account_data ( token)
264
+ . get_account ( token)
272
265
. await
273
266
. map_err ( |err| format ! ( "Token mint {} does not exist: {}" , token, err) ) ?;
274
267
275
- Mint :: unpack ( & mint_account)
276
- . map ( |_| ( ) )
277
- . map_err ( |err| format ! ( "Invalid token mint {}: {}" , token , err ) . into ( ) )
268
+ Mint :: unpack ( & mint_account. data )
269
+ . map_err ( |err| format ! ( "Invalid token mint {}: {}" , token , err ) ) ? ;
270
+ Ok ( mint_account . owner )
278
271
}
279
272
280
273
async fn command_create_accounts (
@@ -287,16 +280,15 @@ async fn command_create_accounts(
287
280
let rpc_client = & config. rpc_client ;
288
281
289
282
println ! ( "Scanning accounts..." ) ;
290
- is_valid_token ( rpc_client, token) . await ?;
283
+ let program_id = get_valid_mint_program_id ( rpc_client, token) . await ?;
291
284
292
285
let minimum_balance_for_rent_exemption = rpc_client
293
286
. get_minimum_balance_for_rent_exemption ( Account :: get_packed_len ( ) )
294
287
. await ?;
295
288
296
289
let mut lamports_required = 0 ;
297
290
298
- let token_addresses_with_seed =
299
- get_token_addresses_with_seed ( & config. program_id , token, owner, n) ;
291
+ let token_addresses_with_seed = get_token_addresses_with_seed ( & program_id, token, owner, n) ;
300
292
let mut messages = vec ! [ ] ;
301
293
for address_chunk in token_addresses_with_seed. chunks ( 100 ) {
302
294
let accounts_chunk = rpc_client
@@ -315,9 +307,9 @@ async fn command_create_accounts(
315
307
seed,
316
308
minimum_balance_for_rent_exemption,
317
309
Account :: get_packed_len ( ) as u64 ,
318
- & config . program_id ,
310
+ & program_id,
319
311
) ,
320
- instruction:: initialize_account ( & config . program_id , address, token, owner) ?,
312
+ instruction:: initialize_account ( & program_id, address, token, owner) ?,
321
313
] ,
322
314
Some ( & config. fee_payer ) ,
323
315
) ) ;
@@ -338,10 +330,9 @@ async fn command_close_accounts(
338
330
let rpc_client = & config. rpc_client ;
339
331
340
332
println ! ( "Scanning accounts..." ) ;
341
- is_valid_token ( rpc_client, token) . await ?;
333
+ let program_id = get_valid_mint_program_id ( rpc_client, token) . await ?;
342
334
343
- let token_addresses_with_seed =
344
- get_token_addresses_with_seed ( & config. program_id , token, owner, n) ;
335
+ let token_addresses_with_seed = get_token_addresses_with_seed ( & program_id, token, owner, n) ;
345
336
let mut messages = vec ! [ ] ;
346
337
for address_chunk in token_addresses_with_seed. chunks ( 100 ) {
347
338
let accounts_chunk = rpc_client
@@ -360,7 +351,7 @@ async fn command_close_accounts(
360
351
} else {
361
352
messages. push ( Message :: new (
362
353
& [ instruction:: close_account (
363
- & config . program_id ,
354
+ & program_id,
364
355
address,
365
356
owner,
366
357
owner,
@@ -389,23 +380,21 @@ async fn command_deposit_into_or_withdraw_from(
389
380
n : usize ,
390
381
owner : & Pubkey ,
391
382
ui_amount : f64 ,
392
- from_or_to : & Pubkey ,
383
+ from_or_to : Option < Pubkey > ,
393
384
deposit_into : bool ,
394
385
) -> Result < ( ) , Error > {
395
386
let rpc_client = & config. rpc_client ;
396
387
397
388
println ! ( "Scanning accounts..." ) ;
398
- is_valid_token ( rpc_client, token) . await ?;
389
+ let program_id = get_valid_mint_program_id ( rpc_client, token) . await ?;
399
390
400
- let ( mint_pubkey, decimals) =
401
- crate :: resolve_mint_info ( config, from_or_to, Some ( * token) , None ) . await ?;
402
- if mint_pubkey != * token {
403
- return Err ( format ! ( "Source account {} is not a {} token" , from_or_to, token) . into ( ) ) ;
404
- }
405
- let amount = spl_token:: ui_amount_to_amount ( ui_amount, decimals) ;
391
+ let mint_info = config. get_mint_info ( token, None ) . await ?;
392
+ let from_or_to = from_or_to
393
+ . unwrap_or_else ( || get_associated_token_address_with_program_id ( owner, token, & program_id) ) ;
394
+ config. check_account ( & from_or_to, Some ( * token) ) . await ?;
395
+ let amount = spl_token:: ui_amount_to_amount ( ui_amount, mint_info. decimals ) ;
406
396
407
- let token_addresses_with_seed =
408
- get_token_addresses_with_seed ( & config. program_id , token, owner, n) ;
397
+ let token_addresses_with_seed = get_token_addresses_with_seed ( & program_id, token, owner, n) ;
409
398
let mut messages = vec ! [ ] ;
410
399
for address_chunk in token_addresses_with_seed. chunks ( 100 ) {
411
400
let accounts_chunk = rpc_client
@@ -416,14 +405,14 @@ async fn command_deposit_into_or_withdraw_from(
416
405
if account. is_some ( ) {
417
406
messages. push ( Message :: new (
418
407
& [ instruction:: transfer_checked (
419
- & config . program_id ,
420
- if deposit_into { from_or_to } else { address } ,
408
+ & program_id,
409
+ if deposit_into { & from_or_to } else { address } ,
421
410
token,
422
- if deposit_into { address } else { from_or_to } ,
411
+ if deposit_into { address } else { & from_or_to } ,
423
412
owner,
424
413
& [ ] ,
425
414
amount,
426
- decimals,
415
+ mint_info . decimals ,
427
416
) ?] ,
428
417
Some ( & config. fee_payer ) ,
429
418
) ) ;
0 commit comments