AeX-402

The AMM That Learns
Lower fees when markets are calm. Higher fees when they're not. AeX-402 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.
git clone https://github.com/openSVM/ammasm && cd ammasm/cli && zig build && ./zig-out/bin/aex pool list
189KB
Binary Size
72
Instruction Handlers
35/35
Audit Issues Resolved
7,700
Lines of Pure C

What You Get

Trade

Better prices. Lower slippage. Safer swaps.
trade size → slippage xy=k AeX low slippage zone
  • Fees adapt to market conditions — you pay less when things are calm
  • StableSwap curve gives near-zero slippage on pegged assets (USDC/USDT)
  • Multi-hop routes chain 2–3 pools in one atomic transaction
  • Circuit breakers halt trading if price moves >10% — protecting you from exploits

Provide Liquidity

Higher yields. Less work. You govern the pool.
price range full range LP (lower capital efficiency) concentrated higher APY in tighter range price
  • Concentrated liquidity — earn fees on your chosen price range, not the whole curve
  • ML brain V2 auto-tunes fee/amp/farming — volatility-aware for volatile pools, configurable weights per pool
  • Flash loan fees (0.09%–1%) earn you yield even on idle liquidity
  • Vote on pool parameters with your LP tokens — pools are DAOs

Launch a Token

0.1 SOL to launch. Built-in farming. Anti-rug by design.
tokens sold price graduate AMM 80% → farm 1h deadline miss it → pool erased → liquidity → AEX holders
  • Bonding curve pricing — no initial liquidity needed, price rises with demand
  • 1-hour deadline to reach target and graduate — miss it and the pool is erased, liquidity goes to AEX token holders
  • 80% of sells build a 90-day farming reward pool for your community
  • 2.5% wallet cap + vesting prevents dumps (creator: 50hr, holders: 20hr)

Build On It

Composable on-chain data. No indexer. No API key.
Your Program / Frontend ↓ reads on-chain ↓ TWAP Oracle 24h OHLCV Balances Trade Stats Pool Account (1024 bytes on-chain)
  • TWAP oracle with confidence scores — other programs can read prices directly
  • 24h + 7d OHLCV candles stored on-chain, updated every swap
  • TypeScript SDK + integration guide + devnet deployment ready
  • 85+ instruction handlers — swap, farm, govern, ML, orderbook, flash loan

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 → erased → AEX holders 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 → pool erased, liquidity to AEX holders

Economics

Swap0.30% fee
50%→ LPs
+
50%→ Protocol
ML Trainingfunded by admin fees
Failed Launchmissed 1h deadline
Pool Erasedall SOL liquidity
AEX Token Holdersprotocol backstop
swap fees: 50% LP / 50% protocol · failed virtual pools: 100% of liquidity → AEX holders

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 target50–250 SOL
Graduation reward0.1% to triggerer
Deadline1 hour (hard)
Failurepool erased → AEX holders
Miss the 1h deadline and the pool is erased. All remaining liquidity is redistributed to AEX token holders. Real consequences create real urgency.

Yield Sources

LP yield swap fees flash farming lot AEX holder yield failed pool liquidations
Swap fees50% of 30 bps
Flash loan fees0.09%–1.0%
Farming rewardstime-locked
LotteryLP ticket system
AEX tokenfailed pool liquidations
LP yield from fees, flash loans, farming. AEX holders receive liquidity from all virtual pools that fail to graduate — the protocol's insurance backstop.

Protocol Rules

Amplification (A) 1 (volatile) 100,000 (stable) A=100 Swap fee (ML range) 1-100 bps 30 bps default Graduation target 50 SOL min 250 SOL max Governance quorum 10% 50% pass threshold

Pool Parameters

Amplification range1 – 100,000
Minimum swap100,000 lamports
Minimum deposit100,000,000 lamports
Max tokens per pool8 (N-pool)
Newton iterations255 max (converges ~6–10)
Pool account size1,024 bytes (2-token)
N-Pool account size2,048 bytes

Timelocks & Limits

Amp change delay1 hour commit
Amp ramp minimum24 hours
Authority transfer1 hour delay
Governance voting3 days
Governance timelock1 day after vote
Quorum10% of LP supply
Pass threshold50%+ of votes

Virtual Pool Rules

Max wallet2.5% of supply
Creator vesting2%/hour (50 hours)
Holder vesting5%/hour (20 hours)
Graduation deadline1 hour (hard)
Deadline misserased → AEX
Farming duration90 days
Holders per poolup to 1,400

Safety Thresholds

