014-OVM_L1StandardBridge.deploy.ts 4.56 KB
Newer Older
1 2 3
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { ethers } from 'ethers'
4
import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
5 6 7 8 9

/* Imports: Internal */
import { getContractDefinition } from '../src/contract-defs'
import {
  getContractFromArtifact,
10 11
  deployAndVerifyAndThen,
  isHardhatNode,
12
} from '../src/deploy-utils'
13
import { names } from '../src/address-names'
14 15 16 17 18 19

const deployFn: DeployFunction = async (hre) => {
  const { deployer } = await hre.getNamedAccounts()

  const ChugSplashDictator = await getContractFromArtifact(
    hre,
20
    names.unmanaged.ChugSplashDictator,
21 22 23 24 25 26 27
    {
      signerOrProvider: deployer,
    }
  )

  const Proxy__OVM_L1StandardBridge = await getContractFromArtifact(
    hre,
28
    names.managed.contracts.Proxy__OVM_L1StandardBridge,
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    {
      iface: 'L1ChugSplashProxy',
      signerOrProvider: deployer,
    }
  )

  // Make sure the dictator has been initialized with the correct bridge code.
  const bridgeArtifact = getContractDefinition('L1StandardBridge')
  const bridgeCode = bridgeArtifact.deployedBytecode
  const codeHash = await ChugSplashDictator.codeHash()
  if (ethers.utils.keccak256(bridgeCode) !== codeHash) {
    throw new Error('code hash does not match actual bridge code')
  }

  const currentOwner = await Proxy__OVM_L1StandardBridge.connect(
    Proxy__OVM_L1StandardBridge.signer.provider
  ).callStatic.getOwner({
    from: ethers.constants.AddressZero,
  })
  const finalOwner = await ChugSplashDictator.finalOwner()

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  const messengerSlotKey = await ChugSplashDictator.messengerSlotKey()
  const messengerSlotVal = await ChugSplashDictator.messengerSlotVal()
  const bridgeSlotKey = await ChugSplashDictator.bridgeSlotKey()
  const bridgeSlotVal = await ChugSplashDictator.bridgeSlotVal()

  console.log(`
    The ChugSplashDictator contract (glory to Arstotzka) has been deployed.

    FOLLOW THESE INSTRUCTIONS CAREFULLY!

    (1) Review the storage key/value pairs below and make sure they match the expected values:

        ${messengerSlotKey}:   ${messengerSlotVal}
        ${bridgeSlotKey}:   ${bridgeSlotVal}

    (2) Review the CURRENT and FINAL proxy owners and verify that these are the expected values:

        Current proxy owner: (${currentOwner})
        Final proxy owner:   (${finalOwner})

        [${
          currentOwner === finalOwner
            ? 'THESE ARE THE SAME ADDRESSES'
            : 'THESE ARE >>>NOT<<< THE SAME ADDRESSES'
        }]

    (3) Transfer ownership of the L1ChugSplashProxy located at (${
      Proxy__OVM_L1StandardBridge.address
    })
        to the ChugSplashDictator contract located at the following address:

        TRANSFER OWNERSHIP TO THE FOLLOWING ADDRESS ONLY:
        >>>>> (${ChugSplashDictator.address}) <<<<<

    (4) Wait for the deploy process to continue.
  `)

87 88
  // Check if if we're on the hardhat chain ID. This will only happen in CI. If this is the case, we
  // can skip directly to transferring ownership over to the ChugSplashDictator contract.
89 90 91 92
  if (
    (await isHardhatNode(hre)) ||
    process.env.AUTOMATICALLY_TRANSFER_OWNERSHIP === 'true'
  ) {
93 94 95 96 97 98 99
    const owner = await hre.ethers.getSigner(currentOwner)
    await Proxy__OVM_L1StandardBridge.connect(owner).setOwner(
      ChugSplashDictator.address
    )
  }

  // Wait for ownership to be transferred to the AddressDictator contract.
100
  await awaitCondition(
101 102 103 104 105 106 107 108 109 110
    async () => {
      return hexStringEquals(
        await Proxy__OVM_L1StandardBridge.connect(
          Proxy__OVM_L1StandardBridge.signer.provider
        ).callStatic.getOwner({
          from: ethers.constants.AddressZero,
        }),
        ChugSplashDictator.address
      )
    },
111 112
    30000,
    1000
113 114 115 116 117 118 119
  )

  // Set the addresses!
  console.log('Ownership successfully transferred. Invoking doActions...')
  await ChugSplashDictator.doActions(bridgeCode)

  console.log(`Confirming that owner address was correctly set...`)
120 121 122 123 124 125 126 127 128 129 130 131 132 133
  await awaitCondition(
    async () => {
      return hexStringEquals(
        await Proxy__OVM_L1StandardBridge.connect(
          Proxy__OVM_L1StandardBridge.signer.provider
        ).callStatic.getOwner({
          from: ethers.constants.AddressZero,
        }),
        finalOwner
      )
    },
    5000,
    100
  )
134 135 136

  // Deploy a copy of the implementation so it can be successfully verified on Etherscan.
  console.log(`Deploying a copy of the bridge for Etherscan verification...`)
137
  await deployAndVerifyAndThen({
138 139 140 141 142 143 144 145 146 147
    hre,
    name: 'L1StandardBridge_for_verification_only',
    contract: 'L1StandardBridge',
    args: [],
  })
}

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

export default deployFn