Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[package]
name = "spl-associated-token-account-client"
version = "2.0.0"
description = "Solana Program Library Associated Token Account Client"
name = "spl-associated-token-account-interface"
version = "1.0.0"
description = "Solana Program Library Associated Token Account Interface"
authors = ["Anza Maintainers <maintainers@anza.xyz>"]
repository = "https://github.com/solana-program/associated-token-account"
license = "Apache-2.0"
edition = "2021"

[features]
borsh = ["dep:borsh"]

[dependencies]
borsh = { version = "1", optional = true, features = ["unstable__schema"] }
solana-instruction = { version = "2.2.1", features = ["std"] }
solana-pubkey = { version = "2.2.1", features = ["curve25519"] }

Expand Down
53 changes: 53 additions & 0 deletions interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,59 @@ use {

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

#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};

/// Instructions supported by the `AssociatedTokenAccount` program
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "borsh",
derive(BorshDeserialize, BorshSerialize, BorshSchema)
)]
pub enum AssociatedTokenAccountInstruction {
/// Creates an associated token account for the given wallet address and
/// token mint Returns an error if the account exists.
///
/// 0. `[writeable,signer]` Funding account (must be a system account)
/// 1. `[writeable]` Associated token account address to be created
/// 2. `[]` Wallet address for the new associated token account
/// 3. `[]` The token mint for the new associated token account
/// 4. `[]` System program
/// 5. `[]` SPL Token program
Create,
/// Creates an associated token account for the given wallet address and
/// token mint, if it doesn't already exist. Returns an error if the
/// account exists, but with a different owner.
///
/// 0. `[writeable,signer]` Funding account (must be a system account)
/// 1. `[writeable]` Associated token account address to be created
/// 2. `[]` Wallet address for the new associated token account
/// 3. `[]` The token mint for the new associated token account
/// 4. `[]` System program
/// 5. `[]` SPL Token program
CreateIdempotent,
/// Transfers from and closes a nested associated token account: an
/// associated token account owned by an associated token account.
///
/// The tokens are moved from the nested associated token account to the
/// wallet's associated token account, and the nested account lamports are
/// moved to the wallet.
///
/// Note: Nested token accounts are an anti-pattern, and almost always
/// created unintentionally, so this instruction should only be used to
/// recover from errors.
///
/// 0. `[writeable]` Nested associated token account, must be owned by `3`
/// 1. `[]` Token mint for the nested associated token account
/// 2. `[writeable]` Wallet's associated token account
/// 3. `[]` Owner associated token account address, must be owned by `5`
/// 4. `[]` Token mint for the owner associated token account
/// 5. `[writeable, signer]` Wallet address for the owner associated token
/// account
/// 6. `[]` SPL Token program
RecoverNested,
}

