Skip to content

Commit

Permalink
feat: add script for rehypothecated markets on Morpho
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec authored and GuillaumeNervoXS committed Apr 19, 2024
1 parent c70a309 commit e961963
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 0 deletions.
196 changes: 196 additions & 0 deletions scripts/foundry/mainnet/CreateHypothecatedMorphoMarkets.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { IMorpho, MarketParams } from "../../../contracts/interfaces/external/morpho/IMorpho.sol";
import { IMorphoChainlinkOracleV2Factory, IMorphoOracle } from "../../../contracts/interfaces/external/morpho/IMorphoChainlinkOracleV2.sol";
import "./MainnetConstants.s.sol";
import { StdCheats, StdAssertions } from "forge-std/Test.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

// Before running this script, ensure that the deployer has the necessary balance in all tokens to seed the markets
contract CreateMorphoMarkets is Script, MainnetConstants, StdCheats, StdAssertions {
error ZeroAdress();

function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
console.log("Address: %s", deployer);
console.log(deployer.balance);
vm.startBroadcast(deployerPrivateKey);
console.log(USDA);

MarketParams memory params;
bytes memory emptyData;

deal(GTETHPRIME, deployer, BASE_DEPOSIT_ETH_AMOUNT);
deal(RE7ETH, deployer, BASE_DEPOSIT_ETH_AMOUNT);
deal(GTUSDCPRIME, deployer, BASE_DEPOSIT_USD_AMOUNT);
deal(RE7USDT, deployer, BASE_DEPOSIT_USD_AMOUNT);

IERC20(USDA).approve(MORPHO_BLUE, type(uint256).max);
address oracle;
bytes32 salt;
string memory marketName;

{
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GTETH PRIME
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

marketName = "gtETH";
uint256 baseDepositAmount = BASE_DEPOSIT_ETH_AMOUNT;
oracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2(
address(GTETHPRIME),
1 ether,
CHAINLINK_ETH_USD_ORACLE,
address(0),
18,
address(0),
1,
address(0),
address(0),
18,
salt
);
uint256 price = IMorphoOracle(oracle).price();
assertApproxEqRel(price, 3500 * 10 ** 36, 10 ** 35);
params.collateralToken = GTETHPRIME;
params.irm = IRM_MODEL;
params.lltv = LLTV_77;
params.oracle = oracle;
params.loanToken = USDA;
_logMarket(params, marketName);
IMorpho(MORPHO_BLUE).createMarket(params);
IMorpho(MORPHO_BLUE).supply(params, 0.5 ether, 0, deployer, emptyData);
IERC20(params.collateralToken).approve(MORPHO_BLUE, baseDepositAmount);
console.log(IERC20(params.collateralToken).balanceOf(deployer));
IMorpho(MORPHO_BLUE).supplyCollateral(params, baseDepositAmount, deployer, emptyData);
IMorpho(MORPHO_BLUE).borrow(params, (0.5 ether * 9) / 10, 0, deployer, deployer);
}

{
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RE7ETH
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

marketName = "RE7 ETH";
uint256 baseDepositAmount = BASE_DEPOSIT_ETH_AMOUNT;
oracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2(
address(RE7ETH),
1 ether,
CHAINLINK_ETH_USD_ORACLE,
address(0),
18,
address(0),
1,
address(0),
address(0),
18,
salt
);
uint256 price = IMorphoOracle(oracle).price();
assertApproxEqRel(price, 3500 * 10 ** 36, 10 ** 35);
params.collateralToken = RE7ETH;
params.irm = IRM_MODEL;
params.lltv = LLTV_77;
params.oracle = oracle;
params.loanToken = USDA;
_logMarket(params, marketName);
IMorpho(MORPHO_BLUE).createMarket(params);
IMorpho(MORPHO_BLUE).supply(params, 0.5 ether, 0, deployer, emptyData);
IERC20(params.collateralToken).approve(MORPHO_BLUE, baseDepositAmount);
IMorpho(MORPHO_BLUE).supplyCollateral(params, baseDepositAmount, deployer, emptyData);
IMorpho(MORPHO_BLUE).borrow(params, (0.5 ether * 9) / 10, 0, deployer, deployer);
}

{
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GTUSDCPRIME
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

marketName = "gtUSDC";
uint256 baseDepositAmount = BASE_DEPOSIT_USD_AMOUNT;
oracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2(
address(GTUSDCPRIME),
1 ether,
CHAINLINK_USDC_USD_ORACLE,
address(0),
6,
address(0),
1,
address(0),
address(0),
18,
salt
);
uint256 price = IMorphoOracle(oracle).price();
assertApproxEqRel(price, 1 * 10 ** 36, 10 ** 35);
params.collateralToken = GTUSDCPRIME;
params.lltv = LLTV_86;
params.irm = IRM_MODEL;
params.oracle = oracle;
params.loanToken = USDA;
_logMarket(params, marketName);
IMorpho(MORPHO_BLUE).createMarket(params);
IMorpho(MORPHO_BLUE).supply(params, 0.5 ether, 0, deployer, emptyData);
IERC20(params.collateralToken).approve(MORPHO_BLUE, baseDepositAmount);
console.log(IERC20(params.collateralToken).balanceOf(deployer));
IMorpho(MORPHO_BLUE).supplyCollateral(params, baseDepositAmount, deployer, emptyData);
IMorpho(MORPHO_BLUE).borrow(params, (0.5 ether * 9) / 10, 0, deployer, deployer);
}

{
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RE7USDT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

marketName = "RE7 USDT";
uint256 baseDepositAmount = BASE_DEPOSIT_USD_AMOUNT;
oracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2(
address(RE7USDT),
1 ether,
CHAINLINK_USDT_USD_ORACLE,
address(0),
6,
address(0),
1,
address(0),
address(0),
18,
salt
);
uint256 price = IMorphoOracle(oracle).price();
assertApproxEqRel(price, 1 * 10 ** 36, 10 ** 35);
params.collateralToken = RE7USDT;
params.lltv = LLTV_86;
params.irm = IRM_MODEL;
params.oracle = oracle;
params.loanToken = USDA;
_logMarket(params, marketName);
IMorpho(MORPHO_BLUE).createMarket(params);
IMorpho(MORPHO_BLUE).supply(params, 0.5 ether, 0, deployer, emptyData);
IERC20(params.collateralToken).approve(MORPHO_BLUE, baseDepositAmount);
console.log(IERC20(params.collateralToken).balanceOf(deployer));
IMorpho(MORPHO_BLUE).supplyCollateral(params, baseDepositAmount, deployer, emptyData);
IMorpho(MORPHO_BLUE).borrow(params, (0.5 ether * 9) / 10, 0, deployer, deployer);
}

vm.stopBroadcast();
}

