Skip to content

anshuman008/solana-arb-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Solana Arbitrage Scanner

A TypeScript-based tool for discovering arbitrage opportunities across various Solana decentralized exchanges (DEXs).

πŸš€ Overview

This tool monitors and compares token prices across multiple Solana AMMs (Automated Market Makers) in real-time to identify potential arbitrage opportunities. It currently supports the following DEXs:

  • PumpSwap - Decentralized exchange built on Solana
  • Raydium - Leading AMM and liquidity provider on Solana
  • Orca Whirlpools - Concentrated liquidity pools
  • Meteora DMM - Dynamic market maker protocol

βš™οΈ Features

  • Real-time Price Monitoring: Continuously fetches and compares token prices across multiple DEXs
  • Arbitrage Detection: Automatically identifies profitable arbitrage opportunities with customizable profit thresholds
  • Live Console Dashboard: Real-time display of prices, spreads, and opportunities
  • Direct Trading Links: Provides direct URLs to execute trades on respective platforms
  • Error Handling: Robust error handling for failed API calls or network issues
  • Configurable Refresh Rate: Adjustable monitoring intervals (default: 1 second)

πŸ”§ Installation

# Clone the repository
git clone https://github.com/yourusername/solana-arbitrage-scanner.git
cd solana-arbitrage-scanner

# Install dependencies
npm install

# Build the TypeScript project
npm run build

πŸ“‹ Prerequisites

  • Node.js (v14 or higher)
  • npm (v6 or higher)
  • TypeScript (installed as dev dependency)
  • Stable internet connection for DEX API calls

πŸ› οΈ Configuration

The application is configured to monitor SOL/USDC pairs by default. You can modify the token pairs in src/index.ts:

const QUOTE_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
const BASE_MINT = "So11111111111111111111111111111111111111112"; // SOL
const FETCH_INTERVAL = 1000; // 1 second refresh rate
const MIN_PROFIT_THRESHOLD = 0.1; // Minimum 0.1% profit threshold

πŸƒβ€β™‚οΈ Usage

Basic Usage

# Run the arbitrage scanner
npm start

# Or run in development mode (builds and runs)
npm run dev

Available Scripts

npm run build    # Compile TypeScript to JavaScript
npm run start    # Run the compiled application
npm run dev      # Build and run in one command
npm run clean    # Remove compiled files

🧩 How It Works

  1. Data Fetching: Simultaneously fetches pool data from all supported DEXs using their respective APIs
  2. Price Normalization: Extracts and normalizes price data for accurate comparison
  3. Arbitrage Calculation: Compares prices across platforms and calculates profit percentages
  4. Opportunity Ranking: Sorts opportunities by profit potential
  5. Real-time Display: Shows live prices, spreads, and profitable opportunities in the console

πŸ“Š Example Output

DEX ARBITRAGE MONITOR - SOL/USDT
Iteration: 1 | Refresh Rate: 1000ms

───────────────────────────────────────────────────────
LIVE PRICES - 2:45:30 PM
──────────────────────────────────────────────────────

PumpSwap        1 SOL = 103.1234 USDT
Pool: 8zx...abc
Trade β†’ https://swap.pump.fun/?input=So111...&output=EPj...

Raydium         1 SOL = 102.9876 USDT
Pool: 7yz...def
Trade β†’ https://raydium.io/swap/?inputMint=sol&outputMint=EPj...

Whirlpool       1 SOL = 103.4567 USDT
Pool: 9ab...ghi
Trade β†’ https://www.orca.so/pools/9ab...ghi

Meteora DMM     1 SOL = 103.2345 USDT
Pool: 5cd...jkl
Trade β†’ https://www.meteora.ag/pools/5cd...jkl

───────────────────────────────────────────────────────
Highest: Whirlpool (103.4567 USDT)
Lowest:  Raydium (102.9876 USDT)
Spread:  0.455%

═══════════════════════════════════════════════════════
ARBITRAGE OPPORTUNITIES
═══════════════════════════════════════════════════════

- Opportunity #1
   Buy from:  Raydium @ 102.9876 USDT
   Sell to:   Whirlpool @ 103.4567 USDT
   Profit:  0.4691 USDT per SOL (0.455%)

 Buy:  https://raydium.io/swap/?inputMint=sol&outputMint=EPj...
   Sell: https://www.orca.so/pools/9ab...ghi

πŸ“‚ Project Structure

