Technically, Morpho Blue is a single
contract holding all the markets and providing all the necessary functions. The first stop is the
Market struct, which contains information about a particular market: total amounts of supply/borrow assets, borrow/supply shares, fees, and the last timestamp update. Market
parameters include addresses of collateral/debt tokens the Interest Rate Model (IRM) as a contract address, the price oracle (also as an address), and the LLTV.
The creation of a new market (function
createMarket()) is straightforward. It's one of the few places where the governance intervenes, ensuring that the market being created uses an "enabled" (by governance) interest rate model (IRM) and LLTV. Another governance setup function is the
setFee() function, which sets a new market fee and assigns a new fee
recipient.
It’s important to mention the set of requirements for used tokens, IRMs and LLTVs, as described by Morpho Blue's team to ensure that the created market is "healthy," with no issues in the calculation of token amounts, and to maintain protocol liveness. Described
here. These guidelines are valuable for any DeFi project, as rebaseable tokens, tokens with on-transfer fees or non-standard reverts, and similar "balance modifying/locking" features are always tricky and often pose problems for the protocols' security and liveness.
All functions providing
supply/
withdraw/
borrow/
repay operations in Morpho Blue accept
assets or
shares as parameters, allowing users to choose the most convenient parameters (tokens or shares) and simplify interaction with protocols built around Morpho Blue, such as vaults or liquidity management projects.
All these functions (including liquidations) accrue market interest at the beginning of the operations. The
_accrueInterest() function is present everywhere and even has a separate external
accrueInterest() function that can be called directly. The procedure for accruing interest is very clear, increasing both
totalBorrowAssets and
totalSupplyAssets at the rate
returned by the interest rate model (IRM). The conversion to the absolute amount of accrued interest is handled by the
wTaylorCompounded(x,n) function, which uses the first three non-zero terms of a Taylor expansion of
eⁿˣ
−1. This approach approximates accrued interest with minimal computations (a good point for DeFi developers). The market fees are
collected in shares, not in supply/borrow tokens.
After applying the interest rate, all
supply/
withdraw/
borrow/
repay functions perform similar actions: calculate shares amounts, update the address' position's shares/assets amounts in the current market, update the totalSupply of shares and assets, call the user provided callback function, and perform the standard ERC20 transfer/transferFrom operations. A straightforward flow with no DeFi surprises. Users' borrowing positions are represented by the
Position struct, which contains the amounts of supply/borrows shares and the direct amount of the user's collateral.
Most of the operations mentioned above in Morpho Blue can be delegated to another address. So, almost every method performing supply/withdraw/borrow/repay includes an
address onBehalf parameter, allowing these operations to be carried out on behalf of other addresses.
Additionally, Morpho Blue has a flashloan capability, implemented in the really compact
flashloan() function. There are no fees, and flashloans in Morpho Blue are completely free.