diff --git a/Cargo.lock b/Cargo.lock index 6740655b..2c7ffb2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6872,16 +6872,17 @@ dependencies = [ "solana-program-test", "solana-sdk", "solana-system-interface", - "spl-associated-token-account-client", + "spl-associated-token-account-interface", "spl-token", "spl-token-2022", "thiserror 2.0.12", ] [[package]] -name = "spl-associated-token-account-client" -version = "2.0.0" +name = "spl-associated-token-account-interface" +version = "1.0.0" dependencies = [ + "borsh 1.5.7", "solana-instruction", "solana-pubkey", "solana-sdk-ids", diff --git a/interface/Cargo.toml b/interface/Cargo.toml index b97344d2..3220c8dd 100644 --- a/interface/Cargo.toml +++ b/interface/Cargo.toml @@ -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 "] 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"] } diff --git a/interface/src/instruction.rs b/interface/src/instruction.rs index ef10922b..622ba02a 100644 --- a/interface/src/instruction.rs +++ b/interface/src/instruction.rs @@ -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, diff --git a/program/Cargo.toml b/program/Cargo.toml index 39c89efc..13f8dbb3 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -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" diff --git a/program/src/instruction.rs b/program/src/instruction.rs index 855b7a2d..1f923fb6 100644 --- a/program/src/instruction.rs +++ b/program/src/instruction.rs @@ -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::*; diff --git a/program/src/lib.rs b/program/src/lib.rs index 5778456a..7c222229 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -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 diff --git a/program/src/processor.rs b/program/src/processor.rs index 170f8986..55956bab 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -3,7 +3,6 @@ use { crate::{ error::AssociatedTokenAccountError, - instruction::AssociatedTokenAccountInstruction, tools::account::{create_pda_account, get_account_len}, }, borsh::BorshDeserialize, @@ -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}, diff --git a/program/tests/create_idempotent.rs b/program/tests/create_idempotent.rs index cb762ae8..4bffbc6a 100644 --- a/program/tests/create_idempotent.rs +++ b/program/tests/create_idempotent.rs @@ -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, diff --git a/program/tests/extended_mint.rs b/program/tests/extended_mint.rs index ddfa8b7b..9ff50e38 100644 --- a/program/tests/extended_mint.rs +++ b/program/tests/extended_mint.rs @@ -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::{ diff --git a/program/tests/process_create_associated_token_account.rs b/program/tests/process_create_associated_token_account.rs index 3b07fb5e..4de39424 100644 --- a/program/tests/process_create_associated_token_account.rs +++ b/program/tests/process_create_associated_token_account.rs @@ -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}, }; diff --git a/program/tests/program_test.rs b/program/tests/program_test.rs index 2ecdb6ab..22988ffb 100644 --- a/program/tests/program_test.rs +++ b/program/tests/program_test.rs @@ -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 // @@ -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 // diff --git a/program/tests/recover_nested.rs b/program/tests/recover_nested.rs index 70fcdd65..b17f0245 100644 --- a/program/tests/recover_nested.rs +++ b/program/tests/recover_nested.rs @@ -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}, diff --git a/program/tests/spl_token_create.rs b/program/tests/spl_token_create.rs index d0b22252..a50a82c8 100644 --- a/program/tests/spl_token_create.rs +++ b/program/tests/spl_token_create.rs @@ -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, };