Skip to content

0xfnzero/fnzero-examples

Repository files navigation

🚀 FnZero Solana Examples

Practical examples and tools for Solana DEX trading and development

A collection of Rust examples, SDKs, and tools for building high-performance Solana trading bots. Includes trading examples, SDKs for DEX integration, transaction parsing, key management, and real-time streaming.

GitHub stars GitHub forks License

Rust Solana DEX Trading

中文 | English | Website | Telegram | Discord


📋 Table of Contents


✨ Features

  • Trading Examples: Ready-to-use bots for PumpSwap (outer pool) and PumpFun (bonding curve) with automated buy/sell
  • Multiple SWQoS Support: Concurrent transaction submission via multiple MEV protection services
  • Comprehensive SDKs: Modular SDKs for trading, parsing, key management, and streaming
  • Real-time Streaming: gRPC-based transaction streaming and parsing with low-latency event processing
  • Secure Key Management: Encrypted keystore support with password protection
  • Production Ready: Optimized builds with cross-platform support (Linux, macOS)

📁 Project Structure

fnzero-examples/
├── pumpswap_trade/              # PumpSwap (outer pool) trading example (direct private key)
├── pumpswap_trade_with_safekey/ # PumpSwap (outer pool) trading example (encrypted keystore)
├── pumpfun_trade/               # PumpFun (bonding curve) trading example (direct private key)
├── pumpfun_trade_with_safekey/  # PumpFun (bonding curve) trading example (encrypted keystore)
├── sol-trade-sdk/              # Unified DEX trading SDK
├── sol-parser-sdk/             # Transaction parsing SDK (gRPC streaming)
├── sol-safekey/                # Encrypted key management library
└── solana-streamer/            # Solana transaction streaming utilities

🛠️ Examples

Trading Examples

Example Description Run Command Source Code
PumpSwap Trading Automated buy→wait→sell loop on PumpSwap (outer AMM); configurable rounds and rest ./run.sh pumpswap_trade
PumpSwap Trading (Encrypted) Same as above with encrypted keystore ./run.sh pumpswap_trade_with_safekey
PumpFun Trading Buy→wait→sell on PumpFun bonding curve; token must not have graduated to PumpSwap ./run.sh pumpfun_trade
PumpFun Trading (Encrypted) Same as above; keystore / KEYPAIR_BASE58 ./run.sh pumpfun_trade_with_safekey

Which example should I use?

Scenario Directory
Token still on PumpFun bonding curve (not graduated to PumpSwap) pumpfun_trade or pumpfun_trade_with_safekey
Token on PumpSwap outer AMM pumpswap_trade or pumpswap_trade_with_safekey
Private key via PRIVATE_KEY or private_key in YAML pumpfun_trade / pumpswap_trade
Encrypted keystore + password (or fallback KEYPAIR_BASE58) pumpfun_trade_with_safekey / pumpswap_trade_with_safekey

Shared behavior (all four trading examples)

  • Flow: Buy → wait ~30s → sell; 1 round by default (change ROUNDS / REST_SECS in each crate’s src/run.rs)
  • Multi-SWQoS: Concurrent submission to several MEV channels
  • YAML + .env: config/dev|prod/solana.yaml, trading.yaml, and env overrides
  • Durable nonce: Required when 2+ SWQoS providers are enabled—set nonce_config or NONCE_ACCOUNT; empty "" placeholders in YAML are skipped so NONCE_ACCOUNT still works
  • Gas / slippage: Configurable in trading.yaml
  • Default: wait_tx_confirmed: false; the bot waits a fixed interval after buy before reading balance—tune for production if needed
  • ⚠️ Sell size: Each round sells the wallet’s full token balance for that mint (including any balance you held before the buy)

Example README index

Example Chinese English
PumpSwap (private key) README_CN.md README.md
PumpSwap (encrypted) README_CN.md README.md
PumpFun (private key) README_CN.md README.md
PumpFun (encrypted) README_CN.md README.md

Configuration

  • The repo only ships *.yaml.example and .env.example. Your local solana.yaml, trading.yaml, and .env are created from those templates and are git-ignored (see “Before you run & privacy”).
  • Environment variables can override YAML. With multiple SWQoS providers, configure durable nonce or NONCE_ACCOUNT.

