Add Hello Moon Lunar Lander support
This commit is contained in:
@@ -155,6 +155,20 @@ pub const SPEEDLANDING_TIP_ACCOUNTS: &[Pubkey] = &[
|
||||
pubkey!("speede8xCcUq2Tiv1efXeTuE3k9TDNq8TnGKaKSc6J4"),
|
||||
];
|
||||
|
||||
// LunarLander (HelloMoon) tip accounts
|
||||
pub const LUNARLANDER_TIP_ACCOUNTS: &[Pubkey] = &[
|
||||
pubkey!("moon17L6BgxXRX5uHKudAmqVF96xia9h8ygcmG2sL3F"),
|
||||
pubkey!("moon26Sek222Md7ZydcAGxoKG832DK36CkLrS3PQY4c"),
|
||||
pubkey!("moon7fwyajcVstMoBnVy7UBcTx87SBtNoGGAaH2Cb8V"),
|
||||
pubkey!("moonBtH9HvLHjLqi9ivyrMVKgFUsSfrz9BwQ9khhn1u"),
|
||||
pubkey!("moonCJg8476LNFLptX1qrK8PdRsA1HD1R6XWyu9MB93"),
|
||||
pubkey!("moonF2sz7qwAtdETnrgxNbjonnhGGjd6r4W4UC9284s"),
|
||||
pubkey!("moonKfftMiGSak3cezvhEqvkPSzwrmQxQHXuspC96yj"),
|
||||
pubkey!("moonQBUKBpkifLcTd78bfxxt4PYLwmJ5admLW6cBBs8"),
|
||||
pubkey!("moonXwpKwoVkMegt5Bc776cSW793X1irL5hHV1vJ3JA"),
|
||||
pubkey!("moonZ6u9E2fgk6eWd82621eLPHt9zuJuYECXAYjMY1C"),
|
||||
];
|
||||
|
||||
// NewYork,
|
||||
// Frankfurt,
|
||||
// Amsterdam,
|
||||
@@ -314,6 +328,19 @@ pub const SWQOS_ENDPOINTS_SPEEDLANDING: [&str; 8] = [
|
||||
"fra.speedlanding.trade:17778",
|
||||
];
|
||||
|
||||
/// HelloMoon Lunar Lander: JSON-RPC sendTransaction, auth via ?api-key= query param.
|
||||
/// Region order: NewYork(NYC), Frankfurt, Amsterdam, SLC(Ashburn), Tokyo, London(→Frankfurt), LosAngeles(→NYC), Default(geolocated).
|
||||
pub const SWQOS_ENDPOINTS_LUNARLANDER: [&str; 8] = [
|
||||
"http://nyc.lunar-lander.hellomoon.io/send", // NewYork
|
||||
"http://fra.lunar-lander.hellomoon.io/send", // Frankfurt
|
||||
"http://ams.lunar-lander.hellomoon.io/send", // Amsterdam
|
||||
"http://ash.lunar-lander.hellomoon.io/send", // SLC (closest: Ashburn)
|
||||
"http://tyo.lunar-lander.hellomoon.io/send", // Tokyo
|
||||
"http://fra.lunar-lander.hellomoon.io/send", // London (fallback to Frankfurt)
|
||||
"http://nyc.lunar-lander.hellomoon.io/send", // LosAngeles (fallback to NYC)
|
||||
"http://lunar-lander.hellomoon.io/send", // Default (geolocated)
|
||||
];
|
||||
|
||||
/// Helius Sender: POST /fast, dual routing to validators and Jito. API key optional (custom TPS only).
|
||||
/// Region order: NewYork(EWR), Frankfurt, Amsterdam, SLC, Tokyo, London, LosAngeles(SG), Default(Global).
|
||||
pub const SWQOS_ENDPOINTS_HELIUS: [&str; 8] = [
|
||||
@@ -343,5 +370,6 @@ pub const SWQOS_MIN_TIP_SOYAS: f64 = 0.001; // Soyas requires minimum 0.001 SOL
|
||||
pub const SWQOS_MIN_TIP_SPEEDLANDING: f64 = 0.001; // Speedlanding requires minimum 0.001 SOL tip
|
||||
/// Helius Sender: 0.0002 SOL when not swqos_only; use SWQOS_MIN_TIP_HELIUS_SWQOS_ONLY when swqos_only=true.
|
||||
pub const SWQOS_MIN_TIP_HELIUS: f64 = 0.0002;
|
||||
pub const SWQOS_MIN_TIP_LUNARLANDER: f64 = 0.001; // LunarLander 最低小费 0.001 SOL
|
||||
/// Helius Sender with swqos_only: minimum 0.000005 SOL (much lower tip allowed).
|
||||
pub const SWQOS_MIN_TIP_HELIUS_SWQOS_ONLY: f64 = 0.000005;
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
//! HelloMoon Lunar Lander SWQOS client.
|
||||
//!
|
||||
//! High-performance transaction landing service with keep-alive ping.
|
||||
//! Auth via `?api-key=` query parameter. Minimum tip: 0.001 SOL.
|
||||
|
||||
use crate::swqos::common::{default_http_client_builder, poll_transaction_confirmation, serialize_transaction_and_encode};
|
||||
use rand::seq::IndexedRandom;
|
||||
use reqwest::Client;
|
||||
use serde_json::json;
|
||||
use std::{sync::Arc, time::Instant};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use std::time::Duration;
|
||||
use solana_transaction_status::UiTransactionEncoding;
|
||||
|
||||
use anyhow::Result;
|
||||
use solana_sdk::transaction::VersionedTransaction;
|
||||
use crate::swqos::{SwqosType, TradeType};
|
||||
use crate::swqos::SwqosClientTrait;
|
||||
|
||||
use crate::{common::SolanaRpcClient, constants::swqos::LUNARLANDER_TIP_ACCOUNTS};
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LunarLanderClient {
|
||||
pub endpoint: String,
|
||||
pub api_key: String,
|
||||
pub rpc_client: Arc<SolanaRpcClient>,
|
||||
pub http_client: Client,
|
||||
stop_ping: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SwqosClientTrait for LunarLanderClient {
|
||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction, wait_confirmation: bool) -> Result<()> {
|
||||
self.send_transaction(trade_type, transaction, wait_confirmation).await
|
||||
}
|
||||
|
||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>, wait_confirmation: bool) -> Result<()> {
|
||||
self.send_transactions(trade_type, transactions, wait_confirmation).await
|
||||
}
|
||||
|
||||
fn get_tip_account(&self) -> Result<String> {
|
||||
let tip_account = *LUNARLANDER_TIP_ACCOUNTS.choose(&mut rand::rng()).or_else(|| LUNARLANDER_TIP_ACCOUNTS.first()).unwrap();
|
||||
Ok(tip_account.to_string())
|
||||
}
|
||||
|
||||
fn get_swqos_type(&self) -> SwqosType {
|
||||
SwqosType::LunarLander
|
||||
}
|
||||
}
|
||||
|
||||
impl LunarLanderClient {
|
||||
/// Derive the ping URL from the send endpoint by replacing the last path segment.
|
||||
fn ping_url(endpoint: &str, api_key: &str) -> String {
|
||||
// Find the last '/' that is part of the path (after "://")
|
||||
let scheme_end = endpoint.find("://").map(|i| i + 3).unwrap_or(0);
|
||||
let base = endpoint[scheme_end..].rfind('/')
|
||||
.map(|i| &endpoint[..scheme_end + i])
|
||||
.unwrap_or(endpoint);
|
||||
format!("{}/ping?api-key={}", base, api_key)
|
||||
}
|
||||
|
||||
/// Derive the send URL with the API key query parameter.
|
||||
fn send_url(endpoint: &str, api_key: &str) -> String {
|
||||
let separator = if endpoint.contains('?') { '&' } else { '?' };
|
||||
format!("{}{}api-key={}", endpoint, separator, api_key)
|
||||
}
|
||||
|
||||
pub fn new(rpc_url: String, endpoint: String, api_key: String) -> Self {
|
||||
let rpc_client = SolanaRpcClient::new(rpc_url);
|
||||
let http_client = default_http_client_builder().build().unwrap();
|
||||
|
||||
let stop_ping = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let client = Self {
|
||||
rpc_client: Arc::new(rpc_client),
|
||||
endpoint: endpoint.clone(),
|
||||
api_key: api_key.clone(),
|
||||
http_client: http_client.clone(),
|
||||
stop_ping: stop_ping.clone(),
|
||||
};
|
||||
|
||||
// Start ping task
|
||||
let client_clone = client.clone();
|
||||
tokio::spawn(async move {
|
||||
client_clone.start_ping_task().await;
|
||||
});
|
||||
|
||||
client
|
||||
}
|
||||
|
||||
/// Start periodic ping task to keep connections active.
|
||||
/// GET /ping every 30s on the same TCP connection (recommended 30-45s by HelloMoon).
|
||||
async fn start_ping_task(&self) {
|
||||
let ping_url = Self::ping_url(&self.endpoint, &self.api_key);
|
||||
let http_client = self.http_client.clone();
|
||||
let stop_ping = self.stop_ping.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
// Immediate first ping to warm connection and reduce first-submit cold start latency
|
||||
if let Ok(resp) = http_client.get(&ping_url).timeout(Duration::from_millis(1500)).send().await {
|
||||
let status = resp.status();
|
||||
let _ = resp.bytes().await;
|
||||
if !status.is_success() && crate::common::sdk_log::sdk_log_enabled() {
|
||||
eprintln!(" [lunarlander] ping failed with status: {}", status);
|
||||
}
|
||||
}
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(30));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if stop_ping.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
match http_client.get(&ping_url).timeout(Duration::from_millis(1500)).send().await {
|
||||
Ok(response) => {
|
||||
let status = response.status();
|
||||
let _ = response.bytes().await;
|
||||
if !status.is_success() && crate::common::sdk_log::sdk_log_enabled() {
|
||||
eprintln!(" [lunarlander] ping failed with status: {}", status);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if crate::common::sdk_log::sdk_log_enabled() {
|
||||
eprintln!(" [lunarlander] ping request error: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction, wait_confirmation: bool) -> Result<()> {
|
||||
let start_time = Instant::now();
|
||||
let (content, signature) = serialize_transaction_and_encode(transaction, UiTransactionEncoding::Base64)?;
|
||||
|
||||
let request_body = serde_json::to_string(&json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "sendTransaction",
|
||||
"params": [
|
||||
content,
|
||||
{ "encoding": "base64" }
|
||||
]
|
||||
}))?;
|
||||
|
||||
let url = Self::send_url(&self.endpoint, &self.api_key);
|
||||
|
||||
let response_text = self.http_client.post(&url)
|
||||
.body(request_body)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Connection", "keep-alive")
|
||||
.header("Keep-Alive", "timeout=30, max=1000")
|
||||
.send()
|
||||
.await?
|
||||
.text()
|
||||
.await?;
|
||||
|
||||
// Parse response
|
||||
if let Ok(response_json) = serde_json::from_str::<serde_json::Value>(&response_text) {
|
||||
if crate::common::sdk_log::sdk_log_enabled() {
|
||||
if response_json.get("result").is_some() {
|
||||
println!(" [lunarlander] {} submitted: {:?}", trade_type, start_time.elapsed());
|
||||
} else if let Some(error) = response_json.get("error") {
|
||||
eprintln!(" [lunarlander] {} submission failed: {:?}", trade_type, error);
|
||||
}
|
||||
}
|
||||
} else if crate::common::sdk_log::sdk_log_enabled() {
|
||||
eprintln!(" [lunarlander] {} submission failed: {:?}", trade_type, response_text);
|
||||
}
|
||||
|
||||
let start_time: Instant = Instant::now();
|
||||
match poll_transaction_confirmation(&self.rpc_client, signature, wait_confirmation).await {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
if crate::common::sdk_log::sdk_log_enabled() {
|
||||
println!(" signature: {:?}", signature);
|
||||
println!(" [lunarlander] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
|
||||
}
|
||||
return Err(e);
|
||||
},
|
||||
}
|
||||
if wait_confirmation && crate::common::sdk_log::sdk_log_enabled() {
|
||||
println!(" signature: {:?}", signature);
|
||||
println!(" [lunarlander] {} confirmed: {:?}", trade_type, start_time.elapsed());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>, wait_confirmation: bool) -> Result<()> {
|
||||
for transaction in transactions {
|
||||
self.send_transaction(trade_type, transaction, wait_confirmation).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stop the ping task
|
||||
pub fn stop_ping_task(&self) {
|
||||
self.stop_ping.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LunarLanderClient {
|
||||
fn drop(&mut self) {
|
||||
// Stop ping task when client is dropped
|
||||
self.stop_ping.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ pub mod lightspeed;
|
||||
pub mod soyas;
|
||||
pub mod speedlanding;
|
||||
pub mod helius;
|
||||
pub mod lunarlander;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -57,6 +58,8 @@ use crate::{
|
||||
SWQOS_MIN_TIP_SOYAS,
|
||||
SWQOS_MIN_TIP_SPEEDLANDING,
|
||||
SWQOS_MIN_TIP_HELIUS,
|
||||
SWQOS_ENDPOINTS_LUNARLANDER,
|
||||
SWQOS_MIN_TIP_LUNARLANDER,
|
||||
},
|
||||
swqos::{
|
||||
bloxroute::BloxrouteClient,
|
||||
@@ -74,6 +77,7 @@ use crate::{
|
||||
soyas::SoyasClient,
|
||||
speedlanding::SpeedlandingClient,
|
||||
helius::HeliusClient,
|
||||
lunarlander::LunarLanderClient,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -134,6 +138,7 @@ pub enum SwqosType {
|
||||
Soyas,
|
||||
Speedlanding,
|
||||
Helius,
|
||||
LunarLander,
|
||||
Default,
|
||||
}
|
||||
|
||||
@@ -154,6 +159,7 @@ impl SwqosType {
|
||||
Self::Soyas,
|
||||
Self::Speedlanding,
|
||||
Self::Helius,
|
||||
Self::LunarLander,
|
||||
Self::Default,
|
||||
]
|
||||
}
|
||||
@@ -185,6 +191,7 @@ pub trait SwqosClientTrait {
|
||||
SwqosType::Soyas => SWQOS_MIN_TIP_SOYAS,
|
||||
SwqosType::Speedlanding => SWQOS_MIN_TIP_SPEEDLANDING,
|
||||
SwqosType::Helius => SWQOS_MIN_TIP_HELIUS,
|
||||
SwqosType::LunarLander => SWQOS_MIN_TIP_LUNARLANDER,
|
||||
SwqosType::Default => SWQOS_MIN_TIP_DEFAULT,
|
||||
}
|
||||
}
|
||||
@@ -237,6 +244,9 @@ pub enum SwqosConfig {
|
||||
/// Helius Sender: dual routing to validators and Jito. API key optional (custom TPS only).
|
||||
/// (api_key, region, custom_url, swqos_only). swqos_only: None => false (min tip 0.0002 SOL); Some(true) => SWQOS-only (min tip 0.000005 SOL, much lower).
|
||||
Helius(String, SwqosRegion, Option<String>, Option<bool>),
|
||||
/// LunarLander(api_key, region, custom_url) - HelloMoon Lunar Lander
|
||||
/// Minimum tip: 0.001 SOL
|
||||
LunarLander(String, SwqosRegion, Option<String>),
|
||||
}
|
||||
|
||||
impl SwqosConfig {
|
||||
@@ -257,6 +267,7 @@ impl SwqosConfig {
|
||||
SwqosConfig::Soyas(_, _, _) => SwqosType::Soyas,
|
||||
SwqosConfig::Speedlanding(_, _, _) => SwqosType::Speedlanding,
|
||||
SwqosConfig::Helius(_, _, _, _) => SwqosType::Helius,
|
||||
SwqosConfig::LunarLander(_, _, _) => SwqosType::LunarLander,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,6 +296,7 @@ impl SwqosConfig {
|
||||
SwqosType::Soyas => SWQOS_ENDPOINTS_SOYAS[region as usize].to_string(),
|
||||
SwqosType::Speedlanding => SWQOS_ENDPOINTS_SPEEDLANDING[region as usize].to_string(),
|
||||
SwqosType::Helius => SWQOS_ENDPOINTS_HELIUS[region as usize].to_string(),
|
||||
SwqosType::LunarLander => SWQOS_ENDPOINTS_LUNARLANDER[region as usize].to_string(),
|
||||
SwqosType::Default => "".to_string(),
|
||||
}
|
||||
}
|
||||
@@ -429,6 +441,15 @@ impl SwqosConfig {
|
||||
);
|
||||
Ok(Arc::new(helius_client))
|
||||
},
|
||||
SwqosConfig::LunarLander(api_key, region, url) => {
|
||||
let endpoint = SwqosConfig::get_endpoint(SwqosType::LunarLander, region, url);
|
||||
let lunarlander_client = LunarLanderClient::new(
|
||||
rpc_url.clone(),
|
||||
endpoint.to_string(),
|
||||
api_key
|
||||
);
|
||||
Ok(Arc::new(lunarlander_client))
|
||||
},
|
||||
SwqosConfig::Default(endpoint) => {
|
||||
let rpc = SolanaRpcClient::new_with_commitment(
|
||||
endpoint,
|
||||
|
||||
Reference in New Issue
Block a user