muthuk1's picture
Initial project: Dynamic RWA Yield Router for Mantle Hackathon
7d5448a verified
|
Raw
History Blame
10.3 kB

πŸ—οΈ 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, with all decisions recorded on-chain via ERC-8004 agent identity NFTs.

πŸ“Š What It Does

The Dynamic RWA Yield Router manages a portfolio across three core RWA assets on Mantle L2:

Asset Type Target APY Risk Profile
USDY (Ondo Finance) Tokenized US T-Bills ~4.25% Low β€” USD-pegged, regulated
mETH (Mantle LSP) Liquid Staked ETH ~3-5% Medium β€” ETH price exposure
MI4 (Mantle Index Four) Tokenized Index Fund ~5-8% Medium β€” diversified basket

The agent uses a PPO (Proximal Policy Optimization) reinforcement learning policy to learn optimal allocation weights given real-time market conditions, yield rates, and risk signals.

πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DYNAMIC RWA YIELD ROUTER                      β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚ OBSERVE  β”‚β†’β”‚  REASON  β”‚β†’β”‚   PLAN   β”‚β†’β”‚ AUTHORIZEβ”‚       β”‚
β”‚  β”‚          β”‚  β”‚          β”‚  β”‚          β”‚  β”‚          β”‚       β”‚
β”‚  β”‚DeFiLlamaβ”‚  β”‚RL Policy β”‚  β”‚Rebalance β”‚  β”‚  Risk    β”‚       β”‚
β”‚  β”‚CoinGeckoβ”‚  β”‚  (PPO)   β”‚  β”‚ Trades   β”‚  β”‚ Manager  β”‚       β”‚
β”‚  β”‚Mantle   β”‚  β”‚          β”‚  β”‚          β”‚  β”‚          β”‚       β”‚
β”‚  β”‚RPC/FRED β”‚  β”‚          β”‚  β”‚          β”‚  β”‚          β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚       ↓                                          ↓               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ EXECUTE  │←───────────────────────────│  VERIFY  β”‚           β”‚
β”‚  β”‚          β”‚                            β”‚          β”‚           β”‚
β”‚  β”‚Unsigned  β”‚    Mantle L2 (Chain 5000)  β”‚On-chain  β”‚           β”‚
β”‚  β”‚Tx Builderβ”‚    Fluxion / Agni DEX      β”‚Confirm   β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              ON-CHAIN CONTRACTS                          β”‚    β”‚
β”‚  β”‚  YieldRouterAgent.sol  β”‚  AgentIdentity8004.sol        β”‚    β”‚
β”‚  β”‚  (Allocation Records)  β”‚  (ERC-8004 Reputation)        β”‚    β”‚
β”‚  β”‚  RiskRegistry.sol      β”‚  (Risk Parameters)            β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

6-Stage Agent Pipeline

  1. OBSERVE β€” Fetch real-time yield rates, prices, and macro data from DeFiLlama, CoinGecko/Bybit, Mantle RPC, and FRED
  2. REASON β€” RL policy (PPO with actor-critic MLP) predicts optimal allocation weights
  3. PLAN β€” Compute required trades if weights drift beyond threshold (5%)
  4. AUTHORIZE β€” Multi-layer risk manager validates: depeg detection, volatility guard, position limits, drawdown protection, circuit breaker
  5. EXECUTE β€” Construct unsigned transaction payloads (construct-only safety: never holds private keys)
  6. VERIFY β€” Confirm execution, update portfolio state, record on-chain via ERC-8004

🧠 RL Model

Algorithm: Proximal Policy Optimization (PPO)

State Space (18-dimensional):

  • Yield rates: USDY APY, mETH APY, MI4 APY, Aave supply APYs
  • Prices: ETH, BTC, MNT (normalized)
  • Macro: Fed funds rate, BTC dominance
  • Risk: USDY peg, mETH peg, ETH 30d volatility
  • Portfolio: current weights [USDY, mETH, MI4]

Action Space (3-dimensional, continuous):

  • Raw logits β†’ softmax β†’ portfolio weights [USDY, mETH, MI4]
  • Position limits enforced: 5-60% per asset

Reward Function:

reward = sharpe_ratio Γ— 100 
       - drawdown Γ— 50 
       - depeg_penalty 
       - rebalance_cost Γ— 1000

Training Environment: Custom Gymnasium env with synthetic yield processes (Ornstein-Uhlenbeck for mean-reverting yields, GBM for prices).

πŸ›‘οΈ Risk Management

