diff --git a/.env.example b/.env.example index e4da1c6..86f8729 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ ALCHEMY_KEY= +ETHERSCAN_API_KEY= diff --git a/lib/metamorpho b/lib/metamorpho index 42f0bc2..9b31890 160000 --- a/lib/metamorpho +++ b/lib/metamorpho @@ -1 +1 @@ -Subproject commit 42f0bc24feedb2eeac955d57ed45d943f1c7f75b +Subproject commit 9b31890e72a948741c82552579fb33c332e2c8d5 diff --git a/lib/morpho-blue b/lib/morpho-blue index 9f4fc70..184fc24 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit 9f4fc70a1282002b5c40eacbfcd7b4ce59956b06 +Subproject commit 184fc2445b7ce52b82eba903b75c4e6351915e90 diff --git a/lib/morpho-blue-irm b/lib/morpho-blue-irm index 12ce108..7f1ec18 160000 --- a/lib/morpho-blue-irm +++ b/lib/morpho-blue-irm @@ -1 +1 @@ -Subproject commit 12ce108473b73c1d3f90ab501b6bfca07a66c783 +Subproject commit 7f1ec1846450132f34069a3ae9a7e00d90c2b1ec diff --git a/lib/morpho-blue-oracles b/lib/morpho-blue-oracles index 875667c..1ed0ca4 160000 --- a/lib/morpho-blue-oracles +++ b/lib/morpho-blue-oracles @@ -1 +1 @@ -Subproject commit 875667c01c78b7b2423ccfe5d402c39cd75f6d3f +Subproject commit 1ed0ca427f80ff13690c656946a01f6ba9b1a09a diff --git a/package.json b/package.json index fbb4dee..1161e06 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,19 @@ "license": "GPL-2.0-or-later", "version": "0.0.0", "scripts": { - "prepare": "husky install && forge install && yarn build", + "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)\"", "build": "yarn build:blue && yarn build:irm && yarn build:oracles && yarn build:metamorpho", - "build:blue": "cd lib/morpho-blue/ && yarn build:forge && cd ../..", - "build:irm": "cd lib/morpho-blue-irm/ && forge build && cd ../..", - "build:oracles": "cd lib/morpho-blue-oracles/ && forge build && cd ../..", - "build:bundlers": "cd lib/morpho-blue-bundlers/ && yarn build:forge && cd ../..", - "build:metamorpho": "cd lib/metamorpho/ && yarn build:forge && cd ../..", - "test": "FOUNDRY_PROFILE=test forge test", + "build:blue": "cd lib/morpho-blue/ && yarn build:forge", + "build:irm": "cd lib/morpho-blue-irm/ && forge build", + "build:oracles": "cd lib/morpho-blue-oracles/ && forge build", + "build:bundlers": "cd lib/morpho-blue-bundlers/ && yarn build:forge", + "build:metamorpho": "cd lib/metamorpho/ && yarn build:forge", + "test": "yarn build && FOUNDRY_PROFILE=test forge test", "lint": "forge fmt --check", "lint:fix": "forge fmt" }, diff --git a/script/DeployBundlers.sol b/script/DeployBundlers.sol index b90af38..999f3b0 100644 --- a/script/DeployBundlers.sol +++ b/script/DeployBundlers.sol @@ -26,13 +26,7 @@ contract DeployBundlers is ConfiguredScript { constructorArgs = bytes.concat(constructorArgs, abi.encode(bundlerConfig.args[j])); } - vm.broadcast(); - address bundler = deployCode( - string.concat("lib/morpho-blue-bundlers/out/", bundlerConfig.name, ".sol/", bundlerConfig.name, ".json"), - constructorArgs - ); - - console2.log("Deployed %s at: %s", bundlerConfig.name, bundler); + _deployCode("morpho-blue-bundlers", bundlerConfig.name, constructorArgs); } } } diff --git a/script/DeployMetaMorphoFactory.sol b/script/DeployMetaMorphoFactory.sol index d939b47..4aea66e 100644 --- a/script/DeployMetaMorphoFactory.sol +++ b/script/DeployMetaMorphoFactory.sol @@ -20,15 +20,9 @@ contract DeployMetaMorphoFactory is ConfiguredScript { function run(string memory network) public returns (DeployMetaMorphoFactoryConfig memory config) { config = abi.decode(_init(network, true), (DeployMetaMorphoFactoryConfig)); - vm.broadcast(); - metaMorphoFactory = IMetaMorphoFactory( - _deployCreate2Code( - "lib/metamorpho/out/MetaMorphoFactory.sol/MetaMorphoFactory.json", - abi.encode(address(morpho)), - config.salt - ) - ); - - console2.log("Deployed MetaMorphoFactory at: %s", address(metaMorphoFactory)); + bytes memory constructorArgs = abi.encode(address(morpho)); + + metaMorphoFactory = + IMetaMorphoFactory(_deployCreate2Code("metamorpho", "MetaMorphoFactory", constructorArgs, config.salt)); } } diff --git a/script/DeployMorpho.sol b/script/DeployMorpho.sol index 4066353..f4d0754 100644 --- a/script/DeployMorpho.sol +++ b/script/DeployMorpho.sol @@ -6,17 +6,8 @@ import {MarketParamsLib} from "../lib/morpho-blue/src/libraries/MarketParamsLib. import "./config/ConfiguredScript.sol"; -/// @dev Warning: keys must be ordered alphabetically. -struct AdaptiveCurveIrmConfig { - int256 adjustmentSpeed; - int256 curveSteepness; - int256 initialRateAtTarget; - int256 targetUtilization; -} - /// @dev Warning: keys must be ordered alphabetically. struct DeployMorphoConfig { - AdaptiveCurveIrmConfig adaptiveCurveIrm; uint256[] lltvs; address owner; bytes32 salt; @@ -33,38 +24,12 @@ contract DeployMorpho is ConfiguredScript { config = abi.decode(_init(network, false), (DeployMorphoConfig)); // Deploy Morpho Blue - vm.broadcast(); - morpho = IMorpho( - _deployCreate2Code("lib/morpho-blue/out/Morpho.sol/Morpho.json", abi.encode(msg.sender), config.salt) - ); - - console2.log("Deployed Morpho Blue at: %s", address(morpho)); + morpho = IMorpho(_deployCreate2Code("morpho-blue", "Morpho", abi.encode(msg.sender), config.salt)); // Deploy & enable AdaptiveCurveIrm - vm.broadcast(); - irm = IAdaptiveCurveIrm( - deployCode( - "lib/morpho-blue-irm/out/AdaptiveCurveIrm.sol/AdaptiveCurveIrm.json", - abi.encode( - address(morpho), - config.adaptiveCurveIrm.curveSteepness, - config.adaptiveCurveIrm.adjustmentSpeed, - config.adaptiveCurveIrm.targetUtilization, - config.adaptiveCurveIrm.initialRateAtTarget - ) - ) - ); + irm = IAdaptiveCurveIrm(_deployCode("morpho-blue-irm", "AdaptiveCurveIrm", abi.encode(address(morpho)))); require(irm.MORPHO() == address(morpho), "unexpected morpho"); - require(irm.CURVE_STEEPNESS() == config.adaptiveCurveIrm.curveSteepness, "unexpected curve steepness"); - require(irm.ADJUSTMENT_SPEED() == config.adaptiveCurveIrm.adjustmentSpeed, "unexpected adjustment speed"); - require(irm.TARGET_UTILIZATION() == config.adaptiveCurveIrm.targetUtilization, "unexpected target utilization"); - require( - irm.INITIAL_RATE_AT_TARGET() == config.adaptiveCurveIrm.initialRateAtTarget, - "unexpected initial rate at target" - ); - - console2.log("Deployed AdaptiveCurveIrm at: %s", address(irm)); vm.broadcast(); morpho.enableIrm(address(irm)); diff --git a/script/DeployOracles.sol b/script/DeployOracles.sol index 49d3e37..2e5bd03 100644 --- a/script/DeployOracles.sol +++ b/script/DeployOracles.sol @@ -32,14 +32,17 @@ contract DeployOracle is ConfiguredScript { for (uint256 i; i < config.length; ++i) { OracleConfig memory oracleConfig = config[i]; + console2.log(" Market [%s]", oracleConfig.name); + address vault = oracleConfig.vaultConversionSample > 1 ? oracleConfig.collateralToken : address(0); uint256 baseTokenDecimals = IERC20(oracleConfig.collateralToken).decimals(); uint256 quoteTokenDecimals = IERC20(oracleConfig.loanToken).decimals(); vm.broadcast(); IChainlinkOracle oracle = IChainlinkOracle( - deployCode( - "lib/morpho-blue-oracles/out/ChainlinkOracle.sol/ChainlinkOracle.json", + _deployCode( + "morpho-blue-oracles", + "ChainlinkOracle", abi.encode( vault, oracleConfig.baseFeed1, @@ -63,8 +66,6 @@ contract DeployOracle is ConfiguredScript { require(address(oracle.QUOTE_FEED_1()) == oracleConfig.quoteFeed1, "unexpected quoteFeed1"); require(address(oracle.QUOTE_FEED_2()) == oracleConfig.quoteFeed2, "unexpected quoteFeed2"); - console2.log(" Deployed ChainlinkOracle for market [%s] at: %s", oracleConfig.name, address(oracle)); - uint256 price = oracle.price(); require(price <= oracleConfig.maxPrice, string.concat("price too high: ", vm.toString(price))); require(price >= oracleConfig.minPrice, string.concat("price too low: ", vm.toString(price))); diff --git a/script/config/ConfiguredScript.sol b/script/config/ConfiguredScript.sol index 61d8cf1..9b6036a 100644 --- a/script/config/ConfiguredScript.sol +++ b/script/config/ConfiguredScript.sol @@ -42,13 +42,49 @@ abstract contract ConfiguredScript is Script { return vm.parseJson(vm.readFile(configPath)); } - function _deployCreate2Code(string memory what, bytes memory args, bytes32 salt) internal returns (address addr) { - bytes memory bytecode = abi.encodePacked(vm.getCode(what), args); + function _deployCode(string memory submodule, string memory what, bytes memory args) + internal + returns (address addr) + { + vm.broadcast(); + addr = deployCode(string.concat("lib/", submodule, "/out/", what, ".sol/", what, ".json"), args); + + _logDeployment(submodule, what, args, addr); + } + + function _deployCreate2Code(string memory submodule, string memory what, bytes memory args, bytes32 salt) + internal + returns (address addr) + { + bytes memory bytecode = + abi.encodePacked(vm.getCode(string.concat("lib/", submodule, "/out/", what, ".sol/", what, ".json")), args); + vm.broadcast(); assembly ("memory-safe") { addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt) } require(addr != address(0), "create2 deployment failed"); + + _logDeployment(submodule, what, args, addr); + } + + function _logDeployment(string memory submodule, string memory what, bytes memory args, address addr) + internal + view + { + 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(" > cd ../../"); + console2.log(""); } } diff --git a/script/config/morpho/ethereum.json b/script/config/morpho/ethereum.json index c554eee..8519395 100644 --- a/script/config/morpho/ethereum.json +++ b/script/config/morpho/ethereum.json @@ -1,12 +1,6 @@ { "owner": "0x6ABfd6139c7C3CC270ee2Ce132E309F59cAaF6a2", "salt": "0x0000000000000000000000000000000000000000000000000000000000000000", - "adaptiveCurveIrm": { - "adjustmentSpeed": 1585489599188, - "curveSteepness": 4000000000000000000, - "initialRateAtTarget": 317097919, - "targetUtilization": 900000000000000000 - }, "lltvs": [ 0, 385000000000000000, diff --git a/script/config/morpho/goerli.json b/script/config/morpho/goerli.json index 0e54dff..55eae05 100644 --- a/script/config/morpho/goerli.json +++ b/script/config/morpho/goerli.json @@ -1,12 +1,6 @@ { "owner": "0x50d0dE2207989017398e33919A3ed6558eBc6644", - "salt": "0x0000000000000000000000000000000000000000000000000000000000000001", - "adaptiveCurveIrm": { - "adjustmentSpeed": 1585489599188, - "curveSteepness": 4000000000000000000, - "initialRateAtTarget": 317097919, - "targetUtilization": 900000000000000000 - }, + "salt": "0x0000000000000000000000000000000000000000000000000000000000000002", "lltvs": [ 0, 385000000000000000,