Skip to content

JaDi03/SpreadHunter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SpreadHunter

An autonomous AI arbitrage agent operating on Arc Testnet, scanning cross-DEX price spreads for EURC/USDC and executing profitable trades with on-chain reputation tracking.

Node.js React Vite ethers.js Circle W3S Circle App Kit Arc Testnet ERC-8004 License


Overview

SpreadHunter is a hybrid deterministic + AI arbitrage agent that continuously monitors price spreads across decentralized exchanges on Arc Testnet. When a profitable opportunity is detected, it generates a natural-language reasoning trace via an advanced LLM, executes the trade, and records its reputation on-chain via the ERC-8004 Agent Registry.

flowchart TD
    subgraph Arc["Arc Testnet"]
        DEX[("DEX Liquidity Pools")]
        ERC8004{"ERC-8004 Registry"}
    end

    subgraph Agent["SpreadHunter Core"]
        direction TB
        PE["๐Ÿ” Price Engine<br/>(On-chain reads)"]
        Calc["๐Ÿงฎ Calculator<br/>(Deterministic math)"]
        RE["๐Ÿง  Reasoning Engine<br/>(AI Analysis)"]
        Exec["โš™๏ธ Executor<br/>(Calldata Builder)"]
    end

    DEX -. "slot0 data" .-> PE
    PE ==> Calc
    Calc ==>|"Profitable Spread"| RE
    RE ==>|"Natural Language Trace"| Exec
    Exec -. "Execution & Feedback" .-> ERC8004

    %% Styling
    classDef blockchain fill:#1e293b,stroke:#475569,stroke-width:2px,color:#f8fafc,rx:8px
    classDef logic fill:#2563eb,stroke:#1e40af,stroke-width:2px,color:#fff,rx:6px
    classDef ai fill:#d946ef,stroke:#a21caf,stroke-width:2px,color:#fff,rx:6px
    classDef action fill:#059669,stroke:#047857,stroke-width:2px,color:#fff,rx:6px

    class DEX,ERC8004 blockchain
    class PE,Calc logic
    class RE ai
    class Exec action

    style Arc fill:#020617,stroke:#334155,stroke-width:2px,color:#cbd5e1,stroke-dasharray: 5 5
    style Agent fill:#0f172a,stroke:#3b82f6,stroke-width:2px,color:#bfdbfe
Loading

Architecture & Workflows

SpreadHunter is designed for maximum abstraction, allowing users to deploy an AI agent without dealing with private keys or complex bridging protocols. We utilize Circle Web3 Services (W3S) and Arc Agent Standards to achieve this.

1. Zero-Friction Wallet Generation (Circle W3S)

To operate autonomously, the agent requires its own keys. Instead of forcing users to manage private keys, SpreadHunter leverages Circle Developer-Controlled Wallets (WaaS).

During the initial setup, the backend generates a secure Wallet Set that automatically creates:

  • The Owner Wallet: A multi-chain wallet (Arc Testnet, Base Sepolia, ETH Sepolia, Arbitrum Sepolia) sharing the exact same address. This acts as the Agent's main portfolio.
  • The Validator Wallet: A single-chain wallet on Arc Testnet responsible solely for signing and verifying the Agent's reputation feedback.
sequenceDiagram
    participant User
    participant App as SpreadHunter UI
    participant Backend as SpreadHunter Backend
    participant W3S as Circle W3S API
    
    User->>App: Launch Application
    App->>Backend: Initialize Agent Setup
    Backend->>W3S: Authenticate (API Key & RSA Ciphertext)
    W3S-->>Backend: Authentication Success
    Backend->>W3S: createWallets(ARC, BASE, ETH, ARB)
    W3S-->>Backend: Return Multi-Chain Owner Wallet
    Backend->>W3S: createWallets(ARC)
    W3S-->>Backend: Return Arc Validator Wallet
    Backend-->>App: Agent Identity Secured
    App-->>User: Display Agent Portfolio Dashboard
Loading

2. Auto-Bridging Deposits (Circle App Kit + CCTP)

Funding an agent on a specific L2/AppChain can be a high-friction process for users. SpreadHunter abstracts this away entirely using the Circle App Kit and CCTP.

Users simply transfer USDC to the Agent's address on their preferred network (e.g., Ethereum Sepolia). Our backend detects these funds and utilizes the Circle App Kit SDK to automatically bridge the USDC directly into the Agent's active portfolio on Arc Testnet.

