🏗️Moonwell Core
Moonwell Core is a Compound V2-compatible lending protocol deployed on Base and OP Mainnet. Developers interact with two main contracts: mTokens (market-level supply, borrow, repay, liquidate) and the Comptroller (collateral management, account health, risk parameters).
Architecture
┌──────────────────────────────────────────────────────┐
│ Comptroller │
│ Policy layer - collateral, health checks, rewards │
└──────────┬────────────────────────────┬──────────────┘
│ │
┌─────▼──────┐ ┌──────▼───────┐
│ mToken A │ │ mToken B │
│ (e.g. │ │ (e.g. │
│ mUSDC) │ │ mWETH) │
└────────────┘ └──────────────┘
mint / redeem borrow / repay
supply / withdraw liquidateBorrowAll user-facing operations (supply, borrow, repay, withdraw, liquidate) go through mToken contracts. The Comptroller enforces collateral requirements and risk limits behind the scenes.
Components
Market contracts - supply, borrow, repay, withdraw, liquidate
Policy layer - collateral, health checks, risk parameters, rewards
Oracle wrappers - early price access for liquidations
ERC-4626 wrappers around mToken markets
Where to Start
Integrate Moonwell lending markets
Build a yield product on top of Moonwell
Build an OEV liquidation bot
Full mToken function reference
mTokens - mint(), redeem(), borrow(), liquidateBorrow()
Full Comptroller function reference
Comptroller - enterMarkets(), getAccountLiquidity(), claimReward()
Understand risk controls
OEV mechanism details
OEV - updatePriceEarlyAndLiquidate()
Key Patterns
Error handling - mToken and Comptroller functions use two failure modes:
Error codes - Business logic failures return a non-zero
uintwithout reverting. Always check the return value.Reverts - Transfer failures, math overflows, and pause/cap enforcement revert the transaction.
Interest accrual - Interest accrues per-second (not per-block). The exchange rate between mTokens and underlying grows automatically as interest accrues.
Collateral flow - Supply → enterMarkets() → Borrow. You must explicitly enable an asset as collateral before borrowing against it.
For step-by-step integration walkthroughs, see the Guides.
Last updated

