Skip to content
Enmilo-devPublic

About

A stateless, two-hop atomic arbitrage program on Solana. Executes atomic swaps between Raydium CLMM and Orca Whirlpools with strict on-chain profitability checks and LiteSVM mock testing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Arbiger: Stateless Atomic Arbitrage

Solana Anchor TypeScript Rust

A highly-optimized, completely stateless on-chain MEV (Maximal Extractable Value) program built on Solana using the Anchor framework. This program executes two-hop atomic arbitrage strategies between the two largest DEXes on Solana: Raydium (CLMM) and Orca (Whirlpools).

📋 Table of Contents

✨ Features

  • Stateless Execution: The program holds absolute zero funds in Program Derived Addresses (PDAs), drastically reducing smart contract risk.
  • Atomic Reversions: Transactions mathematically guarantee no loss of principal by reverting entirely if a strict, configurable minimum profit threshold is not met.
  • Dynamic CPI Construction: Efficiently handles complex state routing for Concentrated Liquidity Market Makers (CLMMs) across multiple protocols.
  • Live Tick-Array Derivation: Derives Tick Array PDAs dynamically via live RPC state to bypass common SDK caching bugs and stale-state errors.

🏗 Architecture

Because Arbiger is stateless, it relies on strict account validation rather than persistent state accounts.

Account Structures

  1. Operator Accounts

    • Temporarily borrows funds directly from the operator's Associated Token Accounts (ATAs).
    • Tracks starting_token_account and intermediate_token_account to route the swap logic.
  2. Raydium CPI Accounts

    • Expects validated Raydium CLMM state accounts (amm_config, pool_state, vaults, observation_state).
    • Dynamically accepts variable-length Tick Array accounts via Anchor's remaining_accounts pattern.
  3. Orca CPI Accounts

    • Expects validated Whirlpool state accounts (whirlpool, token_vaults, oracle).
    • Requires deterministic Tick Array accounts based on the swap direction and tick spacing.

🛠 Prerequisites

Ensure you have the following installed before getting started:

🚀 Getting Started

  1. Clone the repository

    git clone https://github.com/Enmilo-dev/arbiger
    cd arbiger
  2. Install dependencies

    pnpm install
  3. Build the Anchor program

    anchor build
  4. Sync program ID Update the program ID in Anchor.toml and programs/arbiger/src/lib.rs with the newly generated key from target/deploy/arbiger-keypair.json.

    anchor keys sync

🧪 Testing

Standard local validators are insufficient for testing MEV bots because they lack live liquidity state. This project utilizes Local Mainnet Forking to test against live AMM state.

To test the program, start a local mainnet fork (e.g., using surfpool) that has cloned the Raydium and Orca SOL/USDC pools.

Deploy the program to the fork:

solana program deploy target/deploy/arbiger.so -u http://127.0.0.1:8899

Run the end-to-end integration tests:

bunx ts-node test/test.ts

📖 Program Instructions

execute_arb

Executes a two-hop atomic arbitrage trade.

  • Parameters:
    • raydium_swap_data: Struct containing amount, threshold, and price limits for Raydium.
    • orca_swap_data: Struct containing amount, threshold, and price limits for Orca.
    • min_profit_bps (u64): The minimum acceptable profit in basis points (e.g., 100 = 1%).
  • Behavior: Takes a snapshot of the starting ATA balance, executes the Raydium swap (USDC -> WSOL), immediately executes the Orca swap (WSOL -> USDC), and compares the final balance against the starting balance plus the required profit threshold.

🛑 Error Codes

Code Name Description
6000 InsufficientProfit The final balance after both swaps did not meet the min_profit_bps threshold.

🛡 Security Considerations

  • Principal Protection: The min_profit_bps guard ensures that even if slippage is high or price oracles are manipulated, the transaction will revert rather than execute at a loss.
  • Stateless Custody: The operator retains full custody of all funds at all times. The program is completely incapable of holding or trapping user funds.
  • Strict CPI Validation: All external accounts passed to the Raydium and Orca programs are validated by their respective target programs.

📄 License

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

About

A stateless, two-hop atomic arbitrage program on Solana. Executes atomic swaps between Raydium CLMM and Orca Whirlpools with strict on-chain profitability checks and LiteSVM mock testing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages