A high-performance Solana sniper bot for the Bagsapp (bags.fm) DEX that automatically buys tokens when new liquidity pools are created and manages positions with stop loss and take profit.
- 🚀 Instant Pool Detection: Monitors new liquidity pool creation on bags.fm using Yellowstone gRPC streaming
- 💰 Automated Trading: Automatically buys tokens when new pools are detected
- 📊 Risk Management: Built-in stop loss and take profit mechanisms
- ⚡ Fast Execution: Uses Jito for transaction confirmation and Helius RPC for blockhash retrieval
- 🔒 Secure: Private key management and transaction signing
- Yellowstone gRPC: Real-time transaction streaming for pool detection
- Helius RPC: Fast blockhash retrieval
- Jito: Transaction confirmation and priority execution
- TypeScript: Type-safe implementation
- Node.js 18+ and npm/yarn
- Solana wallet with SOL for trading
- Helius API key (for RPC access)
- Yellowstone gRPC endpoint (or self-hosted)
- Jito RPC access (optional, defaults to public endpoint)
- Clone the repository:
git clone <repository-url>
cd Bagsapp-Sniper-Bot- Install dependencies:
npm install- Copy
.env.exampleto.envand configure:
cp .env.example .env- Edit
.envwith your configuration:
HELIUS_RPC_URL: Your Helius RPC endpointPRIVATE_KEY: Your wallet's base58-encoded private keyBAGSAPP_PROGRAM_ID: The actual Bagsapp program ID (update when available)- Adjust trading parameters as needed
HELIUS_RPC_URL: Helius RPC endpoint URLPRIVATE_KEY: Base58-encoded wallet private key
JITO_RPC_URL: Jito RPC endpoint (defaults to mainnet)YELLOWSTONE_GRPC_URL: Yellowstone gRPC endpoint (defaults to localhost)BAGSAPP_PROGRAM_ID: Bagsapp program IDSLIPPAGE_BPS: Slippage in basis points (default: 500 = 5%)MAX_BUY_AMOUNT_SOL: Maximum buy amount in SOL (default: 1.0)MIN_BUY_AMOUNT_SOL: Minimum buy amount in SOL (default: 0.1)STOP_LOSS_PERCENT: Stop loss percentage (default: 10%)TAKE_PROFIT_PERCENT: Take profit percentage (default: 50%)CHECK_INTERVAL_MS: Position check interval in milliseconds (default: 1000)LOG_LEVEL: Logging level (default: info)
npm run dev- Build the project:
npm run build- Run the bot:
npm start- Pool Detection: The bot connects to Yellowstone gRPC and monitors transactions involving the Bagsapp program
- Buy Execution: When a new pool is detected, the bot immediately creates and executes a buy transaction
- Position Monitoring: The bot continuously monitors open positions for stop loss and take profit conditions
- Sell Execution: When conditions are met, the bot automatically sells the position
-
Bagsapp Program IDL:
- Update
BAGSAPP_PROGRAM_IDin.envwith the real program ID - Implement instruction parsing in
src/services/bagsapp.tsbased on the program's IDL - Complete
parsePoolCreationInstruction()method to detect new pools - Implement
createBuyTransaction()andcreateSellTransaction()with actual program instructions
- Update
-
Yellowstone gRPC:
- The Yellowstone client in
src/clients/yellowstone.tsis a skeleton implementation - You'll need to integrate with the actual Yellowstone gRPC client library
- Update the connection and subscription methods based on your Yellowstone setup
- Alternative: Use WebSocket subscriptions or other real-time data sources
- The Yellowstone client in
-
Jito Integration:
- The Jito client uses the block engine API
- You may need to adjust the API endpoint based on your Jito setup
- Consider adding tip payments for priority transaction inclusion
-
Pool Detection:
- Update pool detection logic in
BagsappService.detectNewPool()based on actual transaction structure - Implement proper account data parsing for pool information
- Add validation for pool liquidity and other safety checks
- Update pool detection logic in
- Never commit your
.envfile - it contains sensitive private keys - Use a dedicated trading wallet with limited funds
- Test thoroughly on devnet before using on mainnet
- Monitor your positions regularly
- Verify your Helius RPC URL is correct and accessible
- Check Yellowstone gRPC endpoint connectivity
- Ensure your network allows gRPC connections
- Verify you have sufficient SOL for fees and trading
- Check slippage settings
- Ensure the pool has sufficient liquidity
- Verify the Bagsapp program ID is correct
- Check Yellowstone stream is receiving transactions
- Review logs for parsing errors
src/
├── clients/ # External service clients
│ ├── helius.ts # Helius RPC client
│ ├── jito.ts # Jito transaction client
│ └── yellowstone.ts # Yellowstone gRPC client
├── services/ # Business logic
│ ├── bagsapp.ts # Bagsapp DEX integration
│ └── trading.ts # Trading logic
├── config/ # Configuration
│ └── index.ts # Config loader
├── utils/ # Utilities
│ └── logger.ts # Logging
└── index.ts # Main entry point
MIT
This software is provided as-is for educational purposes. Trading cryptocurrencies involves substantial risk. Use at your own risk. The authors are not responsible for any financial losses.