Morpho
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
Name | Type | Description |
---|---|---|
addressesProvider | address | The address of the pool addresses provider. |
eModeCategoryId | uint8 | The e-mode category of the deployed Morpho. 0 for the general mode. |
positionsManager | address | The address of the _positionsManager to set. |
defaultIterations | Types.Iterations | The _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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to supply. |
amount | uint256 | The amount of underlying to supply. |
onBehalf | address | The address that will receive the supply position. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to supply. |
amount | uint256 | The amount of underlying to supply. |
onBehalf | address | The address that will receive the supply position. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. |
deadline | uint256 | The deadline for the permit2 signature. |
signature | Types.Signature | The permit2 signature. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to supply. |
amount | uint256 | The amount of underlying to supply. |
onBehalf | address | The address that will receive the collateral position. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to supply. |
amount | uint256 | The amount of underlying to supply. |
onBehalf | address | The address that will receive the collateral position. |
deadline | uint256 | The deadline for the permit2 signature. |
signature | Types.Signature | The permit2 signature. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to borrow. |
amount | uint256 | The amount of underlying to borrow. |
onBehalf | address | The address that will receive the debt position. |
receiver | address | The address that will receive the borrowed funds. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to borrow. |
amount | uint256 | The amount of underlying to repay. |
onBehalf | address | The address whose position will be repaid. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to borrow. |
amount | uint256 | The amount of underlying to repay. |
onBehalf | address | The address whose position will be repaid. |
deadline | uint256 | The deadline for the permit2 signature. |
signature | Types.Signature | The permit2 signature. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to withdraw. |
amount | uint256 | The amount of underlying to withdraw. |
onBehalf | address | The address whose position will be withdrawn. |
receiver | address | The address that will receive the withdrawn funds. |
maxIterations | uint256 | The 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
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
underlying | address | The address of the underlying asset to withdraw. |
amount | uint256 | The amount of underlying to withdraw. |
onBehalf | address | The address whose position will be withdrawn. |
receiver | address | The address that will receive the withdrawn funds. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The collateral amount withdrawn (in underlying). |
liquidate
Liquidates user
.
function liquidate(address underlyingBorrowed, address underlyingCollateral, address user, uint256 amount)
external
returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
underlyingBorrowed | address | The address of the underlying borrowed to repay. |
underlyingCollateral | address | The address of the underlying collateral to seize. |
user | address | The address of the user to liquidate. |
amount | uint256 | The amount of underlyingBorrowed to repay. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
manager | address | The address of the manager. |
isAllowed | bool | Whether 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
Name | Type | Description |
---|---|---|
delegator | address | The address of the delegator. |
manager | address | The address of the manager. |
isAllowed | bool | Whether manager is allowed to manage msg.sender 's position or not. |
nonce | uint256 | The nonce of the signed message. |
deadline | uint256 | The deadline of the signed message. |
signature | Types.Signature | The 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
Name | Type | Description |
---|---|---|
assets | address[] | The assets to claim rewards from (aToken or variable debt token). |
onBehalf | address | The address for which rewards are claimed and sent to. |
Returns
Name | Type | Description |
---|---|---|
rewardTokens | address[] | The addresses of each reward token. |
claimedAmounts | uint256[] | 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);