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

Commit 0abe8e6

Browse files
committed
use spl_associated_token_address in spl crates
1 parent 08f0ec0 commit 0abe8e6

File tree

19 files changed

+41
-88
lines changed

19 files changed

+41
-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-token = { version = "6.0", path = "../../token/program", features = [
2122
"no-entrypoint",
2223
] }

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

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,12 @@ use solana_program::{
1717
sysvar,
1818
};
1919

20-
solana_program::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
2120

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

8127
/// Create an associated token account for the given wallet address and token
8228
/// 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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use solana_program::pubkey::Pubkey;
66

7+
solana_program::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
8+
79
/// Derives the associated token account address and bump seed
810
/// for the given wallet address, token mint and token program id
911
pub fn get_associated_token_address_and_bump_seed(
@@ -20,8 +22,9 @@ pub fn get_associated_token_address_and_bump_seed(
2022
)
2123
}
2224

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

2629
/// Derives the associated token account address for the given wallet address
2730
/// and token mint
@@ -32,7 +35,7 @@ pub fn get_associated_token_address(
3235
get_associated_token_address_with_program_id(
3336
wallet_address,
3437
token_mint_address,
35-
&TOKEN_PROGRAM,
38+
&TOKEN_PROGRAM_ID,
3639
)
3740
}
3841

@@ -46,13 +49,14 @@ pub fn get_associated_token_address_with_program_id(
4649
get_associated_token_address_and_bump_seed(
4750
wallet_address,
4851
token_mint_address,
49-
&ASSOCIATED_TOKEN_PROGRAM,
52+
&ASSOCIATED_TOKEN_PROGRAM_ID,
5053
token_program_id,
5154
)
5255
.0
5356
}
5457

55-
fn get_associated_token_address_and_bump_seed_internal(
58+
/// For internal use only.
59+
pub fn get_associated_token_address_and_bump_seed_internal(
5660
wallet_address: &Pubkey,
5761
token_mint_address: &Pubkey,
5862
program_id: &Pubkey,

0 commit comments

Comments
 (0)