Skip to content

dante4rt/iclash

Repository files navigation

iClash — AI Trade Arena

Two AI agents debate whether an Injective market is a good trade right now. Watch the fight, read the verdict.

Built for the Injective Solo AI Builder Sprint (May 7–31 2026)

Next.js TypeScript Injective AI


What it does

iClash turns trade analysis into a watchable fight:

  1. Connect wallet (Keplr/Leap) — read-only, no signing
  2. Pick a market — any Injective perp or spot market
  3. Watch the debate — two AI agents argue long/short/skip using live on-chain data
  4. See the damage — a neutral Judge scores each argument, HP drains
  5. Get the verdict — Strong Long / Moderate Long / Neutral Wait / Caution Short + confidence %

The debate is the explanation. You watch evidence accumulate as HP swings, instead of reading a verdict you have to take on faith.


How AI is used

iClash uses three separate LLMs via OpenRouter:

Role Model What it does
The Chartist Kimi K2.6 Technical analyst — price action, funding, OI, orderbook
The Floor Gemini 2.0 Flash Sentiment analyst — crowd positioning, flow, squeeze detection
Judge MiniMax M2.5 Neutral referee — scores arguments on 4 axes (0–25 each)

Why three models?

Different models reason differently. Using the same model for both agents produces repetitive arguments. With different models, the Chartist and The Floor disagree in ways that are worth watching — and the verdict carries more weight.

The Data-Gate

Every argument must cite specific on-chain metrics. The Judge validates which metrics are real. If an agent cites no valid data, their attack takes a 60% damage penalty. This mechanically forces the AI to ground its reasoning in actual Injective data — not hallucination.

Damage Math

The score → damage → HP → verdict pipeline is 100% deterministic code (no LLM). Every number is reproducible. "Why did Bull win?" has a math answer.


How Injective is integrated

On-chain data (read-only)

Every round, iClash fetches live data from Injective mainnet:

Metric Source
Price / 24h change IQ API
Funding rate @injectivelabs/sdk-ts (derivatives API)
Open interest SDK (derivatives API)
Orderbook depth + imbalance SDK (orderbook v2)
24h volume IQ API

Wallet (read-only)

  • Keplr + Leap via @injectivelabs/wallet-ts
  • Used for: connecting, reading balances/portfolio
  • Never signs transactions — no trades, no transfers

Trade execution

iClash does NOT execute trades in-app. The verdict shows a "Trade on Helix ↗" link (Injective's DEX) with a DYOR disclaimer. Safe demo, clear loop for traders.


How to run

Prerequisites

Setup

git clone https://github.com/dante4rt/iclash.git
cd iclash
pnpm install
cp .env.example .env.local

Edit .env.local:

OPENROUTER_API_KEY=sk-or-v1-your-key-here
AGENT_MODEL_ID=moonshotai/kimi-k2.6:free
FLOOR_MODEL_ID=google/gemini-2.0-flash-001
JUDGE_MODEL_ID=minimax/minimax-m2.5:free

Run

pnpm dev

Open http://localhost:3000.

Build

pnpm build
pnpm start

Environment variables

Variable Required Default Description
OPENROUTER_API_KEY Yes Your OpenRouter API key
INJECTIVE_NETWORK No mainnet mainnet or testnet
AGENT_MODEL_ID No moonshotai/kimi-k2.6:free Model for The Chartist (technical agent)
FLOOR_MODEL_ID No google/gemini-2.0-flash-001 Model for The Floor (sentiment agent)
JUDGE_MODEL_ID No minimax/minimax-m2.5:free Model for the Judge (scorer)

Project structure

iclash/
├── app/                        # Next.js App Router
│   ├── page.tsx                # Landing page (public)
│   ├── arena/page.tsx          # Debate arena (wallet-gated)
│   ├── demo/page.tsx           # Pre-recorded demo (public)
│   ├── how-it-works/page.tsx   # Explainer (public)
│   ├── portfolio/page.tsx      # Wallet balances (gated)
│   ├── history/page.tsx        # Past clashes (gated)
│   └── api/
│       ├── markets/route.ts    # GET Injective market roster
│       ├── snapshot/route.ts   # GET live market data
│       └── clash/route.ts      # POST → SSE debate stream
├── lib/
│   ├── injective/              # Data layer — chain access
│   │   ├── client.ts           # SDK clients (mainnet)
│   │   ├── markets.ts          # Market roster (IQ API + SDK)
│   │   ├── snapshot.ts         # Live data → DataContext
│   │   └── helix.ts            # External Helix DEX URLs
│   ├── agents/                 # Brain layer — LLM integration
│   │   ├── technical.ts        # The Chartist persona
│   │   ├── sentiment.ts        # The Floor persona
│   │   ├── judge.ts            # Scoring rubric
│   │   ├── orchestrator.ts     # Round loop + SSE events
│   │   └── openrouter.ts       # OpenRouter client wrapper
│   └── clash/                  # Pure math (no I/O)
│       ├── types.ts            # Shared type contract
│       ├── damage.ts           # Score → damage → HP → verdict
│       └── damage.test.ts      # 27 unit tests
├── components/                 # UI components
├── fixtures/                   # Demo clash data
├── wallet/                     # Keplr + Leap integration
└── DESIGN.md                   # Visual spec (Stitch ground truth)

Architecture

Three logical layers that never bleed into each other:

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  Data Layer  │────▶│  Brain Layer │────▶│  View Layer  │
│  (Injective) │     │   (LLMs)    │     │   (React)    │
└─────────────┘     └─────────────┘     └─────────────┘
     │                    │                    │
     ▼                    ▼                    ▼
  DataContext         Argument/Score       SSE Events
  (plain objects)     (plain objects)      (JSON stream)
  • Data layer imports @injectivelabs/sdk-ts, exposes typed objects. No LLM, no React.
  • Brain layer imports OpenRouter + data layer. Produces Argument and Score. Never touches React.
  • lib/clash/damage.ts is pure — no I/O, no network, no LLM. Fully unit-testable.
  • View layer renders SSE events. Knows nothing about Injective or OpenRouter.

Routes

Route Page Access
/ Landing page (hero, features, agents, mechanics) Public
/arena Market picker + live debate + HP bars + verdict Wallet required
/portfolio Wallet balances Wallet required
/history Past clashes Wallet required
/how-it-works System Protocol explainer Public
/demo Pre-recorded 3-round clash replay Public

Key design decisions

Decision Rationale
Three separate LLMs Different models = different reasoning styles = more interesting debates
Data-gate (60% penalty) Forces AI to cite real on-chain data, not hallucinate
Pure damage math Reproducible verdicts — every number has a code answer
No in-app trading Safe demo — verdict links to Helix with DYOR disclaimer
SSE streaming One-way server→client, no WebSocket complexity
Wallet read-only No signing, no funds at risk

Testing

# Unit tests (damage math)
pnpm vitest run lib/clash/damage.test.ts

# Full pipeline test (requires API key)
npx tsx scripts/test-wave2.ts

License

MIT


Links

About

Two AI agents debate Injective trades using live on-chain data. A judge scores every argument — HP drains on weak points. Watch the fight, trade with edge.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors