Morpho

Git Source

Inherits: IMorpho, MorphoGetters, MorphoSetters

Author: Morpho Labs

The main Morpho contract exposing all user entry points.

Functions

initialize

Initializes the contract.

function initialize(
    address addressesProvider,
    uint8 eModeCategoryId,
    address positionsManager,
    Types.Iterations memory defaultIterations
) external initializer;

Parameters

NameTypeDescription
addressesProvideraddressThe address of the pool addresses provider.
eModeCategoryIduint8The e-mode category of the deployed Morpho. 0 for the general mode.
positionsManageraddressThe address of the _positionsManager to set.
defaultIterationsTypes.IterationsThe _defaultIterations to set.

supply

Supplies amount of underlying on behalf of onBehalf. The supplied amount cannot be used as collateral but is eligible for the peer-to-peer matching.

function supply(address underlying, uint256 amount, address onBehalf, uint256 maxIterations)
    external
    returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to supply.
amountuint256The amount of underlying to supply.
onBehalfaddressThe address that will receive the supply position.
maxIterationsuint256The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations.

Returns

NameTypeDescription
<none>uint256The amount supplied (in underlying).

supplyWithPermit

Supplies amount of underlying of onBehalf using permit2 in a single tx. The supplied amount cannot be used as collateral but is eligible for the peer-to-peer matching.

function supplyWithPermit(
    address underlying,
    uint256 amount,
    address onBehalf,
    uint256 maxIterations,
    uint256 deadline,
    Types.Signature calldata signature
) external returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to supply.
amountuint256The amount of underlying to supply.
onBehalfaddressThe address that will receive the supply position.
maxIterationsuint256The maximum number of iterations allowed during the matching process.
deadlineuint256The deadline for the permit2 signature.
signatureTypes.SignatureThe permit2 signature.

Returns

NameTypeDescription
<none>uint256The amount supplied (in underlying).

supplyCollateral

Supplies amount of underlying collateral to the pool on behalf of onBehalf. The supplied amount cannot be matched peer-to-peer but can be used as collateral.

function supplyCollateral(address underlying, uint256 amount, address onBehalf) external returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to supply.
amountuint256The amount of underlying to supply.
onBehalfaddressThe address that will receive the collateral position.

Returns

NameTypeDescription
<none>uint256The collateral amount supplied (in underlying).

supplyCollateralWithPermit

Supplies amount of underlying collateral to the pool on behalf of onBehalf using permit2 in a single tx. The supplied amount cannot be matched peer-to-peer but can be used as collateral.

function supplyCollateralWithPermit(
    address underlying,
    uint256 amount,
    address onBehalf,
    uint256 deadline,
    Types.Signature calldata signature
) external returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to supply.
amountuint256The amount of underlying to supply.
onBehalfaddressThe address that will receive the collateral position.
deadlineuint256The deadline for the permit2 signature.
signatureTypes.SignatureThe permit2 signature.

Returns

NameTypeDescription
<none>uint256The collateral amount supplied (in underlying).

borrow

Borrows amount of underlying on behalf of onBehalf. If sender is not onBehalf, sender must have previously been approved by onBehalf using approveManager.

function borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
    external
    returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to borrow.
amountuint256The amount of underlying to borrow.
onBehalfaddressThe address that will receive the debt position.
receiveraddressThe address that will receive the borrowed funds.
maxIterationsuint256The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations.

Returns

NameTypeDescription
<none>uint256The amount borrowed (in underlying).

repay

Repays amount of underlying on behalf of onBehalf.

function repay(address underlying, uint256 amount, address onBehalf) external returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to borrow.
amountuint256The amount of underlying to repay.
onBehalfaddressThe address whose position will be repaid.

Returns

NameTypeDescription
<none>uint256The amount repaid (in underlying).

repayWithPermit

Repays amount of underlying on behalf of onBehalf using permit2 in a single tx.

When repaying all, one should pass type(uint160).max as amount because Permit2 does not support approvals larger than 160 bits.

function repayWithPermit(
    address underlying,
    uint256 amount,
    address onBehalf,
    uint256 deadline,
    Types.Signature calldata signature
) external returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to borrow.
amountuint256The amount of underlying to repay.
onBehalfaddressThe address whose position will be repaid.
deadlineuint256The deadline for the permit2 signature.
signatureTypes.SignatureThe permit2 signature.

