morpho-v1-deprecated icon indicating copy to clipboard operation
morpho-v1-deprecated copied to clipboard

Core contracts of Morpho's protocol V1.

Morpho Core Protocol V1

What is Morpho?

Morpho is a lending pool optimizer: it improves the capital efficiency of positions on existing lending pools by seamlessly matching users peer-to-peer.

  • Morpho's rates stay between the supply rate and the borrow rate of the pool, reducing the interests paid by the borrowers while increasing the interests earned by the suppliers. It means that you are getting boosted peer-to-peer rates or, in the worst case scenario, the APY of the pool.
  • Morpho also preserves the same experience, the same liquidity and the same parameters (collateral factors, oracles, …) as the underlying pool.

TL;DR: Instead of borrowing or lending on your favorite pool like Compound or Aave, you would be better off using Morpho-Compound or Morpho-Aave directly.

Contracts overview

Morpho protocol is designed at its core with a set of contracts acting as a proxy and communicating with upgradeable pieces of logic via calls (to implementation contracts) and delegate calls (to delegation contracts). Here is a brief overview of the Morpho protocol's contracts interactions:

image

The protocol's storage, located at Morpho's main proxy contract, is defined in the MorphoStorage contract and is used by every delegation contract. Having this overview in mind, Morpho contracts typically fall under the following 4 main categories:

  • Core features (supply, borrow, withdraw, repay, liquidate)
  • Underlying logic (peer-to-peer matching, positions management)
  • Peripheral contracts (lending/borrowing incentives, underlying protocol rewards management)
  • Miscellaneous (maths, solidity calls, types)

Documentation

Bug bounty

A bug bounty is open on Immunefi. The rewards and scope are defined here. You can also send an email to [email protected] if you find something worrying.

Morpho-Compound on Ethereum

Morpho-Aave on Ethereum

Common contracts on Ethereum

Licensing

The code is under the GNU General Public License v3.0 license, see LICENSE.

Setup & Testing

First, you must install dependencies with:

yarn

To conduct test or deploy contracts you must create an environment file named .env.local and fill the environment variables.

cp .env.example .env.local

For the RPC endpoint you can choose your preferred one (do not forget to update the Makefile or hardhat.config.js accordingly). DEPLOYER_PRIVATE_KEY is only required to deploy contracts.

Testing with Foundry

Tests are run against a fork of the Ethereum mainnet, which allows us to interact directly with Compound.

You must install Foundry. Run the command below to get foundryup, the Foundry toolchain installer:

curl -L https://foundry.paradigm.xyz | bash

If you do not want to use the redirect, feel free to manually download the foundryup installation script from here.

Then in a new terminal session or after reloading your PATH, run it to get the latest forge version:

foundryup

Finally, update git submodules:

git submodule init
git submodule update

To run tests on different platforms, navigate a Unix terminal to the root folder of the project and run the command of your choice.

To run every tests:

make test-compound

or to run only the desired test contract:

make c-{TestContractName}
make c-TestBorrow
make c-TestGovernance
...

or to run individual tests:

make s-{testFunctionName}
make s-testSupply1
make s-testSupply2
...

For the other commands, check the Makefile.

Testing with hardhat

Some hardhat tests are also present on this repository (testing of the IncentivesVault contract). You just need to run:

yarn test

For the other commands, check the package.json file.

Questions & Feedback

For any question or feedback you can send an email to [email protected].