Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit 8669ade

Browse files
Merge pull request #1257 from morpho-dao/dev
Dev
2 parents 2c134d1 + 02f1a5b commit 8669ade

50 files changed

Lines changed: 3353 additions & 676 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,49 @@ NETWORK?=eth-mainnet
88
FOUNDRY_SRC=contracts/${PROTOCOL}/
99
FOUNDRY_TEST=test-foundry/${PROTOCOL}/
1010
FOUNDRY_REMAPPINGS=@config/=config/${NETWORK}/${PROTOCOL}/
11-
FOUNDRY_ETH_RPC_URL?=https://${NETWORK}.g.alchemy.com/v2/${ALCHEMY_KEY}
11+
1212
FOUNDRY_PRIVATE_KEY?=${DEPLOYER_PRIVATE_KEY}
1313

14-
ifeq (${NETWORK}, eth-mainnet)
15-
FOUNDRY_CHAIN_ID=1
16-
FOUNDRY_FORK_BLOCK_NUMBER=14292587
17-
endif
14+
ifdef FOUNDRY_ETH_RPC_URL
15+
FOUNDRY_TEST=test-foundry/prod/${PROTOCOL}/
16+
FOUNDRY_FUZZ_RUNS=4096
17+
FOUNDRY_FUZZ_MAX_LOCAL_REJECTS=16384
18+
FOUNDRY_FUZZ_MAX_GLOBAL_REJECTS=1048576
19+
else
20+
FOUNDRY_ETH_RPC_URL=https://${NETWORK}.g.alchemy.com/v2/${ALCHEMY_KEY}
1821

19-
ifeq (${NETWORK}, eth-ropsten)
20-
FOUNDRY_CHAIN_ID=3
21-
endif
22+
ifeq (${NETWORK}, eth-mainnet)
23+
FOUNDRY_CHAIN_ID=1
24+
FOUNDRY_FORK_BLOCK_NUMBER?=14292587
25+
endif
2226

23-
ifeq (${NETWORK}, eth-goerli)
24-
FOUNDRY_CHAIN_ID=5
25-
endif
27+
ifeq (${NETWORK}, eth-ropsten)
28+
FOUNDRY_CHAIN_ID=3
29+
endif
2630

27-
ifeq (${NETWORK}, polygon-mainnet)
28-
FOUNDRY_CHAIN_ID=137
29-
FOUNDRY_FORK_BLOCK_NUMBER=22116728
31+
ifeq (${NETWORK}, eth-goerli)
32+
FOUNDRY_CHAIN_ID=5
33+
endif
3034

31-
ifeq (${PROTOCOL}, aave-v3)
32-
FOUNDRY_FORK_BLOCK_NUMBER=29116728
33-
FOUNDRY_CONTRACT_PATTERN_INVERSE=(Fees|IncentivesVault|Rewards)
35+
ifeq (${NETWORK}, polygon-mainnet)
36+
ifeq (${PROTOCOL}, aave-v3)
37+
FOUNDRY_FORK_BLOCK_NUMBER?=29116728
38+
FOUNDRY_CONTRACT_PATTERN_INVERSE=(Fees|IncentivesVault|Rewards)
39+
endif
40+
41+
FOUNDRY_CHAIN_ID=137
42+
FOUNDRY_FORK_BLOCK_NUMBER?=22116728
3443
endif
35-
endif
3644

37-
ifeq (${NETWORK}, avalanche-mainnet)
38-
FOUNDRY_CHAIN_ID=43114
39-
FOUNDRY_ETH_RPC_URL=https://api.avax.network/ext/bc/C/rpc
40-
FOUNDRY_FORK_BLOCK_NUMBER=12675271
45+
ifeq (${NETWORK}, avalanche-mainnet)
46+
ifeq (${PROTOCOL}, aave-v3)
47+
FOUNDRY_FORK_BLOCK_NUMBER?=15675271
48+
endif
4149

42-
ifeq (${PROTOCOL}, aave-v3)
43-
FOUNDRY_FORK_BLOCK_NUMBER=15675271
50+
FOUNDRY_CHAIN_ID=43114
51+
FOUNDRY_ETH_RPC_URL=https://api.avax.network/ext/bc/C/rpc
52+
FOUNDRY_FORK_BLOCK_NUMBER?=12675271
4453
endif
45-
else
4654
endif
4755

4856
ifeq (${SMODE}, local)
@@ -70,44 +78,44 @@ create-market:
7078
./scripts/${PROTOCOL}/create-market.sh
7179

