Morpho Protocol
Overview
The Morpho protocol supports DeFi lending and borrowing by serving as an on-chain peer-to-peer layer atop protocols like Aave and Compound. By leveraging a matching process akin to an on-chain order book, Morpho optimizes rates for lenders and borrowers while maintaining underlying liquidity and risk parameters. In essence, Morpho acts as a lending pool optimizer, streamlining and enhancing the efficiency of DeFi operations.
The Nexera-Fi MorphoAdapter interacts with and utilizes the following four components of Morpho:
- Aave V2 Optimizer contract
- Compound V2 Optimizer contract
- Aave V3 Optimizer contract
- RewardsDistributor contract
In the following sections, we'll provide an overview of these contracts and their methods that Nexera-Fi MorphoAdapter interacts with.
Interactions with MorphoAdapter
The MorphoAdapter interacts with Morpho protocol by calling the methods presented in the diagram below. Each method serves a specific purpose within the Adapter, enabling strategies to seamlessly integrate liquidity provision, liquidity withdrawal, and borrowing/lending functionality via Morpho.
Aave V2 & Compound V2 Optimizers
Aave V2 and Compound V2 Morpho Optimizers enhance the capital efficiency of positions within established lending pools of the said underlying protocols. They form a peer-to-peer layer facilitating peer-to-peer matches between lenders and borrowers.
In the context of the Nexera-Fi MorphoAdapter, these six methods come into play:
Methods
supply
Supplies underlying tokens to a specific market.
This method is invoked by the following MorphoAdapter function:
This function invokes the supply
method of the Morpho Optimizer for either Aave V2 or Compound V2, based on
the underlying protocol specified in the encoded DepositExtraData.
withdraw
Withdraws underlying tokens from a specific market.
This method is invoked by the following MorphoAdapter function:
This function invokes the withdraw
method of the Morpho Optimizer for either Aave V2 or Compound V2, based on
the underlying protocol specified in the encoded WithdrawExtraData.
borrow
Borrows underlying tokens from a specific market.
This method is invoked by the following MorphoAdapter function:
This function invokes the borrow
method of the Morpho Optimizer for either Aave V2 or Compound V2, based on
the underlying protocol specified in the encoded OperateExtraData.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as BORROW.
repay
Repays the debt of the sender, up to the amount provided.
This method is invoked by the following MorphoAdapter function:
This function invokes the repay
method of the Morpho Optimizer for either Aave V2 or Compound V2, based on
the underlying protocol specified in the encoded OperateExtraData.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as REPAY.
liquidate
Liquidates a position.
This method is invoked by the following MorphoAdapter function:
This function invokes the liquidate
method of the Morpho Optimizer for either Aave V2 or Compound V2, based on
the underlying protocol specified in the encoded OperateExtraData.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as LIQUIDATE.
claimRewards
Claims rewards for the given assets.
Notes:
- Deprecated for Aave V2
- The incentives vault will never be implemented, thus second parameter of this function becomes useless
This method is invoked by the following MorphoAdapter function:
This function invokes the claimRewards
method of the Compound V2 Morpho Optimizer when
the underlying protocol specified in the encoded OperateExtraData is Compound V2.
It is triggered within the context of the Adapter's _collect function when CollectOperation is configured as CLAIM_PROTOCOL_REWARDS.
Aave V3 Optimizer
Aave V3 Morpho Optimizer enhances the capital efficiency of positions within established Aave V3 lending pools by facilitating peer-to-peer matches between lenders and borrowers.
In the context of the Nexera-Fi MorphoAdapter, these eight methods come into play:
Methods
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.
This method is invoked by the following MorphoAdapter function:
This function invokes the supply
method of the Aave V3 Morpho Optimizer when
the underlying protocol specified in the encoded DepositExtraData is Aave V3.
The Adapter's address is provided as onBehalf
parameter and the AAVE_V3_SUPPLY_MAX_ITERATIONS value is provided as maxIterations
.
withdraw
Withdraws amount
of underlying
on behalf of onBehalf
.
This method is invoked by the following MorphoAdapter function:
This function invokes the withdraw
method of the Aave V3 Morpho Optimizer when
the underlying protocol specified in the encoded WithdrawExtraData is Aave V3.
The Adapter's address is provided as onBehalf
and receiver
parameters and the AAVE_V3_WITHDRAW_MAX_ITERATIONS value is provided as maxIterations
.
borrow
Borrows amount
of underlying
on behalf of onBehalf
.
This method is invoked by the following MorphoAdapter function:
This function invokes the borrow
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as BORROW, and
the underlying protocol specified in the encoded OperateExtraData is Aave V3.
The Adapter's address is provided as onBehalf
and receiver
parameters and the AAVE_V3_BORROW_MAX_ITERATIONS value is provided as maxIterations
.
repay
Repays amount
of underlying
on behalf of onBehalf
.
This method is invoked by the following MorphoAdapter function:
This function invokes the repay
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as REPAY, and
the underlying protocol specified in the encoded OperateExtraData is Aave V3.
The Adapter's address is provided as onBehalf
parameter.
liquidate
Liquidates user
.
This method is invoked by the following MorphoAdapter function:
This function invokes the liquidate
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as LIQUIDATE, and
the underlying protocol specified in the encoded OperateExtraData is Aave V3.
claimRewards
Claims rewards for the given assets.
This method is invoked by the following MorphoAdapter function:
This function invokes the claimRewards
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _collect function when CollectOperation is configured as CLAIM_PROTOCOL_REWARDS, and
the underlying protocol specified in the encoded CollectExtraData is Aave V3.
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.
This method is invoked by the following MorphoAdapter function:
This function invokes the supplyCollateral
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as SUPPLY_COLLATERAL, and
the underlying protocol specified in the encoded OperateExtraData is Aave V3.
withdrawCollateral
Withdraws amount
of underlying
collateral on behalf of onBehalf
This method is invoked by the following MorphoAdapter function:
This function invokes the withdrawCollateral
method of the Aave V3 Morpho Optimizer.
It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as WITHDRAW_COLLATERAL, and
the underlying protocol specified in the encoded OperateExtraData is Aave V3.
RewardsDistributor
This contract allows Morpho users to claim their rewards. The rewards are in the form of MORPHO governance token.
Methods
claim
Claims MORPHO rewards for _account
, involving an overall _claimable
amount and the inclusion of a merkle proof validating the claim.
This method is invoked by the following MorphoAdapter function:
This function invokes the claim
method of the Morpho RewardsDistributor contract.
It is triggered within the context of the Adapter's _collect function when CollectOperation is configured as CLAIM_MORPHO_REWARDS.
Please note: For detailed information about Morpho protocol, consult the official Morpho documentation.