# CLI + On-Chain Arbitrage Program

The **CLI + On-Chain Arbitrage Program** is the operational core of the **Atomic Arbitrage Ecosystem**.\
It connects analytical insights from the off-chain tools (Monitor and Strategy Platform) to the actual execution logic that performs real arbitrage operations directly on the **Solana blockchain**.

Together, the CLI and the on-chain program form a **lightweight, low-latency execution engine** capable of scanning, validating, and executing arbitrage opportunities entirely on-chain, without reliance on external APIs or RPCs.

***

### **Overview**

This component acts as the **bridge between decision and execution**.\
It consumes optimized strategy configurations from the Strategy Platform, applies them in real time, and interacts directly with Solana smart contracts to execute trades.

By running the CLI locally (or in a hosted environment) and connecting to the Atomic Program deployed on-chain, users can perform arbitrage with **minimal infrastructure overhead** and **maximum transparency**.

The result is a **self-sustained execution layer** that operates without any external dependencies or centralized intermediaries.

***

### **Design Principles**

The CLI + On-Chain Arbitrage Program was built around three key design goals:

1. **Native Performance** – Every transaction and calculation is handled directly through Solana’s runtime, removing external RPC latency and third-party overhead.
2. **Cost Efficiency** – Each arbitrage “scan” typically consumes only **5,000–12,000 lamports**, depending on route depth and transaction density.
3. **Interoperability** – Seamlessly integrates with all other ecosystem modules, ensuring smooth data exchange between analysis, monitoring, and execution.

This architecture ensures high-frequency operation even during periods of heavy network congestion.

***

### **Execution Flow**

Below is the high-level lifecycle of a single arbitrage operation:

1. **Strategy Initialization**\
   The user loads a configuration generated by the Strategy Platform.\
   It contains all relevant parameters — spread threshold, fee limits, and preferred DEX pools.
2. **Scanning Phase**\
   The CLI scans live Solana data streams for price deviations that meet the configured criteria.\
   These scans are performed continuously with extremely low compute overhead.
3. **Commitment Phase**\
   When a potential arbitrage is detected, the On Chain program validates the route.
4. **Execution Phase**\
   The on-chain program executes the full trade atomically.\
   It handles swaps, transfers, and profit calculation entirely within the Solana runtime.
5. **Reporting Phase**\
   After execution, the program emits structured logs that are parsed by the CLI and forwarded to the Real-Time Monitor.\
   The Strategy Platform uses this data to improve subsequent simulations.

This cycle repeats continuously, maintaining constant alignment between the analytics, monitor, and execution layers.

***

### **Key Advantages**

#### **1. Full Autonomy**

The CLI and on-chain program together form a **self-operating arbitrage engine** that requires no centralized servers or infrastructure.\
All computations, validations, and executions occur on-chain or within your own local environment.

#### **2. Minimal Fees**

Through optimized instruction batching and efficient transaction construction, average cost per arbitrage attempt remains between **5,000–12,000 lamports** — significantly lower than RPC-based bots.

#### **3. Low Latency**

Because execution happens directly on Solana, there are no RPC bottlenecks.\
Typical transaction landing times average below 300ms, depending on network load.

#### **4. Reliability**

Each operation is atomic and verifiable on-chain.\
Failures, partial executions, or inconsistent states are impossible by design — every transaction either completes or reverts entirely.

#### **5. Transparency**

All executions are visible on-chain and fully traceable through the Real-Time Monitor.\
No hidden endpoints or proprietary APIs — just pure, verifiable Solana transactions.

***

### **Integration with Other Components**

* **Real-Time Monitor:**\
  Displays wallet activity, fee consumption, and transaction success in real time based on CLI output.
* **Strategy Platform:**\
  Generates and exports configuration files that determine the CLI’s scanning and execution behavior.
* **Transaction Landing Engine:**\
  Handles final transaction delivery and confirmation, bypassing external RPCs to ensure high landing consistency.

Each connection is native — no manual linking or setup required.

***

### **Security Considerations**

* The on-chain program uses Solana’s standard instruction model — all operations are signed and verified by the wallet owner.
* It’s strongly recommended to use a **dedicated wallet** for arbitrage operations.
* The system is fully transparent — you can verify every instruction and transaction directly on-chain.
