Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 66b6fa3

Browse files
committed
use spl_associated_token_address in spl crates
1 parent 3571d08 commit 66b6fa3

File tree

19 files changed

+36
-88
lines changed

19 files changed

+36
-88
lines changed

Cargo.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

associated-token-account/program-test/tests/create_idempotent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use {
1717
},
1818
spl_associated_token_account::{
1919
error::AssociatedTokenAccountError,
20-
get_associated_token_address_with_program_id,
2120
instruction::{
2221
create_associated_token_account, create_associated_token_account_idempotent,
2322
},
2423
},
24+
spl_associated_token_address::get_associated_token_address_with_program_id,
2525
spl_token_2022::{
2626
extension::ExtensionType,
2727
instruction::initialize_account,

associated-token-account/program-test/tests/extended_mint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use {
1313
signer::keypair::Keypair,
1414
transaction::{Transaction, TransactionError},
1515
},
16-
spl_associated_token_account::{
17-
get_associated_token_address_with_program_id, instruction::create_associated_token_account,
18-
},
16+
spl_associated_token_account::instruction::create_associated_token_account,
17+
spl_associated_token_address::get_associated_token_address_with_program_id,
1918
spl_token_2022::{
2019
error::TokenError,
2120
extension::{

associated-token-account/program-test/tests/process_create_associated_token_account.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ use {
1212
signature::Signer,
1313
transaction::{Transaction, TransactionError},
1414
},
15-
spl_associated_token_account::{
16-
get_associated_token_address_with_program_id, instruction::create_associated_token_account,
17-
},
15+
spl_associated_token_account::instruction::create_associated_token_account,
16+
spl_associated_token_address::get_associated_token_address_with_program_id,
1817
spl_token_2022::{extension::ExtensionType, state::Account},
1918
};
2019

associated-token-account/program-test/tests/recover_nested.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use {
1414
signer::keypair::Keypair,
1515
transaction::{Transaction, TransactionError},
1616
},
17-
spl_associated_token_account::{get_associated_token_address_with_program_id, instruction},
17+
spl_associated_token_account::instruction,
18+
spl_associated_token_address::get_associated_token_address_with_program_id,
1819
spl_token_2022::{
1920
extension::{ExtensionType, StateWithExtensionsOwned},
2021
state::{Account, Mint},

associated-token-account/program-test/tests/spl_token_create.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use {
1111
solana_program::pubkey::Pubkey,
1212
solana_program_test::*,
1313
solana_sdk::{program_pack::Pack, signature::Signer, transaction::Transaction},
14-
spl_associated_token_account::{
15-
get_associated_token_address, instruction::create_associated_token_account,
16-
},
14+
spl_associated_token_account::instruction::create_associated_token_account,
15+
spl_associated_token_address::get_associated_token_address,
1716
spl_token::state::Account,
1817
};
1918

associated-token-account/program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ borsh = "1.5.1"
1717
num-derive = "0.4"
1818
num-traits = "0.2"
1919
solana-program = "2.0.0"
20+
spl-associated-token-address = { version = "1.0.0", path = "../../associated-token-address" }
2021
spl-program-ids = { version = "1.0.0", path = "../../program-ids" }
2122
spl-token = { version = "6.0", path = "../../token/program", features = [
2223
"no-entrypoint",

associated-token-account/program/src/lib.rs

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,8 @@ use solana_program::{
1616
// Export current SDK types for downstream users building with a different SDK
1717
// version
1818
pub use {solana_program, spl_program_ids::spl_associated_token_account::*};
19-
20-
pub(crate) fn get_associated_token_address_and_bump_seed(
21-
wallet_address: &Pubkey,
22-
token_mint_address: &Pubkey,
23-
program_id: &Pubkey,
24-
token_program_id: &Pubkey,
25-
) -> (Pubkey, u8) {
26-
get_associated_token_address_and_bump_seed_internal(
27-
wallet_address,
28-
token_mint_address,
29-
program_id,
30-
token_program_id,
31-
)
32-
}
33-
34-
/// Derives the associated token account address for the given wallet address
35-
/// and token mint
36-
pub fn get_associated_token_address(
37-
wallet_address: &Pubkey,
38-
token_mint_address: &Pubkey,
39-
) -> Pubkey {
40-
get_associated_token_address_with_program_id(
41-
wallet_address,
42-
token_mint_address,
43-
&spl_token::id(),
44-
)
45-
}
46-
47-
/// Derives the associated token account address for the given wallet address,
48-
/// token mint and token program id
49-
pub fn get_associated_token_address_with_program_id(
50-
wallet_address: &Pubkey,
51-
token_mint_address: &Pubkey,
52-
token_program_id: &Pubkey,
53-
) -> Pubkey {
54-
get_associated_token_address_and_bump_seed(
55-
wallet_address,
56-
token_mint_address,
57-
&id(),
58-
token_program_id,
59-
)
60-
.0
61-
}
62-
63-
fn get_associated_token_address_and_bump_seed_internal(
64-
wallet_address: &Pubkey,
65-
token_mint_address: &Pubkey,
66-
program_id: &Pubkey,
67-
token_program_id: &Pubkey,
68-
) -> (Pubkey, u8) {
69-
Pubkey::find_program_address(
70-
&[
71-
&wallet_address.to_bytes(),
72-
&token_program_id.to_bytes(),
73-
&token_mint_address.to_bytes(),
74-
],
75-
program_id,
76-
)
77-
}
19+
#[deprecated(since = "4.1.0", note = "Use `spl-associated-token-address` crate instead.")]
20+
pub use spl_associated_token_address::{get_associated_token_address, get_associated_token_address_with_program_id};
7821

7922
/// Create an associated token account for the given wallet address and token
8023
/// mint

associated-token-account/program/src/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use {
55
error::AssociatedTokenAccountError,
66
instruction::AssociatedTokenAccountInstruction,
77
tools::account::{create_pda_account, get_account_len},
8-
*,
98
},
109
borsh::BorshDeserialize,
1110
solana_program::{
@@ -19,6 +18,7 @@ use {
1918
system_program,
2019
sysvar::Sysvar,
2120
},
21+
spl_associated_token_address::get_associated_token_address_and_bump_seed_internal,
2222
spl_token_2022::{
2323
extension::{ExtensionType, StateWithExtensions},
2424
state::{Account, Mint},

associated-token-address/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ pub fn get_associated_token_address_and_bump_seed(
2020
)
2121
}
2222

23-
const TOKEN_PROGRAM: Pubkey = solana_program::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
24-
const ASSOCIATED_TOKEN_PROGRAM: Pubkey = solana_program::pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
23+
const TOKEN_PROGRAM_ID: Pubkey = solana_program::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
24+
/// Program ID for the Associated Token Program
25+
pub const ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = solana_program::pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
2526

2627
/// Derives the associated token account address for the given wallet address
2728
/// and token mint
@@ -32,7 +33,7 @@ pub fn get_associated_token_address(
3233
get_associated_token_address_with_program_id(
3334
wallet_address,
3435
token_mint_address,
35-
&TOKEN_PROGRAM,
36+
&TOKEN_PROGRAM_ID,
3637
)
3738
}
3839

@@ -46,13 +47,14 @@ pub fn get_associated_token_address_with_program_id(
4647
get_associated_token_address_and_bump_seed(
4748
wallet_address,
4849
token_mint_address,
49-
&ASSOCIATED_TOKEN_PROGRAM,
50+
&ASSOCIATED_TOKEN_PROGRAM_ID,
5051
token_program_id,
5152
)
5253
.0
5354
}
5455

55-
fn get_associated_token_address_and_bump_seed_internal(
56+
/// For internal use only.
57+
pub fn get_associated_token_address_and_bump_seed_internal(
5658
wallet_address: &Pubkey,
5759
token_mint_address: &Pubkey,
5860
program_id: &Pubkey,

0 commit comments

Comments
 (0)