File size: 14,262 Bytes
7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a cce3fb3 7d5448a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | # ποΈ Dynamic RWA Yield Router
> **Mantle Turing Test Hackathon 2026 β Phase 2 "AI Awakening" β AI Γ RWA Track**
An autonomous AI agent that dynamically allocates capital across Mantle's Real World Asset (RWA) stack using reinforcement learning + LSTM yield prediction, with MEV-protected execution, auto-compounding, social sentiment analysis, and all decisions recorded on-chain via ERC-8004 agent identity NFTs. Ships with a **Binance-grade Next.js dashboard**.
---
## π₯ What Makes This 10x Different
| Innovation | Description | Status |
|-----------|-------------|--------|
| **Ensemble AI Engine** | PPO RL optimizer + LSTM yield predictor + sentiment analyzer working in concert | β
Active |
| **MEV Protection Layer** | Sandwich detection, trade splitting, private mempool routing, optimal slippage | β
Active |
| **Auto-Compounding** | Gas-optimized yield restaking with mathematically optimal compound frequency | β
Active |
| **LSTM Yield Predictor** | 7-day yield forecasting with MC Dropout confidence intervals & regime detection | β
Active |
| **Social Sentiment** | Real-time crypto sentiment aggregation (Fear & Greed, social volume, news) | β
Active |
| **ERC-8004 Agent Identity** | Soulbound NFT with capabilities, attestations, reputation scoring, decision history | β
On-chain |
| **zkML-Ready Architecture** | Verifiable inference proofs for on-chain AI transparency (EZKL/Giza compatible) | π Planned |
| **Binance-Grade Dashboard** | Next.js + Tailwind + Recharts with full Binance design system (dark theme, trading UI) | β
Built |
---
## π Portfolio Assets
| Asset | Type | Target APY | Risk | Protocol |
|-------|------|-----------|------|----------|
| **USDY** | Tokenized US T-Bills | ~4.25% + lending | Low | Ondo Finance |
| **mETH** | Liquid Staked ETH | ~3.9% + lending | Medium | Mantle LSP |
| **MI4** | Tokenized Index Fund | ~5.4% + lending | Medium | Securitize |
The agent captures **base yield + lending yield** (Aave V3 supply) for each asset, achieving total APYs of 4.7-6.2%.
---
## ποΈ Architecture
```
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DYNAMIC RWA YIELD ROUTER v2.0 β
β β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β OBSERVE βββ PREDICT βββ REASON βββ PLAN β β
β β β β β β β β β β
β β DeFiLlama β β LSTM Yield β β PPO Policy β β Rebalance β β
β β CoinGecko β β Predictor β β + Ensembleβ β + MEV Opt β β
β β Mantle RPCβ β + Sentimentβ β β β + Splitter β β
β β FRED/News β β + Regime β β β β β β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β β β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β AUTHORIZE βββ EXECUTE βββAUTOCOMPOUNDβββ VERIFY β β
β β β β β β β β β β
β β 6-Layer β β Unsigned Txβ β Gas-Optimalβ β On-chain β β
β β Risk Mgr β β + MEV Prot β β Restaking β β + ERC-8004 β β
β β + Sentimentβ β + Whitelistβ β Automation β β Attestationβ β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ON-CHAIN CONTRACTS β β
β β YieldRouterAgent.sol β AgentIdentity8004.sol β RiskRegistry.solβ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β BINANCE-STYLE NEXT.JS DASHBOARD β β
β β Portfolio β Markets β AI Optimizer β Risk β Agent Identity β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### 8-Stage Agent Pipeline (v2.0)
1. **OBSERVE** β Fetch real-time yield, price, macro, and sentiment data
2. **PREDICT** β LSTM yield forecasting with MC Dropout confidence + regime detection
3. **REASON** β PPO policy + ensemble (combine RL action with LSTM prediction + sentiment)
4. **PLAN** β Compute trades with MEV analysis (sandwich detection, trade splitting)
5. **AUTHORIZE** β 6-layer risk manager (depeg, volatility, concentration, drawdown, circuit breaker, sentiment)
6. **EXECUTE** β Construct MEV-protected unsigned transactions (private mempool, optimal deadline)
7. **AUTO-COMPOUND** β Gas-optimized yield restaking at mathematically optimal frequency
8. **VERIFY** β Confirm on-chain, update ERC-8004 reputation, generate strategy report
---
## π§ AI/ML Stack
### PPO Reinforcement Learning
- **Algorithm:** Proximal Policy Optimization with Actor-Critic MLP
- **State Space:** 18-dimensional (yields, prices, macro, risk signals, portfolio weights)
- **Action Space:** 3-dimensional continuous β softmax β weights [USDY, mETH, MI4]
- **Reward:** Risk-adjusted Sharpe ratio - drawdown penalty - depeg penalty - gas costs
### LSTM Yield Predictor *(Novel)*
- **Architecture:** 2-layer LSTM with attention mechanism
- **Input:** Yield history, price momentum, fed rate, volatility, sentiment
- **MC Dropout:** 50 forward passes for uncertainty estimation (confidence intervals)
- **Regime Detection:** Bull/Bear/Sideways classification head
- **Feature Importance:** Attention weights reveal which features drove the prediction
### Social Sentiment Analyzer *(Novel)*
- **Sources:** Fear & Greed Index, social volume, news sentiment
- **Integration:** Sentiment score feeds into both LSTM predictor and risk manager
- **Impact:** High fear β increase USDY (safe haven), High greed β lean into mETH/MI4
---
## π‘οΈ Novel Risk & Execution Features
### MEV Protection Layer *(Novel)*
- **Sandwich Attack Detection:** Estimates price impact per trade
- **Trade Splitting:** Automatically splits large trades to reduce MEV exposure
- **Private Mempool:** Routes high-impact trades through private channels
- **Optimal Deadlines:** Shorter deadlines for high-risk trades, longer for low-risk
### Auto-Compounding Engine *(Novel)*
- **Optimal Frequency:** Calculates gas-optimal compound interval using calculus optimization
- **Formula:** `n* = β(APY Γ Principal / (2 Γ GasCost))` compounds per year
- **Break-even:** Computes minimum principal where compounding beats simple yield
- **Smart Triggers:** Only compounds when accumulated yield > 3Γ gas cost
### 6-Layer Risk Management
| Layer | Description | Trigger |
|-------|-------------|---------|
| Depeg Detection | USDY/USD and mETH/ETH peg monitoring | >0.5% / >2% |
| Volatility Guard | Dynamic exposure reduction in high-vol regimes | ETH 30d vol >80% |
| Concentration Limits | Position size enforcement | >60% or <5% |
| Smart Contract Risk | Protocol-weighted risk scoring | Per-protocol scores |
| Drawdown Protection | Circuit breaker on portfolio losses | DD >10% |
| Sentiment Guard *(Novel)* | Reduces risky exposure on extreme fear | Score <20 |
---
## π¨ Dashboard (Next.js + Binance Design)
Full-featured financial dashboard built with the **Binance Design System**:
- **Dark canvas** (#0b0e11) with card surfaces (#1e2329)
- **Binance Yellow** (#FCD535) accent for CTAs and brand elements
- **Trading green/red** (#0ecb81/#f6465d) for price direction semantics
- **BinancePlex substitute** (JetBrains Mono) for all financial numbers
- **6 dashboard sections:** Portfolio, Markets, AI Optimizer, Risk Monitor, Reports, Agent Identity
### Dashboard Features
- π Real-time portfolio value chart with timeframe selector
- π₯§ Live allocation pie chart + weight history area chart
- π RWA markets table with yield comparison bar chart
- π§ LSTM yield predictions with confidence bars + AI recommendations
- π‘οΈ Social sentiment gauge with source breakdown
- π‘οΈ Risk score ring, protection layer status, activity log
- π€ ERC-8004 agent identity card with reputation, capabilities, attestations
- π± Fully responsive (mobile hamburger, tablet 2-up, desktop full layout)
```bash
# Run the dashboard
cd dashboard && npm install && npm run dev
```
---
## π Quick Start
```bash
# Clone from HuggingFace
git clone https://huggingface.co/muthuk1/mantle-rwa-yield-router
cd mantle-rwa-yield-router
# Install Python dependencies
pip install -r requirements.txt
# Run demo (3 cycles with live data)
python scripts/demo.py
# Train RL agent
python scripts/train.py
# Run continuous agent
python -m agent.main --mode run --interval 3600 --capital 100000
# Run tests (25 passing)
pytest tests/ -v
# Run dashboard
cd dashboard && npm install && npm run dev
```
---
## π Project Structure
```
mantle-rwa-yield-router/
βββ agent/
β βββ main.py # 8-stage orchestrator pipeline
β βββ data_pipeline.py # Real-time data aggregation (8 sources)
β βββ rl_optimizer.py # PPO agent + Gymnasium environment
β βββ risk_manager.py # 6-layer risk management
β βββ executor.py # MEV-protected unsigned tx builder
β βββ strategy_reporter.py # LLM strategy letter generator
β βββ novel_features.py # LSTM predictor, MEV shield, auto-compound, sentiment
βββ contracts/
β βββ YieldRouterAgent.sol # On-chain allocation router
β βββ AgentIdentity8004.sol # ERC-8004 soulbound agent identity
β βββ RiskRegistry.sol # On-chain risk parameters
βββ dashboard/ # Next.js Binance-style UI
β βββ src/app/page.tsx # Main dashboard page
β βββ src/components/ # TopNav, Charts, RiskMonitor, AIOptimizer, AgentIdentity
β βββ src/lib/data.ts # Data generators and mock data
βββ telegram_bot/
β βββ bot.py # Telegram UI (/status, /yields, /risk)
βββ config/
β βββ constants.py # All contract addresses, ABIs, parameters
βββ scripts/
β βββ demo.py # Demo runner
β βββ train.py # RL training script
βββ tests/
β βββ test_agent.py # 25 unit + integration tests
βββ requirements.txt
βββ .env.example
βββ README.md
```
---
## π Smart Contracts
### `YieldRouterAgent.sol`
On-chain allocation records, position limits, circuit breaker, operator authorization.
### `AgentIdentity8004.sol` (ERC-8004)
Soulbound agent identity NFT: capabilities, attestations, reputation (0-10000), decision history.
### `RiskRegistry.sol`
On-chain risk parameters, depeg event tracking, allocation validation.
---
## π Contract Addresses (Mantle Mainnet, Chain ID 5000)
| Contract | Address |
|----------|---------|
| USDY (Ondo) | `0x5bE26527e817998A7206475496fDE1E68957c5A6` |
| mETH | `0xcDA86A272531e8640cD7F1a92c01839911B90bb0` |
| USDC | `0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9` |
| WMNT | `0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8` |
| Fluxion Router | `0x5628a59df0ecac3f3171f877a94beb26ba6dfaa0` |
| Agni Router | `0x319B69888b0d11cEC22caA5034e25FfFBDc88421` |
| Aave V3 Pool | `0x458F293454fE0d67EC0655f3672301301DD51422` |
---
## π Key Design Decisions
1. **Construct-Only Safety** β Never holds private keys. All outputs are unsigned tx payloads.
2. **Ensemble Intelligence** β PPO + LSTM + Sentiment provide richer signals than any single model.
3. **MEV-Aware** β Every trade goes through sandwich detection + optimal splitting.
4. **Gas-Optimized Compounding** β Mathematical optimization of compound frequency vs gas costs.
5. **On-Chain Audit Trail** β ERC-8004 records every decision with content hashes.
6. **Binance-Grade UI** β Production dashboard, not a demo. Full dark theme, live charts, responsive.
---
## π Hackathon Track
**Mantle Turing Test Hackathon 2026 β Phase 2 "AI Awakening"**
- **Track:** AI Γ RWA ($100K prize pool)
- **Focus:** Autonomous AI agents managing tokenized real-world assets
- **Key Tech:** RL optimization, LSTM prediction, ERC-8004, MEV protection, Mantle L2
## π License
MIT
---
*Built with π€ for the Mantle Turing Test Hackathon 2026*
|