A Rust library that discovers BAM (Blockspace Assembly Marketplace) RPC regions, measures their latency in parallel, and sends Solana transactions to the fastest healthy endpoint built by naruto11.
- Built-in metadata for BAM mainnet and testnet regions.
- Concurrent latency probes via async Solana RPC calls.
- Intelligent retries for transient network failures.
- Helpers for
VersionedTransaction, legacyTransaction, base64, base58, or raw bytes. - Default submission via public Solana RPC (testnet/mainnet) with hooks for future TPU submission.
- Docs through mdbook.
The crate targets Rust 1.75+ and depends on tokio for async runtime support.
[dependencies]
bam-smart-routing-client = { path = "." }
tokio = { version = "1.40", features = ["macros", "rt-multi-thread"] }
solana-sdk = "=3.0.0"Quick probe example:
use bam_smart_routing_client::{BamSmartRouter, RouterConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let router = BamSmartRouter::new(RouterConfig::default())?;
let selection = router.select_fastest().await?;
println!(
"{} ({:?}) in {} ms",
selection.region.endpoint,
selection.region.network,
selection.latency.as_millis()
);
Ok(())
}By default txns go to the public Solana RPC that matches the network
filter (testnet -> https://api.testnet.solana.com, mainnet ->
https://api.mainnet-beta.solana.com). Override this behaviour as needed:
use bam_smart_routing_client::{
BamSmartRouter, RouterConfig, SubmissionEndpoint,
};
let mut config = RouterConfig::default();
config.submission_endpoint = SubmissionEndpoint::FastestRegion;
let router = BamSmartRouter::new(config)?;To target the validator TPU directly once QUIC credentials are available:
use bam_smart_routing_client::{BamSmartRouter, RouterConfig, SubmissionEndpoint};
let mut config = RouterConfig::default();
config.submission_endpoint = SubmissionEndpoint::Tpu {
host: "ny.testnet.bam.jito.wtf".into(),
port: 10000, // replace with actual TPU port
};
// NOTE: the current implementation returns an error for `Tpu`. good TODO.
let router = BamSmartRouter::new(config)?;cargo run --example probe
# Submit a signed transaction (base64) through the configured RPC
cargo run --example probe -- --tx-base64 <BASE64_TX>
Use the helper example to mint a fresh base64 payload without juggling CLI flags manually:
cargo run --example make_tx -- <RECIPIENT_PUBKEY> <AMOUNT_SOL|LAMPORTS> [KEYPAIR_PATH] [RPC_URL]
# Example: send 0.01 SOL from a local keypair on testnet
cargo run --example make_tx -- <RECIPIENT_PUBKEY> 0.01 ~/solana-test.json
# Pipe the output into the router example
BASE64_TX=$(cargo run --example make_tx -- <RECIPIENT_PUBKEY> 0.01 ~/solana-test.json | tail -n1)
cargo run --example probe -- --tx-base64 "$BASE64_TX"
The helper fetches a fresh blockhash, signs the transfer, and prints the serialized transaction as base64 without broadcasting it.
See the docs for more examples and API details.
cargo fmt
cargo clippy --all-targets --all-features
cargo testThe latency and routing logic is covered by async unit tests that leverage
httpmock to control simulated RPC delays.
This repo ships an mdBook site under
docs/.
mdbook serve docs
-> http://localhost:3000 for live preview├── Cargo.toml
├── src/
│ ├── config.rs
│ ├── error.rs
│ ├── lib.rs
│ ├── probe.rs
│ ├── regions.rs
│ └── router.rs
├── docs/
│ ├── book.toml
│ └── src/
│ ├── SUMMARY.md
│ ├── index.md
│ ├── quickstart.md
│ ├── latency.md
│ └── api.md
└── README.md
- Optional dynamic region discovery over HTTPS.
- Metrics integration for reporting latency trends.
- CLI wrapper for manual transaction dispatch.
MIT