diff --git a/README.md b/README.md index 7fc1853..de112aa 100755 --- a/README.md +++ b/README.md @@ -382,6 +382,8 @@ use sol_trade_sdk::{ raydium_cpmm::common::{get_buy_token_amount, get_sell_sol_amount} }, }; +use spl_token; // For standard SPL Token +// use spl_token_2022; // For Token 2022 standard (if needed) async fn test_raydium_cpmm() -> Result<(), Box> { println!("Testing Raydium CPMM trading..."); @@ -408,6 +410,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // If not provided, will auto-calculate wsol-mint direction pool + mint_token_program: Some(spl_token::ID), // Support spl_token or spl_token_2022::ID minimum_amount_out: Some(buy_amount_out), // If not provided, defaults to 0 auto_handle_wsol: true, // Automatically handle wSOL wrapping/unwrapping })), @@ -427,6 +430,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // If not provided, will auto-calculate wsol-mint direction pool + mint_token_program: Some(spl_token::ID), // Support spl_token or spl_token_2022::ID minimum_amount_out: Some(sell_sol_amount), // If not provided, defaults to 0 auto_handle_wsol: true, // Automatically handle wSOL wrapping/unwrapping })), diff --git a/README_CN.md b/README_CN.md index acc4b0b..dd7ab26 100755 --- a/README_CN.md +++ b/README_CN.md @@ -380,6 +380,8 @@ use sol_trade_sdk::{ raydium_cpmm::common::{get_buy_token_amount, get_sell_sol_amount} }, }; +use spl_token; // 用于标准 SPL Token +// use spl_token_2022; // 用于 Token 2022 标准(如果需要) async fn test_raydium_cpmm() -> Result<(), Box> { println!("Testing Raydium CPMM trading..."); @@ -406,6 +408,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // 如果不传,会自动计算 wsol-mint 方向的池子 + mint_token_program: Some(spl_token::ID), // 支持 spl_token 或 spl_token_2022::ID minimum_amount_out: Some(buy_amount_out), // 如果不传,默认为0 auto_handle_wsol: true, // 自动处理 wSOL 包装/解包装 })), @@ -425,6 +428,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // 如果不传,会自动计算 wsol-mint 方向的池子 + mint_token_program: Some(spl_token::ID), // 支持 spl_token 或 spl_token_2022::ID minimum_amount_out: Some(sell_sol_amount), // 如果不传,默认为0 auto_handle_wsol: true, // 自动处理 wSOL 包装/解包装 })), diff --git a/src/constants/bonk.rs b/src/constants/bonk.rs index e677d60..20a5f73 100755 --- a/src/constants/bonk.rs +++ b/src/constants/bonk.rs @@ -23,7 +23,7 @@ pub mod accounts { pub const AUTHORITY: Pubkey = pubkey!("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"); pub const GLOBAL_CONFIG: Pubkey = pubkey!("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX"); pub const PLATFORM_CONFIG: Pubkey = pubkey!("FfYek5vEz23cMkWsdJwG2oa6EphsvXSHrGpdALN4g6W1"); - pub const TOKEN_PROGRAM: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); + pub const TOKEN_PROGRAM: Pubkey = spl_token::ID; pub const EVENT_AUTHORITY: Pubkey = pubkey!("2DPAtwB8L12vrMRExbLuyGnC7n2J5LNoZQSejeQGpwkr"); pub const WSOL_TOKEN_ACCOUNT: Pubkey = pubkey!("So11111111111111111111111111111111111111112"); pub const BONK: Pubkey = pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"); diff --git a/src/constants/pumpfun.rs b/src/constants/pumpfun.rs index a163109..0434671 100755 --- a/src/constants/pumpfun.rs +++ b/src/constants/pumpfun.rs @@ -96,7 +96,7 @@ pub mod accounts { pub const SYSTEM_PROGRAM: Pubkey = pubkey!("11111111111111111111111111111111"); /// Token Program ID - pub const TOKEN_PROGRAM: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); + pub const TOKEN_PROGRAM: Pubkey = spl_token::ID; /// Associated Token Program ID pub const ASSOCIATED_TOKEN_PROGRAM: Pubkey = diff --git a/src/constants/pumpswap.rs b/src/constants/pumpswap.rs index db2ee4a..0981123 100755 --- a/src/constants/pumpswap.rs +++ b/src/constants/pumpswap.rs @@ -46,7 +46,7 @@ pub mod accounts { pub const SYSTEM_PROGRAM: Pubkey = pubkey!("11111111111111111111111111111111"); /// Token Program ID - pub const TOKEN_PROGRAM: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); + pub const TOKEN_PROGRAM: Pubkey = spl_token::ID; /// Associated Token Program ID pub const ASSOCIATED_TOKEN_PROGRAM: Pubkey = diff --git a/src/constants/raydium_cpmm.rs b/src/constants/raydium_cpmm.rs index edf806e..389966d 100755 --- a/src/constants/raydium_cpmm.rs +++ b/src/constants/raydium_cpmm.rs @@ -22,7 +22,7 @@ pub mod accounts { use solana_sdk::{pubkey, pubkey::Pubkey}; pub const AUTHORITY: Pubkey = pubkey!("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"); pub const AMM_CONFIG: Pubkey = pubkey!("D4FPEruKEHrG5TenZ2mpDGEfu1iUvTiqBxvpU8HLBvC2"); - pub const TOKEN_PROGRAM: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); + pub const TOKEN_PROGRAM: Pubkey = spl_token::ID; pub const WSOL_TOKEN_ACCOUNT: Pubkey = pubkey!("So11111111111111111111111111111111111111112"); pub const RAYDIUM_CPMM: Pubkey = pubkey!("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"); } diff --git a/src/instruction/raydium_cpmm.rs b/src/instruction/raydium_cpmm.rs index f792249..f63569c 100755 --- a/src/instruction/raydium_cpmm.rs +++ b/src/instruction/raydium_cpmm.rs @@ -124,7 +124,7 @@ impl RaydiumCpmmInstructionBuilder { ¶ms.payer.pubkey(), ¶ms.payer.pubkey(), ¶ms.mint, - &accounts::TOKEN_PROGRAM, + &protocol_params.mint_token_program.unwrap_or(accounts::TOKEN_PROGRAM), )); // 创建买入指令 @@ -138,7 +138,7 @@ impl RaydiumCpmmInstructionBuilder { solana_sdk::instruction::AccountMeta::new(wsol_vault_account, false), // Input Vault Account solana_sdk::instruction::AccountMeta::new(mint_vault_account, false), // Output Vault Account solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Input Token Program (readonly) - solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Output Token Program (readonly) + solana_sdk::instruction::AccountMeta::new_readonly(protocol_params.mint_token_program.unwrap_or(accounts::TOKEN_PROGRAM), false), // Output Token Program (readonly) solana_sdk::instruction::AccountMeta::new_readonly(accounts::WSOL_TOKEN_ACCOUNT, false), // Input token mint (readonly) solana_sdk::instruction::AccountMeta::new_readonly(params.mint, false), // Output token mint (readonly) solana_sdk::instruction::AccountMeta::new(observation_state_account, false), // Observation State Account @@ -253,7 +253,7 @@ impl RaydiumCpmmInstructionBuilder { ¶ms.payer.pubkey(), ¶ms.payer.pubkey(), &accounts::WSOL_TOKEN_ACCOUNT, - &accounts::TOKEN_PROGRAM, + &protocol_params.mint_token_program.unwrap(), ), ); @@ -267,7 +267,7 @@ impl RaydiumCpmmInstructionBuilder { solana_sdk::instruction::AccountMeta::new(wsol_token_account, false), // Output Token Account solana_sdk::instruction::AccountMeta::new(mint_vault_account, false), // Input Vault Account solana_sdk::instruction::AccountMeta::new(wsol_vault_account, false), // Output Vault Account - solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Input Token Program (readonly) + solana_sdk::instruction::AccountMeta::new_readonly(protocol_params.mint_token_program.unwrap_or(accounts::TOKEN_PROGRAM), false), // Input Token Program (readonly) solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Output Token Program (readonly) solana_sdk::instruction::AccountMeta::new_readonly(params.mint, false), // Input token mint (readonly) solana_sdk::instruction::AccountMeta::new_readonly(accounts::WSOL_TOKEN_ACCOUNT, false), // Output token mint (readonly) diff --git a/src/main.rs b/src/main.rs index c2660f7..c204f95 100755 --- a/src/main.rs +++ b/src/main.rs @@ -354,6 +354,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // 如果不传,会自动计算 wsol-mint 方向的池子 + mint_token_program: Some(spl_token::ID), // spl_token_2022::ID minimum_amount_out: Some(buy_amount_out), // 如果不传、默认为0 auto_handle_wsol: true, })), @@ -373,6 +374,7 @@ async fn test_raydium_cpmm() -> Result<(), Box> { None, Some(Box::new(RaydiumCpmmParams { pool_state: Some(pool_state), // 如果不传,会自动计算 wsol-mint 方向的池子 + mint_token_program: Some(spl_token::ID), // spl_token_2022::ID minimum_amount_out: Some(sell_sol_amount), // 如果不传、默认为0 auto_handle_wsol: true, })), diff --git a/src/trading/core/params.rs b/src/trading/core/params.rs index 806253b..0145789 100755 --- a/src/trading/core/params.rs +++ b/src/trading/core/params.rs @@ -219,6 +219,7 @@ impl ProtocolParams for BonkParams { #[derive(Clone)] pub struct RaydiumCpmmParams { pub pool_state: Option, + pub mint_token_program: Option, // spl_token_2022::ID pub minimum_amount_out: Option, pub auto_handle_wsol: bool, } @@ -227,6 +228,7 @@ impl RaydiumCpmmParams { pub fn default() -> Self { Self { pool_state: None, + mint_token_program: Some(spl_token::ID), minimum_amount_out: None, auto_handle_wsol: true, }