Skip to content

solship/BNB-Copytrading-TS-Rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Copy-Trading Bots (BNB Chain) — Monorepo Overview

This workspace contains two copy-trading bots targeting BNB Chain (PancakeSwap + Four.meme):

  • BNB-Copytrading-Bot — TypeScript/Node.js implementation using ethers v6
  • Rust-Copytrading-Bot — Rust implementation using ethers-rs and Tokio

Both listen to on-chain logs via WebSocket providers and mirror trades from configured target wallets using one or more copy wallets.


Shared Capabilities

  • DEX coverage: PancakeSwap swaps and Four.meme buy/sell events
  • Target wallet filtering: Mirror only when initiator is in TARGET_WALLETS
  • Multiple copy wallets: Comma-separated private keys
  • Sizing controls: Scale by COPY_PERCENT (TS) or COPY_PERCENT/COPY_PERCENTS (Rust)
  • Gas controls: Minimum gas price and multiplier
  • Fallback decoding: Pair-contract inspection when router calldata parsing fails (PancakeSwap)

Repository Layout

Main/
  BNB-Copytrading-Bot/   # TypeScript implementation
  Rust-Copytrading-Bot/  # Rust implementation
  README.md              # This file

TypeScript Bot — BNB-Copytrading-Bot

A unified, production-ready TypeScript bot that copy-trades target wallets across PancakeSwap and Four.meme on BNB Chain.

Requirements

  • Node.js 18+
  • NPM 9+ (or pnpm/yarn)
  • BSC WS + HTTP endpoints

Install

cd BNB-Copytrading-Bot
npm install

Configuration (.env)

Create BNB-Copytrading-Bot/.env:

# RPC endpoints
WS_URL=wss://bsc-mainnet.nodereal.io/ws/v1/XXXXX
BSC_RPC_URL=https://bsc-dataseed.binance.org

# Optional secondary endpoints
WS_URL_2=
BSC_RPC_URL_2=

# PancakeSwap core contracts
PANCAKE_SWAP_ROUTER_ADDR=0x10ED43C718714eb63d5aA57B78B54704E256024E
PANCAKE_SWAP_FACTORY_ADDR=0xCA143Ce32Fe78f1f7019d7d551a6402fC5350c73

# Four.meme contract
FOUR_MEME_ADDRESS=0xYourFourMemeContractAddress

# Copy-trading wallets (comma-separated private keys)
COPY_KEYS=0xabc...,0xdef...

# Target wallets to follow (comma-separated addresses, lowercase)
TARGET_WALLETS=0xwallet1,0xwallet2

# Sizing and risk controls
COPY_PERCENT=1.0
SLIPPAGE_BPS=300
GAS_MULTIPLIER=1.0
MIN_GAS_PRICE_GWEI=5

Run

# Dev (unified listener)
npm run dev

# Production (build + run)
npm start

# Dev per-DEX
npm run pancakeswap
npm run fourmeme

How it works (TS)

  • Unified listener subscribes to PancakeSwap Swap and Four.meme TokenPurchase/TokenSale events
  • Fetches original tx to identify initiator and filter via TARGET_WALLETS
  • Derives path/amount via router decode or pair fallback
  • Executes via:
    • pancakeSwap/tradeExecutorOnPancakeswap.ts
    • fourmeme/tradeExecutorOnFourmeme.ts

Rust Bot — Rust-Copytrading-Bot

High-performance copy-trading bot written in Rust, built on ethers-rs and Tokio.

Requirements

  • Rust toolchain (stable) via rustup
  • BSC WS + HTTP endpoints

Install

cd Rust-Copytrading-Bot
cargo build --release

Configuration (.env)

Create Rust-Copytrading-Bot/.env:

# RPC endpoints
WS_URL=wss://bsc.your-provider.example/ws
BSC_RPC_URL=https://bsc.your-provider.example

# Contracts
PANCAKE_SWAP_ROUTER_ADDR=0x10ED43C718714eb63d5aA57B78B54704E256024E
FOUR_MEME_ADDRESS=0xYourFourMemeContractAddress

# Wallets and copy settings
COPY_KEYS=0xabc...,0xdef...
TARGET_WALLETS=0xtrader1,0xtrader2

# Copy behavior
COPY_PERCENT=1.0
COPY_PERCENTS=1.0,0.5,2.0
SLIPPAGE_BPS=300
GAS_MULTIPLIER=1.0
MIN_GAS_PRICE_GWEI=5
GAS_LIMIT_OVERRIDE=400000

Run

cargo run --release

How it works (Rust)

  • Subscribes to combined topic filter for PancakeSwap Swap and Four.meme buy/sell
  • Validates initiator against TARGET_WALLETS and excludes copy wallets
  • Infers trade params and executes via executors in pancakeswap/ and fourmeme/
  • Supports per-wallet COPY_PERCENTS with fallback to COPY_PERCENT

Operational Notes (Both)

  • Fund copy wallets with sufficient BNB for gas; Four.meme buys consume value + gas
  • Use reliable WebSocket providers; outages will disrupt event flow
  • For PancakeSwap native input, BNB→WBNB is detected and handled
  • Approvals are automatic where needed; consider periodic allowance reviews

Safety and Risk

  • This software sends real transactions from your wallets
  • Start with small sizes; double-check all env vars and addresses
  • Keep private keys secure; prefer dedicated wallets with limited funds

Troubleshooting

  • Missing env errors: ensure .env exists with required keys
  • No trades mirrored: verify TARGET_WALLETS and that targets are active
  • Allowance/balance issues: ensure tokens/BNB and wait for approvals to confirm
  • Router decode failures: pair fallback logic attempts to infer path/amount

Licenses

  • TypeScript bot: MIT
  • Rust bot: MIT

Acknowledgements

  • TypeScript: ethers v6
  • Rust: ethers-rs + Tokio

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published