Returns

NameTypeDescription
<none>uint256The amount repaid (in underlying).

withdraw

Withdraws amount of underlying on behalf of onBehalf. If sender is not onBehalf, sender must have previously been approved by onBehalf using approveManager.

function withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
    external
    returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to withdraw.
amountuint256The amount of underlying to withdraw.
onBehalfaddressThe address whose position will be withdrawn.
receiveraddressThe address that will receive the withdrawn funds.
maxIterationsuint256The maximum number of iterations allowed during the matching process. If it is less than _defaultIterations.withdraw, the latter will be used. Pass 0 to fallback to the _defaultIterations.withdraw.

Returns

NameTypeDescription
<none>uint256The amount withdrawn.

withdrawCollateral

Withdraws amount of underlying collateral on behalf of onBehalf. If sender is not onBehalf, sender must have previously been approved by onBehalf using approveManager.

function withdrawCollateral(address underlying, uint256 amount, address onBehalf, address receiver)
    external
    returns (uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to withdraw.
amountuint256The amount of underlying to withdraw.
onBehalfaddressThe address whose position will be withdrawn.
receiveraddressThe address that will receive the withdrawn funds.

Returns

NameTypeDescription
<none>uint256The collateral amount withdrawn (in underlying).

liquidate

Liquidates user.

function liquidate(address underlyingBorrowed, address underlyingCollateral, address user, uint256 amount)
    external
    returns (uint256, uint256);

Parameters

NameTypeDescription
underlyingBorrowedaddressThe address of the underlying borrowed to repay.
underlyingCollateraladdressThe address of the underlying collateral to seize.
useraddressThe address of the user to liquidate.
amountuint256The amount of underlyingBorrowed to repay.

Returns

NameTypeDescription
<none>uint256The underlyingBorrowed amount repaid (in underlying) and the underlyingCollateral amount seized (in underlying).
<none>uint256

approveManager

Approves a manager to borrow/withdraw on behalf of the sender.

function approveManager(address manager, bool isAllowed) external;

Parameters

NameTypeDescription
manageraddressThe address of the manager.
isAllowedboolWhether manager is allowed to manage msg.sender's position or not.

approveManagerWithSig

Approves a manager to manage the position of msg.sender using EIP712 signature in a single tx.

function approveManagerWithSig(
    address delegator,
    address manager,
    bool isAllowed,
    uint256 nonce,
    uint256 deadline,
    Types.Signature calldata signature
) external;

Parameters

NameTypeDescription
delegatoraddressThe address of the delegator.
manageraddressThe address of the manager.
isAllowedboolWhether manager is allowed to manage msg.sender's position or not.
nonceuint256The nonce of the signed message.
deadlineuint256The deadline of the signed message.
signatureTypes.SignatureThe signature of the message.

claimRewards

Claims rewards for the given assets.

function claimRewards(address[] calldata assets, address onBehalf)
    external
    returns (address[] memory rewardTokens, uint256[] memory claimedAmounts);

Parameters

NameTypeDescription
assetsaddress[]The assets to claim rewards from (aToken or variable debt token).
onBehalfaddressThe address for which rewards are claimed and sent to.

Returns

NameTypeDescription
rewardTokensaddress[]The addresses of each reward token.
claimedAmountsuint256[]The amount of rewards claimed (in reward tokens).

_supply

function _supply(address underlying, uint256 amount, address from, address onBehalf, uint256 maxIterations)
    internal
    returns (uint256);

_supplyCollateral

function _supplyCollateral(address underlying, uint256 amount, address from, address onBehalf)
    internal
    returns (uint256);

_borrow

function _borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
    internal
    returns (uint256);

_repay

function _repay(address underlying, uint256 amount, address from, address onBehalf) internal returns (uint256);

_withdraw

function _withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
    internal
    returns (uint256);

_withdrawCollateral

function _withdrawCollateral(address underlying, uint256 amount, address onBehalf, address receiver)
    internal
    returns (uint256);

_liquidate

function _liquidate(
    address underlyingBorrowed,
    address underlyingCollateral,
    uint256 amount,
    address borrower,
    address liquidator
) internal returns (uint256 repaid, uint256 seized);