Skip to content

Automated trading bot for Polymarket with real-time mempool monitoring, same-block execution, and priority gas bidding. Mirrors top traders and supports arbitrage across markets.

Notifications You must be signed in to change notification settings

Novus-Tech-LLC/Polymarket-Sniper-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Polymarket Sniper Bot

TypeScript Node.js License

Automated trading bot for Polymarket with mempool monitoring and priority execution

Features β€’ Quick Start β€’ Architecture β€’ Documentation β€’ Contributing


Contact

Platform Link
πŸ“± Telegram t.me/novustch
πŸ“² WhatsApp wa.me/14105015750
πŸ’¬ Discord discordapp.com/users/985432160498491473
Telegram WhatsApp Discord

Feel free to reach out for implementation assistance or integration support.

πŸ“‹ Table of Contents

🎯 Overview

Polymarket Sniper Bot is a sophisticated automated trading system designed for the Polymarket prediction market platform. It monitors the Polygon mempool and Polymarket API for pending trades from target addresses, then executes orders with higher priority gas pricing to frontrun target transactions.

Key Capabilities

  • Real-time Mempool Monitoring: Subscribes to pending transactions on Polygon network
  • Hybrid Detection: Combines mempool monitoring with API polling for comprehensive trade detection
  • Priority Execution: Configurable gas price multipliers for competitive frontrunning
  • Intelligent Sizing: Proportional frontrun sizing based on target trade size
  • Error Handling: Robust retry mechanisms and error recovery
  • Balance Management: Automatic balance validation before trade execution

✨ Features

  • πŸ” Mempool Monitoring: Real-time detection of pending transactions to Polymarket contracts
  • πŸ“Š API Integration: Hybrid approach combining mempool and API monitoring for faster detection
  • ⚑ Priority Execution: Configurable gas price multipliers for frontrunning
  • πŸ’° Smart Sizing: Proportional frontrun sizing (configurable multiplier)
  • πŸ›‘οΈ Error Handling: Comprehensive error handling with retry logic
  • πŸ“ˆ Trade Filtering: Minimum trade size thresholds to focus on profitable opportunities
  • πŸ”„ Balance Validation: Automatic checks for sufficient USDC and POL balances
  • πŸ“ Structured Logging: Color-coded console logging with debug support
  • 🐳 Docker Support: Containerized deployment with Docker and Docker Compose
  • πŸ”§ CLI Tools: Utility commands for allowance management and manual operations

πŸ—οΈ Architecture

Project Structure

polymarket-sniper-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/              # Application entry point
β”‚   β”œβ”€β”€ cli/              # CLI commands and utilities
β”‚   β”œβ”€β”€ config/           # Configuration management
β”‚   β”œβ”€β”€ constants/        # Application constants
β”‚   β”œβ”€β”€ domain/           # Domain models and types
β”‚   β”œβ”€β”€ errors/           # Custom error classes
β”‚   β”œβ”€β”€ infrastructure/  # External service integrations
β”‚   β”œβ”€β”€ services/         # Core business logic
β”‚   └── utils/            # Utility functions
β”œβ”€β”€ docs/                 # Documentation
β”œβ”€β”€ docker-compose.yml    # Docker Compose configuration
β”œβ”€β”€ Dockerfile           # Docker image definition
└── package.json         # Project dependencies

System Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Mempool Monitorβ”‚
β”‚   Service       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                 β”‚
         β–Ό                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Pending TX     β”‚  β”‚  API Polling β”‚
β”‚  Detection      β”‚  β”‚  (Activity)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                    β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  Trade Signal    β”‚
         β”‚  Generation      β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  Trade Executor  β”‚
         β”‚  Service         β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚              β”‚
                  β–Ό              β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  Balance     β”‚  β”‚  Order       β”‚
         β”‚  Validation  β”‚  β”‚  Execution   β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  • MempoolMonitorService: Monitors Polygon mempool for pending transactions
  • TradeExecutorService: Executes frontrun trades with priority gas pricing
  • ClobClientFactory: Creates and configures Polymarket CLOB client instances
  • Configuration: Centralized environment variable management
  • Error Handling: Custom error classes for better error management

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Polygon wallet with USDC balance
  • POL/MATIC for gas fees
  • RPC endpoint supporting pending transaction monitoring

