Architecture

How Mensa works: the contracts, the agent loop, and why every piece is on Mantle.

The thesis

You can't trust an AI with your money if you can't verify its reasoning.

Mensa solves this with three primitives. Every decision is logged on-chain. Every decision is explained in plain English. Every decision is challenged by humans in a head-to-head tournament. The results are a permanent, verifiable record of whether the AI deserves your funds.

Flow

User walletmETH / USDYMensaAgentTreasurydeposit / withdraw / executeAllocationTournamentVaultAI vs Human roundsopenRound / voteHuman / settleRoundDecisionLogon-chain reasoningReputationsqrt-weighted votesMensaBadgessoulbound NFT awardsBountyPool15% perf fee → 50/30/20 splitAI Operator (Claude Haiku 4.5)off-chain · Coingecko + DefiLlama · executes via aiOperator role
All contracts deployed on Mantle (Mainnet 5000 + Sepolia 5003).

Contracts

The treasury. Holds user-deposited mETH and USDY. AI operator triggers executeAllocation() to rebalance, log a decision, and open a tournament round atomically.

Risk caps: max 95% in single asset, min 2% rebalance threshold, AI operator address can only execute pre-approved actions.

Permanent on-chain record of every agent decision. Each decision stores action, confidence, reasoning hash, and parameters. Full reasoning text is emitted as event data for indexers.

Append-only. Only the agent contract can write. Mantle's low gas makes per-decision logging economically viable.

TournamentVault

0x92E6B4...77d122

The Turing Test mechanic. Each round opens with the AI's allocation snapshot. Anyone can vote with their human allocation. After settlement, performance is computed on-chain and outcome (AI_WINS / HUMAN_WINS / TIE) recorded.

Settler role can settle rounds and supply human allocation aggregate. In production, this would use a price oracle and a median of human votes.

Tracks each voter's on-chain history: total votes, correct votes (rounds they beat the AI), reputation score, first-participation timestamp. Read by TournamentVault to compute sqrt-weighted vote weight.

Only TournamentVault can update scores. Sqrt weighting caps the influence of any single account, mitigating Sybil attacks and whale dominance.

Receives 15% of yield as performance fee from MensaAgent. On each settled round, distributes a share to humans who outperformed the AI. Split: 50% to round winners, 30% to a reputation pool (top monthly), 20% to ops.

Pull-based claim pattern (no push transfers) — winners must claim, no reentrancy surface. Only MensaAgent funds it; only TournamentVault triggers payouts.

Soulbound (non-transferable) ERC-721 badges minted automatically on milestones: First Vote, Beat AI 10x, Beat AI 100x, 5-Win Streak, Reputation 500, Reputation 1000, Top 10 Monthly.

Transfer functions disabled (transfer reverts). Only TournamentVault can mint. No admin burn.

MensaAgentIdentity (ERC-8004)

0x6671E5...8560B6

ERC-8004 IdentityRegistry implementation. The Mensa agent is registered as agentId #1 with a tokenURI pointing to a discoverable agent card (capabilities, services, model, contracts) served from /api/agent-card. Any A2A-compatible agent or protocol can read this NFT to discover what Mensa is and how to compose with it.

Spec-compliant with eips.ethereum.org/EIPS/eip-8004 — register / setAgentURI / setMetadata / getAgentWallet. EIP-712 wallet rotation deferred (standard ERC-721 transfer is sufficient for the MVP).

Stack

Frontend
Next.js 16, Tailwind CSS v4, Turbopack
Wallet
wagmi v2, viem (Mantle Mainnet + Sepolia)
Smart contracts
Solidity 0.8.24, OpenZeppelin v5, Foundry
AI
Claude Haiku 4.5 via Anthropic SDK
RWA
Mantle mETH (liquid staking), Ondo USDY (T-bills)
Market data
Coingecko (ETH price), DefiLlama (yields)
Automation
GitHub Actions cron (agent loop + auto-settlement)
Deploy
Vercel (frontend), Mantle Sepolia + Mainnet (contracts)

Why Mantle

mETH liquid staking
Mantle's native LST is a first-class asset in our treasury. The agent rebalances its yield against USDY in real time. Not portable to other chains.
USDY availability
Real T-bill yield via Ondo's deployment on Mantle. The risk-adjusted alternative to mETH that makes the allocation problem interesting.
Low-gas decision logging
Every agent decision — including the full reasoning text emitted as event data — is written on-chain. Mantle's low fees make this economically viable; on Ethereum L1 it would be prohibitive.
Self-feedback memory loop
Before each Claude call, the agent reads its own track record from on-chain settled rounds and injects it into the prompt: per-round alpha vs 50/50 baseline, recent decisions vs in-hindsight optimal. Self-correction without external retraining.
Auto-settlement cron
GitHub Actions runs every 30 min: settle any expired rounds with current prices, then call Claude for the next allocation. Fully autonomous, the only human in the loop is whoever deposits or votes.
On-chain Turing tournament
A Mantle smart contract pits AI vs human allocators on identical inputs. Outcomes settle on-chain. The Turing Test is verifiable, not subjective.

Hackathon tracks

Mantle Turing Test 2026 · Phase 2 (AI Awakening). Mensa is submitted to multiple tracks (a single BUIDL can be entered into several, but only one prize wins).

Primary
AI × RWA

Path B — end-user-facing AI × RWA product. Mensa is exactly an "intelligent RWA portfolio management agent" managing mETH (Mantle LST) and USDY (Ondo tokenized T-bills), the two RWAs the track explicitly names.

Grand Champion

