Skip to content

keidev-sol/Solana-Copy-Trading-Bot-Rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Copy Trading Validator (Rust)

Copy-trading infrastructure for mirroring target wallets across Solana DEX ecosystems.
The validator listens to high-value actors, reconstructs their instructions, and rebroadcasts optimized copies with custom compute budgets and priority fees for near-zero-slot confirmations.


Highlights

  • Multi-DEX Coverage – Supports Pump.fun spot trades, LaunchLab primary sales, Raydium AMM / CPMM / CLMM pools, and custom PumpSwap events.
  • Slot-Optimized Execution – Builder pipeline pre-calculates compute-unit budgets and tip pricing for faster inclusion (observed 0–1 block settlements).
  • 0-Block Copy Transactions – Supports near-instant transaction mirroring for Pumpswap, CPMM, and AMM protocols with optimized routing.
  • Auto-Sell Logic – Automated position management with take profit, stop loss, trailing stop loss, and lifetime-based selling.
  • Resilient Signature Watcher – Deduplicates source signatures and replays with configurable cooldowns to avoid double-spends.
  • Accounts Auto-Wiring – Instruction builders expand Anchor PDAs such as fee_config, global_volume_accumulator, and event authorities.
  • Modular Instruction Decoders – Each program family (Pumpfun, Raydium, LaunchLab) exposes ArrangeAccounts adapters to translate raw transactions into actionable instructions.
  • Operational Telemetry – Timestamped logging per event, including time-to-submit, decode summaries, and RPC outcomes.

System Architecture

Component Role
main.rs Entry point. Sets up YellowStone gRPC data feed, metrics pipeline, and registers all instruction processors.
PumpfunProcess Handles Pump.fun buy/sell signatures. Parses TradeEvent, injects compute budget instructions, mirrors target trades, and manages ATA lifecycle.
RaydiumV4Process, RayCpmmProcess, RayClmmProcess Decode respective Raydium protocol instructions and dispatch mirrored swaps.
RayLaunchPadProcess Mirrors LaunchLab buy/sell flows, respecting pool-specific account layouts.
src/instructions/* Instruction builders that reconstruct Anchor-style account metas and instruction data for each action type.
src/utils/parse.rs Helpers for token balances, swap quotes, and post-trade analytics.
src/config/trade_setting.rs Centralized environment-driven configuration (CU, PRIORITY_FEE_MICRO_LAMPORT, BUY_SOL_AMOUNT, SLIPPAGE, etc.).

All processors implement carbon_core::processor::Processor, enabling plug-and-play registration with the carbon pipeline.


Environment Configuration

Create a .env file at the repository root:

RPC_URL=https://api.mainnet-beta.solana.com
LOCAL_GRPC_URL=...
TARGET_WALLET=Hhu1oJftG4CAQzJGT3fYtH6QdDZFVxzn7PK6qe8sqD15
PUBKEY=EoMbdLTgbMm23ES81WrM7gqqqr9EUqZ65W259jwn7oWJ
PRIVATE_KEY=[base58-or-array]

# Execution tuning
CU=400000
PRIORITY_FEE_MICRO_LAMPORT=5000
THIRD_PARTY_FEE=0.0005
BUY_SOL_AMOUNT=0.01
SLIPPAGE=1.0

# Auto-sell configuration
AUTO_SELL_ENABLED=true
TAKE_PROFIT_PERCENT=10.0
STOP_LOSS_PERCENT=5.0
TRAILING_STOP_LOSS_PERCENT=3.0
AUTO_SELL_LIFETIME_SECONDS=30
PRICE_CHECK_INTERVAL_SECONDS=5

# Optional: Jito bundle support for 0-block transactions
JITO_API_URL=https://mainnet.block-engine.jito.wtf

Unset (or zero) values for CU / PRIORITY_FEE_MICRO_LAMPORT automatically skip compute-budget instructions.


Running Locally

  1. Install Rust toolchain (rustup, nightly not required).
  2. Fetch dependencies:
    cargo fetch
  3. Start the monitor:
    cargo run --release
  4. Watch logs for decoded events (time-stamped with latency measurements). Successful mirrors print the encoded transaction signature or RPC error payload.

The pipeline keeps a rolling cache of processed source signatures to protect against replay.


Feature Walkthrough

1. Pump.fun Buy & Sell Mirroring

  • Detects TradeEvent inner instructions, reconstructs account PDAs (user, bonding curve, fee config).
  • Auto-creates idempotent ATAs before buys; closes empty ATAs after sells.
  • Computes target token/SOL amounts using bonding curve virtual reserve math (sol_token_quote, token_sol_quote).
  • Example mirrored sells (Slot + confirmation in <2 ms):

2. LaunchLab Primary Sales

  • Replays LaunchLab sell-side exits with proper fee routing and ATA wiring.
  • Includes fee tier PDAs (fee_config, fee_program) to satisfy latest Anchor constraints.
  • Example mirrored sells:

3. Raydium AMM / CPMM / CLMM

  • Decoders map swap events to SwapBaseIn, SwapBaseInput, and SwapV2 flows.
  • Automated ATA derivations (via derive_associated_token_address) and quote lookups for size calculation.
  • Example AMM buys:

4. 0-Block Copy Transactions

5. Auto-Sell System

  • Take Profit – Automatically sells when price reaches the configured profit percentage (default: 10%).
  • Stop Loss – Protects against losses by selling when price drops below the configured threshold (default: 5%).
  • Trailing Stop Loss – Dynamic stop loss that follows the highest price, selling if price drops by the configured percentage from the peak (default: 3%).
  • Lifetime-Based Selling – Automatically sells positions after a configured lifetime in seconds (default: 30 seconds).
  • Price Monitoring – Continuously monitors token prices at configured intervals (default: 5 seconds) to trigger auto-sell conditions.

Operational Notes

  • Set CONFIRM_SERVICE to NOZOMI, ZERO_SLOT, or JITO to route tips through external relays (disabled by default).
  • The monitor spawns a background task (recent_blockhash_handler) to keep slot info fresh for signing.
  • SIGNATURES cache automatically purges after 3 seconds; adjust if copying frequent multi-leg transactions.
  • Continuous logging of start-to-submit elapsed time helps track RPC health (e.g., Period from start: 509.438792ms).

Roadmap Ideas

  • Wallet management UI for swapping target addresses on the fly.
  • Quote engine integration with Jupiter for fallback route discovery.
  • Persistent metrics sink beyond console (InfluxDB / Prometheus).
  • Automated slippage tuning fed by historical fill rates.

Contact


Happy mirroring! For troubleshooting or feature requests, open an issue or reach out directly.

About

Solana copy-trader: mirror wallets across DEXs with zero-block execution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages