๐Ÿ—๏ธ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          liquidateBorrow

All user-facing operations (supply, borrow, repay, withdraw, liquidate) go through mToken contracts. The Comptroller enforces collateral requirements and risk limits behind the scenes.

Components

Component
Purpose

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

Goal
Start here

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 uint without 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