Skip to content

Commit

Permalink
deployment and verification scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Sep 30, 2024
1 parent fc54493 commit 1070c84
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async function main() {
'phase2-assets/collaterals/deploy_aave_v3_usdc.ts',
'phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts',
'phase2-assets/collaterals/deploy_cbeth_collateral.ts',
'phase2-assets/collaterals/deploy_morphoeUSD.ts',
'phase2-assets/assets/deploy_stg.ts'
)
} else if (chainId == '42161' || chainId == '421614') {
Expand Down
94 changes: 94 additions & 0 deletions scripts/deployment/phase2-assets/collaterals/deploy_morphoeUSD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import fs from 'fs'
import hre from 'hardhat'
import { getChainId } from '../../../../common/blockchain-utils'
import { baseL2Chains, networkConfig } from '../../../../common/configuration'
import { fp } from '../../../../common/numbers'
import { expect } from 'chai'
import { CollateralStatus } from '../../../../common/constants'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
getDeploymentFilename,
fileExists,
} from '../../common'
import {
eUSD_ORACLE_TIMEOUT,
eUSD_ORACLE_ERROR,
eUSD_USD_FEED,
PRICE_TIMEOUT,
DELAY_UNTIL_DEFAULT,
} from '../../../../test/plugins/individual-collateral/meta-morpho/constants'
import { MetaMorphoFiatCollateral } from '../../../../typechain'
import { ContractFactory } from 'ethers'

async function main() {
// ==== Read Configuration ====
const [deployer] = await hre.ethers.getSigners()

const chainId = await getChainId(hre)

console.log(`Deploying Collateral to network ${hre.network.name} (${chainId})
with burner account: ${deployer.address}`)

if (!networkConfig[chainId]) {
throw new Error(`Missing network configuration for ${hre.network.name}`)
}

// Get phase1 deployment
const phase1File = getDeploymentFilename(chainId)
if (!fileExists(phase1File)) {
throw new Error(`${phase1File} doesn't exist yet. Run phase 1`)
}
// Check previous step completed
const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId)
const assetCollDeployments = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)

const deployedCollateral: string[] = []

/******** Deploy MetaMorpho Morpho eUSD - meUSD **************************/

// Only for base
if (baseL2Chains.includes(hre.network.name)) {
const MetaMorphoFiatCollateralFactory: ContractFactory = await hre.ethers.getContractFactory(
'MetaMorphoFiatCollateral'
)

const collateral = <MetaMorphoFiatCollateral>await MetaMorphoFiatCollateralFactory.connect(
deployer
).deploy(
{
priceTimeout: PRICE_TIMEOUT.toString(),
chainlinkFeed: eUSD_USD_FEED,
oracleError: eUSD_ORACLE_ERROR.toString(),
erc20: networkConfig[chainId].tokens.meUSD,
maxTradeVolume: fp('1e6').toString(), // 17m vault
oracleTimeout: eUSD_ORACLE_TIMEOUT.toString(),
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: eUSD_ORACLE_ERROR.add(fp('0.01')).toString(), // +1% buffer rule
delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(),
},
fp('1e-4') // can have mild drawdowns
)
await collateral.deployed()

console.log(`Deployed meUSD to ${hre.network.name} (${chainId}): ${collateral.address}`)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.meUSD = collateral.address
assetCollDeployments.erc20s.meUSD = networkConfig[chainId].tokens.meUSD
deployedCollateral.push(collateral.address.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

console.log(`Deployed collateral to ${hre.network.name} (${chainId})
New deployments: ${deployedCollateral}
Deployment file: ${assetCollDeploymentFilename}`)
}
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
60 changes: 60 additions & 0 deletions scripts/verification/collateral-plugins/verify_morphoeUSD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import hre from 'hardhat'
import { getChainId } from '../../../common/blockchain-utils'
import { developmentChains, networkConfig } from '../../../common/configuration'
import { fp } from '../../../common/numbers'
import {
getDeploymentFile,
getAssetCollDeploymentFilename,
IAssetCollDeployments,
} from '../../deployment/common'
import {
eUSD_ORACLE_TIMEOUT,
eUSD_ORACLE_ERROR,
eUSD_USD_FEED,
PRICE_TIMEOUT,
DELAY_UNTIL_DEFAULT,
} from '../../../test/plugins/individual-collateral/meta-morpho/constants'
import { verifyContract } from '../../deployment/utils'

let deployments: IAssetCollDeployments

async function main() {
// ********** Read config **********
const chainId = await getChainId(hre)
if (!networkConfig[chainId]) {
throw new Error(`Missing network configuration for ${hre.network.name}`)
}

if (developmentChains.includes(hre.network.name)) {
throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`)
}

const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId)
deployments = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)

/******** Verify meUSD **************************/
await verifyContract(
chainId,
deployments.collateral.steakUSDC,
[
{
priceTimeout: PRICE_TIMEOUT.toString(),
chainlinkFeed: eUSD_USD_FEED,
oracleError: eUSD_ORACLE_ERROR.toString(),
erc20: networkConfig[chainId].tokens.meUSD,
maxTradeVolume: fp('1e6').toString(),
oracleTimeout: eUSD_ORACLE_TIMEOUT.toString(),
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: eUSD_ORACLE_ERROR.add(fp('0.01')).toString(), // +1% buffer rule
delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(),
},
fp('1e-4'), // can have small drawdowns
],
'contracts/plugins/assets/meta-morpho/MetaMorphoFiatCollateral.sol:MetaMorphoFiatCollateral'
)
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
1 change: 1 addition & 0 deletions scripts/verify_etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function main() {
'collateral-plugins/verify_aave_v3_usdc.ts',
'collateral-plugins/verify_wsteth.ts',
'collateral-plugins/verify_cbeth.ts',
'collateral-plugins/verify_morphoeUSD.ts',
'assets/verify_stg.ts'
)
} else if (chainId == '42161' || chainId == '421614') {
Expand Down

0 comments on commit 1070c84

Please sign in to comment.