function _logMarket(MarketParams memory params, string memory marketName) internal view {
console.log("");
console.log(marketName);
console.log("collateral", params.collateralToken);
console.log("irm", params.irm);
console.log("lltv", params.lltv);
console.log("oracle", params.oracle);
console.log("loan token", params.loanToken);
uint256 price = IMorphoOracle(params.oracle).price();
console.log("oracle price", price);
console.log("formatted oracle price", price / 10 ** 36);
console.log("");
}
}
9 changes: 9 additions & 0 deletions scripts/foundry/mainnet/MainnetConstants.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ contract MainnetConstants is CommonUtils {
address constant EZETH = 0xbf5495Efe5DB9ce00f80364C8B423567e58d2110;
address constant PTWeETH = 0xc69Ad9baB1dEE23F4605a82b3354F8E40d1E5966;
address constant RSETH = 0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7;
address constant GTETHPRIME = 0x2371e134e3455e0593363cBF89d3b6cf53740618;
address constant GTUSDCPRIME = 0xdd0f28e19C1780eb6396170735D45153D261490d;
address constant RE7ETH = 0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0;
address constant RE7USDT = 0x95EeF579155cd2C5510F312c8fA39208c3Be01a8;

address constant EZETH_ETH_ORACLE = 0xF4a3e183F59D2599ee3DF213ff78b1B3b1923696;
address constant RSETH_ETH_ORACLE = 0xA736eAe8805dDeFFba40cAB8c99bCB309dEaBd9B;
Expand All @@ -40,6 +44,8 @@ contract MainnetConstants is CommonUtils {
address constant WEETH_USD_ORACLE = 0xdDb6F90fFb4d3257dd666b69178e5B3c5Bf41136;

address constant CHAINLINK_ETH_USD_ORACLE = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;
address constant CHAINLINK_USDT_USD_ORACLE = 0x3E7d1eAB13ad0104d2750B8863b489D65364e32D;
address constant CHAINLINK_USDC_USD_ORACLE = 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6;

address constant MORPHO_ORACLE_FACTORY = 0x3A7bB36Ee3f3eE32A60e9f2b33c1e5f2E83ad766;
address constant MORPHO_BLUE = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb;
Expand All @@ -49,6 +55,9 @@ contract MainnetConstants is CommonUtils {
uint256 constant LLTV_77 = 0.77 ether;
uint256 constant LLTV_62 = 0.625 ether;

uint256 BASE_DEPOSIT_ETH_AMOUNT = 9 * 10 ** 15;
uint256 BASE_DEPOSIT_USD_AMOUNT = 5 ether;

function deployUpgradeable(address implementation, bytes memory data) public returns (address) {
return address(new TransparentUpgradeableProxy(implementation, PROXY_ADMIN, data));
}
Expand Down

0 comments on commit e961963

Please sign in to comment.