Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/repo #14

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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ALCHEMY_KEY=
ETHERSCAN_API_KEY=
2 changes: 1 addition & 1 deletion lib/morpho-blue
Submodule morpho-blue updated 61 files
+51 −0 .github/workflows/certora.yml
+1 −1 .github/workflows/foundry.yml
+4 −0 .gitignore
+1 −1 README.md
+389 −0 certora/LICENSE
+287 −0 certora/README.md
+12 −0 certora/confs/AccrueInterest.conf
+8 −0 certora/confs/AssetsAccounting.conf
+8 −0 certora/confs/ConsistentState.conf
+12 −0 certora/confs/ExactMath.conf
+12 −0 certora/confs/Health.conf
+8 −0 certora/confs/LibSummary.conf
+8 −0 certora/confs/Liveness.conf
+13 −0 certora/confs/RatioMath.conf
+11 −0 certora/confs/Reentrancy.conf
+8 −0 certora/confs/Reverts.conf
+11 −0 certora/confs/Transfer.conf
+48 −0 certora/dispatch/ERC20NoRevert.sol
+42 −0 certora/dispatch/ERC20Standard.sol
+45 −0 certora/dispatch/ERC20USDT.sol
+6 −0 certora/gambit.conf
+92 −0 certora/harness/MorphoHarness.sol
+17 −0 certora/harness/MorphoInternalAccess.sol
+35 −0 certora/harness/TransferHarness.sol
+138 −0 certora/specs/AccrueInterest.spec
+126 −0 certora/specs/AssetsAccounting.spec
+294 −0 certora/specs/ConsistentState.spec
+123 −0 certora/specs/ExactMath.spec
+108 −0 certora/specs/Health.spec
+26 −0 certora/specs/LibSummary.spec
+386 −0 certora/specs/Liveness.spec
+184 −0 certora/specs/RatioMath.spec
+61 −0 certora/specs/Reentrancy.spec
+179 −0 certora/specs/Reverts.spec
+82 −0 certora/specs/Transfer.spec
+1 −1 lib/forge-std
+48 −33 src/Morpho.sol
+3 −2 src/interfaces/IIrm.sol
+14 −11 src/interfaces/IMorpho.sol
+3 −0 src/libraries/ErrorsLib.sol
+10 −7 src/libraries/EventsLib.sol
+4 −3 src/libraries/SafeTransferLib.sol
+3 −0 src/libraries/SharesMathLib.sol
+1 −1 src/libraries/UtilsLib.sol
+6 −7 src/libraries/periphery/MorphoBalancesLib.sol
+5 −3 test/forge/BaseTest.sol
+1 −1 test/forge/helpers/SigUtils.sol
+12 −0 test/forge/integration/AccrueInterestIntegrationTest.sol
+33 −1 test/forge/integration/AuthorizationIntegrationTest.sol
+2 −2 test/forge/integration/BorrowIntegrationTest.sol
+5 −0 test/forge/integration/CallbacksIntegrationTest.sol
+37 −17 test/forge/integration/CreateMarketIntegrationTest.sol
+29 −4 test/forge/integration/LiquidateIntegrationTest.sol
+3 −2 test/forge/integration/OnlyOwnerIntegrationTest.sol
+12 −0 test/forge/integration/SupplyCollateralIntegrationTest.sol
+12 −0 test/forge/integration/SupplyIntegrationTest.sol
+1 −1 test/forge/integration/WithdrawCollateralIntegrationTest.sol
+5 −3 test/forge/invariant/MorphoInvariantTest.sol
+14 −0 test/forge/libraries/SafeTransferLibTest.sol
+31 −1 test/hardhat/Morpho.spec.ts
+1 −1 tsconfig.json
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 1 addition & 7 deletions script/DeployBundlers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
14 changes: 4 additions & 10 deletions script/DeployMetaMorphoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
39 changes: 2 additions & 37 deletions script/DeployMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
9 changes: 5 additions & 4 deletions script/DeployOracles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)));
Expand Down
40 changes: 38 additions & 2 deletions script/config/ConfiguredScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
" > 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("");
}
}
6 changes: 0 additions & 6 deletions script/config/morpho/ethereum.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"owner": "0x6ABfd6139c7C3CC270ee2Ce132E309F59cAaF6a2",
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
"adaptiveCurveIrm": {
"adjustmentSpeed": 1585489599188,
"curveSteepness": 4000000000000000000,
"initialRateAtTarget": 317097919,
"targetUtilization": 900000000000000000
},
"lltvs": [
0,
385000000000000000,
Expand Down
8 changes: 1 addition & 7 deletions script/config/morpho/goerli.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"owner": "0x50d0dE2207989017398e33919A3ed6558eBc6644",
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
"adaptiveCurveIrm": {
"adjustmentSpeed": 1585489599188,
"curveSteepness": 4000000000000000000,
"initialRateAtTarget": 317097919,
"targetUtilization": 900000000000000000
},
"salt": "0x0000000000000000000000000000000000000000000000000000000000000002",
"lltvs": [
0,
385000000000000000,
Expand Down