Skip to content

Commit

Permalink
Merge pull request #1202 from morpho-labs/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MerlinEgalite authored Aug 12, 2022
2 parents d1bdbec + 61f83c0 commit 3669fef
Show file tree
Hide file tree
Showing 65 changed files with 2,369 additions and 2,545 deletions.
13 changes: 7 additions & 6 deletions .github/actions/ci-foundry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ runs:
path: |
cache
out
key: ${{ github.base_ref || github.ref_name }}-foundry-${{ inputs.protocol }} # always keep compiled contracts from base branch
key: ${{ github.base_ref || github.ref_name }}-foundry-${{ inputs.protocol }}-${{ inputs.network }} # always keep compiled contracts from base branch

- name: Run tests
run: make ci > ${{ inputs.protocol }}.gasreport.ansi
run: make gas-report | tee ${{ inputs.protocol }}.${{ inputs.network }}.gasreport.ansi
shell: bash
env:
PROTOCOL: ${{ inputs.protocol }}
NETWORK: ${{ inputs.network }}
ALCHEMY_KEY: ${{ inputs.alchemyKey }}
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}

- name: Compare gas reports
uses: Rubilmax/foundry-gas-diff@v3.7
uses: Rubilmax/foundry-gas-diff@v3.9
with:
workflowId: ci-foundry-${{ inputs.protocol }}.yml
report: ${{ inputs.protocol }}.gasreport.ansi
report: ${{ inputs.protocol }}.${{ inputs.network }}.gasreport.ansi
ignore: test-foundry/**/*
title: Morpho-${{ inputs.protocol }} gas impacts (${{ inputs.network }})
header: |
# Morpho-${{ inputs.protocol }} gas impacts (${{ inputs.network }})
id: gas_diff

- name: Add gas diff to sticky comment
Expand Down
54 changes: 30 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
-include .env.local
.EXPORT_ALL_VARIABLES:

SMODE?=network
PROTOCOL?=compound
NETWORK?=eth-mainnet

FOUNDRY_SRC=contracts/${PROTOCOL}/
FOUNDRY_TEST=test-foundry/${PROTOCOL}/
FOUNDRY_REMAPPINGS=@config/=config/${NETWORK}/${PROTOCOL}/
FOUNDRY_ETH_RPC_URL?=https://${NETWORK}.g.alchemy.com/v2/${ALCHEMY_KEY}
FOUNDRY_PRIVATE_KEY?=${DEPLOYER_PRIVATE_KEY}

ifeq (${NETWORK}, eth-mainnet)
FOUNDRY_CHAIN_ID=1
FOUNDRY_FORK_BLOCK_NUMBER=14292587
endif

ifeq (${NETWORK}, eth-ropsten)
FOUNDRY_CHAIN_ID=3
endif

ifeq (${NETWORK}, eth-goerli)
FOUNDRY_CHAIN_ID=5
endif

ifeq (${NETWORK}, polygon-mainnet)
FOUNDRY_CHAIN_ID=137
FOUNDRY_FORK_BLOCK_NUMBER=22116728
Expand All @@ -35,8 +45,8 @@ ifeq (${NETWORK}, avalanche-mainnet)
else
endif

ifneq (, $(filter ${NETWORK}, ropsten rinkeby))
FOUNDRY_ETH_RPC_URL=https://${NETWORK}.infura.io/v3/${INFURA_PROJECT_ID}
ifeq (${SMODE}, local)
FOUNDRY_ETH_RPC_URL=http://localhost:8545
endif


Expand All @@ -48,61 +58,57 @@ install:
@chmod +x ./scripts/**/*.sh

deploy:
@echo Deploying Morpho-${PROTOCOL} on ${NETWORK}
./scripts/${PROTOCOL}/deploy.sh

initialize:
@echo Initializing Morpho-${PROTOCOL} on ${NETWORK}
./scripts/${PROTOCOL}/initialize.sh

create-market:
./scripts/create-market.sh
@echo Creating market on Morpho-${PROTOCOL} on ${NETWORK}
./scripts/${PROTOCOL}/create-market.sh

ci:
@forge test -vv --gas-report --no-match-test testFuzz
anvil:
@echo Starting fork of ${NETWORK}
@anvil --fork-url ${FOUNDRY_ETH_RPC_URL}

test:
@echo Running all ${PROTOCOL} tests on ${NETWORK}
@forge test -vv --no-match-test testFuzz
script-%:
@echo Running script $* of ${PROTOCOL} on ${NETWORK} with script mode: ${SMODE}
@forge script scripts/${PROTOCOL}/$*.s.sol:$* --broadcast -vvvv

