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:
ysq
2025-09-22 23:18:53 +08:00
parent 020187a57a
commit ce5243702c
19 changed files with 274 additions and 435 deletions
+9 -7
View File
@@ -3,7 +3,6 @@ use std::sync::{
Arc,
};
use sol_trade_sdk::solana_streamer_sdk::streaming::YellowstoneGrpc;
use sol_trade_sdk::solana_streamer_sdk::{
match_event, streaming::event_parser::protocols::raydium_cpmm::RaydiumCpmmSwapEvent,
};
@@ -28,6 +27,7 @@ use sol_trade_sdk::{
solana_streamer_sdk::streaming::event_parser::common::EventType,
trading::core::params::RaydiumCpmmParams,
};
use sol_trade_sdk::{solana_streamer_sdk::streaming::YellowstoneGrpc, TradeTokenType};
use solana_sdk::signer::Signer;
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
use spl_associated_token_account::get_associated_token_address;
@@ -145,15 +145,16 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
let buy_sol_amount = 100_000;
let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::RaydiumCpmm,
input_token_type: TradeTokenType::WSOL,
mint: mint_pubkey,
sol_amount: buy_sol_amount,
input_token_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(buy_params),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: true,
create_input_token_ata: true,
close_input_token_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
@@ -176,16 +177,17 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
println!("Selling {} tokens", amount_token);
let sell_params = sol_trade_sdk::TradeSellParams {
dex_type: DexType::RaydiumCpmm,
output_token_type: TradeTokenType::WSOL,
mint: mint_pubkey,
token_amount: amount_token,
input_token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(sell_params),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: true,
create_output_token_ata: true,
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
};