Commit e93ee9ec authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

refactor(Contracts): combine getReusableContract and getDeployedContract into getLiveContract

parent 75b1e727
......@@ -67,7 +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',
tags: 'fresh',
})
// Stuff below this line is currently required for CI to work properly. We probably want to
......
......@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
hre,
......
......@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
hre,
......
......@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
hre,
......
......@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
hre,
......
......@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
hre,
......
......@@ -5,12 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
deployAndPostDeploy,
getReusableContract,
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
const Lib_AddressManager = await getLiveContract(
hre,
'Lib_AddressManager'
)
......
......@@ -5,15 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
deployAndPostDeploy,
getReusableContract,
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(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.
......
......@@ -4,16 +4,12 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
getDeployedContract,
getReusableContract,
getLiveContract,
} 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 getLiveContract(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.
......@@ -31,7 +27,7 @@ const deployFn: DeployFunction = async (hre) => {
const addresses = await Promise.all(
names.map(async (n) => {
return (await getDeployedContract(hre, n)).address
return (await getLiveContract(hre, n)).address
})
)
......
......@@ -3,23 +3,26 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
import { getLiveContract, waitUntilTrue } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
// There is a risk that on a fresh deployment we could get front-run,
// and the Proxy would be bricked. But that feels unlikely, and we can recover from it.
console.log(`Initializing Proxy__L1CrossDomainMessenger...`)
const proxy = getLiveContract('Proxy__L1CrossDomainMessenger')
await proxy.initialize(Lib_AddressManager.address)
const proxy = await getLiveContract(hre, 'Proxy__L1CrossDomainMessenger', {
iface: 'L1CrossDomainMessenger',
signerOrProvider: deployer,
})
const libAddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await proxy.initialize(libAddressManager.address)
console.log(`Checking that contract was correctly initialized...`)
await waitUntilTrue(async () => {
return hexStringEquals(
await proxy.libAddressManager(),
Lib_AddressManager.address
libAddressManager.address
)
})
}
......
......@@ -136,7 +136,14 @@ export const getAdvancedContract = (opts: {
return contract
}
export const getDeployedContract = async (
// A map from contract names to config names which can be passed as arguments to hardhat deploy
const configNames = {
Lib_AddressManager: 'libAddressManager',
Proxy__L1CrossDomainMessenger: 'proxyL1CrossDomainMessenger',
Proxy__L1StandardBridge: 'proxyL1StandardBridge',
}
export const getLiveContract = async (
hre: any,
name: string,
options: {
......@@ -144,14 +151,24 @@ export const getDeployedContract = async (
signerOrProvider?: Signer | Provider | string
} = {}
): Promise<Contract> => {
const deployed = await hre.deployments.get(name)
let factory = await hre.ethers.getContractFactory(name)
let iface = factory.interface
// First check to see if the contract is being reused in an upgrade, rather than freshly deployed.
// If so, then a valid address would have been provided for one of the 3 contracts in configNames.
const addr = (hre as any).deployConfig[configNames[name]]
if (hre.ethers.utils.isAddress(addr)) {
return new Contract(addr, iface)
}
// Otherwise, look for a previously deployed contract
const deployed = await hre.deployments.get(name)
await hre.ethers.provider.waitForTransaction(deployed.receipt.transactionHash)
// Get the correct interface.
let iface = new hre.ethers.utils.Interface(deployed.abi)
iface = new hre.ethers.utils.Interface(deployed.abi)
if (options.iface) {
const factory = await hre.ethers.getContractFactory(options.iface)
factory = await hre.ethers.getContractFactory(options.iface)
iface = factory.interface
}
......
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