check-l2-config.ts 3.05 KB
Newer Older
1
import { task, types } from 'hardhat/config'
2
import { providers, Contract } from 'ethers'
3
import '@nomiclabs/hardhat-ethers'
4
import 'hardhat-deploy'
5

6 7
import { predeploys } from '../src'

8 9 10 11 12 13 14 15
task('check-l2-config', 'Validate L2 config')
  .addParam(
    'l2ProviderUrl',
    'L2 provider URL.',
    'http://localhost:9545',
    types.string
  )
  .setAction(async (args, hre) => {
16
    const l2Provider = new providers.JsonRpcProvider(args.l2ProviderUrl)
17

18 19 20 21
    const loadPredeploy = async (name: string): Promise<Contract> => {
      const artifact = await hre.artifacts.readArtifact(name)
      return new Contract(predeploys[name], artifact.abi, l2Provider)
    }
22

23 24 25 26
    const getContractAddress = async (name: string): Promise<string> => {
      const deployment = await hre.deployments.get(name)
      return deployment.address
    }
27

28 29 30 31 32 33 34 35
    // Verify that all predeploys have code.
    // TODO: Actually check that the predeploys have the expected code.
    for (const [name, address] of Object.entries(predeploys)) {
      const code = await l2Provider.getCode(address)
      if (code === '0x') {
        throw new Error(`Missing code for ${name}`)
      }
    }
36

37 38 39
    // Confirming that L2CrossDomainMessenger.otherMessenger() is set properly.
    const L2CrossDomainMessenger = await loadPredeploy('L2CrossDomainMessenger')
    const actualOtherMessenger = await getContractAddress(
40 41
      'L1CrossDomainMessengerProxy'
    )
42 43
    const expectedOtherMessenger = await L2CrossDomainMessenger.otherMessenger()
    if (expectedOtherMessenger !== actualOtherMessenger) {
44
      throw new Error(
45
        `L2CrossDomainMessenger otherMessenger not set correctly. Got ${actualOtherMessenger}, expected ${actualOtherMessenger}`
46 47 48
      )
    }

49 50 51 52 53
    // Confirming that L2StandardBridge.messenger() is set properly.
    const L2StandardBridge = await loadPredeploy('L2StandardBridge')
    const actualMessenger = await L2StandardBridge.messenger()
    const expectedMessenger = predeploys.L2CrossDomainMessenger
    if (expectedMessenger !== actualMessenger) {
54
      throw new Error(
55
        `L2StandardBridge messenger not set correctly. Got ${actualMessenger}, expected ${expectedMessenger}`
56 57 58
      )
    }

59 60 61 62
    // Confirming that L2StandardBridge.otherBridge() is set properly.
    const actualOtherBridge = await getContractAddress('L1StandardBridgeProxy')
    const expectedOtherBridge = await L2StandardBridge.otherBridge()
    if (expectedOtherBridge !== actualOtherBridge) {
63
      throw new Error(
64
        `L2StandardBridge otherBridge not set correctly. Got ${actualMessenger}, expected ${expectedOtherBridge}`
65 66 67
      )
    }

68 69 70
    // Confirming that OptimismMintableERC20Factory.bridge() is set properly.
    const OptimismMintableERC20Factory = await loadPredeploy(
      'OptimismMintableERC20Factory'
71
    )
72 73 74
    const actualBridge = await OptimismMintableERC20Factory.bridge()
    const expectedBridge = predeploys.L2StandardBridge
    if (expectedBridge !== actualBridge) {
75
      throw new Error(
76
        `OptimismMintableERC20Factory bridge not set correctly. Got ${actualBridge}, expected ${expectedBridge}`
77 78 79
      )
    }
  })