016-Proxy__OVM_L1ETHGateway.deploy.ts 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'

/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'

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

  const Lib_AddressManager = await getDeployedContract(
    hre,
    'Lib_AddressManager',
    {
      signerOrProvider: deployer,
    }
  )

  const result = await deploy('Proxy__OVM_L1ETHGateway', {
    contract: 'Lib_ResolvedDelegateProxy',
    from: deployer,
    args: [Lib_AddressManager.address, 'OVM_L1ETHGateway'],
    log: true,
  })

  if (!result.newlyDeployed) {
    return
  }

  const Proxy__OVM_L1ETHGateway = await getDeployedContract(
    hre,
    'Proxy__OVM_L1ETHGateway',
    {
      signerOrProvider: deployer,
      iface: 'OVM_L1ETHGateway',
    }
  )

  await Proxy__OVM_L1ETHGateway.initialize(
    Lib_AddressManager.address,
    predeploys.OVM_ETH
  )

  const libAddressManager = await Proxy__OVM_L1ETHGateway.libAddressManager()
  if (libAddressManager !== Lib_AddressManager.address) {
    throw new Error(
      `\n**FATAL ERROR. THIS SHOULD NEVER HAPPEN. CHECK YOUR DEPLOYMENT.**:\n` +
        `Proxy__OVM_L1ETHGateway could not be succesfully initialized.\n` +
        `Attempted to set Lib_AddressManager to: ${Lib_AddressManager.address}\n` +
        `Actual address after initialization: ${libAddressManager}\n` +
        `This could indicate a compromised deployment.`
    )
  }

  await Lib_AddressManager.setAddress('Proxy__OVM_L1ETHGateway', result.address)
}

deployFn.dependencies = ['Lib_AddressManager', 'OVM_L1ETHGateway']
deployFn.tags = ['Proxy__OVM_L1ETHGateway']

export default deployFn