Skip to content

Commit dfca33e

Browse files
authored
deps: Upgrade to SDK v3 (#92)
#### Problem SDK v3 has been out for some time, but the sample program and CLI have not been upgraded to it. #### Summary of changes Do all the upgrades! This PR also uses the split-up crates, including SPL interface crates instead of program crates. To properly use the interface crate, also add the token-2022 BPF program as a fixture. Also add a `TryFrom<u32>` implementation for TransferHookError, and stop using solana-program in the interface.
1 parent 10f3882 commit dfca33e

File tree

14 files changed

+1703
-2018
lines changed

14 files changed

+1703
-2018
lines changed

Cargo.lock

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

clients/cli/Cargo.toml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ edition = { workspace = true }
1212
[dependencies]
1313
clap = { version = "3", features = ["cargo"] }
1414
futures-util = "0.3.31"
15-
solana-clap-v3-utils = "2.3.4"
16-
solana-cli-config = "2.3.4"
17-
solana-client = "2.3.4"
15+
solana-clap-v3-utils = "3.0.0"
16+
solana-cli-config = "3.0.0"
17+
solana-client = "3.0.0"
18+
solana-commitment-config = "3.0.0"
19+
solana-instruction = "3.0.0"
1820
solana-logger = "3.0.0"
19-
solana-remote-wallet = "2.3.4"
20-
solana-sdk = "2.2.1"
21-
solana-sdk-ids = "2.2.1"
22-
solana-system-interface = "1"
23-
spl-tlv-account-resolution = { version = "0.10.0", features = ["serde-traits"] }
24-
spl-transfer-hook-interface = "0.10.0"
21+
solana-pubkey = "3.0.0"
22+
solana-remote-wallet = "3.0.0"
23+
solana-sdk-ids = "3.0.0"
24+
solana-signature = "3.0.0"
25+
solana-signer = "3.0.0"
26+
solana-system-interface = "2"
27+
solana-transaction = "3.0.0"
28+
spl-tlv-account-resolution = { version = "0.11.0", features = ["serde-traits"] }
29+
spl-transfer-hook-interface = { version = "2.0.0", path = "../../interface" }
2530
strum = "0.27"
2631
strum_macros = "0.27"
2732
tokio = { version = "1", features = ["full"] }
@@ -30,9 +35,12 @@ serde_json = "1.0.142"
3035
serde_yaml = "0.9.34"
3136

3237
[dev-dependencies]
33-
solana-test-validator = "2.3.4"
34-
spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"] }
35-
spl-token-client = "0.16.1"
38+
solana-account = "3.0.0"
39+
solana-keypair = "3.0.0"
40+
solana-program-option = "3.0.0"
41+
solana-test-validator = "3.0.0"
42+
spl-token-2022-interface = "2.0.0"
43+
spl-token-client = "0.18.0"
3644
spl-transfer-hook-example = { version = "0.6.0", path = "../../program" }
3745

3846
[lints]

clients/cli/src/main.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ use {
1212
keypair::signer_from_path,
1313
},
1414
solana_client::nonblocking::rpc_client::RpcClient,
15+
solana_commitment_config::CommitmentConfig,
16+
solana_instruction::Instruction,
17+
solana_pubkey::Pubkey,
1518
solana_remote_wallet::remote_wallet::RemoteWalletManager,
16-
solana_sdk::{
17-
commitment_config::CommitmentConfig,
18-
instruction::Instruction,
19-
pubkey::Pubkey,
20-
signature::{Signature, Signer},
21-
transaction::Transaction,
22-
},
19+
solana_signature::Signature,
20+
solana_signer::Signer,
2321
solana_system_interface::{instruction as system_instruction, program as system_program},
22+
solana_transaction::Transaction,
2423
spl_tlv_account_resolution::{account::ExtraAccountMeta, state::ExtraAccountMetaList},
2524
spl_transfer_hook_interface::{
2625
get_extra_account_metas_address,
@@ -533,13 +532,13 @@ extraMetas:
533532
mod test {
534533
use {
535534
super::*,
536-
solana_sdk::{
537-
account::Account, instruction::AccountMeta, program_option::COption,
538-
signer::keypair::Keypair,
539-
},
535+
solana_account::Account,
536+
solana_instruction::AccountMeta,
537+
solana_keypair::Keypair,
538+
solana_program_option::COption,
540539
solana_sdk_ids::bpf_loader_upgradeable,
541540
solana_test_validator::{TestValidator, TestValidatorGenesis, UpgradeableProgramInfo},
542-
spl_token_2022::{
541+
spl_token_2022_interface::{
543542
extension::{ExtensionType, StateWithExtensionsMut},
544543
state::Mint,
545544
},
@@ -582,7 +581,7 @@ mod test {
582581
Account {
583582
lamports: 1_000_000_000,
584583
data: mint_data,
585-
owner: spl_token_2022::id(),
584+
owner: spl_token_2022_interface::id(),
586585
..Account::default()
587586
}
588587
.into(),
@@ -607,7 +606,7 @@ mod test {
607606

608607
let token = Token::new(
609608
client.clone(),
610-
&spl_token_2022::id(),
609+
&spl_token_2022_interface::id(),
611610
&spl_transfer_hook_example::mint::id(),
612611
Some(decimals),
613612
payer.clone(),

clients/cli/src/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
serde::{Deserialize, Serialize},
3-
solana_sdk::pubkey::Pubkey,
3+
solana_pubkey::Pubkey,
44
spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed},
55
std::{path::Path, str::FromStr},
66
strum_macros::{EnumString, IntoStaticStr},

interface/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ crate-type = ["lib"]
3636
workspace = true
3737

3838
[dev-dependencies]
39-
solana-program = "2.3.0"
39+
solana-sha256-hasher = "3.0.0"
4040
tokio = { version = "1.47.1", features = ["full"] }
4141

4242
[package.metadata.docs.rs]

interface/src/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ impl ToStr for TransferHookError {
4040
}
4141
}
4242
}
43+
44+
impl TryFrom<u32> for TransferHookError {
45+
type Error = ProgramError;
46+
fn try_from(code: u32) -> Result<Self, Self::Error> {
47+
num_traits::FromPrimitive::from_u32(code).ok_or(ProgramError::InvalidArgument)
48+
}
49+
}

interface/src/instruction.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ pub fn update_extra_account_meta_list(
252252

253253
#[cfg(test)]
254254
mod test {
255-
use {super::*, crate::NAMESPACE, solana_program::hash, spl_pod::bytemuck::pod_from_bytes};
255+
use {
256+
super::*, crate::NAMESPACE, solana_sha256_hasher::hashv, spl_pod::bytemuck::pod_from_bytes,
257+
};
256258

257259
#[test]
258260
fn system_program_id() {
@@ -266,7 +268,7 @@ mod test {
266268
let packed = check.pack();
267269
// Please use ExecuteInstruction::SPL_DISCRIMINATOR in your program, the
268270
// following is just for test purposes
269-
let preimage = hash::hashv(&[format!("{NAMESPACE}:execute").as_bytes()]);
271+
let preimage = hashv(&[format!("{NAMESPACE}:execute").as_bytes()]);
270272
let discriminator = &preimage.as_ref()[..ArrayDiscriminator::LENGTH];
271273
let mut expect = vec![];
272274
expect.extend_from_slice(discriminator.as_ref());
@@ -296,8 +298,7 @@ mod test {
296298
let packed = check.pack();
297299
// Please use INITIALIZE_EXTRA_ACCOUNT_METAS_DISCRIMINATOR in your program,
298300
// the following is just for test purposes
299-
let preimage =
300-
hash::hashv(&[format!("{NAMESPACE}:initialize-extra-account-metas").as_bytes()]);
301+
let preimage = hashv(&[format!("{NAMESPACE}:initialize-extra-account-metas").as_bytes()]);
301302
let discriminator = &preimage.as_ref()[..ArrayDiscriminator::LENGTH];
302303
let mut expect = vec![];
303304
expect.extend_from_slice(discriminator.as_ref());

program/Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ forbid-additional-mints = []
1616

1717
[dependencies]
1818
arrayref = "0.3.9"
19-
solana-program = "2.3.0"
20-
solana-system-interface = "1"
21-
spl-tlv-account-resolution = "0.10.0"
22-
spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"] }
23-
spl-transfer-hook-interface = "0.10.0"
19+
solana-account-info = "3.0.0"
20+
solana-cpi = "3.0.0"
21+
solana-msg = "3.0.0"
22+
solana-program-entrypoint = "3.0.0"
23+
solana-program-error = "3.0.0"
24+
solana-pubkey = "3.0.0"
25+
solana-system-interface = { version = "2", features = ["bincode"] }
26+
spl-tlv-account-resolution = "0.11.0"
27+
spl-token-2022-interface = "2.0.0"
28+
spl-transfer-hook-interface = { version = "2.0.0", path = "../interface" }
2429
spl-type-length-value = "0.9.0"
2530

2631
[dev-dependencies]
27-
solana-program-test = "2.3.4"
28-
solana-sdk = "2.2.1"
29-
solana-system-interface = "1"
32+
solana-program-test = "3.0.0"
33+
solana-sdk = "3.0.0"
3034

3135
[lib]
3236
crate-type = ["cdylib", "lib"]

program/src/entrypoint.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
//! Program entrypoint
22
33
use {
4-
crate::processor,
5-
solana_program::{
6-
account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError,
7-
pubkey::Pubkey,
8-
},
4+
crate::processor, solana_account_info::AccountInfo, solana_msg::msg,
5+
solana_program_error::ProgramResult, solana_pubkey::Pubkey,
96
spl_transfer_hook_interface::error::TransferHookError,
107
};
118

12-
solana_program::entrypoint!(process_instruction);
9+
solana_program_entrypoint::entrypoint!(process_instruction);
1310
fn process_instruction(
1411
program_id: &Pubkey,
1512
accounts: &[AccountInfo],
1613
instruction_data: &[u8],
1714
) -> ProgramResult {
1815
if let Err(error) = processor::process(program_id, accounts, instruction_data) {
19-
// catch the error so we can print it
20-
error.print::<TransferHookError>();
16+
msg!(error.to_str::<TransferHookError>());
2117
return Err(error);
2218
}
2319
Ok(())

program/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ pub mod state;
1313
#[cfg(not(feature = "no-entrypoint"))]
1414
mod entrypoint;
1515

16-
// Export current sdk types for downstream users building with a different sdk
17-
// version
18-
pub use solana_program;
19-
2016
/// Place the mint id that you want to target with your transfer hook program.
2117
/// Any other mint will fail to initialize, protecting the transfer hook program
2218
/// from rogue mints trying to get access to accounts.
@@ -26,5 +22,5 @@ pub use solana_program;
2622
/// unsafe, this simple example implementation only allows for one mint.
2723
#[cfg(feature = "forbid-additional-mints")]
2824
pub mod mint {
29-
solana_program::declare_id!("Mint111111111111111111111111111111111111111");
25+
solana_pubkey::declare_id!("Mint111111111111111111111111111111111111111");
3026
}

0 commit comments

Comments
 (0)