Supported SWQoS Services

Service Transport Protocols
Astralane HTTP, QUIC ⚡
BlockRazor HTTP, gRPC
Bloxroute HTTP
FlashBlock HTTP
Jito HTTP
NextBlock HTTP
Node1 HTTP, QUIC ⚡
Soyas QUIC ⚡
Speedlanding QUIC ⚡
Stellium HTTP
Temporal HTTP
ZeroSlot HTTP
Default RPC

API Key Application: Apply for API keys through the official website: https://fnzero.dev/swqos

Note: ⚡ = QUIC (Quick UDP Internet Connections) provides lower latency compared to HTTP/gRPC. Services using QUIC (Astralane, Node1, Soyas, Speedlanding) typically offer the best transaction submission performance.


📦 SDKs & Tools

sol-trade-sdk

Comprehensive Rust SDK for Solana DEX trading with unified interface for multiple protocols.

Features:

  • Support for PumpFun, PumpSwap, Bonk, Raydium CPMM, Raydium AMM V4, Meteora DAMM V2
  • Multiple MEV protection services (Jito, BlockRazor, Astralane, etc.)
  • Middleware system for custom instruction modification
  • Shared infrastructure for multi-wallet scenarios
  • Address Lookup Table (ALT) support
  • Durable Nonce management
  • Gas fee strategy optimization

Documentation: sol-trade-sdk/README.md

sol-parser-sdk

Transaction parsing SDK with gRPC streaming support for real-time event processing.

Features:

  • Parse PumpFun, PumpSwap, Raydium, and other DEX transactions
  • gRPC-based streaming for low-latency event processing
  • Event filtering and transformation
  • Trade event extraction
  • Account filler for optimized account lookups

Documentation: sol-parser-sdk/README.md

sol-safekey

Encrypted key management library for secure Solana keypair storage.

Features:

  • Encrypt/decrypt Solana keypairs with password protection
  • JSON-based keystore format
  • Base58 private key support
  • CLI tools for key management
  • Integration with trading examples

Documentation: sol-safekey/README.md

solana-streamer

Utilities for Solana transaction streaming and real-time data processing.

Features:

  • Shred stream subscription
  • Transaction streaming
  • Event processing pipeline
  • Performance-optimized parsing

Documentation: solana-streamer/README.md


📋 Before you run & privacy

Do this before running any trading example for the first time. This repository does not ship your private keys, SWQoS API tokens, or production RPC URLs—only *.yaml.example and .env.example templates.

1. Clone this repository

git clone https://github.com/0xfnzero/fnzero-examples.git
cd fnzero-examples

2. Create local config from templates (required)

cd into the example you need (pumpswap_trade, pumpfun_trade, etc.) and copy templates per environment:

cd pumpswap_trade   # or pumpfun_trade / *_with_safekey

cp .env.example .env
cp config/dev/solana.yaml.example config/dev/solana.yaml
cp config/dev/trading.yaml.example config/dev/trading.yaml
# For prod, also copy config/prod/*.example → config/prod/*.yaml

Then edit locally (do not commit):

File What to fill in
.env PRIVATE_KEY or KEYSTORE_PASSWORD, SOLANA_RPC_URL, NONCE_ACCOUNT (if multi-SWQoS), …
config/*/solana.yaml rpc_url, private_key or keystore_path, SWQoS api_token, nonce_config, …
config/*/trading.yaml Buy size, slippage, gas, …

APP_ENV=dev uses config/dev/, APP_ENV=prod uses config/prod/.

3. Encrypted keystore: install sol-safekey separately

This repo’s .gitignore excludes the sol-safekey tree. Clone that project to generate keystore.json:

cd /path/to/parent
git clone https://github.com/0xfnzero/sol-safekey.git
cd sol-safekey
cargo run --release -- export <private_key_or_mnemonic> /path/to/fnzero-examples/pumpswap_trade_with_safekey/keystore.json

Then set keystore_path in the example’s solana.yaml (e.g. ./keystore.json).

4. Privacy & Git: never commit