7280
anvil:
73-
@echo Starting fork of ${NETWORK}
74-
@anvil --fork-url ${FOUNDRY_ETH_RPC_URL}
81+
@echo Starting fork of ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
82+
@anvil --fork-url ${FOUNDRY_ETH_RPC_URL} --fork-block-number ${FOUNDRY_FORK_BLOCK_NUMBER}
7583

7684
script-%:
7785
@echo Running script $* of ${PROTOCOL} on ${NETWORK} with script mode: ${SMODE}
7886
@forge script scripts/${PROTOCOL}/$*.s.sol:$* --broadcast -vvvv
7987

8088
test:
81-
@echo Running all ${PROTOCOL} tests on ${NETWORK}
89+
@echo Running all ${PROTOCOL} tests on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
8290
@forge test -vv | tee trace.ansi
8391

8492
coverage:
85-
@echo Create coverage report for ${PROTOCOL} tests on ${NETWORK}
93+
@echo Create coverage report for ${PROTOCOL} tests on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
8694
@forge coverage
8795

8896
coverage-lcov:
89-
@echo Create coverage lcov for ${PROTOCOL} tests on ${NETWORK}
97+
@echo Create coverage lcov for ${PROTOCOL} tests on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
9098
@forge coverage --report lcov
9199

92100
fuzz:
93101
$(eval FOUNDRY_TEST=test-foundry/fuzzing/${PROTOCOL}/)
94-
@echo Running all ${PROTOCOL} fuzzing tests on ${NETWORK}
102+
@echo Running all ${PROTOCOL} fuzzing tests on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
95103
@forge test -vv
96104

97105
gas-report:
98-
@echo Creating gas report for ${PROTOCOL} on ${NETWORK}
106+
@echo Creating gas report for ${PROTOCOL} on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
99107
@forge test --gas-report
100108

101109
test-common:
102110
@echo Running all common tests on ${NETWORK}
103111
@FOUNDRY_TEST=test-foundry/common forge test -vvv
104112

105113
contract-% c-%:
106-
@echo Running tests for contract $* of ${PROTOCOL} on ${NETWORK}
114+
@echo Running tests for contract $* of ${PROTOCOL} on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
107115
@forge test -vvv --match-contract $* | tee trace.ansi
108116

109117
single-% s-%:
110-
@echo Running single test $* of ${PROTOCOL} on ${NETWORK}
118+
@echo Running single test $* of ${PROTOCOL} on ${NETWORK} at block ${FOUNDRY_FORK_BLOCK_NUMBER}
111119
@forge test -vvv --match-test $* | tee trace.ansi
112120

113121
storage-layout-generate:

README.md

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,91 @@
1-
# Morpho Protocol V1 🦋
1+
# Morpho Core Protocol V1
22