Layer Description Trigger
Depeg Detection Monitors USDY/USD and mETH/ETH pegs USDY > 0.5%, mETH > 2% deviation
Volatility Guard Reduces risky assets in high-vol regimes ETH 30d vol > 80%
Concentration Limits Enforces min/max position sizes Any asset > 60% or < 5%
Smart Contract Risk Weights by protocol audit status Per-protocol risk scores
Drawdown Protection Circuit breaker on losses Portfolio DD > 10%
Emergency Exit Flee to USDC on critical risk Severe depeg or compounding risks

πŸ“œ Smart Contracts

YieldRouterAgent.sol

  • Records allocation decisions on-chain (audit trail)
  • Enforces position limits and rebalance intervals
  • Circuit breaker mechanism (OPEN/CLOSED/HALF_OPEN)
  • Operator authorization for ERC-4337 wallets

AgentIdentity8004.sol (ERC-8004)

  • Soulbound agent identity NFT (non-transferable)
  • Capability registration and verification
  • Attestation system (performance audits, security reviews)
  • On-chain reputation scoring (0-10000 bps)
  • Decision history references with outcome scoring

RiskRegistry.sol

  • Per-asset risk parameters (max/min weights, depeg thresholds)
  • Global risk parameters (max drawdown, slippage, gas limits)
  • Depeg event tracking and resolution
  • Allocation validation function

πŸš€ Quick Start

# Clone
git clone https://huggingface.co/muthuk1/mantle-rwa-yield-router
cd mantle-rwa-yield-router

# Install dependencies
pip install -r requirements.txt

# Run demo (3 cycles, live data)
python scripts/demo.py

# Train RL agent (optional, uses synthetic data)
python scripts/train.py

# Run continuous agent
python -m agent.main --mode run --interval 3600 --capital 100000

# Run tests
pytest tests/ -v

Environment Variables

cp .env.example .env
# Edit .env with your configuration

πŸ“‚ Project Structure

mantle-rwa-yield-router/
β”œβ”€β”€ agent/
β”‚   β”œβ”€β”€ main.py              # 6-stage orchestrator pipeline
β”‚   β”œβ”€β”€ data_pipeline.py     # Real-time yield & price data aggregation
β”‚   β”œβ”€β”€ rl_optimizer.py      # PPO agent + Gymnasium environment
β”‚   β”œβ”€β”€ risk_manager.py      # Multi-layer risk management
β”‚   β”œβ”€β”€ executor.py          # Unsigned transaction builder
β”‚   └── strategy_reporter.py # LLM strategy letter generator
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ YieldRouterAgent.sol  # On-chain allocation router
β”‚   β”œβ”€β”€ AgentIdentity8004.sol # ERC-8004 agent identity NFT
β”‚   └── RiskRegistry.sol      # On-chain risk parameters
β”œβ”€β”€ telegram_bot/
β”‚   └── bot.py               # Telegram UI (/status, /yields, /risk)
β”œβ”€β”€ config/
β”‚   └── constants.py         # 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

πŸ”‘ Key Design Decisions

  1. Construct-Only Safety β€” The agent constructs unsigned transaction payloads but NEVER holds private keys. Execution requires external signing via ERC-4337 wallet or multisig.

  2. Python-Native β€” Built in Python (not TypeScript) because RL/ML libraries (PyTorch, stable-baselines3, Gymnasium) are Python-native.

  3. Fluxion DEX Primary β€” Fluxion is Mantle's native RWA-focused AMM, primary routing for RWA token swaps.

  4. Risk-Parity Adaptive β€” Portfolio construction adapts to risk regimes. High volatility β†’ more USDY (safe haven). Depeg β†’ emergency exit to USDC.

  5. On-Chain Audit Trail β€” Every allocation decision is recorded on-chain with content hashes linking to IPFS-stored strategy reports.

  6. ERC-8004 + ERC-4337 β€” Agent identity via ERC-8004 (reputation, capabilities, attestations) + account abstraction via ERC-4337 (spending limits, session keys).

πŸ“Š Contract Addresses (Mantle Mainnet)

Contract Address
USDY (Ondo) 0x5bE26527e817998A7206475496fDE1E68957c5A6
mETH 0xcDA86A272531e8640cD7F1a92c01839911B90bb0
USDC 0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9
WMNT 0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8
Fluxion Router 0x5628a59df0ecac3f3171f877a94beb26ba6dfaa0
Agni Router 0x319B69888b0d11cEC22caA5034e25FfFBDc88421
Aave V3 Pool 0x458F293454fE0d67EC0655f3672301301DD51422

πŸ† Hackathon Track

Mantle Turing Test Hackathon 2026 β€” Phase 2 "AI Awakening"

  • Track: AI Γ— RWA
  • Focus: Autonomous AI agents managing tokenized real-world assets
  • Key Technologies: RL optimization, ERC-8004 agent identity, Mantle L2

πŸ“ License

MIT


Built with πŸ€– for the Mantle Turing Test Hackathon 2026