aeX402

The AMM That Learns
Lower fees when markets are calm. Higher fees when they're not. aeX402 is the first AMM with on-chain reinforcement learning — a Q-Learning brain that watches every swap and autonomously tunes fees, amplification, and farming rewards to maximize returns for liquidity providers. Launch tokens for 0.1 SOL. Provide concentrated liquidity. Govern pool parameters with your LP tokens. All in 189KB of pure C on Solana.

How It Works

Swap

Token A input AeX Pool curve + ML fee candles updated Token B output TWAP updated
1
Pick a pool — SOL/USDC, stables, or any pair on devnet
2
Set amount + slippage — ML-adjusted fee shown upfront
3
One transaction — swap executes atomically, pool updates candles + TWAP

Provide Liquidity

A + B Pool mint LP LP Token swap fees flash fees farming auto-accrues ML auto-tunes fee + amp for max yield
1
Choose a range — full range or concentrated (higher APY, more risk)
2
Deposit tokens — receive LP tokens representing your share
3
Earn — swap fees + flash loan fees + farming rewards accumulate automatically

Launch a Token

0.1 SOL create Bond buy/sell Graduate AMM Farm miss 1h deadline → flush → protocol treasury 1h real stakes: graduate or lose everything
1
Create virtual pool — 0.1 SOL, bonding curve starts, 1-hour clock begins
2
Community trades — buys raise price, sells extract 80% to farming pool
3
Graduate or die — hit target within 1h → real AMM + farming. Miss it → 99.9% to protocol treasury, 0.1% to cranker

Economics

Swap0.30% fee
50%→ LPs
+
50%→ Protocol
ML Trainingfunded by admin fees
Failed Launchflushed after 1h
Pool Erasedall SOL liquidity
Protocol Treasury99.9% of flush
swap fees: 50% LP / 50% protocol · failed virtual pools: 99.9% → protocol treasury + 0.1% → cranker

Swap Fees

0.30% of every swap 50% → LPs 50% → Protocol
Default fee30 bps (0.30%)
LP share50% of every swap
Admin share50% (funds ML)
ML fee range1–100 bps
ML auto-adjusts within bounds. Calm market = lower fee = more volume = more total revenue for LPs.

Token Launches

each sell splits tokens: 80% extracted → farming pool 20% 1% trade fee: 0.5% to pool balance, 0.5% to global treasury returns to supply
Launch cost0.1 SOL
Bonding curve fee1% (100 bps)
Sell → farming80% extracted
Graduation target10–200 SOL
Graduation reward0.1% to triggerer
Deadline1 hour (hard)
Failurepool flushed → protocol treasury (99.9%)
Miss the 1h deadline and the pool is flushed. 99.9% goes to protocol treasury with 0.1% cranker reward. Real consequences create real urgency.

Yield Sources

LP yield swap fees flash farming lot protocol treasury yield 99.9% of failed pool flushes
Swap fees50% of 30 bps
Flash loan fees0.09%–1.0%
Farming rewardstime-locked
LotteryLP ticket system
Treasury99.9% of failed pool flushes
LP yield from fees, flash loans, farming. Protocol treasury receives 99.9% of all virtual pools that fail to graduate (0.1% to cranker) — the protocol's insurance backstop.

Security

35 audit findings. All resolved. Two independent security audits covering every handler, math function, and edge case. 366 test cases. Honggfuzz invariant fuzzing on all StableSwap math. Full audit report available on request.
defense-in-depth: 6 layers around every swap oracle validation (staleness + deviation) rate limiting (5-min epoch caps) circuit breaker (10% price / 10x volume) admin timelocks SWAP flash guard anti-JIT
Circuit BreakersAuto-pause on 10% price deviation or 10x volume spike. 6-hour auto-resume. Manual override for admin.
Rate LimitingPer-epoch volume and swap count caps in 5-minute windows. Prevents sustained wash trading and manipulation.
Oracle ValidationPyth/Switchboard price checks on every swap. 5-minute staleness limit. Swap fails if price deviates >5%.
Admin Timelocks1-hour commit delay on amp changes and authority transfers. Two-step process prevents instant privilege escalation.
Flash Loan GuardReentrancy prevention via state flag. Dynamic fees scale with borrow size and volatility. Atomic repayment enforced.
Anti-ManipulationCL positions require 5-minute hold (anti-JIT). Governance snapshots prevent flash-loan voting. Virtual pool wallet caps and vesting prevent dumps.

Under the Hood

Single-file C. Manual u128 arithmetic. Switch dispatch (no vtables in BPF). Delta-encoded analytics. No allocator, no runtime. Here's how the core mechanisms work.
StableSwap Invariant 4A(x + y) + D = 4AD + D³/(4xy)

Hybrid curve blending constant-product (xy=k) and constant-sum (x+y=k) via amplification coefficient A. Newton-Raphson solving converges in 6–10 iterations. A=1 behaves like Uniswap, A=100K near-zero slippage for pegged assets. N-token generalization supports 2–8 token pools.

token x balance token y xy = k (A=1) x+y = D (A=∞) aeX402 (A=100) flat here = low slippage
On-Chain Q-Learning V2 Q[s][a] ← Q[s][a] + α(r + γ max Q[s′][a′] − Q[s][a])