flowchart TD
    User["๐Ÿ‘ค User (Any Wallet)"]
    W3SOwner["๐Ÿฆ Agent's W3S Wallet<br/>(Sepolia, Base, Arb)"]
    AppKit["โš™๏ธ SpreadHunter Backend<br/>(Circle App Kit SDK)"]
    CCTP["๐ŸŒ‰ Circle CCTP Protocol"]
    ArcAgent["๐Ÿ“ˆ Agent Portfolio<br/>(Arc Testnet)"]

    User -- "1. Standard USDC Transfer" --> W3SOwner
    AppKit -- "2. Detects Balance & Triggers Bridge" --> W3SOwner
    W3SOwner -- "3. Initiates Cross-Chain Transfer" --> CCTP
    CCTP -- "4. Burns Source & Mints on Arc" --> ArcAgent
    ArcAgent -- "5. Funds Available for Trading" --> Trade["SpreadHunter Execution Engine"]

    style User fill:#1e293b,stroke:#475569,stroke-width:2px,color:#fff
    style W3SOwner fill:#059669,stroke:#047857,stroke-width:2px,color:#fff
    style AppKit fill:#2563eb,stroke:#1e40af,stroke-width:2px,color:#fff
    style CCTP fill:#6366F1,stroke:#4338ca,stroke-width:2px,color:#fff
    style ArcAgent fill:#059669,stroke:#047857,stroke-width:2px,color:#fff
    style Trade fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff
Loading

3. Execution & On-Chain Reputation (ERC-8004)

  1. Price Scanning: Reads slot0 from V3 liquidity pools deterministically (no oracle).
  2. Spread Calculation: Computes raw spread, deducts estimated fees, and flags profitable arbitrage opportunities.
  3. AI Reasoning: The Reasoning Engine calls an advanced LLM to generate a trader-like analysis of the opportunity.
  4. Execution: The Executor builds calldata and submits the transaction.
  5. Reputation Anchoring: After the trade, the AgentRegistry submits a giveFeedback call to the Arc Testnet ERC-8004 Identity Registry, anchoring the keccak256 hash of the LLM reasoning on-chain to build verifiable trust.

Directory Structure

SpreadHunter/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ config.js           # Environment & static configuration
โ”‚   โ”‚   โ”œโ”€โ”€ walletManager.js    # W3S WaaS generation & Circle CCTP Auto-Bridging
โ”‚   โ”‚   โ”œโ”€โ”€ priceEngine.js      # On-chain reads via ethers.js
โ”‚   โ”‚   โ”œโ”€โ”€ calculator.js       # Deterministic spread math
โ”‚   โ”‚   โ”œโ”€โ”€ reasoningEngine.js  # AI analysis integration
โ”‚   โ”‚   โ”œโ”€โ”€ executor.js         # DEX Swap execution
โ”‚   โ”‚   โ”œโ”€โ”€ agentRegistry.js    # ERC-8004 identity & reputation
โ”‚   โ”‚   โ””โ”€โ”€ index.js            # Express API + WebSocket Broadcaster
โ”‚   โ”œโ”€โ”€ config.json             # Persistent agent state & network configs
โ”‚   โ””โ”€โ”€ package.json            
โ”œโ”€โ”€ frontend/
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ App.jsx             # React dashboard & WebSocket client
โ”‚       โ””โ”€โ”€ components/         # UI Elements (Stats, Modal, Setup Wizard)
โ””โ”€โ”€ README.md

Adding a New DEX

SpreadHunter is fully modular. To add a new DEX, add an entry to backend/config.json:

{
  "name": "NewDex",
  "enabled": true,
  "type": "UniswapV3",
  "contracts": {
    "factory": "0x...",
    "router":  "0x..."
  },
  "routerType": "SwapRouter02"
}

No code changes are required. The DEX is automatically picked up on the next restart.


Setup & Installation

Prerequisites

  • Node.js 22+
  • npm or pnpm

Installation

# Install backend dependencies
cd backend && npm install

# Install frontend dependencies
cd ../frontend && npm install

Configuration

Copy the example environment file and add your keys:

cp backend/.env.example backend/.env
Variable Description
ARC_RPC_URL Arc Testnet RPC endpoint
LLM_API_KEY API key for the LLM provider (Anthropic)
CIRCLE_API_KEY Circle Developer API Key for WaaS
CIRCLE_ENTITY_SECRET 32-byte hex Entity Secret for W3S authentication

Running the Application

# Terminal 1 โ€” Backend
cd backend && npm run dev

# Terminal 2 โ€” Frontend
cd frontend && npm run dev

Open http://localhost:5173 in your browser. The Setup Wizard will guide you through creating your W3S Developer-Controlled Wallets and registering your Agent's ERC-8004 identity on Arc Testnet automatically.


Tech Stack

Layer Technology
Agent Wallets Circle Web3 Services (Developer-Controlled Wallets)
Auto-Bridging Circle App Kit + CCTP Protocol
Agent Identity ERC-8004 (Arc Identity + Reputation Registry)
Blockchain interactions ethers.js v6 (RPC reads/writes)
AI Reasoning Advanced LLM (Anthropic)
Backend Node.js + Express + WebSocket
Frontend React 19 + Vite 8
Network Arc Testnet (ChainID: 5042002)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors