This commit is contained in:
ysq
2025-09-17 11:14:15 +08:00
parent da28f40889
commit fad343ffbf
43 changed files with 1732 additions and 2017 deletions
+199 -179
View File
@@ -1,15 +1,17 @@
use clap::Parser;
use sol_trade_sdk::{
common::{fast_fn::get_associated_token_address_with_program_id_fast_use_seed, AnyResult},
constants::trade::trade::{DEFAULT_CU_LIMIT, DEFAULT_CU_PRICE},
swqos::{settings::SwqosSettings, SwqosConfig},
common::{
fast_fn::get_associated_token_address_with_program_id_fast_use_seed, AnyResult,
PriorityFee, TradeConfig,
},
swqos::SwqosConfig,
trading::{
core::params::{
BonkParams, PumpFunParams, PumpSwapParams, RaydiumAmmV4Params, RaydiumCpmmParams,
},
factory::DexType,
},
SolanaTrade, TradeBuyParams, TradeSellParams,
SolanaTrade,
};
use solana_sdk::{
commitment_config::CommitmentConfig, native_token::sol_str_to_lamports, pubkey::Pubkey,
@@ -602,22 +604,24 @@ async fn handle_buy_pumpfun(
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let buy_params = TradeBuyParams {
dex_type: DexType::PumpFun,
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: false,
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
custom_cu_limit: None,
};
match client.buy(buy_params).await {
match client
.buy(
DexType::PumpFun,
mint_pubkey,
sol_lamports,
slippage,
recent_blockhash,
None,
Box::new(param),
None,
true,
false,
false,
create_mint_ata,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully bought tokens from PumpFun!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -650,22 +654,24 @@ async fn handle_buy_pumpswap(
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let buy_params = TradeBuyParams {
dex_type: DexType::PumpSwap,
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
custom_cu_limit: None,
};
match client.buy(buy_params).await {
match client
.buy(
DexType::PumpSwap,
mint_pubkey,
sol_lamports,
slippage,
recent_blockhash,
None,
Box::new(param),
None,
true,
true,
false,
create_mint_ata,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully bought tokens from PumpSwap!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -697,22 +703,24 @@ async fn handle_buy_bonk(
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let buy_params = TradeBuyParams {
dex_type: DexType::Bonk,
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
custom_cu_limit: None,
};
match client.buy(buy_params).await {
match client
.buy(
DexType::Bonk,
mint_pubkey,
sol_lamports,
slippage,
recent_blockhash,
None,
Box::new(param),
None,
true,
true,
false,
create_mint_ata,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully bought tokens from Bonk!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -748,22 +756,24 @@ async fn handle_buy_raydium_v4(
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let buy_params = TradeBuyParams {
dex_type: DexType::RaydiumAmmV4,
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
custom_cu_limit: None,
};
match client.buy(buy_params).await {
match client
.buy(
DexType::RaydiumAmmV4,
mint_pubkey,
sol_lamports,
slippage,
recent_blockhash,
None,
Box::new(param),
None,
true,
true,
false,
create_mint_ata,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully bought tokens from Raydium V4!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -799,22 +809,24 @@ async fn handle_buy_raydium_cpmm(
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let buy_params = TradeBuyParams {
dex_type: DexType::RaydiumCpmm,
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
custom_cu_limit: None,
};
match client.buy(buy_params).await {
match client
.buy(
DexType::RaydiumCpmm,
mint_pubkey,
sol_lamports,
slippage,
recent_blockhash,
None,
Box::new(param),
None,
true,
true,
false,
create_mint_ata,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully bought tokens from Raydium CPMM!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -960,23 +972,24 @@ async fn handle_sell_pumpfun(
let param = PumpFunParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sell_params = TradeSellParams {
dex_type: DexType::PumpFun,
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(param),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
};
match client.sell(sell_params).await {
match client
.sell(
DexType::PumpFun,
mint_pubkey,
amount as u64,
slippage,
recent_blockhash,
None,
false,
Box::new(param),
None,
true,
true,
false,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully sold tokens from PumpFun!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -1011,22 +1024,24 @@ async fn handle_sell_pumpswap(
let param = PumpSwapParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sell_params = TradeSellParams {
dex_type: DexType::PumpSwap,
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(param),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
};
match client.sell(sell_params).await {
match client
.sell(
DexType::PumpSwap,
mint_pubkey,
amount as u64,
slippage,
recent_blockhash,
None,
false,
Box::new(param),
None,
true,
true,
false,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully sold tokens from PumpSwap!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -1061,22 +1076,24 @@ async fn handle_sell_bonk(
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sell_params = TradeSellParams {
dex_type: DexType::Bonk,
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(param),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
};
match client.sell(sell_params).await {
match client
.sell(
DexType::Bonk,
mint_pubkey,
amount as u64,
slippage,
recent_blockhash,
None,
false,
Box::new(param),
None,
true,
true,
false,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully sold tokens from Bonk!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -1114,22 +1131,24 @@ async fn handle_sell_raydium_v4(
let param = RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, amm_pubkey).await?;
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sell_params = TradeSellParams {
dex_type: DexType::RaydiumAmmV4,
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(param),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
};
match client.sell(sell_params).await {
match client
.sell(
DexType::RaydiumAmmV4,
mint_pubkey,
amount as u64,
slippage,
recent_blockhash,
None,
false,
Box::new(param),
None,
true,
true,
false,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully sold tokens from Raydium V4!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -1167,22 +1186,24 @@ async fn handle_sell_raydium_cpmm(
let param = RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &pool_pubkey).await?;
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let sell_params = TradeSellParams {
dex_type: DexType::RaydiumCpmm,
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(param),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
};
match client.sell(sell_params).await {
match client
.sell(
DexType::RaydiumCpmm,
mint_pubkey,
amount as u64,
slippage,
recent_blockhash,
None,
false,
Box::new(param),
None,
true,
true,
false,
use_seed,
)
.await
{
Ok(signature) => {
println!(" ✅ Successfully sold tokens from Raydium CPMM!");
println!(" ✅ Transaction Signature: {}", signature);
@@ -1287,21 +1308,20 @@ async fn handle_wallet() -> Result<(), Box<dyn std::error::Error>> {
async fn initialize_real_client() -> AnyResult<SolanaTrade> {
// You need to update this with a real RPC URL
let swqos_settings: Vec<SwqosSettings> = vec![SwqosSettings::new(
SwqosConfig::Default(RPC_URL.to_string()),
DEFAULT_CU_LIMIT,
DEFAULT_CU_PRICE,
0.0,
0.0,
)];
let swqos_configs = vec![SwqosConfig::Default(RPC_URL.to_string())];
let client = SolanaTrade::new(
Arc::new(Keypair::try_from(&PAYER.to_bytes()[..]).unwrap()),
RPC_URL.to_string(),
CommitmentConfig::confirmed(),
swqos_settings,
)
.await;
let mut priority_fee = PriorityFee::default();
priority_fee.rpc_unit_limit = 200000;
let trade_config = TradeConfig {
rpc_url: RPC_URL.to_string(),
commitment: CommitmentConfig::confirmed(),
priority_fee,
swqos_configs,
};
let client =
SolanaTrade::new(Arc::new(Keypair::try_from(&PAYER.to_bytes()[..]).unwrap()), trade_config)
.await;
Ok(client)
}