update jito and nextblock
This commit is contained in:
+2
-1
@@ -95,7 +95,8 @@ impl SolanaTrade {
|
|||||||
let jito_client = JitoClient::new(
|
let jito_client = JitoClient::new(
|
||||||
rpc_url.clone(),
|
rpc_url.clone(),
|
||||||
swqos.endpoint,
|
swqos.endpoint,
|
||||||
).await.expect("Failed to create Jito client");
|
swqos.auth_token
|
||||||
|
);
|
||||||
swqos_clients.push(Arc::new(jito_client));
|
swqos_clients.push(Arc::new(jito_client));
|
||||||
}
|
}
|
||||||
SwqosType::NextBlock => {
|
SwqosType::NextBlock => {
|
||||||
|
|||||||
+13
-1
@@ -10,8 +10,20 @@ use tokio::time::sleep;
|
|||||||
use crate::common::types::SolanaRpcClient;
|
use crate::common::types::SolanaRpcClient;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use base64::engine::general_purpose::STANDARD;
|
use base64::engine::general_purpose::{self, STANDARD};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use solana_sdk::transaction::VersionedTransaction;
|
||||||
|
|
||||||
|
pub trait FormatBase64VersionedTransaction {
|
||||||
|
fn to_base64_string(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FormatBase64VersionedTransaction for VersionedTransaction {
|
||||||
|
fn to_base64_string(&self) -> String {
|
||||||
|
let tx_bytes = bincode::serialize(self).unwrap();
|
||||||
|
general_purpose::STANDARD.encode(tx_bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn poll_transaction_confirmation(rpc: &SolanaRpcClient, txt_sig: Signature) -> Result<Signature> {
|
pub async fn poll_transaction_confirmation(rpc: &SolanaRpcClient, txt_sig: Signature) -> Result<Signature> {
|
||||||
let timeout: Duration = Duration::from_secs(5);
|
let timeout: Duration = Duration::from_secs(5);
|
||||||
|
|||||||
+11
-9
@@ -1,23 +1,25 @@
|
|||||||
pub const SWQOS_ENDPOINTS_JITO: [&str; 3] = [
|
pub const SWQOS_ENDPOINTS_JITO: [&str; 3] = [
|
||||||
"https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles",
|
"https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles",
|
||||||
"https://ams.block-engine.jito.wtf/api/v1/bundles",
|
|
||||||
"https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/bundles",
|
"https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/bundles",
|
||||||
|
"https://ams.block-engine.jito.wtf/api/v1/bundles",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const SWQOS_ENDPOINTS_NEXTBLOCK: [&str; 3] = [
|
pub const SWQOS_ENDPOINTS_NEXTBLOCK: [&str; 5] = [
|
||||||
"https://fra.nextblock.io",
|
"http://ny.nextblock.io",
|
||||||
"https://ams.nextblock.io",
|
"http://fra.nextblock.io",
|
||||||
"https://ny.nextblock.io",
|
"http://slc.nextblock.io",
|
||||||
|
"http://tokyo.nextblock.io",
|
||||||
|
"http://london.nextblock.io",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const SWQOS_ENDPOINTS_ZERO_SLOT: [&str; 3] = [
|
pub const SWQOS_ENDPOINTS_ZERO_SLOT: [&str; 3] = [
|
||||||
|
"http://ny1.0slot.trade",
|
||||||
"http://de1.0slot.trade",
|
"http://de1.0slot.trade",
|
||||||
"http://ams.0slot.trade",
|
"http://ams1.0slot.trade",
|
||||||
"http://ny.0slot.trade",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const SWQOS_ENDPOINTS_TEMPORAL: [&str; 3] = [
|
pub const SWQOS_ENDPOINTS_TEMPORAL: [&str; 3] = [
|
||||||
|
"http://ewr1.nozomi.temporal.xyz",
|
||||||
"http://fra2.nozomi.temporal.xyz",
|
"http://fra2.nozomi.temporal.xyz",
|
||||||
"http://ams2.nozomi.temporal.xyz",
|
"http://ams1.nozomi.temporal.xyz",
|
||||||
"http://ny2.nozomi.temporal.xyz",
|
|
||||||
];
|
];
|
||||||
+104
-29
@@ -1,13 +1,15 @@
|
|||||||
|
|
||||||
use tonic::transport::Channel;
|
use crate::swqos::common::{poll_transaction_confirmation, serialize_transaction_and_encode, FormatBase64VersionedTransaction};
|
||||||
use tokio::sync::Mutex;
|
use rand::seq::IndexedRandom;
|
||||||
|
use reqwest::Client;
|
||||||
|
use serde_json::json;
|
||||||
|
use std::{sync::Arc, time::Instant};
|
||||||
|
|
||||||
use rand::{rng, seq::IteratorRandom};
|
use std::time::Duration;
|
||||||
use anyhow::{anyhow, Result};
|
use solana_transaction_status::UiTransactionEncoding;
|
||||||
use std::sync::Arc;
|
|
||||||
use solana_sdk::{transaction::VersionedTransaction, signature::Signature};
|
use anyhow::Result;
|
||||||
use crate::protos::searcher::searcher_service_client::SearcherServiceClient;
|
use solana_sdk::transaction::VersionedTransaction;
|
||||||
use crate::protos::searcher_client::{self, get_searcher_client_no_auth, send_bundle_with_confirmation};
|
|
||||||
use crate::swqos::{SwqosType, TradeType};
|
use crate::swqos::{SwqosType, TradeType};
|
||||||
use crate::swqos::SwqosClientTrait;
|
use crate::swqos::SwqosClientTrait;
|
||||||
|
|
||||||
@@ -15,25 +17,27 @@ use crate::{common::SolanaRpcClient, constants::pumpfun::accounts::JITO_TIP_ACCO
|
|||||||
|
|
||||||
|
|
||||||
pub struct JitoClient {
|
pub struct JitoClient {
|
||||||
|
pub endpoint: String,
|
||||||
|
pub auth_token: String,
|
||||||
pub rpc_client: Arc<SolanaRpcClient>,
|
pub rpc_client: Arc<SolanaRpcClient>,
|
||||||
pub searcher_client: Arc<Mutex<SearcherServiceClient<Channel>>>,
|
pub http_client: Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SwqosClientTrait for JitoClient {
|
impl SwqosClientTrait for JitoClient {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
self.send_bundle_with_confirmation(trade_type, &vec![transaction.clone()]).await?.first().cloned().ok_or(anyhow!("Failed to send transaction"))
|
self.send_transaction(trade_type, transaction).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
self.send_bundle_with_confirmation(trade_type, transactions).await
|
self.send_transactions(trade_type, transactions).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tip_account(&self) -> Result<String> {
|
fn get_tip_account(&self) -> Result<String> {
|
||||||
if let Some(acc) = JITO_TIP_ACCOUNTS.iter().choose(&mut rng()) {
|
if let Some(acc) = JITO_TIP_ACCOUNTS.choose(&mut rand::rng()) {
|
||||||
Ok(acc.to_string())
|
Ok(acc.to_string())
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("no valid tip accounts found"))
|
Err(anyhow::anyhow!("no valid tip accounts found"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,24 +47,95 @@ impl SwqosClientTrait for JitoClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl JitoClient {
|
impl JitoClient {
|
||||||
pub async fn new(rpc_url: String, block_engine_url: String) -> Result<Self> {
|
pub fn new(rpc_url: String, endpoint: String, auth_token: String) -> Self {
|
||||||
let rpc_client = SolanaRpcClient::new(rpc_url);
|
let rpc_client = SolanaRpcClient::new(rpc_url);
|
||||||
let searcher_client = get_searcher_client_no_auth(block_engine_url.as_str()).await?;
|
let http_client = Client::builder()
|
||||||
Ok(Self { rpc_client: Arc::new(rpc_client), searcher_client: Arc::new(Mutex::new(searcher_client)) })
|
.pool_idle_timeout(Duration::from_secs(60))
|
||||||
|
.pool_max_idle_per_host(64)
|
||||||
|
.tcp_keepalive(Some(Duration::from_secs(1200)))
|
||||||
|
.http2_keep_alive_interval(Duration::from_secs(15))
|
||||||
|
.timeout(Duration::from_secs(10))
|
||||||
|
.connect_timeout(Duration::from_secs(5))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_bundle_with_confirmation(
|
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
&self,
|
let start_time = Instant::now();
|
||||||
trade_type: TradeType,
|
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
||||||
transactions: &Vec<VersionedTransaction>,
|
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
||||||
) -> Result<Vec<Signature>> {
|
|
||||||
send_bundle_with_confirmation(self.rpc_client.clone(), trade_type, &transactions, self.searcher_client.clone()).await
|
let request_body = serde_json::to_string(&json!({
|
||||||
|
"id": 1,
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "sendTransaction",
|
||||||
|
"params": [
|
||||||
|
content,
|
||||||
|
{
|
||||||
|
"encoding": "base64"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))?;
|
||||||
|
|
||||||
|
let endpoint = format!("{}/api/v1/transactions", self.endpoint);
|
||||||
|
let response_text = self.http_client.post(&endpoint)
|
||||||
|
.body(request_body)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
|
||||||
|
if response_json.get("result").is_some() {
|
||||||
|
println!(" jito{}提交: {:?}", trade_type, start_time.elapsed());
|
||||||
|
} else if let Some(_error) = response_json.get("error") {
|
||||||
|
eprintln!(" jito{}提交失败: {:?}", trade_type, _error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let start_time: Instant = Instant::now();
|
||||||
|
match poll_transaction_confirmation(&self.rpc_client, signature).await {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(" jito{}确认: {:?}", trade_type, start_time.elapsed());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_bundle_no_wait(
|
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
&self,
|
let start_time = Instant::now();
|
||||||
transactions: &Vec<VersionedTransaction>,
|
let txs_base64 = transactions.iter().map(|tx| tx.to_base64_string()).collect::<Vec<String>>();
|
||||||
) -> Result<Vec<Signature>> {
|
let body = serde_json::json!({
|
||||||
searcher_client::send_bundle_no_wait(&transactions, self.searcher_client.clone()).await
|
"jsonrpc": "2.0",
|
||||||
|
"method": "sendBundle",
|
||||||
|
"params": [
|
||||||
|
txs_base64,
|
||||||
|
{ "encoding": "base64" }
|
||||||
|
],
|
||||||
|
"id": 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
let endpoint = format!("{}/api/v1/bundles", self.endpoint);
|
||||||
|
let response_text = self.http_client.post(&endpoint)
|
||||||
|
.body(body.to_string())
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
|
||||||
|
if response_json.get("result").is_some() {
|
||||||
|
println!(" jito{}提交: {:?}", trade_type, start_time.elapsed());
|
||||||
|
} else if let Some(_error) = response_json.get("error") {
|
||||||
|
eprintln!(" jito{}提交失败: {:?}", trade_type, _error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-3
@@ -7,7 +7,6 @@ pub mod zeroslot;
|
|||||||
pub mod temporal;
|
pub mod temporal;
|
||||||
pub mod define;
|
pub mod define;
|
||||||
|
|
||||||
use solana_sdk::signature::Signature;
|
|
||||||
use solana_sdk::transaction::VersionedTransaction;
|
use solana_sdk::transaction::VersionedTransaction;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
@@ -52,8 +51,8 @@ pub type SwqosClient = dyn SwqosClientTrait + Send + Sync + 'static;
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait SwqosClientTrait {
|
pub trait SwqosClientTrait {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature>;
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()>;
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>>;
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()>;
|
||||||
fn get_tip_account(&self) -> Result<String>;
|
fn get_tip_account(&self) -> Result<String>;
|
||||||
fn get_swqos_type(&self) -> SwqosType;
|
fn get_swqos_type(&self) -> SwqosType;
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-110
@@ -1,20 +1,11 @@
|
|||||||
use crate::protos::nextblock_grpc;
|
use crate::swqos::common::{poll_transaction_confirmation, serialize_transaction_and_encode};
|
||||||
use crate::protos::nextblock_grpc::api_client::ApiClient;
|
|
||||||
use crate::swqos::common::{poll_transaction_confirmation, serialize_smart_transaction_and_encode};
|
|
||||||
use rand::seq::IndexedRandom;
|
use rand::seq::IndexedRandom;
|
||||||
use rustls::crypto::ring::default_provider;
|
use reqwest::Client;
|
||||||
use rustls::crypto::CryptoProvider;
|
use serde_json::json;
|
||||||
use tonic::transport::Channel;
|
|
||||||
use yellowstone_grpc_client::Interceptor;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::{sync::Arc, time::Instant};
|
use std::{sync::Arc, time::Instant};
|
||||||
|
|
||||||
use solana_sdk::{signature::Signature};
|
|
||||||
|
|
||||||
use tonic::{service::interceptor::InterceptedService, transport::Uri, Status};
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use solana_transaction_status::UiTransactionEncoding;
|
use solana_transaction_status::UiTransactionEncoding;
|
||||||
use tonic::transport::ClientTlsConfig;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use solana_sdk::transaction::VersionedTransaction;
|
use solana_sdk::transaction::VersionedTransaction;
|
||||||
@@ -23,42 +14,21 @@ use crate::swqos::SwqosClientTrait;
|
|||||||
|
|
||||||
use crate::{common::SolanaRpcClient, constants::pumpfun::accounts::NEXTBLOCK_TIP_ACCOUNTS};
|
use crate::{common::SolanaRpcClient, constants::pumpfun::accounts::NEXTBLOCK_TIP_ACCOUNTS};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct MyInterceptor {
|
|
||||||
auth_token: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MyInterceptor {
|
|
||||||
pub fn new(auth_token: String) -> Self {
|
|
||||||
Self { auth_token }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Interceptor for MyInterceptor {
|
|
||||||
fn call(&mut self, mut request: tonic::Request<()>) -> Result<tonic::Request<()>, Status> {
|
|
||||||
request.metadata_mut().insert(
|
|
||||||
"authorization",
|
|
||||||
tonic::metadata::MetadataValue::from_str(&self.auth_token)
|
|
||||||
.map_err(|_| Status::invalid_argument("Invalid auth token"))?
|
|
||||||
);
|
|
||||||
Ok(request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct NextBlockClient {
|
pub struct NextBlockClient {
|
||||||
|
pub endpoint: String,
|
||||||
|
pub auth_token: String,
|
||||||
pub rpc_client: Arc<SolanaRpcClient>,
|
pub rpc_client: Arc<SolanaRpcClient>,
|
||||||
pub client: ApiClient<InterceptedService<Channel, MyInterceptor>>,
|
pub http_client: Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SwqosClientTrait for NextBlockClient {
|
impl SwqosClientTrait for NextBlockClient {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
self.send_transaction(trade_type, transaction).await
|
self.send_transaction(trade_type, transaction).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
self.send_transactions(trade_type, transactions).await
|
self.send_transactions(trade_type, transactions).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,93 +44,63 @@ impl SwqosClientTrait for NextBlockClient {
|
|||||||
|
|
||||||
impl NextBlockClient {
|
impl NextBlockClient {
|
||||||
pub fn new(rpc_url: String, endpoint: String, auth_token: String) -> Self {
|
pub fn new(rpc_url: String, endpoint: String, auth_token: String) -> Self {
|
||||||
if CryptoProvider::get_default().is_none() {
|
|
||||||
let _ = default_provider()
|
|
||||||
.install_default()
|
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to install crypto provider: {:?}", e));
|
|
||||||
}
|
|
||||||
|
|
||||||
let endpoint = endpoint.parse::<Uri>().unwrap();
|
|
||||||
let tls = ClientTlsConfig::new().with_native_roots();
|
|
||||||
let channel = Channel::builder(endpoint)
|
|
||||||
.tls_config(tls).expect("Failed to create TLS config")
|
|
||||||
.tcp_keepalive(Some(Duration::from_secs(60)))
|
|
||||||
.http2_keep_alive_interval(Duration::from_secs(30))
|
|
||||||
.keep_alive_while_idle(true)
|
|
||||||
.timeout(Duration::from_secs(30))
|
|
||||||
.connect_timeout(Duration::from_secs(10))
|
|
||||||
.connect_lazy();
|
|
||||||
|
|
||||||
let client = ApiClient::with_interceptor(channel, MyInterceptor::new(auth_token));
|
|
||||||
let rpc_client = SolanaRpcClient::new(rpc_url);
|
let rpc_client = SolanaRpcClient::new(rpc_url);
|
||||||
Self { rpc_client: Arc::new(rpc_client), client }
|
let http_client = Client::builder()
|
||||||
|
.pool_idle_timeout(Duration::from_secs(60))
|
||||||
|
.pool_max_idle_per_host(64)
|
||||||
|
.tcp_keepalive(Some(Duration::from_secs(1200)))
|
||||||
|
.http2_keep_alive_interval(Duration::from_secs(15))
|
||||||
|
.timeout(Duration::from_secs(10))
|
||||||
|
.connect_timeout(Duration::from_secs(5))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let (content, signature) = serialize_smart_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
||||||
|
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
||||||
|
|
||||||
self.client.clone().post_submit_v2(nextblock_grpc::PostSubmitRequest {
|
let request_body = serde_json::to_string(&json!({
|
||||||
transaction: Some(nextblock_grpc::TransactionMessage {
|
"transaction": {
|
||||||
content,
|
"content": content
|
||||||
is_cleanup: false,
|
},
|
||||||
}),
|
"frontRunningProtection": false
|
||||||
skip_pre_flight: true,
|
}))?;
|
||||||
front_running_protection: Some(true),
|
|
||||||
experimental_front_running_protection: Some(true),
|
|
||||||
snipe_transaction: Some(true),
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
println!(" nextblock{}提交: {:?}", trade_type, start_time.elapsed());
|
let response_text = self.http_client.post(&self.endpoint)
|
||||||
|
.body(request_body)
|
||||||
|
.header("Authorization", &self.auth_token)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
|
||||||
|
if response_json.get("result").is_some() {
|
||||||
|
println!(" nextblock{}提交: {:?}", trade_type, start_time.elapsed());
|
||||||
|
} else if let Some(_error) = response_json.get("error") {
|
||||||
|
eprintln!(" nextblock{}提交失败: {:?}", trade_type, _error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let start_time: Instant = Instant::now();
|
let start_time: Instant = Instant::now();
|
||||||
let timeout: Duration = Duration::from_secs(10);
|
match poll_transaction_confirmation(&self.rpc_client, signature).await {
|
||||||
while Instant::now().duration_since(start_time) < timeout {
|
Ok(_) => (),
|
||||||
match poll_transaction_confirmation(&self.rpc_client, signature).await {
|
Err(_) => (),
|
||||||
Ok(_) => break,
|
|
||||||
Err(_) => continue,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(" nextblock{}确认: {:?}", trade_type, start_time.elapsed());
|
println!(" nextblock{}确认: {:?}", trade_type, start_time.elapsed());
|
||||||
|
|
||||||
Ok(signature)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
let mut entries = Vec::new();
|
|
||||||
let encoding = UiTransactionEncoding::Base64;
|
|
||||||
|
|
||||||
let mut signatures = Vec::new();
|
|
||||||
for transaction in transactions {
|
for transaction in transactions {
|
||||||
let (content, signature) = serialize_smart_transaction_and_encode(transaction, encoding).await?;
|
self.send_transaction(trade_type, transaction).await?;
|
||||||
entries.push(nextblock_grpc::PostSubmitRequestEntry {
|
|
||||||
transaction: Some(nextblock_grpc::TransactionMessage {
|
|
||||||
content,
|
|
||||||
is_cleanup: false,
|
|
||||||
}),
|
|
||||||
skip_pre_flight: true,
|
|
||||||
});
|
|
||||||
signatures.push(signature);
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
self.client.clone().post_submit_batch_v2(nextblock_grpc::PostSubmitBatchRequest {
|
|
||||||
entries,
|
|
||||||
submit_strategy: nextblock_grpc::SubmitStrategy::PSubmitAll as i32,
|
|
||||||
use_bundle: Some(true),
|
|
||||||
front_running_protection: Some(true),
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
let start_time: Instant = Instant::now();
|
|
||||||
for signature in signatures.clone() {
|
|
||||||
match poll_transaction_confirmation(&self.rpc_client, signature).await {
|
|
||||||
Ok(_) => continue,
|
|
||||||
Err(_) => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(" nextblock{}确认: {:?}", trade_type, start_time.elapsed());
|
|
||||||
|
|
||||||
Ok(signatures)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ use std::{sync::Arc, time::Instant};
|
|||||||
use solana_client::rpc_config::RpcSendTransactionConfig;
|
use solana_client::rpc_config::RpcSendTransactionConfig;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
commitment_config::CommitmentLevel,
|
commitment_config::CommitmentLevel,
|
||||||
signature::Signature,
|
|
||||||
transaction::VersionedTransaction,
|
transaction::VersionedTransaction,
|
||||||
};
|
};
|
||||||
use solana_transaction_status::UiTransactionEncoding;
|
use solana_transaction_status::UiTransactionEncoding;
|
||||||
@@ -19,7 +18,7 @@ pub struct SolRpcClient {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SwqosClientTrait for SolRpcClient {
|
impl SwqosClientTrait for SolRpcClient {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
let signature = self.rpc_client.send_transaction_with_config(transaction, RpcSendTransactionConfig{
|
let signature = self.rpc_client.send_transaction_with_config(transaction, RpcSendTransactionConfig{
|
||||||
skip_preflight: true,
|
skip_preflight: true,
|
||||||
preflight_commitment: Some(CommitmentLevel::Processed),
|
preflight_commitment: Some(CommitmentLevel::Processed),
|
||||||
@@ -36,16 +35,14 @@ impl SwqosClientTrait for SolRpcClient {
|
|||||||
println!(" signature: {:?}", signature);
|
println!(" signature: {:?}", signature);
|
||||||
println!(" rpc{}确认: {:?}", trade_type, start_time.elapsed());
|
println!(" rpc{}确认: {:?}", trade_type, start_time.elapsed());
|
||||||
|
|
||||||
Ok(signature)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
let mut signatures = Vec::new();
|
|
||||||
for transaction in transactions {
|
for transaction in transactions {
|
||||||
let signature = self.send_transaction(trade_type, transaction).await?;
|
self.send_transaction(trade_type, transaction).await?;
|
||||||
signatures.push(signature);
|
|
||||||
}
|
}
|
||||||
Ok(signatures)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tip_account(&self) -> Result<String> {
|
fn get_tip_account(&self) -> Result<String> {
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ pub struct TemporalClient {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SwqosClientTrait for TemporalClient {
|
impl SwqosClientTrait for TemporalClient {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
self.send_transaction(trade_type, transaction).await
|
self.send_transaction(trade_type, transaction).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
self.send_transactions(trade_type, transactions).await
|
self.send_transactions(trade_type, transactions).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ impl TemporalClient {
|
|||||||
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
||||||
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
||||||
@@ -106,15 +106,13 @@ impl TemporalClient {
|
|||||||
|
|
||||||
println!(" nozomi{}确认: {:?}", trade_type, start_time.elapsed());
|
println!(" nozomi{}确认: {:?}", trade_type, start_time.elapsed());
|
||||||
|
|
||||||
Ok(signature)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
let mut signatures = Vec::new();
|
|
||||||
for transaction in transactions {
|
for transaction in transactions {
|
||||||
let signature = self.send_transaction(trade_type, transaction).await?;
|
self.send_transaction(trade_type, transaction).await?;
|
||||||
signatures.push(signature);
|
|
||||||
}
|
}
|
||||||
Ok(signatures)
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,11 +26,11 @@ pub struct ZeroSlotClient {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SwqosClientTrait for ZeroSlotClient {
|
impl SwqosClientTrait for ZeroSlotClient {
|
||||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
self.send_transaction(trade_type, transaction).await
|
self.send_transaction(trade_type, transaction).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
self.send_transactions(trade_type, transactions).await
|
self.send_transactions(trade_type, transactions).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ impl ZeroSlotClient {
|
|||||||
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
Self { rpc_client: Arc::new(rpc_client), endpoint, auth_token, http_client }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<Signature> {
|
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64).await?;
|
||||||
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
println!(" 交易编码base64: {:?}", start_time.elapsed());
|
||||||
@@ -105,15 +105,13 @@ impl ZeroSlotClient {
|
|||||||
|
|
||||||
println!(" 0slot{}确认: {:?}", trade_type, start_time.elapsed());
|
println!(" 0slot{}确认: {:?}", trade_type, start_time.elapsed());
|
||||||
|
|
||||||
Ok(signature)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<Vec<Signature>> {
|
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>) -> Result<()> {
|
||||||
let mut signatures = Vec::new();
|
|
||||||
for transaction in transactions {
|
for transaction in transactions {
|
||||||
let signature = self.send_transaction(trade_type, transaction).await?;
|
self.send_transaction(trade_type, transaction).await?;
|
||||||
signatures.push(signature);
|
|
||||||
}
|
}
|
||||||
Ok(signatures)
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user