Installation

# Clone the repository
git clone https://github.com/your-org/polymarket-sniper-bot.git
cd polymarket-sniper-bot

# Install dependencies
npm install

# Build the project
npm run build

Configuration

Create a .env file in the project root:

# Required
TARGET_ADDRESSES=0xabc...,0xdef...    # Target addresses to frontrun (comma-separated)
PUBLIC_KEY=your_bot_wallet             # Public address of your bot wallet
PRIVATE_KEY=your_bot_wallet_privatekey # Private key of above address
RPC_URL=https://polygon-mainnet...     # Polygon RPC endpoint

# Optional
FETCH_INTERVAL=1                       # Polling interval (seconds)
MIN_TRADE_SIZE_USD=100                 # Minimum trade size to frontrun (USD)
FRONTRUN_SIZE_MULTIPLIER=0.5           # Frontrun size as % of target (0.0-1.0)
GAS_PRICE_MULTIPLIER=1.2               # Gas price multiplier for priority
USDC_CONTRACT_ADDRESS=0x2791...        # USDC contract (default: Polygon mainnet)

Running the Bot

# Development mode
npm run dev

# Production mode
npm run build && npm start

Docker Deployment

# Using Docker Compose
docker-compose up -d

# Or using Docker directly
docker build -t polymarket-sniper-bot .
docker run --env-file .env polymarket-sniper-bot

βš™οΈ Configuration

Required Environment Variables

Variable Description Example
TARGET_ADDRESSES Comma-separated target addresses to frontrun 0xabc...,0xdef...
PUBLIC_KEY Your Polygon wallet address your_wallet_address
PRIVATE_KEY Your wallet private key your_private_key
RPC_URL Polygon RPC endpoint (must support pending tx monitoring) https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID

Optional Configuration

Variable Default Description
FETCH_INTERVAL 1 Polling frequency in seconds
MIN_TRADE_SIZE_USD 100 Minimum trade size to frontrun (USD)
FRONTRUN_SIZE_MULTIPLIER 0.5 Frontrun size as % of target (0.0-1.0)
GAS_PRICE_MULTIPLIER 1.2 Gas price multiplier for priority (e.g., 1.2 = 20% higher)
RETRY_LIMIT 3 Maximum retry attempts for failed orders
USDC_CONTRACT_ADDRESS 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 USDC contract on Polygon

Finding Target Wallets

To identify successful traders to track:

πŸ“‹ Requirements

  • Node.js: 18 or higher
  • Polygon Wallet: With USDC balance for trading
  • POL/MATIC: For gas fees (recommended: 0.2-1.0 POL)
  • RPC Endpoint: Must support pending transaction monitoring (Infura, Alchemy, QuickNode)

πŸ“œ Scripts

Command Description
npm run dev Development mode with TypeScript
npm run build Compile TypeScript to JavaScript
npm start Run compiled production build
npm run lint Run ESLint
npm run lint:fix Fix ESLint errors automatically
npm run format Format code with Prettier
npm run check-allowance Check token allowance
npm run verify-allowance Verify token allowance
npm run set-token-allowance Set token allowance
npm run manual-sell Manual sell command
npm run simulate Run trading simulations

πŸ“š Documentation

🀝 Contributing

Contributions are welcome! Please see our Contributing Guidelines for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow TypeScript best practices
  • Use ESLint and Prettier for code formatting
  • Write meaningful commit messages
  • Add tests for new features

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

⚠️ Disclaimer

This software is provided as-is for educational and research purposes only.

  • Trading involves substantial risk of loss
  • Past performance does not guarantee future results
  • Use at your own risk
  • The authors and contributors are not responsible for any financial losses
  • Always test thoroughly in a safe environment before using real funds
  • Ensure compliance with local regulations and terms of service

Built with ❀️ for the Polymarket community

⭐ Star this repo if you find it helpful!

About

Automated trading bot for Polymarket with real-time mempool monitoring, same-block execution, and priority gas bidding. Mirrors top traders and supports arbitrage across markets.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published