test-ansi:
test:
@echo Running all ${PROTOCOL} tests on ${NETWORK}
@forge test -vv --no-match-test testFuzz > trace.ansi
@forge test -vv | tee trace.ansi

coverage:
@echo Create coverage report for ${PROTOCOL} tests on ${NETWORK}
@forge coverage --no-match-test testFuzz
@forge coverage

coverage-lcov:
@echo Create coverage lcov for ${PROTOCOL} tests on ${NETWORK}
@forge coverage --report lcov --no-match-test testFuzz
@forge coverage --report lcov

fuzz:
$(eval FOUNDRY_TEST=test-foundry/fuzzing/${PROTOCOL}/)
@echo Running all ${PROTOCOL} fuzzing tests on ${NETWORK}
@forge test -vv

gas-report:
@echo Creating gas consumption report for ${PROTOCOL} on ${NETWORK}
@forge test -vvv --gas-report > gas_report.ansi
@echo Creating gas report for ${PROTOCOL} on ${NETWORK}
@forge test --gas-report

test-common:
@echo Running all common tests on ${NETWORK}
@forge test -vvv -c test-foundry/common

contract-% c-%:
@echo Running tests for contract $* of ${PROTOCOL} on ${NETWORK}
@forge test -vvv/$*.t.sol --match-contract $*

ansi-c-%:
@echo Running tests for contract $* of ${PROTOCOL} on ${NETWORK}
@forge test -vvv/$*.t.sol --match-contract $* > trace.ansi
@forge test -vvv --match-contract $* | tee trace.ansi

single-% s-%:
@echo Running single test $* of ${PROTOCOL} on ${NETWORK}
@forge test -vvv --match-test $*

ansi-s-%:
@echo Running single test $* of ${PROTOCOL} on ${NETWORK}
@forge test -vvvvv --match-test $* > trace.ansi
@forge test -vvv --match-test $* | tee trace.ansi

storage-layout-generate:
@./scripts/storage-layout.sh generate snapshots/.storage-layout-${PROTOCOL} Morpho RewardsManager Lens
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ yarn test:hardhat

---

## Deployment & Upgrades

### Network mode (default)

Run the Foundry deployment script with:

```bash
make script-Deploy PROTOCOL=compound NETWORK=goerli
```

### Local mode

First start a local EVM:

```bash
make anvil NETWORK=goerli
```

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

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

---

## Style guide 💅

### Code Formatting
Expand Down Expand Up @@ -114,14 +140,12 @@ By default, PR are rebased with `dev` before merging to keep a clean historic of

## Deploying a contract on a network 🚀

You can run the following command to deploy Morpho's contracts for Aave on Polygon:
You can run the following command to deploy Morpho-Aave's contracts on Mumbai by using foundry:

```bash
yarn deploy:aave:polygon
make script-DeployMorphoAaveV2 PROTOCOL=aave-v2 NETWORK=polygon-mumbai
```

For the other commands, check the [package.json](./package.json) file.

## Publishing and verifying a contract on Etherscan 📡

An etherscan API key is required to verify the contract and placed into your `.env.local` file.
Expand Down
32 changes: 0 additions & 32 deletions config/goerli-config.json

This file was deleted.

22 changes: 22 additions & 0 deletions config/goerli/compound/Config.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity 0.8.13;

import "@contracts/compound/libraries/Types.sol";

contract Config {
address constant cBat = 0xCCaF265E7492c0d9b7C2f0018bf6382Ba7f0148D;
address constant cDai = 0x822397d9a55d0fefd20F5c4bCaB33C5F65bd28Eb;
address constant cEth = 0x20572e4c090f15667cF7378e16FaD2eA0e2f3EfF;
address constant cRep = 0x1d70B01A2C3e3B2e56FcdcEfe50d5c5d70109a5D;
address constant cSai = 0x5D4373F8C1AF21C391aD7eC755762D8dD3CCA809;
address constant cUsdc = 0xCEC4a43eBB02f9B80916F1c718338169d6d5C1F0;
address constant cWbtc = 0x6CE27497A64fFFb5517AA4aeE908b1E7EB63B9fF;
address constant cZrx = 0xA253295eC2157B8b69C44b2cb35360016DAa25b1;

address constant wEth = 0xb7e94Cce902E34e618A23Cb82432B95d03096146;
address constant comptroller = 0x627EA49279FD0dE89186A58b8758aD02B6Be2867;

uint256 constant defaultMaxSortedUsers = 8;
Types.MaxGasForMatching defaultMaxGasForMatching =
Types.MaxGasForMatching({supply: 1e5, borrow: 1e5, withdraw: 1e5, repay: 1e5});
}
60 changes: 0 additions & 60 deletions config/mainnet-config.json

This file was deleted.

Loading

0 comments on commit 3669fef

Please sign in to comment.