A router holds 60 USDC and calls Morpho Blue’s supply with the user as onBehalf. With the underlying allowance in place, the 60 leaves the router and the user receives an internal supply-share balance in that market. If the router later tries to withdraw for the user, Morpho checks whether the user authorized it. The router’s earlier payment grants it no withdrawal authority.
Send the same 60 through a MetaMorpho V1 vault instead. With deposit(60 USDC, user), the router pays and the user receives transferable vault shares. For the router to redeem those shares later on the user’s behalf, it needs a vault-share allowance. An underlying-token approval, Blue delegation and a vault-share allowance live in three different places. The distinction matters most when the payer, position owner and final recipient are different addresses. Morpho Blue implementation · ERC-4626 entry and exit interfaces
Morpho Core Protocol Integration#
1. Closing positions without dust#
Some older Morpho integration guidance uses a maximum-value sentinel to close a position. The exact ABI determines how to express a full exit.
In Morpho Blue, all four position functions (supply, withdraw, borrow, repay) require exactly one of assets or shares to be zero (exactlyOneZero(assets, shares)). Morpho Blue does not special-case type(uint256).max as "withdraw/repay everything" — if you pass type(uint256).max as shares, the subsequent position[id][onBehalf].supplyShares -= shares will underflow and revert because no one holds that many shares.
Instead, close positions by passing the exact share balance (i.e., use the shares input with assets = 0). The interface documents this for both withdraw and repay in morpho-blue/src/interfaces/IMorpho.sol:
// For withdraw:
/// @dev It is advised to use the `shares` input when withdrawing the full position to avoid reverts due to
/// conversion roundings between shares and assets.
// For repay:
/// @dev It is advised to use the `shares` input when repaying the full position to avoid reverts due to conversion
/// roundings between shares and assets.2. Internal positions and transferable vault shares#
If you call Morpho.supply() directly, the position is linked to your address and cannot be split into transferable pieces. If you use a Morpho vault instead, the position is represented as vault shares, so it can be split into arbitrary amounts and transferred.
3. Supplying on behalf of another address#
function supply(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
bytes calldata data
) external returns (uint256, uint256) {...}In Morpho, onBehalf means “whose position in Morpho’s storage gets updated,” not “who pays the tokens.” When you call supply(marketParams, assets, shares, onBehalf, data), Morpho computes the number of supply shares and then credits position[id][onBehalf].supplyShares += shares. That’s the only place ownership is tracked—Morpho doesn’t mint a receipt token. The important part is that the ERC20 transfer is taken from the caller: it executes IERC20(marketParams.loanToken).safeTransferFrom(msg.sender, address(this), assets). So a third party can pay the loan token and still credit supply shares to someone else by choosing onBehalf accordingly.
Withdrawals are different because they move assets out of Morpho, so they’re permissioned. In withdraw(marketParams, assets, shares, onBehalf, receiver), Morpho first checks _isSenderAuthorized(onBehalf). That helper returns true only if msg.sender == onBehalf or if isAuthorized[onBehalf][msg.sender] is set. If the check passes, Morpho debits the shares from the onBehalf account (position[id][onBehalf].supplyShares -= shares) and transfers the underlying loan token to receiver via safeTransfer. So if Alice supplied “on behalf of Bob,” the shares belong to Bob and only Bob (or someone Bob authorized) can withdraw them; Alice can’t later pull the assets back unless Bob explicitly authorizes her.
Morpho ERC4626 Vaults (MetaMorpho) Integration#
Vaults only pipe assets into Morpho#
A MetaMorpho vault does not have a strategy engine. It holds one ERC20 asset() and, when it wants to deploy or free liquidity, it only interacts with Morpho markets by supplying and withdrawing that same asset.
For an integration, this matters because you should not assume the vault can rebalance through swaps or sell other positions to satisfy withdrawals. If Morpho markets in the withdrawal queue are illiquid (high utilization), the vault can be temporarily unable to source enough cash, and withdrawals may revert with NotEnoughLiquidity. Your product should treat the vault as “Morpho lending exposure,” not as an AMM/LP/leveraged strategy.
It also changes what to review from a security perspective. Since the vault’s core external calls are Morpho and ERC20 transfers/approvals (not arbitrary routers/bridges), the big integration risks tend to be configuration and market risk: which markets are in the queues, how caps are set, and what the underlying Morpho market parameters are (oracle, LLTV, IRM).
Concretely, deposits route through _supplyMorpho(), which iterates supplyQueue and only calls MORPHO.supply():
function _supplyMorpho(uint256 assets) internal {
for (uint256 i; i < supplyQueue.length; ++i) {
Id id = supplyQueue[i];
uint256 supplyCap = config[id].cap;
if (supplyCap == 0) continue;
MarketParams memory marketParams = _marketParams(id);
MORPHO.accrueInterest(marketParams);
Market memory market = MORPHO.market(id);
uint256 supplyShares = MORPHO.supplyShares(id, address(this));
uint256 supplyAssets = supplyShares.toAssetsUp(market.totalSupplyAssets, market.totalSupplyShares);
uint256 toSupply = UtilsLib.min(supplyCap.zeroFloorSub(supplyAssets), assets);
if (toSupply > 0) {
try MORPHO.supply(marketParams, toSupply, 0, address(this), hex"") {
assets -= toSupply;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.AllCapsReached();
}Withdrawals similarly go through _withdrawMorpho(), which iterates withdrawQueue and only calls MORPHO.withdraw(), bounded by available liquidity:
function _withdrawMorpho(uint256 assets) internal {
for (uint256 i; i < withdrawQueue.length; ++i) {
Id id = withdrawQueue[i];
MarketParams memory marketParams = _marketParams(id);
(uint256 supplyAssets,, Market memory market) = _accruedSupplyBalance(marketParams, id);
uint256 toWithdraw = UtilsLib.min(
_withdrawable(marketParams, market.totalSupplyAssets, market.totalBorrowAssets, supplyAssets), assets
);
if (toWithdraw > 0) {
try MORPHO.withdraw(marketParams, toWithdraw, 0, address(this), address(this)) {
assets -= toWithdraw;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.NotEnoughLiquidity();
}Handle ERC4626 receiver vs owner carefully#
ERC4626 intentionally separates “where value goes” from “whose shares are being spent”. That flexibility is useful for managed accounts, vault wrappers, and routers — but it also makes it easy to accidentally point one of the addresses at the wrong party.
// ERC4626.sol
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual {
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
_burn(owner, shares);
_transferOut(receiver, assets);
}This separation has two important integration consequences.
First, you only get “withdraw on behalf of someone else” if the share owner (owner) previously approved the caller for at least shares. If you pass owner = user but your integration contract is the caller, the call will revert unless the user approved your contract’s share allowance.
Second, splitting receiver from owner is a footgun: it is valid to burn Alice’s shares (owner = Alice) and pay Bob (receiver = Bob). That is sometimes intended (explicit payout address, debt repayment, etc.), but it should never happen accidentally.
On the way in, the analogous pitfall is deposit(assets, receiver) / mint(shares, receiver): the depositor provides assets, but the share owner after the call is receiver. Accidentally setting receiver to a router / operator / vault address means the user paid, but someone else owns the shares.
For a user redeeming their own shares to their own wallet, the receiver and owner are the same address. For a router handling a payout to another address, check the share owner’s approval and the chosen asset recipient separately.
Where a reward payment goes#
Campaign rewards have their own eligibility and distribution rules. A supply, loan or collateral balance alone does not guarantee a reward. If a campaign accrues to an integration contract, identify the beneficiary recorded by the distributor and the destination of the claim. Then check who can move those tokens on behalf of the intended recipients. Keep the reward balance separate from the assets already owed to vault shareholders. Morpho rewards documentation
A separate case for legacy Morpho-Compound#
The historical checklist also covered Compound v2. The cETH market accepts native ETH, whereas cUSDC pulls an ERC-20 underlying. cETH contract · cUSDC contract
This item is relevant when your integration touches Morpho's legacy Compound optimizer flavor (Morpho-Compound). You only need to care about cETH if your integration (contract or off-chain code) is interacting with Compound markets where the underlying is native ETH, i.e. the market's cToken is cETH. Typical scenarios:
- Your contract integrates Morpho’s Compound flavor and ends up needing to interact with the underlying cToken (directly or via a “Lens”/market-discovery layer) to:
- detect the underlying asset (
underlying()), or - supply/repay/borrow/redeem through cTokens in some path, or
- do routing/quoting that assumes “every cToken has an underlying ERC20”.
- detect the underlying asset (
- Any generic code that treats all cTokens uniformly (calls
underlying(), usesIERC20approvals, assumes non-payablemint/repay) will break on cETH because:- cETH has no
underlying()(it’s ETH), mint/repayBorroware payable and require the amount asmsg.value,- withdrawals/redemptions send native ETH, so the receiver contract must be able to accept ETH.
- cETH has no
Worth sharing?
Send this analysis to another reviewer.
