• smartcontracts's avatar
    feat: introduce hardhat-deploy-config (#2755) · 27234f68
    smartcontracts authored
    * feat: introduce hardhat-deploy-config
    
    Creates a new package hardhat-deploy-config. We're using the same
    configuration system for all of our contracts package, so might as well
    turn it into a hardhat plugin to avoid duplicating code.
    
    * feat(ct): use hardhat-deploy-config
    
    * plugin: don't validate if spec not passed
    
    * contracts: update deps
    
    * contracts-bedrock: use deploy config plugin
    
    * contracts-bedrock: deploy instructions
    
    * contracts-bedrock: modularize deployment
    
    * contracts-bedrock: add deploy-config
    
    * contracts-bedrock: add in deploy config spec
    
    * lint: fix
    Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
    Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
    27234f68
000-hardhat-setup.ts 2.4 KB
/* eslint @typescript-eslint/no-var-requires: "off" */
import { ethers } from 'ethers'
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { awaitCondition } from '@eth-optimism/core-utils'

import {
  getContractFromArtifact,
  fundAccount,
  sendImpersonatedTx,
  BIG_BALANCE,
} from '../src/deploy-utils'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
  if (!hre.deployConfig.isForkedNetwork) {
    return
  }

  console.log(`Running custom setup for forked experimental networks`)
  const { deployer } = await hre.getNamedAccounts()

  // Fund the deployer account so it can be used for the rest of this deployment.
  console.log(`Funding deployer account...`)
  await fundAccount(hre, deployer, BIG_BALANCE)

  // Get a reference to the AddressManager contract.
  const Lib_AddressManager = await getContractFromArtifact(
    hre,
    names.unmanaged.Lib_AddressManager
  )

  // Transfer ownership of the AddressManager to the deployer.
  console.log(`Setting AddressManager owner to ${deployer}`)
  await sendImpersonatedTx({
    hre,
    contract: Lib_AddressManager,
    fn: 'transferOwnership',
    from: await Lib_AddressManager.owner(),
    gas: ethers.BigNumber.from(2_000_000).toHexString(),
    args: [deployer],
  })

  console.log(`Waiting for owner to be correctly set...`)
  await awaitCondition(
    async () => {
      return (await Lib_AddressManager.owner()) === deployer
    },
    5000,
    100
  )

  // Get a reference to the L1StandardBridge contract.
  const Proxy__OVM_L1StandardBridge = await getContractFromArtifact(
    hre,
    'Proxy__OVM_L1StandardBridge'
  )

  // Transfer ownership of the L1StandardBridge to the deployer.
  console.log(`Setting L1StandardBridge owner to ${deployer}`)
  await sendImpersonatedTx({
    hre,
    contract: Proxy__OVM_L1StandardBridge,
    fn: 'setOwner',
    from: await Proxy__OVM_L1StandardBridge.callStatic.getOwner({
      from: hre.ethers.constants.AddressZero,
    }),
    gas: ethers.BigNumber.from(2_000_000).toHexString(),
    args: [deployer],
  })

  console.log(`Waiting for owner to be correctly set...`)
  await awaitCondition(
    async () => {
      return (
        (await Proxy__OVM_L1StandardBridge.callStatic.getOwner({
          from: hre.ethers.constants.AddressZero,
        })) === deployer
      )
    },
    5000,
    100
  )
}

deployFn.tags = ['hardhat', 'upgrade']

export default deployFn