These paths are ignored by .gitignore—do not force-add them:

  • .env, .env.* (except .env.example)
  • config/**/solana.yaml, config/**/trading.yaml (your local copies)
  • keystore.json and any file containing private keys

Run git status before pushing. If secrets were ever committed, rotate keys and scrub history.

Prerequisites (tooling)

  • Rust 1.70+ and Cargo
  • Solana CLI (optional)
  • A reliable Solana RPC endpoint (prefer your own or paid; public RPCs rate-limit)

🚀 Quick Start

Run trading examples

Run commands inside the example crate directory (each folder is its own Cargo package; there is no repo-root workspace). If you have not completed the steps above, copy templates and edit them first.

Option 1: Private key (PumpSwap or PumpFun)

cd pumpswap_trade          # outer AMM; use cd pumpfun_trade for bonding-curve tokens

cp .env.example .env
cp config/dev/solana.yaml.example config/dev/solana.yaml
cp config/dev/trading.yaml.example config/dev/trading.yaml
# Edit .env and yaml: PRIVATE_KEY, RPC, SWQoS tokens, nonce, … (see “Before you run”)

./run.sh <TOKEN_MINT_ADDRESS>
# or: cargo run --release -- <TOKEN_MINT_ADDRESS>

Option 2: Encrypted keystore (requires a separate sol-safekey clone as described above)

cd /path/to/sol-safekey
cargo run --release -- export <private_key_or_mnemonic> /path/to/fnzero-examples/pumpswap_trade_with_safekey/keystore.json

cd /path/to/fnzero-examples/pumpswap_trade_with_safekey   # or pumpfun_trade_with_safekey

cp .env.example .env
cp config/dev/solana.yaml.example config/dev/solana.yaml
cp config/dev/trading.yaml.example config/dev/trading.yaml
# Edit solana.yaml: keystore_path, SWQoS, nonce, …

./run.sh <TOKEN_MINT_ADDRESS>

Configuration Details

Environment Variables (.env)

# Environment: dev or prod
APP_ENV=dev

# Token mint address to trade
MINT=your_token_mint_address

# Sol amount to buy (SOL)
BUY_SOL_AMOUNT=0.01

# RPC URL
SOLANA_RPC_URL=https://your-rpc-endpoint.com

# Keystore password (for encrypted key)
KEYSTORE_PASSWORD=your_password

# Durable nonce account (required for multiple SWQoS)
NONCE_ACCOUNT=your_nonce_account_address

SWQoS Configuration (config/dev/solana.yaml)

swqos:
  region: "Frankfurt"  # or NewYork, Tokyo, etc.
  enabled_providers:
    - provider: "Astralane"
      api_token: "your_token"
      enabled: true
    - provider: "BlockRazor"
      api_token: "your_token"
      enabled: true
    # Add more providers as needed

Build for production

Each example uses .cargo/config.toml so artifacts go to build-cache/release/ (not the default target/release/).

cd pumpswap_trade    # or pumpfun_trade, pumpswap_trade_with_safekey, pumpfun_trade_with_safekey

cargo build --release
./build-cache/release/pumpswap_trade_with_safekey <TOKEN_MINT_ADDRESS>

# macOS → Linux bundle (requires x86_64-unknown-linux-gnu toolchain)
./build-linux-release.sh   # produces linux-release/deploy.tar.gz

📄 License

MIT License

See LICENSE for details.


💬 Contact


⚠️ Important Notes

  1. Security: Never commit private keys, keystores, local solana.yaml / trading.yaml, or .env; read “Before you run & privacy” before the first run
  2. Testing: Thoroughly test on devnet before using on mainnet
  3. Risk: Trading cryptocurrencies involves significant risk
  4. Compliance: Ensure compliance with local laws and regulations
  5. RPC Limits: Monitor RPC usage to avoid rate limiting
  6. MEV Services: Configure API tokens properly for MEV protection services

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📚 Additional Resources


Built with ❤️ by the FnZero team

About

A collection of Rust examples, SDKs, and tools for building high-performance Solana trading bots. Includes trading examples, SDKs for DEX integration, transaction parsing, key management, and real-time streaming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors