feat: major gas fee strategy and documentation overhaul

- feat(gas): add comprehensive gas fee strategy management system
  * Implement GasFeeStrategyType with Default/LowTipHighCuPrice/HighTipLowCuPrice strategies
  * Add dynamic gas fee configuration per SWQOS service and trade type
  * Integrate arc-swap for thread-safe strategy updates

- docs: restructure documentation with dedicated guides
  * Add ADDRESS_LOOKUP_TABLE.md/CN.md for lookup table configuration
  * Add NONCE_CACHE.md/CN.md for nonce management documentation
  * Add TRADING_PARAMETERS.md/CN.md for comprehensive parameter guides
  * Simplify main README.md with focused overview

- refactor: update all examples with new gas fee strategy integration
  * Modernize 14 trading examples with consistent parameter handling
  * Improve error handling and configuration management
  * Enhance parallel trading implementation
This commit is contained in:
ysq
2025-09-19 00:49:45 +08:00
parent fad343ffbf
commit 006686e8a3
45 changed files with 2133 additions and 1681 deletions
+5 -6
View File
@@ -149,7 +149,6 @@ impl AstralaneClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let request_body = serde_json::to_string(&json!({
"jsonrpc": "2.0",
@@ -175,12 +174,12 @@ impl AstralaneClient {
// Parse JSON response
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" astralane {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [astralane] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" astralane {} submission failed: {:?}", trade_type, _error);
eprintln!(" [astralane] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" astralane {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [astralane] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -188,12 +187,12 @@ impl AstralaneClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" astralane {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [astralane] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" astralane {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [astralane] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+5 -6
View File
@@ -156,7 +156,6 @@ impl BlockRazorClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
// BlockRazor使用fast模式的请求格式
let request_body = serde_json::to_string(&json!({
@@ -177,12 +176,12 @@ impl BlockRazorClient {
// Parse JSON response
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() || response_json.get("signature").is_some() {
println!(" blockrazor {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [blockrazor] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" blockrazor {} submission failed: {:?}", trade_type, _error);
eprintln!(" [blockrazor] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" blockrazor {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [blockrazor] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -190,12 +189,12 @@ impl BlockRazorClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" blockrazor {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [blockrazor] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" blockrazor {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [blockrazor] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+5 -7
View File
@@ -60,7 +60,6 @@ impl BloxrouteClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let body = serde_json::json!({
"transaction": {
@@ -83,12 +82,12 @@ impl BloxrouteClient {
// 5. Use `serde_json::from_str()` to parse JSON, reducing extra wait from `.json().await?`
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" bloxroute {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [bloxroute] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" bloxroute {} submission failed: {:?}", trade_type, _error);
eprintln!(" [bloxroute] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" bloxroute {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [bloxroute] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -96,19 +95,18 @@ impl BloxrouteClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" bloxroute {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [bloxroute] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" bloxroute {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [bloxroute] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
let start_time = Instant::now();
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let body = serde_json::json!({
"entries": transactions
+5 -6
View File
@@ -61,7 +61,6 @@ impl FlashBlockClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
// FlashBlock API format
let request_body = serde_json::to_string(&json!({
@@ -85,12 +84,12 @@ impl FlashBlockClient {
// Parse response
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("success").is_some() || response_json.get("result").is_some() {
println!(" FlashBlock {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [FlashBlock] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" FlashBlock {} submission failed: {:?}", trade_type, _error);
eprintln!(" [FlashBlock] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" FlashBlock {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [FlashBlock] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -98,12 +97,12 @@ impl FlashBlockClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" FlashBlock {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [FlashBlock] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" FlashBlock {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [FlashBlock] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+5 -6
View File
@@ -64,7 +64,6 @@ impl JitoClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let request_body = serde_json::to_string(&json!({
"id": 1,
@@ -99,12 +98,12 @@ impl JitoClient {
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" jito {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [jito] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" jito {} submission failed: {:?}", trade_type, _error);
eprintln!(" [jito] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" jito {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [jito] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -112,12 +111,12 @@ impl JitoClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" jito {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [jito] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" jito {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [jito] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+28 -2
View File
@@ -48,7 +48,7 @@ lazy_static::lazy_static! {
static ref TIP_ACCOUNT_CACHE: RwLock<Vec<String>> = RwLock::new(Vec::new());
}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TradeType {
Create,
CreateAndBuy,
@@ -68,7 +68,7 @@ impl std::fmt::Display for TradeType {
}
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SwqosType {
Jito,
NextBlock,
@@ -82,6 +82,23 @@ pub enum SwqosType {
Default,
}
impl SwqosType {
pub fn values() -> Vec<Self> {
vec![
Self::Jito,
Self::NextBlock,
Self::ZeroSlot,
Self::Temporal,
Self::Bloxroute,
Self::Node1,
Self::FlashBlock,
Self::BlockRazor,
Self::Astralane,
Self::Default,
]
}
}
pub type SwqosClient = dyn SwqosClientTrait + Send + Sync + 'static;
#[async_trait::async_trait]
@@ -107,14 +124,23 @@ pub enum SwqosRegion {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SwqosConfig {
Default(String),
/// Jito(uuid, region, custom_url)
Jito(String, SwqosRegion, Option<String>),
/// NextBlock(api_token, region, custom_url)
NextBlock(String, SwqosRegion, Option<String>),
/// Bloxroute(api_token, region, custom_url)
Bloxroute(String, SwqosRegion, Option<String>),
/// Temporal(api_token, region, custom_url)
Temporal(String, SwqosRegion, Option<String>),
/// ZeroSlot(api_token, region, custom_url)
ZeroSlot(String, SwqosRegion, Option<String>),
/// Node1(api_token, region, custom_url)
Node1(String, SwqosRegion, Option<String>),
/// FlashBlock(api_token, region, custom_url)
FlashBlock(String, SwqosRegion, Option<String>),
/// BlockRazor(api_token, region, custom_url)
BlockRazor(String, SwqosRegion, Option<String>),
/// Astralane(api_token, region, custom_url)
Astralane(String, SwqosRegion, Option<String>),
}
+5 -6
View File
@@ -66,7 +66,6 @@ impl NextBlockClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let request_body = serde_json::to_string(&json!({
"transaction": {
@@ -86,12 +85,12 @@ impl NextBlockClient {
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" nextblock {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [nextblock] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" nextblock {} submission failed: {:?}", trade_type, _error);
eprintln!(" [nextblock] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" nextblock {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [nextblock] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -99,12 +98,12 @@ impl NextBlockClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" nextblock {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [nextblock] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" nextblock {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [nextblock] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+5 -6
View File
@@ -143,7 +143,6 @@ impl Node1Client {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let request_body = serde_json::to_string(&json!({
"jsonrpc": "2.0",
@@ -168,12 +167,12 @@ impl Node1Client {
// Parse JSON response
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" node1 {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [node1] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" node1 {} submission failed: {:?}", trade_type, _error);
eprintln!(" [node1] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" node1 {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [node1] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -181,12 +180,12 @@ impl Node1Client {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" node1 {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [node1] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" node1 {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [node1] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+2 -2
View File
@@ -42,12 +42,12 @@ impl SwqosClientTrait for SolRpcClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" rpc {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [rpc] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
}
}
println!(" signature: {:?}", signature);
println!(" rpc {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [rpc] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+4 -5
View File
@@ -147,7 +147,6 @@ impl TemporalClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
// Build request body according to Nozomi documentation requirements
let request_body = serde_json::to_string(&json!({
@@ -175,12 +174,12 @@ impl TemporalClient {
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" nozomi {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [nozomi] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
// eprintln!("nozomi transaction submission failed: {:?}", _error);
}
} else {
eprintln!(" nozomi {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [nozomi] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -188,12 +187,12 @@ impl TemporalClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" nozomi {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [nozomi] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" nozomi {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [nozomi] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}
+5 -6
View File
@@ -61,7 +61,6 @@ impl ZeroSlotClient {
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
let start_time = Instant::now();
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
println!(" Transaction encoded to base64: {:?}", start_time.elapsed());
let request_body = serde_json::to_string(&json!({
"jsonrpc": "2.0",
@@ -90,12 +89,12 @@ impl ZeroSlotClient {
// 5. Use `serde_json::from_str()` to parse JSON, reducing extra wait from `.json().await?`
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
if response_json.get("result").is_some() {
println!(" 0slot {} submitted: {:?}", trade_type, start_time.elapsed());
println!(" [0slot] {} submitted: {:?}", trade_type, start_time.elapsed());
} else if let Some(_error) = response_json.get("error") {
eprintln!(" 0slot {} submission failed: {:?}", trade_type, _error);
eprintln!(" [0slot] {} submission failed: {:?}", trade_type, _error);
}
} else {
eprintln!(" 0slot {} submission failed: {:?}", trade_type, response_text);
eprintln!(" [0slot] {} submission failed: {:?}", trade_type, response_text);
}
let start_time: Instant = Instant::now();
@@ -103,12 +102,12 @@ impl ZeroSlotClient {
Ok(_) => (),
Err(e) => {
println!(" signature: {:?}", signature);
println!(" 0slot {} confirmation failed: {:?}", trade_type, start_time.elapsed());
println!(" [0slot] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
return Err(e);
},
}
println!(" signature: {:?}", signature);
println!(" 0slot {} confirmed: {:?}", trade_type, start_time.elapsed());
println!(" [0slot] {} confirmed: {:?}", trade_type, start_time.elapsed());
Ok(())
}