010-AddressSetter.deploy.ts 2.73 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 7

/* Imports: Internal */
import {
  deployAndPostDeploy,
8
  getLiveContract,
9
} from '../src/hardhat-deploy-ethers'
10
import { predeploys } from '../src/predeploys'
11 12

const deployFn: DeployFunction = async (hre) => {
13
  const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
14

15 16
  // ToDo: Clean up the method of mapping names to addresses esp.
  // There's probably a more functional way to generate an object or something.
17
  const allContractNames = [
18 19 20 21 22 23
    'ChainStorageContainer-CTC-batches',
    'ChainStorageContainer-SCC-batches',
    'CanonicalTransactionChain',
    'StateCommitmentChain',
    'BondManager',
    'OVM_L1CrossDomainMessenger',
24 25
    'Proxy__OVM_L1CrossDomainMessenger',
    'Proxy__OVM_L1StandardBridge',
26 27
  ]

28 29 30 31 32 33 34 35 36
  let namesAndAddresses: {
    name: string
    address: string
  }[] = await Promise.all(
    allContractNames.map(async (name) => {
      return {
        name,
        address: (await getLiveContract(hre, name)).address,
      }
37 38 39
    })
  )

40
  // Add non-deployed addresses to the Address Dictator arguments.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  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.
    {
      name: 'OVM_Sequencer',
      address: (hre as any).deployConfig.ovmSequencerAddress,
    },
    // OVM_Proposer is the address allowed to submit state roots (transaction results) to the
    // StateCommitmentChain.
    {
      name: 'OVM_Proposer',
      address: (hre as any).deployConfig.ovmProposerAddress,
    },
  ]
63

64 65 66 67 68 69
  // Filter out all addresses that will not change, so that the log statement is maximally
  // verifiable and readable.
  namesAndAddresses = namesAndAddresses.filter(async ({ name, address }) => {
    const existingAddress = await Lib_AddressManager.getAddress(name)
    return !hexStringEquals(existingAddress, address)
  })
70

71 72
  await deployAndPostDeploy({
    hre,
73 74
    name: 'AddressDictator',
    contract: 'AddressDictator',
75 76 77
    args: [
      Lib_AddressManager.address,
      (hre as any).deployConfig.ovmAddressManagerOwner,
78 79 80 81 82 83
      namesAndAddresses.map((pair) => {
        return pair.name
      }),
      namesAndAddresses.map((pair) => {
        return pair.address
      }),
84 85 86 87
    ],
  })
}

88
deployFn.tags = ['upgrade', 'AddressDictator']
89 90

export default deployFn