First production reinforcement learning on a blockchain. 27 states × 9 actions = 243 Q-values stored on-chain. V2: Volatility-aware states — volatile pools track volatility trend (not price) as primary dimension, so the brain raises fees in turbulent markets and lowers them when calm. Explicit action tracking eliminates misattribution. Delegated architecture: swaps record observations at ~200 CU; bot triggers batch training at ~100K CU. Users never pay for ML compute.

Swapuser tx
Observe~200 CU
Buffer×200 samples
Train~100K CU
Q-Table27×9=243
fee± amp±auto-apply
user pays ~200 CU (negligible overhead) · bot pays ~100K CU (funded by protocol fees) · V2: explicit action + volatility tracking
Multi-Objective Reward V2: configurable weights R = w1·rstability + w2·rvolume + w3·rtraders + w4·rtvl + w5·rfees

Five reward components, each configurable per pool. Stable pools penalize price deviation; volatile pools maximize fee×volume product. V2 adds fee efficiency as an explicit objective and lets pool operators tune weights via cfgml. ε-greedy exploration (10%, decaying) prevents local optima.

STABLE POOL DEFAULTS
stability
30%
volume
25%
traders
20%
tvl
15%
fees
10%
VOLATILE POOL DEFAULTS
fees
30%
volume
25%
tvl
25%
traders
15%
stability
5%
all weights configurable per pool via cfgml · volatile pools use volatility-aware state encoding
On-Chain Analytics & TWAP 24 hourly + 7 daily OHLCV candles · 12 bytes each · delta-encoded

Circular buffer candles updated every swap. TWAP oracle with confidence scores based on sample count, trade frequency, and price variance. Composable by other programs — no off-chain indexer dependency. Circuit breakers auto-pause on 10% price deviation or 10x volume spike.

24 hourly OHLCV candles (circular buffer, 12 bytes each) now 7 daily delta-encoded: high=open+Δh, low=open-Δl, close=open+Δc · TWAP computed from candle closes

Comparison

feature coverage (filled = native support) aeX402 Raydium Orca Curve ML Stable CL Launch Gov OHLCV Flash LOB N-tok Adapt Oracle yes partial no
FeatureaeX402RaydiumOrcaCurve (EVM)
On-chain MLQ-Learning V2 brain
Adaptive feesML-optimized 1–100 bpsFixedDynamic tiersFixed per pool
StableSwapA=1..100KStable pools3pool, metapools
Concentrated liq.Tick ranges + CLCLMMWhirlpool
Token launchesVirtual pool grad.AcceleRaytor
LP governanceOn-chain votingveCRV
On-chain candles24h + 7d OHLCV
Flash loansDynamic feesFixed fee
Limit orderbookHybrid AMM+LOBOpenBook
Binary size189 KB (C)~400 KB (Rust)~300 KB (Rust)N/A (EVM)
N-token pools2–8 tokens2 tokens2 tokens2–4 tokens
Binary sizes are approximate. Competitor features based on public documentation as of 2026.

Release Notes

v0.2.0 — February 2026
Browser DEX Terminal

Full terminal DEX at /dex/ — 12 live panels, pool picker, swap execution, wallet management, Nostr-backed community discussions. 375KB WASM, 30 color themes, mouse + keyboard navigation. No extensions, no installs.

Direct Mouse Handling

Reliable click-to-select on pools, tabs, and panels. Direct WASM handle_mouse export bypasses xterm.js escape sequence issues. Scroll wheel support for pool lists and panel content.

Swap UX Overhaul

Pool picker overlay (press p), quick-select amounts (1=25%, 2=50%, 3=75%, 4=MAX), flip direction (f), adjustable slippage (t). On-chain quote with price impact display.

V2 Settings Persistence

32-byte settings format: panel order, custom layout weights, visible panel mask, and theme selection all persist to localStorage. Panel drag-reorder and custom column weights.

Migration Docs Panel

Inline migration documentation with 13 migration types, scrollable viewer (press ? in migration sub-tab). Farm CLI commands for create/close operations.

30 Color Themes

GitHub Dark, Dracula, Monokai, Nord, Solarized, Gruvbox, Tokyo Night, Catppuccin, One Dark, Ayu, Everforest, Kanagawa, Rose Pine, Material, Palenight, Nightfox, Synthwave 84, Horizon, Vesper, Poimandres, plus 4 light themes (Solarized Light, GitHub Light, E-Ink, Paper), High Contrast, Cyberpunk, and DOS.

Mobile & Cross-Platform

Capacitor/Android wrapper for native mobile builds. Cross-compiled release binaries for Linux (amd64/arm64), macOS (amd64/arm64), and Windows (amd64). One-line install: curl -sSf https://aex402.com/install.sh | sh

v0.1.0 — January 2026
Initial release. 85+ instruction handlers, on-chain Q-Learning V2, virtual pool graduation, concentrated liquidity, flash loans, multi-hop routing, limit orderbook, farming, lottery, governance, TWAP oracle, circuit breakers. 189KB pure C binary. 35 audit findings resolved. 366 test cases.

Papers

Curve math, Q-Learning proofs, graduation game theory, and security analysis.

Links