Commit 2a05cc4d authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

refactor(contracts): Add getReusableContract function

parent 586161ae
......@@ -67,6 +67,7 @@ const main = async () => {
ovmAddressManagerOwner: deployer.address,
numDeployConfirmations: 0,
noCompile: process.env.NO_COMPILE ? true : false,
tags: 'upgrade,Lib_AddressManager,Proxy__L1CrossDomainMessenger,Proxy__L1StandardBridge,deployer-set-addresses',
})
// Stuff below this line is currently required for CI to work properly. We probably want to
......
......@@ -9,7 +9,10 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({
hre,
......
......@@ -9,7 +9,10 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({
hre,
......
......@@ -9,7 +9,10 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({
hre,
......
......@@ -9,7 +9,10 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({
hre,
......
......@@ -9,7 +9,10 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({
hre,
......
......@@ -15,6 +15,9 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
// todo: this fails when trying to do a fresh deploy, because Lib_ResolvedDelegateProxy
// requires that the implementation has already been set in the Address Manager.
// The revert message is: 'Target address must be initialized'
await deployAndPostDeploy({
hre,
name: 'Proxy__OVM_L1CrossDomainMessenger',
......
/* Imports: External */
import { DeployFunction, DeploymentsExtension } from 'hardhat-deploy/dist/types'
import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
......@@ -7,10 +7,16 @@ import {
getDeployedContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(hre, 'Lib_AddressManager')
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
// ToDo: Clean up the method of mapping names to addresses esp.
// There's probably a more functional way to generate an object or something.
const names = [
'ChainStorageContainer-CTC-batches',
'ChainStorageContainer-SCC-batches',
......@@ -20,7 +26,6 @@ const deployFn: DeployFunction = async (hre) => {
'OVM_L1CrossDomainMessenger',
'Proxy__L1CrossDomainMessenger',
'Proxy__L1StandardBridge',
'OVM_Proposer',
]
const addresses = await Promise.all(
......@@ -29,6 +34,14 @@ const deployFn: DeployFunction = async (hre) => {
})
)
// Add non-deployed addresses to the arrays
names.push('L2CrossDomainMessenger')
addresses.push(predeploys.L2CrossDomainMessenger)
names.push('OVM_Sequencer')
addresses.push((hre as any).deployConfig.ovmSequencerAddress)
names.push('OVM_Proposer')
addresses.push((hre as any).deployConfig.ovmProposerAddress)
await deployAndPostDeploy({
hre,
name: 'AddressSetter',
......
......@@ -2,7 +2,10 @@
import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import { registerAddress } from '../src/hardhat-deploy-ethers'
import {
registerAddress,
getDeployedContract,
} from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'
const deployFn: DeployFunction = async (hre) => {
......@@ -30,6 +33,24 @@ const deployFn: DeployFunction = async (hre) => {
name: 'OVM_Proposer',
address: (hre as any).deployConfig.ovmProposerAddress,
})
const names = [
'ChainStorageContainer-CTC-batches',
'ChainStorageContainer-SCC-batches',
'CanonicalTransactionChain',
'StateCommitmentChain',
'BondManager',
'OVM_L1CrossDomainMessenger',
'Proxy__L1CrossDomainMessenger',
'Proxy__L1StandardBridge',
]
await Promise.all(
names.map(async (name) => {
const address = (await getDeployedContract(hre, name)).address
await registerAddress({ hre, name, address })
})
)
}
deployFn.tags = ['set-addresses', 'upgrade']
......
/* Imports: External */
import { sleep } from '@eth-optimism/core-utils'
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
defaultHardhatNetworkHdAccountsConfigParams,
defaultHardhatNetworkParams,
} from 'hardhat/internal/core/config/default-config'
import { normalizeHardhatNetworkAccountsConfig } from 'hardhat/internal/core/providers/util'
/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
// This is a TEMPORARY way to fund the default hardhat accounts on L2. The better way to do this is
// to make a modification to hardhat-ovm. However, I don't have the time right now to figure the
// details of how to make that work cleanly. This is fine in the meantime.
const deployFn: DeployFunction = async (hre) => {
// Only execute this step if we're on the hardhat chain ID.
const { chainId } = await hre.ethers.provider.getNetwork()
if (chainId === defaultHardhatNetworkParams.chainId) {
const L1StandardBridge = await getDeployedContract(
hre,
'Proxy__L1StandardBridge',
{
iface: 'L1StandardBridge',
}
)
// Default has 20 accounts but we restrict to 20 accounts manually as well just to prevent
// future problems if the number of default accounts increases for whatever reason.
const accounts = normalizeHardhatNetworkAccountsConfig(
defaultHardhatNetworkHdAccountsConfigParams
).slice(0, 20)
// Fund the accounts in parallel to speed things up.
await Promise.all(
accounts.map(async (account, index) => {
// Add a sleep here to avoid any potential issues with spamming hardhat. Not sure if this
// is strictly necessary but it can't hurt.
await sleep(200 * index)
const wallet = new hre.ethers.Wallet(
account.privateKey,
hre.ethers.provider
)
const balance = await wallet.getBalance()
const depositAmount = balance.div(2) // Deposit half of the wallet's balance into L2.
await L1StandardBridge.connect(wallet).depositETH(8_000_000, '0x', {
value: depositAmount,
gasLimit: 2_000_000, // Idk, gas estimation was broken and this fixes it.
})
console.log(
`✓ Funded ${wallet.address} on L2 with ${hre.ethers.utils.formatEther(
depositAmount
)} ETH`
)
})
)
}
}
deployFn.tags = ['fund-accounts']
export default deployFn
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment