feat: refactor trading API and add multi-token type support (v1.2.0)
- Bump version to 1.2.0 - Remove TradeSwapParams to simplify API structure - Add TradeTokenType enum supporting SOL/WSOL/USD1 tokens - Standardize parameter naming: sol_amount → input_token_amount, token_amount → input_token_amount - Refactor account management parameters: create_wsol_ata → create_input_token_ata etc. - Update all example code to use new API - Synchronize English and Chinese documentation BREAKING CHANGE: - Removed TradeSwapParams struct - Modified field names in TradeBuyParams and TradeSellParams - Existing code needs migration to use new parameter structure
This commit is contained in:
@@ -10,7 +10,7 @@ use sol_trade_sdk::{
|
||||
},
|
||||
factory::DexType,
|
||||
},
|
||||
SolanaTrade, TradeBuyParams, TradeSellParams,
|
||||
SolanaTrade, TradeBuyParams, TradeSellParams, TradeTokenType,
|
||||
};
|
||||
use solana_sdk::{
|
||||
commitment_config::CommitmentConfig, native_token::sol_str_to_lamports, pubkey::Pubkey,
|
||||
@@ -605,15 +605,16 @@ async fn handle_buy_pumpfun(
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::PumpFun,
|
||||
input_token_type: TradeTokenType::SOL,
|
||||
mint: mint_pubkey,
|
||||
sol_amount: sol_lamports,
|
||||
input_token_amount: sol_lamports,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: false,
|
||||
close_wsol_ata: false,
|
||||
create_input_token_ata: false,
|
||||
close_input_token_ata: false,
|
||||
create_mint_ata: create_mint_ata,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
@@ -653,15 +654,16 @@ async fn handle_buy_pumpswap(
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
sol_amount: sol_lamports,
|
||||
input_token_amount: sol_lamports,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: false,
|
||||
create_mint_ata: create_mint_ata,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
@@ -700,15 +702,16 @@ async fn handle_buy_bonk(
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::Bonk,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
sol_amount: sol_lamports,
|
||||
input_token_amount: sol_lamports,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: false,
|
||||
create_mint_ata: create_mint_ata,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
@@ -751,15 +754,16 @@ async fn handle_buy_raydium_v4(
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
sol_amount: sol_lamports,
|
||||
input_token_amount: sol_lamports,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: false,
|
||||
create_mint_ata: create_mint_ata,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
@@ -802,15 +806,16 @@ async fn handle_buy_raydium_cpmm(
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
sol_amount: sol_lamports,
|
||||
input_token_amount: sol_lamports,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: false,
|
||||
create_mint_ata: create_mint_ata,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
@@ -963,16 +968,17 @@ async fn handle_sell_pumpfun(
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::PumpFun,
|
||||
output_token_type: TradeTokenType::SOL,
|
||||
mint: mint_pubkey,
|
||||
token_amount: amount as u64,
|
||||
input_token_amount: amount as u64,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
with_tip: false,
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: false,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
};
|
||||
@@ -1014,16 +1020,17 @@ async fn handle_sell_pumpswap(
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
token_amount: amount as u64,
|
||||
input_token_amount: amount as u64,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
with_tip: false,
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: false,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
};
|
||||
@@ -1064,16 +1071,17 @@ async fn handle_sell_bonk(
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::Bonk,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
token_amount: amount as u64,
|
||||
input_token_amount: amount as u64,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
with_tip: false,
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: false,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
};
|
||||
@@ -1117,16 +1125,17 @@ async fn handle_sell_raydium_v4(
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
token_amount: amount as u64,
|
||||
input_token_amount: amount as u64,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
with_tip: false,
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: false,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
};
|
||||
@@ -1170,16 +1179,17 @@ async fn handle_sell_raydium_cpmm(
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
token_amount: amount as u64,
|
||||
input_token_amount: amount as u64,
|
||||
slippage_basis_points: slippage,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
with_tip: false,
|
||||
extension_params: Box::new(param),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: false,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: false,
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user