Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Fix/repo #19

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,44 @@ The protocol is described in detail in the [Morpho Blue Whitepaper](./morpho-blu
## Getting Started

> [!IMPORTANT]
> It is advised to use a dedicated address whose only purpose is to deploy all contracts associated with Blue on each EVM-compatible chain, so that addresses are common across chains.
> It is advised to use a dedicated account whose only **lifetime** purpose is to deploy all contracts associated with Blue on each EVM-compatible chain so that deployed contract addresses are common across chains.

### Installation

- `yarn`
- `cp .env.example .env`

### Deployment

- Add the desired network key and its corresponding RPC url to `foundry.toml`
- `yarn deploy:{component} {network} --broadcast --slow --sender {sender}` followed with appropriate private key management parameters

> [!NOTE]
> If the provided network's RPC url uses a variable environment (such as `ALCHEMY_KEY`), it should be defined in your `.env`

For example: `yarn deploy:morpho goerli --broadcast --slow --ledger --sender 0x7Ef4174aFdF4514F556439fa2822212278151Db6`

All deployments that require an instance of Morpho expects that instance to have previously been deployed on the same network using `yarn deploy:morpho {network} --broadcast`, so that Morpho's address is saved and committed to this repository in [broadcast logs](./broadcast/DeployMorpho.sol/1/run-latest.json).

> [!NOTE]
> Broadcast run logs are to be committed to this repository for future reference.


### Etherscan verification

> [!NOTE]
> Your `.env` should contain a valid `ETHERSCAN_API_KEY`.

After each contract deployed, a verification command is automatically added to the verify script associated to the component deployed (for example: [`script/morpho/verify.sh`](script/morpho/verify.sh)).

- Verify all contracts deployed for a component: `yarn verify:{component}`

For example: `yarn verify:morpho`

> [!NOTE]
> Verify scripts are **NOT** to be committed to this repository because they are expected to be run only once.


## License

All scripts are licensed under [`GPL-2.0-or-later`](./LICENSE).
9 changes: 8 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ via-ir = false
libs = ["lib"]
fs_permissions = [
{ access = "read", path = "./broadcast/DeployMorpho.sol/"},
{ access = "read", path = "./script/config/"},
{ access = "read", path = "./script/morpho/config/"},
{ access = "read", path = "./script/oracles/config/"},
{ access = "read", path = "./script/bundlers/config/"},
{ access = "read", path = "./script/metamorpho-factory/config/"},
{ access = "write", path = "./script/morpho/verify.sh"},
{ access = "write", path = "./script/oracles/verify.sh"},
{ access = "write", path = "./script/bundlers/verify.sh"},
{ access = "write", path = "./script/metamorpho-factory/verify.sh"},
{ access = "read", path = "./lib/morpho-blue/out/"},
{ access = "read", path = "./lib/morpho-blue-irm/out/"},
{ access = "read", path = "./lib/morpho-blue-oracles/out/"},
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"scripts": {
"prepare": "husky install && forge install",
"script": "FOUNDRY_PROFILE=script forge script",
"deploy:morpho": "yarn build:blue && yarn build:irm && yarn script script/DeployMorpho.sol --sig \"run(string memory)\"",
"deploy:bundlers": "yarn build:bundlers && yarn script script/DeployBundlers.sol --sig \"run(string memory)\"",
"deploy:metamorpho-factory": "yarn build:metamorpho && yarn script script/DeployMetaMorphoFactory.sol --sig \"run(string memory)\"",
"deploy:oracles": "yarn build:oracles && yarn script script/DeployOracles.sol --sig \"run(string memory)\"",
"deploy:morpho": "yarn build:blue && yarn build:irm && yarn script script/morpho/DeployMorpho.sol --sig \"run(string memory)\"",
"deploy:bundlers": "yarn build:bundlers && yarn script script/bundlers/DeployBundlers.sol --sig \"run(string memory)\"",
"deploy:metamorpho-factory": "yarn build:metamorpho && yarn script script/metamorpho-factory/DeployMetaMorphoFactory.sol --sig \"run(string memory)\"",
"deploy:oracles": "yarn build:oracles && yarn script script/oracles/DeployOracles.sol --sig \"run(string memory)\"",
"verify:morpho": "./script/morpho/verify.sh",
"verify:bundlers": "./script/bundlers/verify.sh",
"verify:metamorpho-factory": "./script/metamorpho-factory/verify.sh",
"verify:oracles": "./script/oracles/verify.sh",
"build": "yarn build:blue && yarn build:irm && yarn build:oracles && yarn build:metamorpho",
"build:blue": "cd lib/morpho-blue/ && yarn build:forge",
"build:irm": "cd lib/morpho-blue-irm/ && forge build",
Expand Down
54 changes: 33 additions & 21 deletions script/config/ConfiguredScript.sol → script/ConfiguredScript.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IMorpho} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {IAdaptiveCurveIrm} from "../../lib/morpho-blue-irm/src/interfaces/IAdaptiveCurveIrm.sol";
import {IMorpho} from "../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {IAdaptiveCurveIrm} from "../lib/morpho-blue-irm/src/interfaces/IAdaptiveCurveIrm.sol";

import "../../lib/forge-std/src/Script.sol";
import "../../lib/forge-std/src/console2.sol";
import "../lib/forge-std/src/Script.sol";
import "../lib/forge-std/src/console2.sol";

abstract contract ConfiguredScript is Script {
using stdJson for string;

bool internal immutable SAVE_VERIFY = true;

string internal configPath;

IMorpho internal morpho;
IAdaptiveCurveIrm internal irm;

function _configDir() internal view virtual returns (string memory);
function _scriptDir() internal view virtual returns (string memory);

function _init(string memory network, bool requireMorpho) internal returns (bytes memory) {
vm.createSelectFork(vm.rpcUrl(network));
Expand All @@ -26,7 +28,7 @@ abstract contract ConfiguredScript is Script {
}

function _loadConfig(string memory network, bool requireMorpho) internal returns (bytes memory) {
configPath = string.concat("script/config/", _configDir(), "/", network, ".json");
configPath = string.concat("script/", _scriptDir(), "/config/", network, ".json");

string memory latestRunPath =
string.concat("broadcast/DeployMorpho.sol/", vm.toString(block.chainid), "/run-latest.json");
Expand Down Expand Up @@ -69,22 +71,32 @@ abstract contract ConfiguredScript is Script {
_logDeployment(submodule, what, args, addr);
}

function _logDeployment(string memory submodule, string memory what, bytes memory args, address addr)
internal
view
{
function _logDeployment(string memory submodule, string memory what, bytes memory args, address addr) internal {
console2.log("Deployed %s at: %s", what, addr);

console2.log("");
console2.log("Verify %s using:", what);
console2.log(" > cd %s/", submodule);
console2.log(
" > forge verify-contract --chain-id %s --constructor-args %s",
vm.toString(block.chainid),
vm.toString(args),
string.concat(vm.toString(addr), " src/", what, ".sol:", what)
console2.log("Verify %s using: > yarn verify:%s", _scriptDir());

if (!SAVE_VERIFY) return;

string memory verifyPath = string.concat("script/", _scriptDir(), "/verify.sh");
vm.writeLine(verifyPath, "");
vm.writeLine(verifyPath, string.concat("if cd lib/", submodule, "/;"));
vm.writeLine(verifyPath, "then");
vm.writeLine(
verifyPath,
string.concat(
" forge verify-contract --chain-id ",
vm.toString(block.chainid),
" --constructor-args ",
vm.toString(args),
" ",
vm.toString(addr),
" src/",
what,
".sol:",
what
)
);
console2.log(" > cd ../../");
console2.log("");
vm.writeLine(verifyPath, " cd ../../");
vm.writeLine(verifyPath, "fi");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import "./config/ConfiguredScript.sol";
import "../ConfiguredScript.sol";

/// @dev Warning: keys must be ordered alphabetically.
struct BundlerConfig {
Expand All @@ -10,7 +10,7 @@ struct BundlerConfig {
}

contract DeployBundlers is ConfiguredScript {
function _configDir() internal pure override returns (string memory) {
function _scriptDir() internal pure override returns (string memory) {
return "bundlers";
}

Expand Down
6 changes: 6 additions & 0 deletions script/bundlers/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ -f .env ]
then
export $(grep -v '#.*' .env | xargs)
fi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IMetaMorphoFactory} from "../lib/metamorpho/src/interfaces/IMetaMorphoFactory.sol";
import {IMetaMorphoFactory} from "../../lib/metamorpho/src/interfaces/IMetaMorphoFactory.sol";

import "./config/ConfiguredScript.sol";
import "../ConfiguredScript.sol";

/// @dev Warning: keys must be ordered alphabetically.
struct DeployMetaMorphoFactoryConfig {
Expand All @@ -13,7 +13,7 @@ struct DeployMetaMorphoFactoryConfig {
contract DeployMetaMorphoFactory is ConfiguredScript {
IMetaMorphoFactory internal metaMorphoFactory;

function _configDir() internal pure override returns (string memory) {
function _scriptDir() internal pure override returns (string memory) {
return "metamorpho-factory";
}

Expand Down
6 changes: 6 additions & 0 deletions script/metamorpho-factory/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ -f .env ]
then
export $(grep -v '#.*' .env | xargs)
fi
8 changes: 4 additions & 4 deletions script/DeployMorpho.sol → script/morpho/DeployMorpho.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IMorpho, MarketParams} from "../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {MarketParamsLib} from "../lib/morpho-blue/src/libraries/MarketParamsLib.sol";
import {IMorpho, MarketParams} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {MarketParamsLib} from "../../lib/morpho-blue/src/libraries/MarketParamsLib.sol";

import "./config/ConfiguredScript.sol";
import "../ConfiguredScript.sol";

/// @dev Warning: keys must be ordered alphabetically.
struct DeployMorphoConfig {
Expand All @@ -16,7 +16,7 @@ struct DeployMorphoConfig {
contract DeployMorpho is ConfiguredScript {
using MarketParamsLib for MarketParams;

function _configDir() internal pure override returns (string memory) {
function _scriptDir() internal pure override returns (string memory) {
return "morpho";
}

Expand Down
6 changes: 6 additions & 0 deletions script/morpho/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ -f .env ]
then
export $(grep -v '#.*' .env | xargs)
fi
9 changes: 4 additions & 5 deletions script/DeployOracles.sol → script/oracles/DeployOracles.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IERC20} from "../lib/forge-std/src/interfaces/IERC20.sol";
import {IERC20} from "../../lib/forge-std/src/interfaces/IERC20.sol";
import {IChainlinkOracle} from "../../lib/morpho-blue-oracles/src/interfaces/IChainlinkOracle.sol";

import {IChainlinkOracle} from "../lib/morpho-blue-oracles/src/interfaces/IChainlinkOracle.sol";

import "./config/ConfiguredScript.sol";
import "../ConfiguredScript.sol";

/// @dev Warning: keys must be ordered alphabetically.
struct OracleConfig {
Expand All @@ -22,7 +21,7 @@ struct OracleConfig {
}

contract DeployOracle is ConfiguredScript {
function _configDir() internal pure override returns (string memory) {
function _scriptDir() internal pure override returns (string memory) {
return "oracles";
}

Expand Down
6 changes: 6 additions & 0 deletions script/oracles/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ -f .env ]
then
export $(grep -v '#.*' .env | xargs)
fi
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import "../script/DeployMorpho.sol";
import "../../script/morpho/DeployMorpho.sol";

import "../lib/forge-std/src/Test.sol";
import "../../lib/forge-std/src/Test.sol";

contract DeployMorphoEthereumTest is DeployMorpho, Test {
DeployMorphoConfig internal config;

constructor() {
SAVE_VERIFY = false;
}

function setUp() public {
config = run("ethereum");
}
Expand Down