refactor: Refactor SDK core architecture and trading parameter system
- Refactor SolanaTrade main class structure with improved modular design - Refactor trading parameter system: BuyParams/SellParams -> InternalBuyParams/InternalSellParams - Remove deprecated PriorityFee and related utility functions - Add SwqosSettings to replace legacy SwqosConfig - Add comprehensive technical documentation: • Address Lookup Table usage guide (EN/CN) • Nonce Cache mechanism documentation (EN/CN) • Trading Parameters documentation (EN/CN) - Refactor all example code to adapt to new API interfaces - Optimize public API design and code comments - Clean up redundant utility functions and type definitions Impact: 43 files changed, 2013 insertions(+), 1735 deletions(-)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use sol_trade_sdk::{
|
||||
common::{AnyResult, PriorityFee, TradeConfig},
|
||||
swqos::{SwqosConfig, SwqosRegion},
|
||||
common::AnyResult,
|
||||
constants::trade::trade::{
|
||||
DEFAULT_BUY_TIP_FEE, DEFAULT_CU_LIMIT, DEFAULT_CU_PRICE, DEFAULT_SELL_TIP_FEE,
|
||||
},
|
||||
swqos::{settings::SwqosSettings, SwqosConfig, SwqosRegion},
|
||||
SolanaTrade,
|
||||
};
|
||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||
@@ -8,53 +11,38 @@ use std::sync::Arc;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let _ = test_create_solana_trade_client().await?;
|
||||
let _ = create_solana_trade_client().await?;
|
||||
println!("Successfully created SolanaTrade client!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create SolanaTrade client
|
||||
/// Initializes a new SolanaTrade client with configuration
|
||||
async fn test_create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
println!("Creating SolanaTrade client...");
|
||||
|
||||
let payer = Keypair::new();
|
||||
let rpc_url = "https://mainnet.helius-rpc.com/?api-key=xxxxxx".to_string();
|
||||
|
||||
println!("rpc_url: {}", rpc_url);
|
||||
|
||||
let swqos_configs = create_swqos_configs(&rpc_url);
|
||||
let trade_config = create_trade_config(rpc_url, swqos_configs);
|
||||
|
||||
let solana_trade_client = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
let commitment = CommitmentConfig::processed();
|
||||
let cu_limit = DEFAULT_CU_LIMIT;
|
||||
let cu_price = DEFAULT_CU_PRICE;
|
||||
let buy_tip_fee = DEFAULT_BUY_TIP_FEE;
|
||||
let sell_tip_fee = DEFAULT_SELL_TIP_FEE;
|
||||
let swqos_settings: Vec<SwqosSettings> = vec![
|
||||
SwqosSettings::new(SwqosConfig::Default(rpc_url.clone()), cu_limit, cu_price, 0.0, 0.0),
|
||||
// First parameter is UUID, pass empty string if no UUID
|
||||
SwqosSettings::new(SwqosConfig::Jito("your uuid".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::NextBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::Bloxroute("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::ZeroSlot("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::Temporal("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::FlashBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::Node1("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::BlockRazor("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
SwqosSettings::new(SwqosConfig::Astralane("your api_token".to_string(), SwqosRegion::Frankfurt, None), cu_limit, cu_price, buy_tip_fee, sell_tip_fee),
|
||||
];
|
||||
let solana_trade_client =
|
||||
SolanaTrade::new(Arc::new(payer), rpc_url, commitment, swqos_settings).await;
|
||||
println!("SolanaTrade client created successfully!");
|
||||
|
||||
Ok(solana_trade_client)
|
||||
}
|
||||
|
||||
fn create_swqos_configs(rpc_url: &str) -> Vec<SwqosConfig> {
|
||||
vec![
|
||||
// First parameter is UUID, pass empty string if no UUID
|
||||
SwqosConfig::Jito("your uuid".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::NextBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::Bloxroute("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::ZeroSlot("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::Temporal("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
// Add tg official customer https://t.me/FlashBlock_Official to get free FlashBlock key
|
||||
SwqosConfig::FlashBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
// Add tg official customer https://t.me/node1_me to get free Node1 key
|
||||
SwqosConfig::Node1("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::BlockRazor("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::Astralane("your api_token".to_string(), SwqosRegion::Frankfurt, None),
|
||||
SwqosConfig::Default(rpc_url.to_string()),
|
||||
]
|
||||
}
|
||||
|
||||
fn create_trade_config(rpc_url: String, swqos_configs: Vec<SwqosConfig>) -> TradeConfig {
|
||||
TradeConfig {
|
||||
rpc_url,
|
||||
commitment: CommitmentConfig::confirmed(),
|
||||
priority_fee: PriorityFee::default(),
|
||||
swqos_configs,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user