@@ -42,7 +42,7 @@ use solana_sdk::{
42
42
transaction:: Transaction ,
43
43
} ;
44
44
use spl_associated_token_account:: {
45
- get_associated_token_address , instruction:: create_associated_token_account,
45
+ get_associated_token_address_with_program_id , instruction:: create_associated_token_account,
46
46
} ;
47
47
use spl_token:: {
48
48
instruction:: * ,
@@ -404,7 +404,8 @@ fn command_create_account(
404
404
] ,
405
405
)
406
406
} else {
407
- let account = get_associated_token_address ( & owner, & token) ;
407
+ let account =
408
+ get_associated_token_address_with_program_id ( & owner, & token, & config. program_id ) ;
408
409
println_display ( config, format ! ( "Creating account {}" , account) ) ;
409
410
(
410
411
account,
@@ -413,6 +414,7 @@ fn command_create_account(
413
414
& config. fee_payer,
414
415
& owner,
415
416
& token,
417
+ & config. program_id,
416
418
) ] ,
417
419
)
418
420
} ;
@@ -538,8 +540,11 @@ fn command_authorize(
538
540
}
539
541
} else if let Ok ( token_account) = Account :: unpack ( & target_account. data ) {
540
542
let check_associated_token_account = || -> Result < ( ) , Error > {
541
- let maybe_associated_token_account =
542
- get_associated_token_address ( & token_account. owner , & token_account. mint ) ;
543
+ let maybe_associated_token_account = get_associated_token_address_with_program_id (
544
+ & token_account. owner ,
545
+ & token_account. mint ,
546
+ & config. program_id ,
547
+ ) ;
543
548
if account == maybe_associated_token_account
544
549
&& !force_authorize
545
550
&& Some ( authority) != new_authority
@@ -678,7 +683,7 @@ fn command_transfer(
678
683
let sender = if let Some ( sender) = sender {
679
684
sender
680
685
} else {
681
- get_associated_token_address ( & sender_owner, & token)
686
+ get_associated_token_address_with_program_id ( & sender_owner, & token, & config . program_id )
682
687
} ;
683
688
let ( mint_pubkey, decimals) = resolve_mint_info ( config, & sender, Some ( token) , mint_decimals) ?;
684
689
let maybe_transfer_balance =
@@ -764,7 +769,11 @@ fn command_transfer(
764
769
} ;
765
770
766
771
if !recipient_is_token_account {
767
- recipient_token_account = get_associated_token_address ( & recipient, & mint_pubkey) ;
772
+ recipient_token_account = get_associated_token_address_with_program_id (
773
+ & recipient,
774
+ & mint_pubkey,
775
+ & config. program_id ,
776
+ ) ;
768
777
println_display (
769
778
config,
770
779
format ! (
@@ -817,6 +826,7 @@ fn command_transfer(
817
826
& config. fee_payer ,
818
827
& recipient,
819
828
& mint_pubkey,
829
+ & config. program_id ,
820
830
) ) ;
821
831
} else {
822
832
return Err (
@@ -1104,7 +1114,11 @@ fn command_wrap(
1104
1114
) ?,
1105
1115
]
1106
1116
} else {
1107
- let account = get_associated_token_address ( & wallet_address, & native_mint:: id ( ) ) ;
1117
+ let account = get_associated_token_address_with_program_id (
1118
+ & wallet_address,
1119
+ & native_mint:: id ( ) ,
1120
+ & config. program_id ,
1121
+ ) ;
1108
1122
1109
1123
if !config. sign_only {
1110
1124
if let Some ( account_data) = config
@@ -1121,7 +1135,12 @@ fn command_wrap(
1121
1135
println_display ( config, format ! ( "Wrapping {} SOL into {}" , sol, account) ) ;
1122
1136
vec ! [
1123
1137
system_instruction:: transfer( & wallet_address, & account, lamports) ,
1124
- create_associated_token_account( & config. fee_payer, & wallet_address, & native_mint:: id( ) ) ,
1138
+ create_associated_token_account(
1139
+ & config. fee_payer,
1140
+ & wallet_address,
1141
+ & native_mint:: id( ) ,
1142
+ & config. program_id,
1143
+ ) ,
1125
1144
]
1126
1145
} ;
1127
1146
if !config. sign_only {
@@ -1153,8 +1172,13 @@ fn command_unwrap(
1153
1172
bulk_signers : BulkSigners ,
1154
1173
) -> CommandResult {
1155
1174
let use_associated_account = address. is_none ( ) ;
1156
- let address = address
1157
- . unwrap_or_else ( || get_associated_token_address ( & wallet_address, & native_mint:: id ( ) ) ) ;
1175
+ let address = address. unwrap_or_else ( || {
1176
+ get_associated_token_address_with_program_id (
1177
+ & wallet_address,
1178
+ & native_mint:: id ( ) ,
1179
+ & config. program_id ,
1180
+ )
1181
+ } ) ;
1158
1182
println_display ( config, format ! ( "Unwrapping {}" , address) ) ;
1159
1183
if !config. sign_only {
1160
1184
let lamports = config. rpc_client . get_balance ( & address) ?;
@@ -1445,7 +1469,8 @@ fn command_address(config: &Config, token: Option<Pubkey>, owner: Pubkey) -> Com
1445
1469
} ;
1446
1470
if let Some ( token) = token {
1447
1471
validate_mint ( config, token) ?;
1448
- let associated_token_address = get_associated_token_address ( & owner, & token) ;
1472
+ let associated_token_address =
1473
+ get_associated_token_address_with_program_id ( & owner, & token, & config. program_id ) ;
1449
1474
cli_address. associated_token_address = Some ( associated_token_address. to_string ( ) ) ;
1450
1475
}
1451
1476
Ok ( config. output_format . formatted_string ( & cli_address) )
@@ -1459,7 +1484,8 @@ fn command_account_info(config: &Config, address: Pubkey) -> CommandResult {
1459
1484
. unwrap ( ) ;
1460
1485
let mint = Pubkey :: from_str ( & account. mint ) . unwrap ( ) ;
1461
1486
let owner = Pubkey :: from_str ( & account. owner ) . unwrap ( ) ;
1462
- let is_associated = get_associated_token_address ( & owner, & mint) == address;
1487
+ let is_associated =
1488
+ get_associated_token_address_with_program_id ( & owner, & mint, & config. program_id ) == address;
1463
1489
let cli_token_account = CliTokenAccount {
1464
1490
address : address. to_string ( ) ,
1465
1491
is_associated,
@@ -1569,7 +1595,8 @@ fn command_gc(
1569
1595
1570
1596
for ( token, accounts) in accounts_by_token. into_iter ( ) {
1571
1597
println_display ( config, format ! ( "Processing token: {}" , token) ) ;
1572
- let associated_token_account = get_associated_token_address ( & owner, & token) ;
1598
+ let associated_token_account =
1599
+ get_associated_token_address_with_program_id ( & owner, & token, & config. program_id ) ;
1573
1600
let total_balance: u64 = accounts. values ( ) . map ( |account| account. 0 ) . sum ( ) ;
1574
1601
1575
1602
if total_balance > 0 && !accounts. contains_key ( & associated_token_account) {
@@ -1578,6 +1605,7 @@ fn command_gc(
1578
1605
& config. fee_payer,
1579
1606
& owner,
1580
1607
& token,
1608
+ & config. program_id,
1581
1609
) ] ) ;
1582
1610
lamports_needed += minimum_balance_for_rent_exemption;
1583
1611
}
@@ -3239,7 +3267,7 @@ mod tests {
3239
3267
fn create_associated_account ( config : & Config , payer : & Keypair , mint : Pubkey ) -> Pubkey {
3240
3268
let bulk_signers: Vec < Box < dyn Signer > > = vec ! [ Box :: new( clone_keypair( payer) ) ] ;
3241
3269
command_create_account ( config, mint, payer. pubkey ( ) , None , bulk_signers) . unwrap ( ) ;
3242
- get_associated_token_address ( & payer. pubkey ( ) , & mint)
3270
+ get_associated_token_address_with_program_id ( & payer. pubkey ( ) , & mint, & config . program_id )
3243
3271
}
3244
3272
3245
3273
fn mint_tokens (
@@ -3348,7 +3376,11 @@ mod tests {
3348
3376
] ,
3349
3377
) ;
3350
3378
let value: serde_json:: Value = serde_json:: from_str ( & result. unwrap ( ) ) . unwrap ( ) ;
3351
- let account = get_associated_token_address ( & payer. pubkey ( ) , & token) ;
3379
+ let account = get_associated_token_address_with_program_id (
3380
+ & payer. pubkey ( ) ,
3381
+ & token,
3382
+ & config. program_id ,
3383
+ ) ;
3352
3384
assert_eq ! ( value[ "address" ] , account. to_string( ) ) ;
3353
3385
assert_eq ! ( value[ "mint" ] , token. to_string( ) ) ;
3354
3386
assert_eq ! ( value[ "isAssociated" ] , true ) ;
@@ -3448,7 +3480,11 @@ mod tests {
3448
3480
& [ "spl-token" , CommandName :: Wrap . into ( ) , "0.5" ] ,
3449
3481
)
3450
3482
. unwrap ( ) ;
3451
- let account = get_associated_token_address ( & payer. pubkey ( ) , & native_mint:: id ( ) ) ;
3483
+ let account = get_associated_token_address_with_program_id (
3484
+ & payer. pubkey ( ) ,
3485
+ & native_mint:: id ( ) ,
3486
+ & config. program_id ,
3487
+ ) ;
3452
3488
let ui_account = config
3453
3489
. rpc_client
3454
3490
. get_token_account ( & account)
@@ -3464,7 +3500,11 @@ mod tests {
3464
3500
let config = test_config ( & test_validator, & payer, & spl_token:: id ( ) ) ;
3465
3501
let bulk_signers: Vec < Box < dyn Signer > > = vec ! [ Box :: new( clone_keypair( & payer) ) ] ;
3466
3502
command_wrap ( & config, 0.5 , payer. pubkey ( ) , None , bulk_signers) . unwrap ( ) ;
3467
- let account = get_associated_token_address ( & payer. pubkey ( ) , & native_mint:: id ( ) ) ;
3503
+ let account = get_associated_token_address_with_program_id (
3504
+ & payer. pubkey ( ) ,
3505
+ & native_mint:: id ( ) ,
3506
+ & config. program_id ,
3507
+ ) ;
3468
3508
let result = process_test_command (
3469
3509
& config,
3470
3510
& payer,
@@ -3618,7 +3658,11 @@ mod tests {
3618
3658
let ui_amount = 10.0 ;
3619
3659
command_wrap ( & config, ui_amount, payer. pubkey ( ) , None , bulk_signers) . unwrap ( ) ;
3620
3660
3621
- let recipient = get_associated_token_address ( & payer. pubkey ( ) , & native_mint:: id ( ) ) ;
3661
+ let recipient = get_associated_token_address_with_program_id (
3662
+ & payer. pubkey ( ) ,
3663
+ & native_mint:: id ( ) ,
3664
+ & config. program_id ,
3665
+ ) ;
3622
3666
let _result = process_test_command (
3623
3667
& config,
3624
3668
& payer,
0 commit comments