morpho-org / morpho-optimizers

Core contracts of Morpho V1 Optimizers.
https://app.morpho.org
GNU Affero General Public License v3.0
137 stars 22 forks source link
blockchain decentralized defi finance

Morpho Optimizers V1

Morpho-Compound-Optimizer Morpho-AaveV2-Optimizer


What are Morpho Optimizers?

Morpho Optimizers improve the capital efficiency of positions on existing lending pools by seamlessly matching users peer-to-peer.

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


Contracts overview

Morpho Optimizers are designed at their core with a set of contracts delegating calls to implementation contracts (to overcome the contract size limit).

Here is a brief overview of the Morpho Optimizers' contracts interactions:

image

The main user's entry points are exposed in the Morpho contract. It inherits from MorphoGovernance, which contains all the admin functions of the DAO, MorphoUtils, and MorphoStorage, where the protocol's storage is located. This contract delegates call to other contracts that have the same storage layout:

It also interacts with RewardsManager, which manages the underlying pool's rewards, if any.


Documentation


Audits

All audits are stored in the audits' folder.


Bug bounty

A bug bounty is open on Immunefi. The rewards and scope are defined here. You can email security@morpho.org if you find something worrying.


Deployment Addresses

Morpho-Compound Optimizer on Ethereum

Morpho-AaveV2 Optimizer on Ethereum

Common Ethereum


Importing package

Using npm:

npm install @morpho-dao/morpho-v1

Using forge:

forge install @morpho-dao/morpho-v1@v2.0.0

Using git submodules:

git submodule add @morpho-dao/morpho-v1@v2.0.0 lib/morpho-v1

Testing with Foundry 🔨

Tests are run against a fork of real networks, allowing us to interact directly with Compound or Aave liquidity pools. Note that you need an RPC provider with access to Ethereum or Polygon.

For testing, make sure yarn and foundry are installed and install dependencies (node_modules, git submodules) with:

make install

Alternatively, if you only want to set up

Refer to the env.example for the required environment variable.

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

To run every test of a specific protocol (e.g. for the Morpho-Compound Optimizer):

make test PROTOCOL=compound

or to run only a specific set of tests of a specific protocol (e.g. for the Morpho-AaveV2 Optimizer):

make c-TestBorrow PROTOCOL=aave-v2

or to run an individual test of a specific protocol (e.g. for the Morpho-AaveV2 Optimizer):

make test-testBorrow1 PROTOCOL=aave-v2

For the other commands, check the Makefile.

If you want to call a custom forge command and not have to edit the Makefile, you can source the export_env.sh script by calling . ./export_env.sh.

:warning: The export_env.sh script exports environment variables in the current shell, meaning that subsequent calls to make or forge will use those variables. Variables defined in the .env.local file will still override those if you run make later. If you don't want to change variables in the current shell, you can always create a new shell in one of the following ways:


Testing with Hardhat

Only tests for the RewardsDistributor are run with Hardhat.

Just run:

yarn test

Test coverage

Test coverage is reported using foundry coverage with lcov report formatting (and optionally, genhtml transformer).

To generate the lcov report, run the following:

make coverage

The report is then usable either:

:warning: Test coverage is not available on the Morpho-AaveV2 Optimizer for this reason


Storage seatbelt

2 CI pipelines are currently running on every PR to check that the changes introduced are not modifying the storage layout of proxied smart contracts in an unsafe way:

In the case the storage layout snapshots checked by storage-layout.sh are not identical, the developer must commit the updated storage layout snapshot stored under snapshots/ by running:


Deployment & Upgrades

Network mode (default)

Run the Foundry deployment script with:

make script-Deploy PROTOCOL=compound NETWORK=goerli

Local mode

First start a local EVM:

make anvil NETWORK=goerli

Then run the Foundry deployment script in a separate shell, using SMODE=local:

make script-Deploy PROTOCOL=compound NETWORK=goerli SMODE=local

Questions & Feedback

For any questions or feedback, you can send an email to merlin@morpho.org.


Licensing

The code is under the GNU AFFERO GENERAL PUBLIC LICENSE v3.0, see LICENSE.