solana-arbitrage-scanner/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/                 # Configuration files
β”‚   β”‚   β”œβ”€β”€ constant.ts         # Constants and configuration values
β”‚   β”‚   └── index.ts           # Solana connection setup
β”‚   β”œβ”€β”€ services/              # DEX integration services
β”‚   β”‚   β”œβ”€β”€ ammSimpleCalculation.ts    # AMM price calculations
β”‚   β”‚   β”œβ”€β”€ dexlabPoolsData.ts         # DexLab API integration
β”‚   β”‚   β”œβ”€β”€ meteoraDmmPoolData.ts      # Meteora DMM pool fetching
β”‚   β”‚   β”œβ”€β”€ pumfunBondingCurveData.ts  # Pump.fun bonding curve data
β”‚   β”‚   β”œβ”€β”€ pumpSwapPoolData.ts        # PumpSwap pool fetching
β”‚   β”‚   β”œβ”€β”€ raydiumPoolData.ts         # Raydium pool fetching
β”‚   β”‚   β”œβ”€β”€ whirlPoolData.ts           # Orca Whirlpool fetching
β”‚   β”‚   └── index.ts                   # Service exports
β”‚   β”œβ”€β”€ types/                 # TypeScript type definitions
β”‚   β”‚   β”œβ”€β”€ index.ts          # Common types and exports
β”‚   β”‚   β”œβ”€β”€ meteora.ts        # Meteora-specific types
β”‚   β”‚   β”œβ”€β”€ pumpfun.ts        # Pump.fun types
β”‚   β”‚   β”œβ”€β”€ pumpswap.ts       # PumpSwap types
β”‚   β”‚   β”œβ”€β”€ raydium.ts        # Raydium types
β”‚   β”‚   └── whirlpool.ts      # Whirlpool types
β”‚   └── index.ts              # Main application entry point
β”œβ”€β”€ IDLs/                     # Anchor IDL files
β”‚   └── pumpswap/            # PumpSwap IDL definitions
β”‚       β”œβ”€β”€ pumpswap.json    # PumpSwap program IDL
β”‚       └── pumpswapTypes.ts # Generated TypeScript types
β”œβ”€β”€ dist/                    # Compiled JavaScript output (generated)
β”œβ”€β”€ node_modules/           # Dependencies (generated)
β”œβ”€β”€ package.json            # Project metadata and dependencies
β”œβ”€β”€ package-lock.json       # Dependency lock file
β”œβ”€β”€ tsconfig.json          # TypeScript configuration
β”œβ”€β”€ .gitignore            # Git ignore rules
└── README.md             # This file

πŸ“š Dependencies

Core Dependencies

  • @coral-xyz/anchor (^0.31.1) - Solana Anchor framework for program interaction
  • @pump-fun/pump-swap-sdk (^1.7.9) - Official PumpSwap SDK
  • @solana/kit (^2.3.0) - Solana development toolkit
  • @solana/spl-token (^0.4.14) - Solana Program Library token utilities
  • @solana/web3.js (^1.98.4) - Official Solana web3 library
  • axios (^1.12.2) - HTTP client for API requests
  • bn.js (^5.2.2) - BigNumber library for precise calculations

Development Dependencies

  • @types/bn.js (^5.2.0) - TypeScript types for bn.js
  • typescript (^5.0.0) - TypeScript compiler

πŸ”§ Extending the Scanner

Adding a New DEX

  1. Create a new service file in src/services/:
// src/services/newDexPoolData.ts
export async function fetch_newdex_pools(baseMint: string, quoteMint: string) {
    // Implementation for fetching pool data
}
  1. Add corresponding types in src/types/:
// src/types/newdex.ts
export interface NewDexPoolData {
    // Define the pool data structure
}
  1. Update the main monitoring logic in src/index.ts:
// Add to fetchAllPrices() function
try {
    const newdex_res = await fetch_newdex_pools(BASE_MINT, QUOTE_MINT);
    // Process and add to prices array
} catch (err) {
    console.error("NewDex fetch failed:", err);
}

Customizing Token Pairs

Modify the mint addresses in src/index.ts:

// Example: Monitor BONK/USDC instead of SOL/USDC
const QUOTE_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
const BASE_MINT = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"; // BONK

🚨 Important Notes

  • Network Dependency: This tool requires stable internet connectivity for API calls
  • Rate Limits: Be aware of potential rate limiting by DEX APIs
  • Gas Fees: Consider transaction costs when evaluating arbitrage opportunities
  • Slippage: Large trades may experience slippage that reduces profitability
  • Speed: Arbitrage opportunities may disappear quickly due to market efficiency

πŸ”’ License

MIT License - see LICENSE file for details

🀝 Contributing

Contributions, issues, and feature requests are welcome! Please feel free to:

  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

⚠️ Disclaimer

This tool is provided for educational and informational purposes only. Cryptocurrency trading carries significant financial risk, and automated arbitrage trading can result in substantial losses. The developers are not responsible for any financial losses incurred through the use of this software. Always perform your own due diligence and consider consulting with a financial advisor before engaging in cryptocurrency trading.

Key Risks:

  • Market volatility can eliminate arbitrage opportunities instantly
  • Network congestion may delay transactions
  • Smart contract risks and potential bugs
  • Regulatory changes affecting DEX operations
  • Impermanent loss and slippage considerations

Use this software at your own risk and never invest more than you can afford to lose.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors