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 () => { ...@@ -67,7 +67,7 @@ const main = async () => {
ovmAddressManagerOwner: deployer.address, ovmAddressManagerOwner: deployer.address,
numDeployConfirmations: 0, numDeployConfirmations: 0,
noCompile: process.env.NO_COMPILE ? true : false, 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 // 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' ...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -4,15 +4,11 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -5,12 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils' ...@@ -5,12 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getReusableContract, getLiveContract,
waitUntilTrue, waitUntilTrue,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(
hre, hre,
'Lib_AddressManager' 'Lib_AddressManager'
) )
......
...@@ -5,15 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils' ...@@ -5,15 +5,12 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getReusableContract, getLiveContract,
waitUntilTrue, waitUntilTrue,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
// todo: this fails when trying to do a fresh deploy, because Lib_ResolvedDelegateProxy // 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. // requires that the implementation has already been set in the Address Manager.
......
...@@ -4,16 +4,12 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -4,16 +4,12 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndPostDeploy,
getDeployedContract, getLiveContract,
getReusableContract,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys' import { predeploys } from '../src/predeploys'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getReusableContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
// ToDo: Clean up the method of mapping names to addresses esp. // ToDo: Clean up the method of mapping names to addresses esp.
// There's probably a more functional way to generate an object or something. // There's probably a more functional way to generate an object or something.
...@@ -31,7 +27,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -31,7 +27,7 @@ const deployFn: DeployFunction = async (hre) => {
const addresses = await Promise.all( const addresses = await Promise.all(
names.map(async (n) => { 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' ...@@ -3,23 +3,26 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils' import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import { getLiveContract, waitUntilTrue } from '../src/hardhat-deploy-ethers'
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
// There is a risk that on a fresh deployment we could get front-run, // 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. // and the Proxy would be bricked. But that feels unlikely, and we can recover from it.
console.log(`Initializing Proxy__L1CrossDomainMessenger...`) console.log(`Initializing Proxy__L1CrossDomainMessenger...`)
const proxy = getLiveContract('Proxy__L1CrossDomainMessenger') const proxy = await getLiveContract(hre, 'Proxy__L1CrossDomainMessenger', {
await proxy.initialize(Lib_AddressManager.address) iface: 'L1CrossDomainMessenger',
signerOrProvider: deployer,
})
const libAddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await proxy.initialize(libAddressManager.address)
console.log(`Checking that contract was correctly initialized...`) console.log(`Checking that contract was correctly initialized...`)
await waitUntilTrue(async () => { await waitUntilTrue(async () => {
return hexStringEquals( return hexStringEquals(
await proxy.libAddressManager(), await proxy.libAddressManager(),
Lib_AddressManager.address libAddressManager.address
) )
}) })
} }
......
...@@ -136,7 +136,14 @@ export const getAdvancedContract = (opts: { ...@@ -136,7 +136,14 @@ export const getAdvancedContract = (opts: {
return contract 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, hre: any,
name: string, name: string,
options: { options: {
...@@ -144,14 +151,24 @@ export const getDeployedContract = async ( ...@@ -144,14 +151,24 @@ export const getDeployedContract = async (
signerOrProvider?: Signer | Provider | string signerOrProvider?: Signer | Provider | string
} = {} } = {}
): Promise<Contract> => { ): 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) await hre.ethers.provider.waitForTransaction(deployed.receipt.transactionHash)
// Get the correct interface. // Get the correct interface.
let iface = new hre.ethers.utils.Interface(deployed.abi) iface = new hre.ethers.utils.Interface(deployed.abi)
if (options.iface) { if (options.iface) {
const factory = await hre.ethers.getContractFactory(options.iface) factory = await hre.ethers.getContractFactory(options.iface)
iface = factory.interface 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