feat: upgrade to v2.0.0 with major dependency updates

- Upgrade Solana dependencies from 2.3.x to 3.0.0 series
  - Upgrade solana-streamer-sdk from 0.4.13 to 0.5.0
  - Upgrade yellowstone-grpc from 8.0.0 to 9.0.0
  - Add new SPL token utility modules (spl_token.rs, spl_token_2022.rs,
  spl_associated_token_account.rs)
  - Remove deprecated gRPC protocol definitions (protos/ directory)
  - Remove event_subscription example and update all example dependencies
  - Update README documentation to reflect v2.0.0 changes
  - Refactor imports to use new dependency structure across examples

  BREAKING CHANGES:
  - Solana SDK upgraded to 3.0.0 with API changes
  - Removed gRPC protocol definitions
  - Updated import paths for SPL token operations
This commit is contained in:
ysq
2025-09-27 14:24:41 +08:00
parent e75b0c9480
commit a7f673b43d
70 changed files with 502 additions and 3001 deletions
+2 -4
View File
@@ -1,8 +1,6 @@
use dashmap::DashMap;
use solana_sdk::{
address_lookup_table::state::AddressLookupTable, message::AddressLookupTableAccount,
pubkey::Pubkey,
};
use solana_address_lookup_table_interface::state::AddressLookupTable;
use solana_sdk::{message::AddressLookupTableAccount, pubkey::Pubkey};
use std::{
error::Error,
sync::{Arc, OnceLock},
+1 -1
View File
@@ -33,7 +33,7 @@ use crate::instruction::utils::pumpfun::global_constants::{
TOKEN_TOTAL_SUPPLY,
};
use crate::instruction::utils::pumpfun::{get_bonding_curve_pda, get_creator_vault_pda};
use crate::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
use solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
/// Represents the global configuration account for token pricing and fees
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
+6 -7
View File
@@ -5,11 +5,10 @@ use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use spl_associated_token_account::{
get_associated_token_address_with_program_id, ID as ASSOCIATED_TOKEN_PROGRAM_ID,
};
use std::num::NonZeroUsize;
use crate::common::{spl_associated_token_account::get_associated_token_address_with_program_id, spl_token::close_account};
const MAX_PDA_CACHE_SIZE: usize = 10000;
const MAX_ATA_CACHE_SIZE: usize = 10000;
const MAX_INSTRUCTION_CACHE_SIZE: usize = 10000;
@@ -104,7 +103,7 @@ pub fn _create_associated_token_account_idempotent_fast(
if use_seed
&& !mint.eq(&crate::constants::WSOL_TOKEN_ACCOUNT)
&& !mint.eq(&crate::constants::SOL_TOKEN_ACCOUNT)
&& token_program.eq(&spl_token::ID)
&& token_program.eq(&crate::constants::TOKEN_PROGRAM)
{
// Use cache to get instruction
get_cached_instructions(cache_key, || {
@@ -120,7 +119,7 @@ pub fn _create_associated_token_account_idempotent_fast(
// Create Associated Token Account instruction
// Reference implementation of spl_associated_token_account::instruction::create_associated_token_account
vec![Instruction {
program_id: ASSOCIATED_TOKEN_PROGRAM_ID,
program_id: crate::constants::ASSOCIATED_TOKEN_PROGRAM_ID,
accounts: vec![
AccountMeta::new(*payer, true), // Payer (signer, writable)
AccountMeta::new(associated_token_address, false), // ATA address (writable, non-signer)
@@ -247,7 +246,7 @@ fn _get_associated_token_address_with_program_id_fast(
let ata = if use_seed
&& !token_mint_address.eq(&crate::constants::WSOL_TOKEN_ACCOUNT)
&& !token_mint_address.eq(&crate::constants::SOL_TOKEN_ACCOUNT)
&& token_program_id.eq(&spl_token::ID)
&& token_program_id.eq(&crate::constants::TOKEN_PROGRAM)
{
super::seed::get_associated_token_address_with_program_id_use_seed(
wallet_address,
@@ -292,7 +291,7 @@ pub fn fast_init(payer: &Pubkey) {
wsol_token_account,
},
|| {
vec![spl_token::instruction::close_account(
vec![close_account(
&crate::constants::TOKEN_PROGRAM,
&wsol_token_account,
&payer,
+5 -2
View File
@@ -1,12 +1,15 @@
pub mod address_lookup_cache;
pub mod bonding_curve;
pub mod fast_fn;
pub mod gas_fee_strategy;
pub mod global;
pub mod nonce_cache;
pub mod seed;
pub mod spl_associated_token_account;
pub mod spl_token;
pub mod spl_token_2022;
pub mod subscription_handle;
pub mod types;
pub mod gas_fee_strategy;
pub use gas_fee_strategy::*;
pub use types::*;
pub use gas_fee_strategy::*;
+11 -13
View File
@@ -1,8 +1,8 @@
use parking_lot::Mutex;
use solana_hash::Hash;
use solana_nonce::state::State;
use solana_nonce::versions::Versions;
use solana_sdk::account_utils::StateMut;
use solana_sdk::nonce::state::Versions;
use solana_sdk::nonce::State;
use solana_sdk::pubkey::Pubkey;
use solana_streamer_sdk::common::SolanaRpcClient;
use std::str::FromStr;
@@ -59,8 +59,8 @@ impl NonceCache {
self.update_nonce_info_partial(nonce_account, None, Some(false));
}
/// Get a copy of NonceInfo
pub fn get_nonce_info(&self) -> NonceInfo {
/// Get a copy of NonceInfo
pub fn get_nonce_info(&self) -> NonceInfo {
let nonce_info = self.nonce_info.lock();
NonceInfo {
nonce_account: nonce_info.nonce_account,
@@ -72,15 +72,13 @@ impl NonceCache {
pub fn get_durable_nonce_info() -> DurableNonceInfo {
let nonce_info = Self::get_instance().get_nonce_info();
let nonce_account = nonce_info.nonce_account;
let current_nonce = if nonce_account.is_some() && nonce_info.current_nonce != Hash::default() {
Some(nonce_info.current_nonce)
} else {
None
};
DurableNonceInfo {
nonce_account,
current_nonce,
}
let current_nonce =
if nonce_account.is_some() && nonce_info.current_nonce != Hash::default() {
Some(nonce_info.current_nonce)
} else {
None
};
DurableNonceInfo { nonce_account, current_nonce }
}
/// Partially update NonceInfo, only update the passed fields
+13 -19
View File
@@ -1,7 +1,7 @@
use crate::common::SolanaRpcClient;
use anyhow::anyhow;
use fnv::FnvHasher;
use solana_sdk::{instruction::Instruction, program_pack::Pack, pubkey::Pubkey};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
use solana_system_interface::instruction::create_account_with_seed;
use std::hash::Hasher;
use std::sync::Arc;
@@ -34,15 +34,9 @@ pub fn start_rent_updater(client: Arc<SolanaRpcClient>) {
async fn fetch_rent_for_token_account(
client: &SolanaRpcClient,
is_2022_token: bool,
_is_2022_token: bool,
) -> Result<u64, anyhow::Error> {
Ok(client
.get_minimum_balance_for_rent_exemption(if is_2022_token {
spl_token_2022::state::Account::LEN as usize
} else {
spl_token::state::Account::LEN as usize
})
.await?)
Ok(client.get_minimum_balance_for_rent_exemption(165).await?)
}
pub fn create_associated_token_account_use_seed(
@@ -51,7 +45,7 @@ pub fn create_associated_token_account_use_seed(
mint: &Pubkey,
token_program: &Pubkey,
) -> Result<Vec<Instruction>, anyhow::Error> {
let is_2022_token = token_program == &spl_token_2022::id();
let is_2022_token = token_program == &crate::constants::TOKEN_PROGRAM_2022;
let rent =
if is_2022_token { unsafe { SPL_TOKEN_2022_RENT } } else { unsafe { SPL_TOKEN_RENT } };
if rent.is_none() {
@@ -72,18 +66,14 @@ pub fn create_associated_token_account_use_seed(
let seed = unsafe { std::str::from_utf8_unchecked(&buf) };
let ata_like = Pubkey::create_with_seed(payer, seed, token_program)?;
let len = if is_2022_token {
spl_token_2022::state::Account::LEN as u64
} else {
spl_token::state::Account::LEN as u64
};
let len = 165;
let create_acc =
create_account_with_seed(payer, &ata_like, owner, seed, rent.unwrap(), len, token_program);
let init_acc = if is_2022_token {
spl_token_2022::instruction::initialize_account3(&token_program, &ata_like, mint, owner)?
crate::common::spl_token_2022::initialize_account3(&token_program, &ata_like, mint, owner)?
} else {
spl_token::instruction::initialize_account3(&token_program, &ata_like, mint, owner)?
crate::common::spl_token::initialize_account3(&token_program, &ata_like, mint, owner)?
};
Ok(vec![create_acc, init_acc])
@@ -106,9 +96,13 @@ pub fn get_associated_token_address_with_program_id_use_seed(
_ => b'a' + (nibble - 10),
};
}
let is_2022_token = token_program_id == &spl_token_2022::id();
let is_2022_token = token_program_id == &crate::constants::TOKEN_PROGRAM_2022;
let seed = unsafe { std::str::from_utf8_unchecked(&buf) };
let token_program = if is_2022_token { &spl_token_2022::id() } else { &spl_token::id() };
let token_program = if is_2022_token {
&crate::constants::TOKEN_PROGRAM_2022
} else {
&crate::constants::TOKEN_PROGRAM
};
let ata_like = Pubkey::create_with_seed(wallet_address, seed, token_program)?;
Ok(ata_like)
}
@@ -0,0 +1,55 @@
use solana_sdk::{
message::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use crate::constants::{ASSOCIATED_TOKEN_PROGRAM_ID, SYSTEM_PROGRAM};
pub fn get_associated_token_address_with_program_id(
wallet_address: &Pubkey,
token_mint_address: &Pubkey,
token_program_id: &Pubkey,
) -> Pubkey {
Pubkey::find_program_address(
&[&wallet_address.to_bytes(), &token_program_id.to_bytes(), &token_mint_address.to_bytes()],
&crate::constants::ASSOCIATED_TOKEN_PROGRAM_ID,
)
.0
}
pub fn get_associated_token_address(
wallet_address: &Pubkey,
token_mint_address: &Pubkey,
) -> Pubkey {
get_associated_token_address_with_program_id(
wallet_address,
token_mint_address,
&crate::constants::TOKEN_PROGRAM,
)
}
pub fn create_associated_token_account_idempotent(
funding_address: &Pubkey,
wallet_address: &Pubkey,
token_mint_address: &Pubkey,
token_program_id: &Pubkey,
) -> Instruction {
let instruction = 1;
let associated_account_address = get_associated_token_address_with_program_id(
wallet_address,
token_mint_address,
token_program_id,
);
Instruction {
program_id: ASSOCIATED_TOKEN_PROGRAM_ID,
accounts: vec![
AccountMeta::new(*funding_address, true),
AccountMeta::new(associated_account_address, false),
AccountMeta::new_readonly(*wallet_address, false),
AccountMeta::new_readonly(*token_mint_address, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM, false),
AccountMeta::new_readonly(*token_program_id, false),
],
data: vec![instruction],
}
}
+48
View File
@@ -0,0 +1,48 @@
use solana_program::pubkey;
use solana_sdk::{
message::{AccountMeta, Instruction},
program_error::ProgramError,
pubkey::Pubkey,
};
pub const ID: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
pub fn close_account(
token_program_id: &Pubkey,
account_pubkey: &Pubkey,
destination_pubkey: &Pubkey,
owner_pubkey: &Pubkey,
signer_pubkeys: &[&Pubkey],
) -> Result<Instruction, solana_sdk::program_error::ProgramError> {
// CloseAccount
let mut data = Vec::with_capacity(1);
data.push(9);
let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
accounts.push(solana_sdk::message::AccountMeta::new(*account_pubkey, false));
accounts.push(solana_sdk::message::AccountMeta::new(*destination_pubkey, false));
accounts.push(solana_sdk::message::AccountMeta::new_readonly(
*owner_pubkey,
signer_pubkeys.is_empty(),
));
for signer_pubkey in signer_pubkeys.iter() {
accounts.push(solana_sdk::message::AccountMeta::new_readonly(**signer_pubkey, true));
}
Ok(Instruction { program_id: *token_program_id, accounts, data })
}
pub fn initialize_account3(
token_program_id: &Pubkey,
account_pubkey: &Pubkey,
mint_pubkey: &Pubkey,
owner_pubkey: &Pubkey,
) -> Result<Instruction, ProgramError> {
// InitializeAccount3
let mut data = Vec::with_capacity(33);
data.push(18);
data.extend_from_slice(owner_pubkey.as_ref());
let accounts = vec![
AccountMeta::new(*account_pubkey, false),
AccountMeta::new_readonly(*mint_pubkey, false),
];
Ok(Instruction { program_id: *token_program_id, accounts, data })
}
+25
View File
@@ -0,0 +1,25 @@
use solana_program::pubkey;
use solana_sdk::{
message::{AccountMeta, Instruction},
program_error::ProgramError,
pubkey::Pubkey,
};
pub const ID: Pubkey = pubkey!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
pub fn initialize_account3(
token_program_id: &Pubkey,
account_pubkey: &Pubkey,
mint_pubkey: &Pubkey,
owner_pubkey: &Pubkey,
) -> Result<Instruction, ProgramError> {
// InitializeAccount3
let mut data = Vec::with_capacity(33);
data.push(18);
data.extend_from_slice(owner_pubkey.as_ref());
let accounts = vec![
AccountMeta::new(*account_pubkey, false),
AccountMeta::new_readonly(*mint_pubkey, false),
];
Ok(Instruction { program_id: *token_program_id, accounts, data })
}
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::swqos::SwqosConfig;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_commitment_config::CommitmentConfig;
#[derive(Debug, Clone)]
pub struct TradeConfig {