33
[![Test](https://github.com/morpho-labs/morpho-contracts/actions/workflows/ci-foundry.yml/badge.svg)](https://github.com/morpho-labs/morpho-contracts/actions/workflows/ci-foundry.yml)
44

5-
This repository contains the core smart contracts for the Morpho Protocol V1 🦋.
5+
<picture>
6+
<source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/uLq5V14.png">
7+
<img alt="" src="https://i.imgur.com/ZiL1Lr2.png">
8+
</picture>
9+
10+
---
11+
12+
## What is Morpho?
13+
14+
Morpho is a lending pool optimizer: it improves the capital efficiency of positions on existing lending pools by seamlessly matching users peer-to-peer.
15+
16+
- 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.
17+
- Morpho also preserves the same experience, the same liquidity and the same parameters (collateral factors, oracles, …) as the underlying pool.
18+
19+
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.
20+
21+
---
22+
23+
## Contracts overview
24+
25+
In this repository.
26+
27+
The Morpho protocol is designed at its core with a set of contracts delegating calls to implementation contracts (to overcome the contract size limit).
28+
29+
Here is a brief overview of the Morpho protocol's contracts interactions:
30+
31+
![image](https://user-images.githubusercontent.com/3147812/187162991-d9e94841-0f23-4f25-86d4-a495917b70e7.png)
32+
33+
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 exact same storage layout:
34+
35+
- `PositionsManager`: logic of basic supply, borrow, withdraw, repay and liquidate functions. In Morpho-Aave, it is separated into two contracts, `EntryPositionsManager` and `ExitPositionsManager`. These contracts inherit from `MatchingEngine`, which contains the matching engine internal functions.
36+
- `InterestRatesManager`: logic of indexes computation.
37+
38+
It also interacts with `RewardsManager`, which manages the underlying pool's rewards if any.
39+
40+
---
41+
42+
## Documentation
43+
44+
- [White Paper](https://whitepaper.morpho.xyz)
45+
- [Morpho Documentation](https://docs.morpho.xyz)
46+
- Yellow Paper (coming soon)
47+
48+
---
49+
50+
## Audits
51+
52+
All audits are stored in the [audits](./audits/)' folder.
53+
54+
---
55+
56+
## Bug bounty
57+
58+
A bug bounty is open on Immunefi. The rewards and scope are defined [here](https://immunefi.com/bounty/morpho/).
59+
You can also send an email to [security@morpho.xyz](mailto:security@morpho.xyz) if you find something worrying.
60+
61+
---
62+
63+
## Deployment Addresses
64+
65+
### Morpho-Compound Ethereum
66+
67+
- Morpho Proxy: [0x8888882f8f843896699869179fb6e4f7e3b58888](https://etherscan.io/address/0x8888882f8f843896699869179fb6e4f7e3b58888)
68+
- Morpho Implementation: [0xf29cc0319679b54bd25a8666fc0830b023c6a272](https://etherscan.io/address/0xf29cc0319679b54bd25a8666fc0830b023c6a272)
69+
- PositionsManager: [0x082bf6702e718483c85423bd279088c215a21302](https://etherscan.io/address/0x082bf6702e718483c85423bd279088c215a21302)
70+
- InterestRatesManager: [0x2f2d51f4d68a96859d4f69672cbeefd854bd8289](https://etherscan.io/address/0x2f2d51f4d68a96859d4f69672cbeefd854bd8289)
71+
- RewardsManager Proxy: [0x78681e63b6f3ad81ecd64aecc404d765b529c80d](https://etherscan.io/address/0x78681e63b6f3ad81ecd64aecc404d765b529c80d)
72+
- RewardsManager Implementation: [0x70c59877f5358d8d6f2fc90f53813eb2b2698ab7](https://etherscan.io/address/0x70c59877f5358d8d6f2fc90f53813eb2b2698ab7)
73+
- Lens: [0xe8cfa2edbdc110689120724c4828232e473be1b2](https://etherscan.io/address/0xe8cfa2edbdc110689120724c4828232e473be1b2)
74+
- CompRewardsLens: [0x9e977f745d5ae26c6d47ac5417ee112312873ba7](https://etherscan.io/address/0x9e977f745d5ae26c6d47ac5417ee112312873ba7)
75+
76+
### Morpho-Aave-V2 Ethereum
77+
78+
- Morpho Proxy: [0x299ff2534c6f11624d6a65463b8b40c958ab668f](https://etherscan.io/address/0x299ff2534c6f11624d6a65463b8b40c958ab668f)
79+
- Morpho Implementation: [0x299ff2534c6f11624d6a65463b8b40c958ab668f](https://etherscan.io/address/0x299ff2534c6f11624d6a65463b8b40c958ab668f)
80+
- EntryPositionsManager: [0xdf93cf1ca3acf96bc26783e6fab89400d362d0b4](https://etherscan.io/address/0xdf93cf1ca3acf96bc26783e6fab89400d362d0b4)
81+
- ExitPositionsManager: [0xf6998f72b92b81c8f683d30ed8678d348fe9754b](https://etherscan.io/address/0xf6998f72b92b81c8f683d30ed8678d348fe9754b)
82+
- InterestRatesManager: [0x91b23044d4a8089670309852c7f0a93e5ca8efb7](https://etherscan.io/address/0x91b23044d4a8089670309852c7f0a93e5ca8efb7)
83+
- Lens Proxy: [0x507fa343d0a90786d86c7cd885f5c49263a91ff4](https://etherscan.io/address/0x507fa343d0a90786d86c7cd885f5c49263a91ff4)
84+
- Lens: [0x8706256509684e9cd93b7f19254775ce9324c226](https://etherscan.io/address/0x8706256509684e9cd93b7f19254775ce9324c226)
85+
86+
### Common Ethereum
87+
88+
- ProxyAdmin: [0x99917ca0426fbc677e84f873fb0b726bb4799cd8](https://etherscan.io/address/0x99917ca0426fbc677e84f873fb0b726bb4799cd8)
689

790
---
891

@@ -51,7 +134,7 @@ Only tests for the [RewardsDistributor](./contracts/common/rewards-distribution/
51134
Just run:
52135

53136
```bash
54-
yarn test:hardhat
137+
yarn test
55138
```
56139

57140
---
@@ -82,94 +165,12 @@ make script-Deploy PROTOCOL=compound NETWORK=goerli SMODE=local
82165

83166
---
84167

85-
## Style guide 💅
86-
87-
### Code Formatting
88-
89-
We use prettier with the default configuration mentionned in the [Solidity Prettier Plugin](https://github.com/prettier-solidity/prettier-plugin-solidity).
90-
We recommend developers using VS Code to set their local config as below:
91-
92-
```json
93-
{
94-
"editor.formatOnSave": true,
95-
"solidity.formatter": "prettier",
96-
"editor.defaultFormatter": "esbenp.prettier-vscode"
97-
}
98-
```
99-
100-
In doing so the code will be formatted on each save.
101-
102-
We use Husky hook to format code before being pushed to any remote branch to enforce coding style among all developers.
103-
104-
### Code Style
168+
## Questions & Feedback
105169

106-
We follow the Solidity style guide from the [Solidity Documentation](https://docs.soliditylang.org/en/latest/style-guide.html) and the [NatSpec format](https://docs.soliditylang.org/en/latest/natspec-format.html) using this pattern `///`.
107-
Comments should begin with a capital letter and end with a period. You can check the current code to have an overview of what is expected.
170+
For any question or feedback you can send an email to [merlin@morpho.xyz](mailto:merlin@morpho.xyz).
108171

109172
---
110173

111-
## Contributing 💪
112-
113-
In this section, you will find some guidelines to read before contributing to the project.
114-
115-
### Creating issues and PRs
116-
117-
Guidelines for creating issues and PRs:
118-
119-
- Issues must be created and labelled with relevant labels (type of issues, high/medium/low priority, etc.).
120-
- Nothing should be pushed directly to the `main` branch.
121-
- Pull requests must be created before and branch names must follow this pattern: `feat/<feature-name>`, `test/<test-name>` or `fix/<fix-name>`. `docs`, `ci` can also be used. The goal is to have clear branches names and make easier their management.
122-
- PRs must be labelled with the relevant labels.
123-
- Issues must be linked to PRs so that once the PR is merged related issues are closed at the same time.
124-
- Reviewers must be added to the PR.
125-
- For commits, install the gitmoji VS Code extension and use the appropriate emoji for each commit. It should match this pattern: `<emoji> (<branch-name>) <commit-message>`. For a real world example: `✨ (feat/new-feature) Add new feature`.
126-
127-
### Before merging a PR
128-
129-
Before merging a PR:
130-
131-
- PR must have been reviewed by reviewers. The must deliver a complete report on the smart contracts (see the section below).
132-
- Comments and requested changes must have been resolved.
133-
- PR must have been approved by every reviewers.
134-
- CI must pass.
135-
136-
For smart contract reviews, a complete report must have been done, not just a reading of the changes in the code. This is very important as a simple change on one line of code can bring dramatic consequences on a smart contracts (bad copy/paste have already lead to hacks).
137-
For the guidelines on "How to review contracts and write a report?", you can follow this [link](https://morpho-labs.notion.site/How-to-do-a-Smart-Contract-Review-81d1dc692259463993cc7d81544767d1).
138-
139-
By default, PR are rebased with `dev` before merging to keep a clean historic of commits and the branch is deleted. The same process is done from `dev` to `main`.
140-
141-
## Deploying a contract on a network 🚀
142-
143-
You can run the following command to deploy Morpho-Aave's contracts on Mumbai by using foundry:
144-
145-
```bash
146-
make script-DeployMorphoAaveV2 PROTOCOL=aave-v2 NETWORK=polygon-mumbai
147-
```
148-
149-
## Publishing and verifying a contract on Etherscan 📡
150-
151-
An etherscan API key is required to verify the contract and placed into your `.env.local` file.
152-
The right arguments of the constructor of the smart contract to verify must be write inside `arguments.js`. Then you can run the following command to verify a contract:
153-
154-
```bash
155-
npx hardhat verify --network <network-name> --constructor-args scripts/arguments.js <contract-address>
156-
npx hardhat verify --network <network-name> --constructor-args scripts/arguments.js --contract contracts/Example.sol:ExampleContract <contract-address>
157-
```
158-
159-
The second is necessary if contracts with different names share the same ABI.
160-
161-
## Verification on Tenderly 📡
162-
163-
In your `env.local` file, put your tenderly private key. Then you can deploy and directly verify contracts on your tenderly dashboard.
164-
165-
## External resources & documentation 📚
166-
167-
- [General documentation](https://morpho-labs.gitbook.io/morpho-documentation/)
168-
- [Developer documentation](https://morpho-labs.gitbook.io/technical-documentation/)
169-
- [Whitepaper](https://whitepaper.morpho.best)
170-
- [Foundry](https://github.com/gakonst/foundry)
171-
- [Solidity Prettier Plugin](https://github.com/prettier-solidity/prettier-plugin-solidity)
172-
173-
## Questions & Feedback 💬
174+
## Licensing
174175

175-
For any question you can send an email to [merlin@mopho.best](mailto:merlin@morpho.best) 😊
176+
The code is under the GNU General Public License v3.0 license, see [`LICENSE`](https://github.com/morphodao/morpho-core-v1/blob/main/LICENSE).
667 KB
Binary file not shown.
3.64 MB
Binary file not shown.
311 KB
Binary file not shown.
952 KB
Binary file not shown.

config/avalanche-mainnet/aave-v2/Config.sol

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
// SPDX-License-Identifier: GNU AGPLv3
22
pragma solidity 0.8.13;
33

4+
import {ILendingPool} from "@contracts/aave-v2/interfaces/aave/ILendingPool.sol";
5+
import {IPriceOracleGetter} from "@contracts/aave-v2/interfaces/aave/IPriceOracleGetter.sol";
6+
import {IAaveIncentivesController} from "@contracts/aave-v2/interfaces/aave/IAaveIncentivesController.sol";
7+
import {ILendingPoolAddressesProvider} from "@contracts/aave-v2/interfaces/aave/ILendingPoolAddressesProvider.sol";
8+
import {IIncentivesVault} from "@contracts/aave-v2/interfaces/IIncentivesVault.sol";
9+
import {IEntryPositionsManager} from "@contracts/aave-v2/interfaces/IEntryPositionsManager.sol";
10+
import {IExitPositionsManager} from "@contracts/aave-v2/interfaces/IExitPositionsManager.sol";
11+
import {IInterestRatesManager} from "@contracts/aave-v2/interfaces/IInterestRatesManager.sol";
12+
import {IRewardsManager} from "@contracts/aave-v2/interfaces/IRewardsManager.sol";
13+
14+
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
15+
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
16+
17+
import {Lens} from "@contracts/aave-v2/lens/Lens.sol";
18+
import {Morpho} from "@contracts/aave-v2/Morpho.sol";
19+
420
contract Config {
521
address constant aave = 0x63a72806098Bd3D9520cC43356dD78afe5D386D9;
622
address constant dai = 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70;
@@ -25,7 +41,33 @@ contract Config {
2541
address constant variableDebtDai = 0x1852DC24d1a8956a0B356AA18eDe954c7a0Ca5ae;
2642
address constant variableDebtUsdc = 0x848c080d2700CBE1B894a3374AD5E887E5cCb89c;
2743

28-
address constant poolAddressesProviderAddress = 0xb6A86025F0FE1862B372cb0ca18CE3EDe02A318f;
29-
address constant aaveIncentivesControllerAddress = 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9;
3044
address constant swapRouterAddress = 0x60aE616a2155Ee3d9A68541Ba4544862310933d4;
45+
46+
address public morphoDao;
47+
ILendingPoolAddressesProvider public poolAddressesProvider =
48+
ILendingPoolAddressesProvider(0xb6A86025F0FE1862B372cb0ca18CE3EDe02A318f);
49+
IAaveIncentivesController public aaveIncentivesController =
50+
IAaveIncentivesController(0x01D83Fe6A10D2f2B7AF17034343746188272cAc9);
51+
IPriceOracleGetter public oracle = IPriceOracleGetter(poolAddressesProvider.getPriceOracle());
52+
ILendingPool public pool = ILendingPool(poolAddressesProvider.getLendingPool());
53+
54+
address public REWARD_TOKEN = aaveIncentivesController.REWARD_TOKEN();
55+
56+
ProxyAdmin public proxyAdmin;
57+
58+
TransparentUpgradeableProxy public lensProxy;
59+
TransparentUpgradeableProxy public morphoProxy;
60+
TransparentUpgradeableProxy public rewardsManagerProxy;
61+
62+
Lens public lensImplV1;
63+
Morpho public morphoImplV1;
64+
IRewardsManager public rewardsManagerImplV1;
65+
66+
Lens public lens;
67+
Morpho public morpho;
68+
IRewardsManager public rewardsManager;
69+
IIncentivesVault public incentivesVault;
70+
IEntryPositionsManager public entryPositionsManager;
71+
IExitPositionsManager public exitPositionsManager;
72+
IInterestRatesManager public interestRatesManager;
3173
}

0 commit comments

Comments
 (0)