Cross-track. Scores Technical Depth (AI × on-chain integration, 6 verified contracts), Innovation (Turing tournament + verifiable alpha), Mantle Ecosystem Contribution (RWA-native, low-gas decision logging), and Product Completeness (live deployed app, autonomous loop).

AI Alpha & Data

Path B — trading strategy with verifiable on-chain Alpha. Every decision and outcome is settled on-chain; cumulative alpha vs 50/50 baseline is computed from contract reads, not self-reported.

Best UI/UX Award

Clean dark Mantle-aligned design with sage accent. AI interaction surfaced via the live decision card with reasoning. Fully responsive.

20 Project Deployment Award

First-come, first-served. Mensa hits all bars: 6 contracts deployed and verified on Mantle Mainnet, AI-powered function (executeAllocation) callable on-chain, public frontend, open-source repo with README.

Compliance posture

Mensa is a non-custodial smart-contract treasury. The protocol itself doesn't collect or hold off-chain user data, but RWAs come with jurisdictional rails. How we think about it:

Asset-side (USDY) compliance is upstream

Ondo's USDY is itself KYC-gated at issuance — only whitelisted addresses can receive newly-minted USDY directly from Ondo. Mensa never mints USDY; we accept it from depositors who already hold it. The KYC perimeter sits with Ondo, not us, which is the standard pattern for DeFi protocols composing with permissioned RWAs.

Sanctions screening (next)

For institutional adoption we'd wire a sanctions hook into deposit() and withdraw() that consults Chainalysis Oracle (or equivalent) and reverts on hits. Cost: ~30k gas per call on Mantle, a few cents. Designed but not yet wired into the MVP contract.

Geo-fencing at the frontend (next)

The smart contracts are jurisdiction-neutral, but the frontend can refuse to render deposit UI for IPs in restricted regions (US persons for unregistered RWAs, etc.). Cloudflare Workers / Vercel Edge config — standard pattern, deferred until we have a real go-to-market plan.

Audit & disclosure

Source is open under MIT. GitHub repo with Foundry tests. All 6 contracts verified on Mantlescan (linked in the Contracts section above). A formal audit by a Web3 audit firm (Spearbit / Trail of Bits / Macro) is part of any production launch checklist — not done at hackathon stage.

Mantle yield landscape

The broader DeFi yield universe Mensa monitors on Mantle. Today the agent allocates only to mETH (liquid staking) and USDY (T-bills). Aave, Lendle, and Fluxion are listed for context — adding them to the allocation set is gated on the share-model upgrade in the roadmap below. Click a pool for APY history.

Mantle yield markets

Live APY for protocols Mensa can allocate to. Click a pool for history.

via DefiLlama · 5min cache
Loading yields...

MVP scope & roadmap

Mensa is a hackathon-stage prototype focused on the AI's decision-making loop and the Turing tournament. The treasury layer is intentionally minimal — production-ready features are listed below.

Now
Notional rebalancing

executeAllocation() updates a target allocation variable, opens a tournament round, and logs reasoning on-chain. It does notswap underlying tokens. The treasury holds whatever assets users deposited; the AI's decision is measured against price moves of mETH and USDY but no actual swap is executed.

Why:rebalancing on a single round without slippage controls would be dangerous. Better to first prove the AI's allocation calls beat baseline (which the alpha stat does), then add execution.

Now
Per-user balance tracker (not shares)

userDeposits[address]is a single accumulator that doesn't distinguish mETH from USDY. The MVP is safe because TVL is small / zero, but in a multi-user mainnet deployment a depositor of mETH could in theory withdraw another user's USDY. Not exploited in the demo, but a known design gap.

Next
ERC-4626 share model + real swap execution

Replace the unified balance with shares minted at deposit and burned at withdraw, proportional to USD value of the treasury at the time. Every depositor owns a slice of the entire pool, regardless of asset composition. executeAllocation then routes a real swap via a DEX aggregator with slippage caps and a sanity check on price.

DEX reality check: we surveyed Merchant Moe V2 (router 0xeaEE...232a) for live mETH↔USDY routing. No direct pool. Multi-hop via USDC is technically possible but pool reserves are thin (mETH/USDC ≈ $6 TVL, USDC/USDY ≈ $22 TVL as of this run) — any meaningful swap would slip 30-50%. Real execution is gated less on our code and more on Mantle DEX liquidity maturity. Velora aggregator on mainnet is the production path; until then the tournament mechanism measures the AI's allocation quality on theoretical returns, which is what alpha tracking does.

Next
Real human-vote aggregation in settle

The auto-settle script currently passes a fixed 50% as the human aggregate when no voters showed up — which makes the "Human" column actually a 50/50 baseline. Once voting picks up we'll compute the reputation-weighted average of votes off-chain and pass that into settleRound. Until then the tournament UI labels it as "Baseline 50/50" for honesty.

Later
Hybrid AI / human steering

Right now humans only score against the AI. A future iteration feeds the reputation-weighted human consensus back into the next Claude call as a soft input, turning Mensa into a hybrid where the AI learns from voters who consistently outperform it.

Run locally

# Clone & install git clone https://github.com/obseasd/mensa cd mensa npm install --legacy-peer-deps # Run frontend npm run dev # http://localhost:3000 # Compile + test contracts cd contracts forge install forge test # Deploy to Mantle Mainnet PRIVATE_KEY=0x... forge script script/Deploy.s.sol:Deploy \ --rpc-url https://rpc.mantle.xyz --broadcast --legacy # Run a single agent cycle (or set up GH Actions cron) ANTHROPIC_API_KEY=sk-ant-... PRIVATE_KEY=0x... \ node scripts/agent-loop.mjs --once