Circuit breaker price10% deviation
Circuit breaker volume10x avg spike
CB cooldown1 hour
CB auto-resume6 hours
Rate limit epoch5 minutes
Oracle staleness5 min max
Oracle max deviation5%

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 →
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.

Why It Can't Be Gamed

Virtual pool graduation is a mechanism design problem. Every rule exists to make manipulation more expensive than its expected payoff. The hard 1-hour deadline means real money is at stake — miss it and the pool is erased, liquidity goes to AEX token holders. No second chances.

Sell Extraction

SELL user sells tokens 80% → Farming Pool 20% → supply permanently removed can be rebought more dumping = bigger farming pool = stronger community
sell → 80% extracted to farming pool, 20% returns to bonding supply

Every sell permanently removes 80% of those tokens from circulation and adds them to the post-graduation farming pool. A scammer who dumps builds the farming program for the community. Pump-and-dump creates better farming rewards — the attack funds the defense.

Wallet Concentration Cap

max per wallet vs total supply 2.5% max to control 50% supply a whale needs 20+ wallets: = 20 wallets = 50%
max per wallet = 2.5% of total supply

No single address can hold more than 2.5% of a virtual pool's token supply. This forces wider distribution and prevents any one entity from controlling price action. A whale needing 40+ wallets to accumulate faces higher costs and coordination friction.

Vesting Schedules

hours after graduation unlocked % holders 20h creator 50h 0 10h 20h 50h 100% 0%
holders: 5%/hr (20hr) · creator: 2%/hr (50hr)

Post-graduation tokens unlock gradually. Holders claim 5% per hour over 20 hours; creators claim 2% per hour over 50 hours. This removes "instant dump at graduation" from the strategy space. Any sell pressure is spread across hours, giving the market time to absorb.

Dynamic Graduation Target

sell_ratio (sells / buys) target SOL 250 50 0% 50% 100% more trading = lower target floor: 50 SOL
target = 250 × (1 − 0.8 × sell_ratio) ∈ [50, 250] SOL

More trading activity (higher sell ratio) lowers the graduation target. Active communities graduate faster with larger farming pools. Wash trading raises the sell ratio but also extracts more tokens to farming — the attacker subsidizes the community while lowering the bar.

The Hard Deadline: Graduate or Die

Pool Created 0.1 SOL bonding curve trading (buy/sell) 1 HOUR GRADUATE AMM + 90d farming + vesting MISS pool erased → AEX holders no extensions, no refunds, no second chances — creates maximum urgency for organic community building
if pool fails to graduate within 1 hour: pool account erased, all SOL liquidity redistributed to AEX token holders

The hard deadline is the keystone of the entire mechanism. Without it, pools can linger indefinitely and creators face no urgency. With it, every participant has skin in the game: build real community traction in 1 hour, or everyone loses their position. Failed pools aren't wasted — their liquidity accrues value to AEX token holders, making the protocol token a bet on the failure rate of launches. This creates a self-sustaining economy: successful launches reward participants, failed launches reward protocol holders.

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=∞) AeX-402 (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
35%
volume
30%
tvl
20%
traders
15%
stability
0%
all weights configurable per pool via cfgml · volatile pools use volatility-aware state encoding
Virtual Pool Graduation target = 250 SOL × (1 − 0.8 × sell_ratio) ∈ [50, 250]

Zero-rent token launches via linear bonding curves with a hard 1-hour deadline. 1.49M holders per pool in 7-byte compact format (Caesar-rotated hash). 80% of sell tokens extracted for farming pool. Dynamic graduation target penalizes wash trading. If the pool fails to reach target and graduate within 1 hour, the pool is erased and all remaining liquidity is redistributed to AEX token holders. Vesting schedules (holders 5%/hr, creator 2%/hr) prevent post-graduation dumps.

Create 0.1 SOL Buy/Sell bonding 1h Graduate AMM Farm 90d Vesting miss deadline → ERASED liquidity → AEX holders sells extract 80% to farming · 2.5% wallet cap · failed pools fund AEX token value
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) AeX-402 Raydium Orca Curve ML Stable CL Launch Gov OHLCV Flash LOB N-tok Adapt Oracle yes no
FeatureAeX-402RaydiumOrcaCurve (EVM)
On-chain MLQ-Learning V2 brain
Adaptive feesML-optimized 1–100 bpsFixedFixed tiersFixed per pool
StableSwapA=1..100K3pool, metapools
Concentrated liq.Tick ranges + CLCLMMWhirlpool
Token launchesVirtual pool grad.
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.

Live Pools · devnet

[ FETCHING ]

Pool Analytics

TVL Distribution

waiting for data...

Balance Ratio

waiting for data...

Papers

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

Links