fn build_associated_token_account_instruction(
funding_address: &Pubkey,
wallet_address: &Pubkey,
Expand Down
2 changes: 1 addition & 1 deletion program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ num-derive = "0.4"
num-traits = "0.2"
solana-program = "2.3.0"
solana-system-interface = "1"
spl-associated-token-account-client = { version = "2.0.0", path = "../interface" }
spl-associated-token-account-interface = { version = "1.0.0", path = "../interface", features = ["borsh"] }
spl-token = { version = "8.0", features = ["no-entrypoint"] }
spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"] }
thiserror = "2.0"
Expand Down
49 changes: 1 addition & 48 deletions program/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@
//! Program instructions

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
pub use spl_associated_token_account_client::instruction::*;

/// Instructions supported by the `AssociatedTokenAccount` program
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
pub enum AssociatedTokenAccountInstruction {
/// Creates an associated token account for the given wallet address and
/// token mint Returns an error if the account exists.
///
/// 0. `[writeable,signer]` Funding account (must be a system account)
/// 1. `[writeable]` Associated token account address to be created
/// 2. `[]` Wallet address for the new associated token account
/// 3. `[]` The token mint for the new associated token account
/// 4. `[]` System program
/// 5. `[]` SPL Token program
Create,
/// Creates an associated token account for the given wallet address and
/// token mint, if it doesn't already exist. Returns an error if the
/// account exists, but with a different owner.
///
/// 0. `[writeable,signer]` Funding account (must be a system account)
/// 1. `[writeable]` Associated token account address to be created
/// 2. `[]` Wallet address for the new associated token account
/// 3. `[]` The token mint for the new associated token account
/// 4. `[]` System program
/// 5. `[]` SPL Token program
CreateIdempotent,
/// Transfers from and closes a nested associated token account: an
/// associated token account owned by an associated token account.
///
/// The tokens are moved from the nested associated token account to the
/// wallet's associated token account, and the nested account lamports are
/// moved to the wallet.
///
/// Note: Nested token accounts are an anti-pattern, and almost always
/// created unintentionally, so this instruction should only be used to
/// recover from errors.
///
/// 0. `[writeable]` Nested associated token account, must be owned by `3`
/// 1. `[]` Token mint for the nested associated token account
/// 2. `[writeable]` Wallet's associated token account
/// 3. `[]` Owner associated token account address, must be owned by `5`
/// 4. `[]` Token mint for the owner associated token account
/// 5. `[writeable, signer]` Wallet address for the owner associated token
/// account
/// 6. `[]` SPL Token program
RecoverNested,
}
pub use spl_associated_token_account_interface::instruction::*;
6 changes: 3 additions & 3 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use solana_program::{
};
#[deprecated(
since = "4.1.0",
note = "Use `spl-associated-token-account-client` crate instead."
note = "Use `spl-associated-token-account-interface` crate instead."
)]
pub use spl_associated_token_account_client::address::{
pub use spl_associated_token_account_interface::address::{
get_associated_token_address, get_associated_token_address_with_program_id,
};
// Export current SDK types for downstream users building with a different SDK
// version
pub use spl_associated_token_account_client::program::{check_id, id, ID};
pub use spl_associated_token_account_interface::program::{check_id, id, ID};

/// Create an associated token account for the given wallet address and token
/// mint
Expand Down
6 changes: 4 additions & 2 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use {
crate::{
error::AssociatedTokenAccountError,
instruction::AssociatedTokenAccountInstruction,
tools::account::{create_pda_account, get_account_len},
},
borsh::BorshDeserialize,
Expand All @@ -18,7 +17,10 @@ use {
sysvar::Sysvar,
},
solana_system_interface::program as system_program,
spl_associated_token_account_client::address::get_associated_token_address_and_bump_seed_internal,
spl_associated_token_account_interface::{
address::get_associated_token_address_and_bump_seed_internal,
instruction::AssociatedTokenAccountInstruction,
},
spl_token_2022::{
extension::{ExtensionType, StateWithExtensions},
state::{Account, Mint},
Expand Down
6 changes: 3 additions & 3 deletions program/tests/create_idempotent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use {
system_instruction::create_account,
transaction::{Transaction, TransactionError},
},
spl_associated_token_account::{
error::AssociatedTokenAccountError,
spl_associated_token_account::error::AssociatedTokenAccountError,
spl_associated_token_account_interface::{
address::get_associated_token_address_with_program_id,
instruction::{
create_associated_token_account, create_associated_token_account_idempotent,
},
},
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
spl_token_2022::{
extension::ExtensionType,
instruction::initialize_account,
Expand Down
6 changes: 4 additions & 2 deletions program/tests/extended_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use {
transaction::{Transaction, TransactionError},
},
solana_system_interface::instruction as system_instruction,
spl_associated_token_account::instruction::create_associated_token_account,
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
spl_associated_token_account_interface::{
address::get_associated_token_address_with_program_id,
instruction::create_associated_token_account,
},
spl_token_2022::{
error::TokenError,
extension::{
Expand Down
6 changes: 4 additions & 2 deletions program/tests/process_create_associated_token_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use {
transaction::{Transaction, TransactionError},
},
solana_system_interface::instruction as system_instruction,
spl_associated_token_account::instruction::create_associated_token_account,
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
spl_associated_token_account_interface::{
address::get_associated_token_address_with_program_id,
instruction::create_associated_token_account,
},
spl_token_2022::{extension::ExtensionType, state::Account},
};

Expand Down
17 changes: 4 additions & 13 deletions program/tests/program_test.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use {
solana_program::pubkey::Pubkey,
solana_program_test::{ProgramTest, *},
spl_associated_token_account::{id, processor::process_instruction},
solana_program::pubkey::Pubkey, solana_program_test::ProgramTest,
spl_associated_token_account_interface::program::id,
};

#[allow(dead_code)]
pub fn program_test(token_mint_address: Pubkey) -> ProgramTest {
let mut pc = ProgramTest::new(
"spl_associated_token_account",
id(),
processor!(process_instruction),
);
let mut pc = ProgramTest::new("spl_associated_token_account", id(), None);

// Add a token mint account
//
Expand All @@ -34,11 +29,7 @@ pub fn program_test(token_mint_address: Pubkey) -> ProgramTest {

#[allow(dead_code)]
pub fn program_test_2022(token_mint_address: Pubkey) -> ProgramTest {
let mut pc = ProgramTest::new(
"spl_associated_token_account",
id(),
processor!(process_instruction),
);
let mut pc = ProgramTest::new("spl_associated_token_account", id(), None);

// Add a token mint account
//
Expand Down
5 changes: 3 additions & 2 deletions program/tests/recover_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use {
transaction::{Transaction, TransactionError},
},
solana_system_interface::instruction as system_instruction,
spl_associated_token_account::instruction,
spl_associated_token_account_client::address::get_associated_token_address_with_program_id,
spl_associated_token_account_interface::{
address::get_associated_token_address_with_program_id, instruction,
},
spl_token_2022::{
extension::{ExtensionType, StateWithExtensionsOwned},
state::{Account, Mint},
Expand Down
5 changes: 3 additions & 2 deletions program/tests/spl_token_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use {
solana_program::pubkey::Pubkey,
solana_program_test::*,
solana_sdk::{program_pack::Pack, signature::Signer, transaction::Transaction},
spl_associated_token_account::instruction::create_associated_token_account,
spl_associated_token_account_client::address::get_associated_token_address,
spl_associated_token_account_interface::{
address::get_associated_token_address, instruction::create_associated_token_account,
},
spl_token::state::Account,
};

Expand Down