-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: script to setup Morpho markets
- Loading branch information
Showing
9 changed files
with
693 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
contracts/interfaces/external/morpho/IMorphoChainlinkOracleV2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity >=0.5.0; | ||
|
||
/// @title IMorphoChainlinkOracleV2Factory | ||
/// @author Morpho Labs | ||
/// @custom:contact [email protected] | ||
/// @notice Interface for MorphoChainlinkOracleV2Factory | ||
interface IMorphoChainlinkOracleV2Factory { | ||
/// @notice Emitted when a new Chainlink oracle is created. | ||
/// @param oracle The address of the Chainlink oracle. | ||
/// @param caller The caller of the function. | ||
event CreateMorphoChainlinkOracleV2(address caller, address oracle); | ||
|
||
/// @notice Whether a Chainlink oracle vault was created with the factory. | ||
function isMorphoChainlinkOracleV2(address target) external view returns (bool); | ||
|
||
/// @dev Here is the list of assumptions that guarantees the oracle behaves as expected: | ||
/// - The vaults, if set, are ERC4626-compliant. | ||
/// - The feeds, if set, are Chainlink-interface-compliant. | ||
/// - Decimals passed as argument are correct. | ||
/// - The base vaults's sample shares quoted as assets and the base feed prices don't overflow when multiplied. | ||
/// - The quote vault's sample shares quoted as assets and the quote feed prices don't overflow when multiplied. | ||
/// @param baseVault Base vault. Pass address zero to omit this parameter. | ||
/// @param baseVaultConversionSample The sample amount of base vault shares used to convert to underlying. | ||
/// Pass 1 if the base asset is not a vault. Should be chosen such that converting `baseVaultConversionSample` to | ||
/// assets has enough precision. | ||
/// @param baseFeed1 First base feed. Pass address zero if the price = 1. | ||
/// @param baseFeed2 Second base feed. Pass address zero if the price = 1. | ||
/// @param baseTokenDecimals Base token decimals. | ||
/// @param quoteVault Quote vault. Pass address zero to omit this parameter. | ||
/// @param quoteVaultConversionSample The sample amount of quote vault shares used to convert to underlying. | ||
/// Pass 1 if the quote asset is not a vault. Should be chosen such that converting `quoteVaultConversionSample` to | ||
/// assets has enough precision. | ||
/// @param quoteFeed1 First quote feed. Pass address zero if the price = 1. | ||
/// @param quoteFeed2 Second quote feed. Pass address zero if the price = 1. | ||
/// @param quoteTokenDecimals Quote token decimals. | ||
/// @param salt The salt to use for the CREATE2. | ||
/// @dev The base asset should be the collateral token and the quote asset the loan token. | ||
function createMorphoChainlinkOracleV2( | ||
address baseVault, | ||
uint256 baseVaultConversionSample, | ||
address baseFeed1, | ||
address baseFeed2, | ||
uint256 baseTokenDecimals, | ||
address quoteVault, | ||
uint256 quoteVaultConversionSample, | ||
address quoteFeed1, | ||
address quoteFeed2, | ||
uint256 quoteTokenDecimals, | ||
bytes32 salt | ||
) external returns (address oracle); | ||
} | ||
|
||
interface IMorphoOracle { | ||
/// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. | ||
/// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in | ||
/// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` | ||
/// decimals of precision. | ||
function price() external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#! /bin/bash | ||
|
||
source lib/utils/helpers/common.sh | ||
|
||
function main { | ||
if [ ! -f .env ]; then | ||
echo ".env not found!" | ||
exit 1 | ||
fi | ||
source .env | ||
|
||
echo "Which chain would you like to fork ?" | ||
echo "- 1: Ethereum Mainnet" | ||
echo "- 2: Arbitrum" | ||
echo "- 3: Polygon" | ||
echo "- 4: Gnosis" | ||
echo "- 5: Avalanche" | ||
echo "- 6: Base" | ||
echo "- 7: Binance Smart Chain" | ||
echo "- 8: Celo" | ||
echo "- 9: Polygon ZkEvm" | ||
echo "- 10: Optimism" | ||
echo "- 11: Linea" | ||
|
||
read option | ||
|
||
uri=$(chain_to_uri $option) | ||
if [ -z "$uri" ]; then | ||
echo "Unknown network" | ||
exit 1 | ||
fi | ||
|
||
echo "What block do you want to fork ? (Can leave empty for instant)" | ||
|
||
read block | ||
|
||
if [ -z "$block" ]; then | ||
echo "Forking $uri" | ||
anvil --fork-url $uri | ||
else | ||
echo "Forking $uri at block $block" | ||
anvil --fork-url $uri --fork-block-number $block | ||
fi | ||
} | ||
|
||
main |
Submodule pendle-core-v2-public
added at
fb0fcc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ChainId, registry } from '@angleprotocol/sdk'; | ||
import { deployments, ethers, network } from 'hardhat'; | ||
|
||
import { CoreBorrow, CoreBorrow__factory } from '../typechain'; | ||
|
||
async function main() { | ||
const { deployer } = await ethers.getNamedSigners(); | ||
const coreBorrowAddress = (await deployments.get('CoreBorrowTest')).address | ||
const newGovernor = registry(network.config.chainId as ChainId)?.Governor! | ||
|
||
const coreBorrow = new ethers.Contract(coreBorrowAddress, CoreBorrow__factory.createInterface(), deployer) as CoreBorrow; | ||
console.log("Adding governor") | ||
console.log(newGovernor,coreBorrowAddress); | ||
await coreBorrow.connect(deployer).addGovernor(newGovernor) | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// 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 } 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 { | ||
error ZeroAdress(); | ||
|
||
function run() external { | ||
uint256 deployerPrivateKey = vm.deriveKey(vm.envString("MNEMONIC_MAINNET"), "m/44'/60'/0'/0/", 0); | ||
address deployer = vm.addr(deployerPrivateKey); | ||
console.log("Address: %s", deployer); | ||
console.log(deployer.balance); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
MarketParams memory params; | ||
bytes memory emptyData; | ||
|
||
// TODO: comment when testing in prod | ||
deal(EZETH, deployer, 10 ** 16); | ||
deal(RSETH, deployer, 10 ** 16); | ||
deal(PTETHFI, deployer, 10 ** 16); | ||
deal(USDA, deployer, 3 ether); | ||
|
||
IERC20(USDA).approve(MORPHO_BLUE, type(uint256).max); | ||
|
||
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
SETUP EZETH | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ | ||
{ | ||
bytes32 salt; | ||
address ezETHOracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2( | ||
address(0), | ||
1, | ||
EZETH_ETH_ORACLE, | ||
CHAINLINK_ETH_USD_ORACLE, | ||
18, | ||
address(0), | ||
1, | ||
address(0), | ||
address(0), | ||
18, | ||
salt | ||
); | ||
console.log(IMorphoOracle(ezETHOracle).price()); | ||
params.collateralToken = EZETH; | ||
params.irm = IRM_MODEL; | ||
params.lltv = LLTV_77; | ||
params.oracle = ezETHOracle; | ||
params.loanToken = USDA; | ||
IMorpho(MORPHO_BLUE).createMarket(params); | ||
IMorpho(MORPHO_BLUE).supply(params, 1 ether, 0, deployer, emptyData); | ||
// 0.01 ezETH | ||
IERC20(EZETH).approve(MORPHO_BLUE, 10 ** 16); | ||
IMorpho(MORPHO_BLUE).supplyCollateral(params, 10 ** 16, deployer, emptyData); | ||
IMorpho(MORPHO_BLUE).borrow(params, (1 ether * 9) / 10, 0, deployer, deployer); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
SETUP RSETH | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ | ||
|
||
{ | ||
bytes32 salt; | ||
address rsETHOracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY).createMorphoChainlinkOracleV2( | ||
address(0), | ||
1, | ||
RSETH_ETH_ORACLE, | ||
CHAINLINK_ETH_USD_ORACLE, | ||
18, | ||
address(0), | ||
1, | ||
address(0), | ||
address(0), | ||
18, | ||
salt | ||
); | ||
|
||
console.log(IMorphoOracle(rsETHOracle).price()); | ||
|
||
params.collateralToken = RSETH; | ||
params.irm = IRM_MODEL; | ||
params.lltv = LLTV_77; | ||
params.oracle = rsETHOracle; | ||
params.loanToken = USDA; | ||
IMorpho(MORPHO_BLUE).createMarket(params); | ||
IMorpho(MORPHO_BLUE).supply(params, 1 ether, 0, deployer, emptyData); | ||
IERC20(RSETH).approve(MORPHO_BLUE, 10 ** 16); | ||
IMorpho(MORPHO_BLUE).supplyCollateral(params, 10 ** 16, deployer, emptyData); | ||
IMorpho(MORPHO_BLUE).borrow(params, (1 ether * 9) / 10, 0, deployer, deployer); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
SETUP PT WEETH | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ | ||
|
||
{ | ||
bytes32 salt; | ||
address ptETHFIOracle = IMorphoChainlinkOracleV2Factory(MORPHO_ORACLE_FACTORY) | ||
.createMorphoChainlinkOracleV2( | ||
address(0), | ||
1, | ||
// TODO: make sure it's been updated | ||
PTEETH_WEETH_ORACLE, | ||
WEETH_USD_ORACLE, | ||
18, | ||
address(0), | ||
1, | ||
address(0), | ||
address(0), | ||
18, | ||
salt | ||
); | ||
console.log(IMorphoOracle(ptETHFIOracle).price()); | ||
params.collateralToken = PTETHFI; | ||
params.irm = IRM_MODEL; | ||
params.lltv = LLTV_62; | ||
params.oracle = ptETHFIOracle; | ||
params.loanToken = USDA; | ||
IMorpho(MORPHO_BLUE).createMarket(params); | ||
IMorpho(MORPHO_BLUE).supply(params, 1 ether, 0, deployer, emptyData); | ||
IERC20(PTETHFI).approve(MORPHO_BLUE, 10 ** 16); | ||
IMorpho(MORPHO_BLUE).supplyCollateral(params, 10 ** 16, deployer, emptyData); | ||
IMorpho(MORPHO_BLUE).borrow(params, (1 ether * 9) / 10, 0, deployer, deployer); | ||
} | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ChainId, registry } from '@angleprotocol/sdk/dist'; | ||
import { BigNumber, Contract } from 'ethers'; | ||
import { deployments, ethers, network } from 'hardhat'; | ||
import yargs from 'yargs'; | ||
|
||
import { | ||
AgTokenSideChainMultiBridgeNameable, | ||
AgTokenSideChainMultiBridgeNameable__factory, | ||
} from '../../typechain'; | ||
|
||
const argv = yargs.env('').boolean('ci').parseSync(); | ||
|
||
async function main() { | ||
const { deployer } = await ethers.getNamedSigners(); | ||
const chainId = ChainId.MAINNET; | ||
const stablecoinAddress = registry(chainId)?.agEUR?.AgToken!; | ||
const stableContract = new Contract( | ||
stablecoinAddress, | ||
AgTokenSideChainMultiBridgeNameable__factory.abi, | ||
deployer, | ||
) as AgTokenSideChainMultiBridgeNameable; | ||
|
||
console.log(await stableContract.name()) | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |