Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MorphoAdapter

Git Source

Inherits: ERC4626, Ownable2Step

Title: MorphoAdapter

ERC4626-compliant wrapper for Morpho Blue lending.

Interchangeable with other yield adapters. Only accepts deposits from SyntheticSplitter.

State Variables

MORPHO

Morpho Blue protocol contract.

IMorpho public immutable MORPHO

marketParams

Morpho market parameters for this adapter.

MarketParams public marketParams

MARKET_ID

Computed market ID (keccak256 of marketParams).

bytes32 public immutable MARKET_ID

SPLITTER

SyntheticSplitter authorized to deposit/withdraw.

address public immutable SPLITTER

urd

Universal Rewards Distributor for Morpho incentives.

address public urd

Functions

constructor

Deploys adapter with Morpho market configuration.

constructor(
    IERC20 _asset,
    address _morpho,
    MarketParams memory _marketParams,
    address _owner,
    address _splitter
) ERC4626(_asset) ERC20("Morpho Yield Wrapper", "myUSDC") Ownable(_owner);

Parameters

NameTypeDescription
_assetIERC20Underlying asset (USDC).
_morphoaddressMorpho Blue protocol address.
_marketParamsMarketParamsMarket parameters (must have loanToken == _asset).
_owneraddressAdmin address for rewards and rescue.
_splitteraddressSyntheticSplitter authorized to deposit.

totalAssets

Returns total USDC value of this adapter’s Morpho position.

function totalAssets() public view override returns (uint256);

Returns

NameTypeDescription
<none>uint256Total assets including accrued interest.

_deposit

Deposits assets to Morpho after ERC4626 share minting.

function _deposit(
    address caller,
    address receiver,
    uint256 assets,
    uint256 shares
) internal override;

Parameters

NameTypeDescription
calleraddressMust be SPLITTER.
receiveraddressReceiver of vault shares.
assetsuint256Amount of USDC to deposit.
sharesuint256Amount of vault shares minted.

_withdraw

Withdraws assets from Morpho before ERC4626 share burning.

function _withdraw(
    address caller,
    address receiver,
    address owner,
    uint256 assets,
    uint256 shares
) internal override;

Parameters

NameTypeDescription
calleraddressCaller requesting withdrawal.
receiveraddressReceiver of withdrawn assets.
owneraddressOwner of vault shares being burned.
assetsuint256Amount of USDC to withdraw.
sharesuint256Amount of vault shares burned.

_computeMarketId

Computes market ID from parameters (keccak256 hash).

function _computeMarketId(
    MarketParams memory params
) internal pure returns (bytes32);

Parameters

NameTypeDescription
paramsMarketParamsMarket parameters struct.

Returns

NameTypeDescription
<none>bytes32Market identifier used by Morpho.

_convertMorphoSharesToAssets

Converts Morpho supply shares to asset amount.

function _convertMorphoSharesToAssets(
    uint256 shares
) internal view returns (uint256);

Parameters

NameTypeDescription
sharesuint256Morpho supply shares.

Returns

NameTypeDescription
<none>uint256Equivalent asset amount.

rescueToken

Recovers stuck tokens (excluding the underlying asset).

function rescueToken(
    address token,
    address to
) external onlyOwner;

Parameters

NameTypeDescription
tokenaddressToken to rescue.
toaddressRecipient address.

setUrd

Sets the Universal Rewards Distributor address.

function setUrd(
    address _urd
) external onlyOwner;

Parameters

NameTypeDescription
_urdaddressURD contract address (cannot be zero).

claimRewards

Claims rewards and transfers to specified address.

function claimRewards(
    address reward,
    uint256 claimable,
    bytes32[] calldata proof,
    address to
) external onlyOwner returns (uint256 claimed);

Parameters

NameTypeDescription
rewardaddressReward token address.
claimableuint256Total claimable amount from merkle tree.
proofbytes32[]Merkle proof for claim.
toaddressRecipient of claimed rewards.

Returns

NameTypeDescription
claimeduint256Amount successfully claimed and transferred.

claimRewardsToSelf

Claims rewards to this contract for compounding.

function claimRewardsToSelf(
    address reward,
    uint256 claimable,
    bytes32[] calldata proof
) external onlyOwner returns (uint256 claimed);

Parameters

NameTypeDescription
rewardaddressReward token address.
claimableuint256Total claimable amount from merkle tree.
proofbytes32[]Merkle proof for claim.

Returns

NameTypeDescription
claimeduint256Amount successfully claimed.

Events

UrdUpdated

Emitted when URD address is updated.

event UrdUpdated(address indexed oldUrd, address indexed newUrd);

Errors

MorphoAdapter__OnlySplitter

Thrown when caller is not the SyntheticSplitter.

error MorphoAdapter__OnlySplitter();

MorphoAdapter__InvalidAddress

Thrown when a zero address is provided.

error MorphoAdapter__InvalidAddress();

MorphoAdapter__InvalidMarket

Thrown when market loan token doesn’t match asset.

error MorphoAdapter__InvalidMarket();

MorphoAdapter__CannotRescueUnderlying

Thrown when attempting to rescue the underlying asset.

error MorphoAdapter__CannotRescueUnderlying();