010-AddressDictator.deploy.ts 2.5 KB
Newer Older
1
/* Imports: External */
2
import { DeployFunction } from 'hardhat-deploy/dist/types'
3
import { hexStringEquals } from '@eth-optimism/core-utils'
4 5 6

/* Imports: Internal */
import {
7
  deployAndVerifyAndThen,
8
  getContractFromArtifact,
9
} from '../src/deploy-utils'
10
import { names } from '../src/address-names'
11
import { predeploys } from '../src/predeploys'
12 13

const deployFn: DeployFunction = async (hre) => {
14 15
  const Lib_AddressManager = await getContractFromArtifact(
    hre,
16
    names.unmanaged.Lib_AddressManager
17
  )
18

19 20 21 22
  let namesAndAddresses: {
    name: string
    address: string
  }[] = await Promise.all(
23
    Object.values(names.managed.contracts).map(async (name) => {
24 25
      return {
        name,
26
        address: (await getContractFromArtifact(hre, name)).address,
27
      }
28 29 30
    })
  )

31
  // Add non-deployed addresses to the Address Dictator arguments.
32 33 34 35 36 37 38 39 40 41 42 43
  namesAndAddresses = [
    ...namesAndAddresses,
    // L2CrossDomainMessenger is the address of the predeploy on L2. We can refactor off-chain
    // services such that we can remove the need to set this address, but for now it's easier
    // to simply keep setting the address.
    {
      name: 'L2CrossDomainMessenger',
      address: predeploys.L2CrossDomainMessenger,
    },
    // OVM_Sequencer is the address allowed to submit "Sequencer" blocks to the
    // CanonicalTransactionChain.
    {
44
      name: names.managed.accounts.OVM_Sequencer,
45
      address: hre.deployConfig.ovmSequencerAddress,
46 47 48 49
    },
    // OVM_Proposer is the address allowed to submit state roots (transaction results) to the
    // StateCommitmentChain.
    {
50
      name: names.managed.accounts.OVM_Proposer,
51
      address: hre.deployConfig.ovmProposerAddress,
52 53
    },
  ]
54

55 56
  // Filter out all addresses that will not change, so that the log statement is maximally
  // verifiable and readable.
57 58 59 60 61 62 63 64
  const existingAddresses = {}
  for (const pair of namesAndAddresses) {
    existingAddresses[pair.name] = await Lib_AddressManager.getAddress(
      pair.name
    )
  }
  namesAndAddresses = namesAndAddresses.filter(({ name, address }) => {
    return !hexStringEquals(existingAddresses[name], address)
65
  })
66

67
  await deployAndVerifyAndThen({
68
    hre,
69
    name: names.unmanaged.AddressDictator,
70 71
    args: [
      Lib_AddressManager.address,
72
      hre.deployConfig.ovmAddressManagerOwner,
73 74 75 76 77 78
      namesAndAddresses.map((pair) => {
        return pair.name
      }),
      namesAndAddresses.map((pair) => {
        return pair.address
      }),
79 80 81 82
    ],
  })
}

83
deployFn.tags = ['upgrade', 'AddressDictator']
84 85

export default deployFn