Skip to content

0xfnzero/fnzero-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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 trading bot examples for PumpSwap with automated buy/sell strategies
  • 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 trading example (direct private key)
β”œβ”€β”€ pumpswap_trade_with_safekey/ # PumpSwap 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 trading on PumpSwap with configurable rounds and rest intervals ./run.sh pumpswap_trade
PumpSwap Trading (Encrypted) Same as above, but uses encrypted keystore file with password protection ./run.sh pumpswap_trade_with_safekey

Example Features

Both trading examples include:

  • βœ… Automated Trading Loop: Buy β†’ wait 30s β†’ sell β†’ wait 30s, repeat for 3 rounds (configurable)
  • βœ… Multiple SWQoS: Concurrent transaction submission via multiple MEV protection services
  • βœ… Flexible Configuration: YAML-based config for dev/prod environments
  • βœ… Durable Nonce Support: Transaction replay protection for multi-SWQoS scenarios
  • βœ… Gas Fee Strategy: Configurable priority fees and compute unit prices
  • βœ… Slippage Protection: Customizable slippage settings for buy/sell
  • βœ… Environment Variables: Override config via .env file
  • βœ… Cross-platform Builds: Linux and macOS support with optimized release profiles

Configuration

Each example supports:

  • Environment Variables: .env file for sensitive configuration
  • YAML Config: config/dev/solana.yaml and config/prod/solana.yaml
  • Example Templates: .yaml.example files as configuration templates

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


πŸš€ Quick Start

Prerequisites

  • Rust 1.70+ and Cargo
  • Solana CLI (optional, for wallet management)
  • A Solana RPC endpoint (mainnet-beta or devnet)

Clone Repository

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

Run Trading Example

Option 1: Using direct private key

cd pumpswap_trade

# Configure your settings
cp .env.example .env
# Edit .env with your private key and RPC URL

# Configure SWQoS services
cp config/dev/solana.yaml.example config/dev/solana.yaml
# Edit config/dev/solana.yaml with your API tokens

# Run trading bot
cargo run --release -- <TOKEN_MINT_ADDRESS>

Option 2: Using encrypted keystore

cd pumpswap_trade_with_safekey

# Generate encrypted keystore
cargo run --bin sol-safekey -- export <your_private_key_or_mnemonic> ./keystore.json

# Configure settings
cp .env.example .env
cp config/dev/solana.yaml.example config/dev/solana.yaml

# Run trading bot (will prompt for password)
cargo run --release -- <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

# Optimized release build
cargo build --release

# Cross-compile for Linux (from macOS)
cargo build --release --target x86_64-unknown-linux-gnu

# Run compiled binary
./target/release/pumpswap_trade_with_safekey <TOKEN_MINT_ADDRESS>

πŸ“„ License

MIT License

See LICENSE for details.


πŸ’¬ Contact


⚠️ Important Notes

  1. Security: Never commit private keys or API tokens to version control
  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