Skip to content

Commit d7c71c8

Browse files
authored
interface: Add instruction definition, refactor some (#113)
* interface: Add instruction definition, refactor some #### Problem In order to publish the v3 SDK crates and have them usable in Agave, we also need to have SPL crates using the v3 SDK crates. However, we have a circular dependency between Agave and SPL which currently makes this impossible. The overall plan is to have Agave only use "interface" crates from SPL, which have no dependencies on Agave crates. You can see more info about the project at https://github.com/orgs/anza-xyz/projects/27 ATA is already in a good position since it has a small "interface"-style crate for Agave to use. However, it has two issues: * the instruction definition is still in the program, and Agave needs that to deserialize instructions * the name of the crate is "spl-associated-token-account-client", which is inconsistent with how we normally name these #### Summary of changes Move the instruction definition into the interface crate, gated with the "borsh" feature for those who need it. Rename the crate to "spl-associated-token-account-interface". * Add required feature to borsh dep * Run cargo fmt * Bump version down to v1 for first release
1 parent ae6029d commit d7c71c8

File tree

13 files changed

+94
-84
lines changed

13 files changed

+94
-84
lines changed

Cargo.lock

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

interface/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
[package]
2-
name = "spl-associated-token-account-client"
3-
version = "2.0.0"
4-
description = "Solana Program Library Associated Token Account Client"
2+
name = "spl-associated-token-account-interface"
3+
version = "1.0.0"
4+
description = "Solana Program Library Associated Token Account Interface"
55
authors = ["Anza Maintainers <maintainers@anza.xyz>"]
66
repository = "https://github.com/solana-program/associated-token-account"
77
license = "Apache-2.0"
88
edition = "2021"
99

10+
[features]
11+
borsh = ["dep:borsh"]
12+
1013
[dependencies]
14+
borsh = { version = "1", optional = true, features = ["unstable__schema"] }
1115
solana-instruction = { version = "2.2.1", features = ["std"] }
1216
solana-pubkey = { version = "2.2.1", features = ["curve25519"] }
1317

interface/src/instruction.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,59 @@ use {
77

88
const SYSTEM_PROGRAM_ID: Pubkey = Pubkey::from_str_const("11111111111111111111111111111111");
99

10+
#[cfg(feature = "borsh")]
11+
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
12+
13+
/// Instructions supported by the `AssociatedTokenAccount` program
14+
#[derive(Clone, Debug, PartialEq)]
15+
#[cfg_attr(
16+
feature = "borsh",
17+
derive(BorshDeserialize, BorshSerialize, BorshSchema)
18+
)]
19+
pub enum AssociatedTokenAccountInstruction {
20+
/// Creates an associated token account for the given wallet address and
21+
/// token mint Returns an error if the account exists.
22+
///
23+
/// 0. `[writeable,signer]` Funding account (must be a system account)
24+
/// 1. `[writeable]` Associated token account address to be created
25+
/// 2. `[]` Wallet address for the new associated token account
26+
/// 3. `[]` The token mint for the new associated token account
27+
/// 4. `[]` System program
28+
/// 5. `[]` SPL Token program
29+
Create,
30+
/// Creates an associated token account for the given wallet address and
31+
/// token mint, if it doesn't already exist. Returns an error if the
32+
/// account exists, but with a different owner.
33+
///
34+
/// 0. `[writeable,signer]` Funding account (must be a system account)
35+
/// 1. `[writeable]` Associated token account address to be created
36+
/// 2. `[]` Wallet address for the new associated token account
37+
/// 3. `[]` The token mint for the new associated token account
38+
/// 4. `[]` System program
39+
/// 5. `[]` SPL Token program
40+
CreateIdempotent,
41+
/// Transfers from and closes a nested associated token account: an
42+
/// associated token account owned by an associated token account.
43+
///
44+
/// The tokens are moved from the nested associated token account to the
45+
/// wallet's associated token account, and the nested account lamports are
46+
/// moved to the wallet.
47+
///
48+
/// Note: Nested token accounts are an anti-pattern, and almost always
49+
/// created unintentionally, so this instruction should only be used to
50+
/// recover from errors.
51+
///
52+
/// 0. `[writeable]` Nested associated token account, must be owned by `3`
53+
/// 1. `[]` Token mint for the nested associated token account
54+
/// 2. `[writeable]` Wallet's associated token account
55+
/// 3. `[]` Owner associated token account address, must be owned by `5`
56+
/// 4. `[]` Token mint for the owner associated token account
57+
/// 5. `[writeable, signer]` Wallet address for the owner associated token
58+
/// account
59+
/// 6. `[]` SPL Token program
60+
RecoverNested,
61+
}
62+
1063
fn build_associated_token_account_instruction(
1164
funding_address: &Pubkey,
1265
wallet_address: &Pubkey,

program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ num-derive = "0.4"
1717
num-traits = "0.2"
1818
solana-program = "2.3.0"
1919
solana-system-interface = "1"
20-
spl-associated-token-account-client = { version = "2.0.0", path = "../interface" }
20+
spl-associated-token-account-interface = { version = "1.0.0", path = "../interface", features = ["borsh"] }
2121
spl-token = { version = "8.0", features = ["no-entrypoint"] }
2222
spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"] }
2323
thiserror = "2.0"

program/src/instruction.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,3 @@
11
//! Program instructions
22
3-
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
4-
pub use spl_associated_token_account_client::instruction::*;
5-
6-
/// Instructions supported by the `AssociatedTokenAccount` program
7-
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
8-
pub enum AssociatedTokenAccountInstruction {
9-
/// Creates an associated token account for the given wallet address and
10-
/// token mint Returns an error if the account exists.
11-
///
12-
/// 0. `[writeable,signer]` Funding account (must be a system account)
13-
/// 1. `[writeable]` Associated token account address to be created
14-
/// 2. `[]` Wallet address for the new associated token account
15-
/// 3. `[]` The token mint for the new associated token account
16-
/// 4. `[]` System program
17-
/// 5. `[]` SPL Token program
18-
Create,
19-
/// Creates an associated token account for the given wallet address and
20-
/// token mint, if it doesn't already exist. Returns an error if the
21-
/// account exists, but with a different owner.
22-
///
23-
/// 0. `[writeable,signer]` Funding account (must be a system account)
24-
/// 1. `[writeable]` Associated token account address to be created
25-
/// 2. `[]` Wallet address for the new associated token account
26-
/// 3. `[]` The token mint for the new associated token account
27-
/// 4. `[]` System program
28-
/// 5. `[]` SPL Token program
29-
CreateIdempotent,
30-
/// Transfers from and closes a nested associated token account: an
31-
/// associated token account owned by an associated token account.
32-
///
33-
/// The tokens are moved from the nested associated token account to the
34-
/// wallet's associated token account, and the nested account lamports are
35-
/// moved to the wallet.
36-
///
37-
/// Note: Nested token accounts are an anti-pattern, and almost always
38-
/// created unintentionally, so this instruction should only be used to
39-
/// recover from errors.
40-
///
41-
/// 0. `[writeable]` Nested associated token account, must be owned by `3`
42-
/// 1. `[]` Token mint for the nested associated token account
43-
/// 2. `[writeable]` Wallet's associated token account
44-
/// 3. `[]` Owner associated token account address, must be owned by `5`
45-
/// 4. `[]` Token mint for the owner associated token account
46-
/// 5. `[writeable, signer]` Wallet address for the owner associated token
47-
/// account
48-
/// 6. `[]` SPL Token program
49-
RecoverNested,
50-
}
3+
pub use spl_associated_token_account_interface::instruction::*;

program/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use solana_program::{
1818
};
1919
#[deprecated(
2020
since = "4.1.0",
21-
note = "Use `spl-associated-token-account-client` crate instead."
21+
note = "Use `spl-associated-token-account-interface` crate instead."
2222
)]
23-
pub use spl_associated_token_account_client::address::{
23+
pub use spl_associated_token_account_interface::address::{
2424
get_associated_token_address, get_associated_token_address_with_program_id,
2525
};
2626
// Export current SDK types for downstream users building with a different SDK
2727
// version
28-
pub use spl_associated_token_account_client::program::{check_id, id, ID};
28+
pub use spl_associated_token_account_interface::program::{check_id, id, ID};
2929

3030
/// Create an associated token account for the given wallet address and token
3131
/// mint

program/src/processor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use {
44
crate::{
55
error::AssociatedTokenAccountError,
6-
instruction::AssociatedTokenAccountInstruction,
76
tools::account::{create_pda_account, get_account_len},
87
},
98
borsh::BorshDeserialize,
@@ -18,7 +17,10 @@ use {
1817
sysvar::Sysvar,
1918
},
2019
solana_system_interface::program as system_program,
21-
spl_associated_token_account_client::address::get_associated_token_address_and_bump_seed_internal,
20+
spl_associated_token_account_interface::{
21+
address::get_associated_token_address_and_bump_seed_internal,
22+
instruction::AssociatedTokenAccountInstruction,
23+
},
2224
spl_token_2022::{
2325
extension::{ExtensionType, StateWithExtensions},
2426
state::{Account, Mint},

program/tests/create_idempotent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use {
1313
system_instruction::create_account,
1414
transaction::{Transaction, TransactionError},
1515
},
16-
spl_associated_token_account::{
17-
error::AssociatedTokenAccountError,
16+
spl_associated_token_account::error::AssociatedTokenAccountError,
17+
spl_associated_token_account_interface::{
18+
address::get_associated_token_address_with_program_id,
1819
instruction::{
1920
create_associated_token_account, create_associated_token_account_idempotent,
2021
},
2122
},
22-
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
2323
spl_token_2022::{
2424
extension::ExtensionType,
2525
instruction::initialize_account,

program/tests/extended_mint.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use {
1010
transaction::{Transaction, TransactionError},
1111
},
1212
solana_system_interface::instruction as system_instruction,
13-
spl_associated_token_account::instruction::create_associated_token_account,
14-
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
13+
spl_associated_token_account_interface::{
14+
address::get_associated_token_address_with_program_id,
15+
instruction::create_associated_token_account,
16+
},
1517
spl_token_2022::{
1618
error::TokenError,
1719
extension::{

program/tests/process_create_associated_token_account.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use {
99
transaction::{Transaction, TransactionError},
1010
},
1111
solana_system_interface::instruction as system_instruction,
12-
spl_associated_token_account::instruction::create_associated_token_account,
13-
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
12+
spl_associated_token_account_interface::{
13+
address::get_associated_token_address_with_program_id,
14+
instruction::create_associated_token_account,
15+
},
1416
spl_token_2022::{extension::ExtensionType, state::Account},
1517
};
1618

0 commit comments

Comments
 (0)