Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

associated-token-account: Bump dependent token version to 3.3 #2766

Merged
merged 2 commits into from Jan 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion associated-token-account/program/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ test-bpf = []
[dependencies]
borsh = "0.9.1"
solana-program = "1.9.2"
spl-token = { version = "0.1", path = "../../token/program-2022", features = ["no-entrypoint"], package = "spl-token-2022" }
spl-token = { version = "3.3", path = "../../token/program", features = ["no-entrypoint"] }

[dev-dependencies]
solana-program-test = "1.9.2"
Expand Down
28 changes: 7 additions & 21 deletions associated-token-account/program/src/lib.rs
Expand Up @@ -9,12 +9,7 @@ pub mod tools;

// Export current SDK types for downstream users building with a different SDK version
pub use solana_program;
use solana_program::{
instruction::{AccountMeta, Instruction},
program_pack::Pack,
pubkey::Pubkey,
sysvar,
};
use solana_program::{instruction::Instruction, program_pack::Pack, pubkey::Pubkey};

solana_program::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");

Expand Down Expand Up @@ -65,28 +60,19 @@ fn get_associated_token_address_and_bump_seed_internal(
/// 3. `[]` The token mint for the new associated token account
/// 4. `[]` System program
/// 5. `[]` SPL Token program
/// 6. `[]` Rent sysvar
///
// TODO: Uncomment after 1.0.4 is released
// #[deprecated(
// since = "1.0.4",
// note = "please use `instruction::create_associated_token_account` instead"
// )]
#[deprecated(
since = "1.0.4",
note = "please use `instruction::create_associated_token_account` instead"
)]
pub fn create_associated_token_account(
funding_address: &Pubkey,
wallet_address: &Pubkey,
spl_token_mint_address: &Pubkey,
) -> Instruction {
let mut instruction = instruction::create_associated_token_account(
instruction::create_associated_token_account(
funding_address,
wallet_address,
spl_token_mint_address,
);

// TODO: Remove after ATA 1.0.4 and Token >3.2.0 are released (Token::InitializeAccount3 is required if rent account is not provided)
instruction
.accounts
.push(AccountMeta::new_readonly(sysvar::rent::id(), false));

instruction
)
}
53 changes: 15 additions & 38 deletions associated-token-account/program/src/processor.rs
Expand Up @@ -51,10 +51,7 @@ pub fn process_create_associated_token_account(
let spl_token_program_info = next_account_info(account_info_iter)?;
let spl_token_program_id = spl_token_program_info.key;

// TODO: Remove after ATA 1.0.4 and Token >3.2.0 are released and just use Rent::get()
let (rent_sysvar_info, rent) = next_account_info(account_info_iter)
.map(|info| (Some(info), Rent::from_account_info(info).unwrap()))
.unwrap_or((None, Rent::get().unwrap()));
let rent = Rent::get()?;

let (associated_token_address, bump_seed) = get_associated_token_address_and_bump_seed_internal(
wallet_account_info.key,
Expand Down Expand Up @@ -85,38 +82,18 @@ pub fn process_create_associated_token_account(
)?;

msg!("Initialize the associated token account");

if let Some(rent_sysvar_info) = rent_sysvar_info {
invoke(
&spl_token::instruction::initialize_account(
spl_token_program_id,
associated_token_account_info.key,
spl_token_mint_info.key,
wallet_account_info.key,
)?,
&[
associated_token_account_info.clone(),
spl_token_mint_info.clone(),
wallet_account_info.clone(),
rent_sysvar_info.clone(),
spl_token_program_info.clone(),
],
)
} else {
// Use InitializeAccount3 when Rent account is not provided
invoke(
&spl_token::instruction::initialize_account3(
spl_token_program_id,
associated_token_account_info.key,
spl_token_mint_info.key,
wallet_account_info.key,
)?,
&[
associated_token_account_info.clone(),
spl_token_mint_info.clone(),
wallet_account_info.clone(),
spl_token_program_info.clone(),
],
)
}
invoke(
&spl_token::instruction::initialize_account3(
spl_token_program_id,
associated_token_account_info.key,
spl_token_mint_info.key,
wallet_account_info.key,
)?,
&[
associated_token_account_info.clone(),
spl_token_mint_info.clone(),
wallet_account_info.clone(),
spl_token_program_info.clone(),
],
)
}
Expand Up @@ -300,6 +300,7 @@ async fn test_create_associated_token_account_using_deprecated_instruction_creat
);

// Use legacy instruction creator
#[allow(deprecated)]
let create_associated_token_account_ix = deprecated_create_associated_token_account(
&payer.pubkey(),
&wallet_address,
Expand Down
2 changes: 1 addition & 1 deletion associated-token-account/program/tests/program_test.rs
Expand Up @@ -12,7 +12,7 @@ pub fn program_test(token_mint_address: Pubkey, use_latest_spl_token: bool) -> P
);

if use_latest_spl_token {
// TODO: Remove after Token >3.2.0 is released
// TODO: Remove after Token >3.2.0 is available by default in program-test
pc.add_program(
"spl_token",
spl_token::id(),
Expand Down
4 changes: 3 additions & 1 deletion stake-pool/cli/src/main.rs
Expand Up @@ -37,7 +37,9 @@ use {
system_instruction,
transaction::Transaction,
},
spl_associated_token_account::{create_associated_token_account, get_associated_token_address},
spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
},
spl_stake_pool::state::ValidatorStakeInfo,
spl_stake_pool::{
self, find_stake_program_address, find_transient_stake_program_address,
Expand Down
2 changes: 1 addition & 1 deletion stateless-asks/program/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ test-bpf = []
borsh = "0.9.1"
solana-program = "1.9.2"
spl-token = { version = "3.3", path = "../../token/program", features = ["no-entrypoint"] }
spl-associated-token-account = {version = "1.0.3", features = ["no-entrypoint"]}
spl-associated-token-account = {version = "1.0", path = "../../associated-token-account/program", features = ["no-entrypoint"]}
metaplex-token-metadata = { version = "0.0.1", features = ["no-entrypoint"] }
thiserror = "1.0"

Expand Down
4 changes: 3 additions & 1 deletion token/cli/src/main.rs
Expand Up @@ -41,7 +41,9 @@ use solana_sdk::{
system_instruction, system_program,
transaction::Transaction,
};
use spl_associated_token_account::*;
use spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
};
use spl_token::{
self,
instruction::*,
Expand Down
2 changes: 1 addition & 1 deletion token/rust/Cargo.toml
Expand Up @@ -17,6 +17,6 @@ async-trait = "0.1"
solana-client = "=1.9.2"
solana-program-test = "=1.9.2"
solana-sdk = "=1.9.2"
spl-associated-token-account = { version = "1.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "1.0", path = "../../associated-token-account/program", features = ["no-entrypoint"] }
spl-token-2022 = { version = "0.1", path="../program-2022" }
thiserror = "1.0"
4 changes: 3 additions & 1 deletion token/rust/src/token.rs
Expand Up @@ -10,7 +10,9 @@ use solana_sdk::{
system_instruction,
transaction::Transaction,
};
use spl_associated_token_account::{create_associated_token_account, get_associated_token_address};
use spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
};
use spl_token_2022::{
extension::{transfer_fee, ExtensionType, StateWithExtensionsOwned},
id, instruction,
Expand Down