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

Commit f817cee

Browse files
committed
Rename associated-token-address -> associated-token-account-client
1 parent 4266e4f commit f817cee

File tree

8 files changed

+129
-131
lines changed

8 files changed

+129
-131
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ split-debuginfo = "unpacked"
33

44
[workspace]
55
members = [
6+
"associated-token-account/client",
67
"associated-token-account/program",
78
"associated-token-account/program-test",
8-
"associated-token-address",
99
"binary-option/program",
1010
"binary-oracle-pair/program",
1111
"examples/rust/cross-program-invocation",
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
2-
name = "spl-associated-token-address"
2+
name = "spl-associated-token-account-client"
33
version = "1.0.0"
4-
description = "Solana Program Library Associated Token Address"
4+
description = "Solana Program Library Associated Token Account Client"
55
authors = ["Solana Labs Maintainers <[email protected]>"]
66
repository = "https://github.com/solana-labs/solana-program-library"
77
license = "Apache-2.0"
88
edition = "2021"
99

1010
[dependencies]
11-
solana-inline-spl = "2.1.0"
12-
solana-program = "2.1.0"
11+
solana-inline-spl = "2.0.3"
12+
solana-program = "2.0.3"
1313

1414
[package.metadata.docs.rs]
1515
targets = ["x86_64-unknown-linux-gnu"]

associated-token-address/src/lib.rs renamed to associated-token-account/client/src/address.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
//! Convention for associating token accounts with a user wallet
2-
#![deny(missing_docs)]
3-
#![forbid(unsafe_code)]
1+
//! Address derivation functions
42
53
use solana_program::pubkey::Pubkey;
64

7-
solana_program::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
8-
95
/// Derives the associated token account address and bump seed
106
/// for the given wallet address, token mint and token program id
117
pub fn get_associated_token_address_and_bump_seed(
@@ -31,7 +27,7 @@ pub fn get_associated_token_address(
3127
get_associated_token_address_with_program_id(
3228
wallet_address,
3329
token_mint_address,
34-
&solana_inline_spl::spl_token::ID,
30+
&solana_inline_spl::token::ID,
3531
)
3632
}
3733

@@ -45,7 +41,7 @@ pub fn get_associated_token_address_with_program_id(
4541
get_associated_token_address_and_bump_seed(
4642
wallet_address,
4743
token_mint_address,
48-
&solana_inline_spl::spl_associated_token_account::ID,
44+
&crate::id(),
4945
token_program_id,
5046
)
5147
.0
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//! Instruction creators for the program
2+
use {
3+
crate::{id, address::get_associated_token_address_with_program_id},
4+
solana_program::{
5+
instruction::{AccountMeta, Instruction},
6+
pubkey::Pubkey, system_program,
7+
},
8+
};
9+
10+
fn build_associated_token_account_instruction(
11+
funding_address: &Pubkey,
12+
wallet_address: &Pubkey,
13+
token_mint_address: &Pubkey,
14+
token_program_id: &Pubkey,
15+
instruction: u8,
16+
) -> Instruction {
17+
let associated_account_address = get_associated_token_address_with_program_id(
18+
wallet_address,
19+
token_mint_address,
20+
token_program_id,
21+
);
22+
// safety check, assert if not a creation instruction, which is only 0 or 1
23+
assert!(instruction <= 1);
24+
Instruction {
25+
program_id: id(),
26+
accounts: vec![
27+
AccountMeta::new(*funding_address, true),
28+
AccountMeta::new(associated_account_address, false),
29+
AccountMeta::new_readonly(*wallet_address, false),
30+
AccountMeta::new_readonly(*token_mint_address, false),
31+
AccountMeta::new_readonly(system_program::id(), false),
32+
AccountMeta::new_readonly(*token_program_id, false),
33+
],
34+
data: vec![instruction],
35+
}
36+
}
37+
38+
/// Creates Create instruction
39+
pub fn create_associated_token_account(
40+
funding_address: &Pubkey,
41+
wallet_address: &Pubkey,
42+
token_mint_address: &Pubkey,
43+
token_program_id: &Pubkey,
44+
) -> Instruction {
45+
build_associated_token_account_instruction(
46+
funding_address,
47+
wallet_address,
48+
token_mint_address,
49+
token_program_id,
50+
0, // AssociatedTokenAccountInstruction::Create
51+
)
52+
}
53+
54+
/// Creates CreateIdempotent instruction
55+
pub fn create_associated_token_account_idempotent(
56+
funding_address: &Pubkey,
57+
wallet_address: &Pubkey,
58+
token_mint_address: &Pubkey,
59+
token_program_id: &Pubkey,
60+
) -> Instruction {
61+
build_associated_token_account_instruction(
62+
funding_address,
63+
wallet_address,
64+
token_mint_address,
65+
token_program_id,
66+
1, // AssociatedTokenAccountInstruction::CreateIdempotent
67+
)
68+
}
69+
70+
/// Creates a `RecoverNested` instruction
71+
pub fn recover_nested(
72+
wallet_address: &Pubkey,
73+
owner_token_mint_address: &Pubkey,
74+
nested_token_mint_address: &Pubkey,
75+
token_program_id: &Pubkey,
76+
) -> Instruction {
77+
let owner_associated_account_address = get_associated_token_address_with_program_id(
78+
wallet_address,
79+
owner_token_mint_address,
80+
token_program_id,
81+
);
82+
let destination_associated_account_address = get_associated_token_address_with_program_id(
83+
wallet_address,
84+
nested_token_mint_address,
85+
token_program_id,
86+
);
87+
let nested_associated_account_address = get_associated_token_address_with_program_id(
88+
&owner_associated_account_address, // ATA is wrongly used as a wallet_address
89+
nested_token_mint_address,
90+
token_program_id,
91+
);
92+
93+
Instruction {
94+
program_id: id(),
95+
accounts: vec![
96+
AccountMeta::new(nested_associated_account_address, false),
97+
AccountMeta::new_readonly(*nested_token_mint_address, false),
98+
AccountMeta::new(destination_associated_account_address, false),
99+
AccountMeta::new_readonly(owner_associated_account_address, false),
100+
AccountMeta::new_readonly(*owner_token_mint_address, false),
101+
AccountMeta::new(*wallet_address, true),
102+
AccountMeta::new_readonly(*token_program_id, false),
103+
],
104+
data: vec![2], // AssociatedTokenAccountInstruction::RecoverNested
105+
}
106+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! Client crate for interacting with the spl-associated-token-account program
2+
#![deny(missing_docs)]
3+
#![forbid(unsafe_code)]
4+
5+
pub mod address;
6+
pub mod instruction;
7+
8+
solana_program::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");

associated-token-account/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ borsh = "1.5.1"
1717
num-derive = "0.4"
1818
num-traits = "0.2"
1919
solana-program = "2.0.3"
20-
spl-associated-token-address = { version = "1.0.0", path = "../../associated-token-address" }
20+
spl-associated-token-account-client = { version = "1.0.0", path = "../client" }
2121
spl-token = { version = "6.0", path = "../../token/program", features = [
2222
"no-entrypoint",
2323
] }
Lines changed: 3 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
//! Program instructions
22
3-
use {
4-
crate::id,
5-
assert_matches::assert_matches,
6-
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
7-
solana_program::{
8-
instruction::{AccountMeta, Instruction},
9-
pubkey::Pubkey,
10-
},
11-
spl_associated_token_address::get_associated_token_address_with_program_id,
12-
};
3+
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
4+
pub use spl_associated_token_account_client::intruction::*;
135

146
/// Instructions supported by the AssociatedTokenAccount program
7+
#[deprecated(since = "4.1.0", note = "Use instructions in `spl-associated-token-account-client` crate instead.")]
158
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
169
pub enum AssociatedTokenAccountInstruction {
1710
/// Creates an associated token account for the given wallet address and
@@ -56,107 +49,3 @@ pub enum AssociatedTokenAccountInstruction {
5649
/// 6. `[]` SPL Token program
5750
RecoverNested,
5851
}
59-
60-
fn build_associated_token_account_instruction(
61-
funding_address: &Pubkey,
62-
wallet_address: &Pubkey,
63-
token_mint_address: &Pubkey,
64-
token_program_id: &Pubkey,
65-
instruction: AssociatedTokenAccountInstruction,
66-
) -> Instruction {
67-
let associated_account_address = get_associated_token_address_with_program_id(
68-
wallet_address,
69-
token_mint_address,
70-
token_program_id,
71-
);
72-
// safety check, assert if not a creation instruction
73-
assert_matches!(
74-
instruction,
75-
AssociatedTokenAccountInstruction::Create
76-
| AssociatedTokenAccountInstruction::CreateIdempotent
77-
);
78-
Instruction {
79-
program_id: id(),
80-
accounts: vec![
81-
AccountMeta::new(*funding_address, true),
82-
AccountMeta::new(associated_account_address, false),
83-
AccountMeta::new_readonly(*wallet_address, false),
84-
AccountMeta::new_readonly(*token_mint_address, false),
85-
AccountMeta::new_readonly(solana_program::system_program::id(), false),
86-
AccountMeta::new_readonly(*token_program_id, false),
87-
],
88-
data: borsh::to_vec(&instruction).unwrap(),
89-
}
90-
}
91-
92-
/// Creates Create instruction
93-
pub fn create_associated_token_account(
94-
funding_address: &Pubkey,
95-
wallet_address: &Pubkey,
96-
token_mint_address: &Pubkey,
97-
token_program_id: &Pubkey,
98-
) -> Instruction {
99-
build_associated_token_account_instruction(
100-
funding_address,
101-
wallet_address,
102-
token_mint_address,
103-
token_program_id,
104-
AssociatedTokenAccountInstruction::Create,
105-
)
106-
}
107-
108-
/// Creates CreateIdempotent instruction
109-
pub fn create_associated_token_account_idempotent(
110-
funding_address: &Pubkey,
111-
wallet_address: &Pubkey,
112-
token_mint_address: &Pubkey,
113-
token_program_id: &Pubkey,
114-
) -> Instruction {
115-
build_associated_token_account_instruction(
116-
funding_address,
117-
wallet_address,
118-
token_mint_address,
119-
token_program_id,
120-
AssociatedTokenAccountInstruction::CreateIdempotent,
121-
)
122-
}
123-
124-
/// Creates a `RecoverNested` instruction
125-
pub fn recover_nested(
126-
wallet_address: &Pubkey,
127-
owner_token_mint_address: &Pubkey,
128-
nested_token_mint_address: &Pubkey,
129-
token_program_id: &Pubkey,
130-
) -> Instruction {
131-
let owner_associated_account_address = get_associated_token_address_with_program_id(
132-
wallet_address,
133-
owner_token_mint_address,
134-
token_program_id,
135-
);
136-
let destination_associated_account_address = get_associated_token_address_with_program_id(
137-
wallet_address,
138-
nested_token_mint_address,
139-
token_program_id,
140-
);
141-
let nested_associated_account_address = get_associated_token_address_with_program_id(
142-
&owner_associated_account_address, // ATA is wrongly used as a wallet_address
143-
nested_token_mint_address,
144-
token_program_id,
145-
);
146-
147-
let instruction_data = AssociatedTokenAccountInstruction::RecoverNested;
148-
149-
Instruction {
150-
program_id: id(),
151-
accounts: vec![
152-
AccountMeta::new(nested_associated_account_address, false),
153-
AccountMeta::new_readonly(*nested_token_mint_address, false),
154-
AccountMeta::new(destination_associated_account_address, false),
155-
AccountMeta::new_readonly(owner_associated_account_address, false),
156-
AccountMeta::new_readonly(*owner_token_mint_address, false),
157-
AccountMeta::new(*wallet_address, true),
158-
AccountMeta::new_readonly(*token_program_id, false),
159-
],
160-
data: borsh::to_vec(&instruction_data).unwrap(),
161-
}
162-
}

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

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

20-
2120
// Export current SDK types for downstream users building with a different SDK
2221
// 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};
22+
pub use {solana_program, spl_associated_token_account_client::{id, ID, check_id}};
23+
#[deprecated(since = "4.1.0", note = "Use `spl-associated-token-account-client` crate instead.")]
24+
pub use spl_associated_token_account_client::{get_associated_token_address, get_associated_token_address_with_program_id};
2625

2726
/// Create an associated token account for the given wallet address and token
2827
/// mint

0 commit comments

Comments
 (0)