deploy.ts 4.17 KB
Newer Older
1 2 3 4 5
// WARNING: DO NOT USE THIS FILE TO DEPLOY CONTRACTS TO PRODUCTION
// WE ARE REMOVING THIS FILE IN A FUTURE RELEASE, IT IS ONLY TO BE USED AS PART OF THE LOCAL
// DEPLOYMENT PROCESS. USE A DEPLOYMENT SCRIPT LOCATED IN scripts/deploy-scripts/ WHEN DEPLOYING
// TO A PRODUCTION ENVIRONMENT.

6
import { Wallet } from 'ethers'
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import path from 'path'
import dirtree from 'directory-tree'
import fs from 'fs'

// Ensures that all relevant environment vars are properly set. These lines *must* come before the
// hardhat import because importing will load the config (which relies on these vars). Necessary
// because CI currently uses different var names than the ones we've chosen here.
// TODO: Update CI so that we don't have to do this anymore.
process.env.HARDHAT_NETWORK = 'custom' // "custom" here is an arbitrary name. only used for CI.
process.env.CONTRACTS_TARGET_NETWORK = 'custom'
process.env.CONTRACTS_DEPLOYER_KEY = process.env.DEPLOYER_PRIVATE_KEY
process.env.CONTRACTS_RPC_URL =
  process.env.L1_NODE_WEB3_URL || 'http://127.0.0.1:8545'

import hre from 'hardhat'

23
const sequencer = new Wallet(process.env.SEQUENCER_PRIVATE_KEY)
24
const proposer = new Wallet(process.env.PROPOSER_PRIVATE_KEY)
25 26
const deployer = new Wallet(process.env.DEPLOYER_PRIVATE_KEY)

27 28 29 30 31 32 33 34 35 36 37 38 39 40
const parseEnv = () => {
  const ensure = (env, type) => {
    if (typeof process.env[env] === 'undefined') {
      return undefined
    }
    if (type === 'number') {
      return parseInt(process.env[env], 10)
    }
    return process.env[env]
  }

  return {
    l1BlockTimeSeconds: ensure('BLOCK_TIME_SECONDS', 'number'),
    ctcMaxTransactionGasLimit: ensure('MAX_TRANSACTION_GAS_LIMIT', 'number'),
41 42
    ctcL2GasDiscountDivisor: ensure('L2_GAS_DISCOUNT_DIVISOR', 'number'),
    ctcEnqueueGasCost: ensure('ENQUEUE_GAS_COST', 'number'),
43
    sccFraudProofWindow: ensure('FRAUD_PROOF_WINDOW_SECONDS', 'number'),
44 45 46 47
    sccSequencerPublishWindow: ensure(
      'SEQUENCER_PUBLISH_WINDOW_SECONDS',
      'number'
    ),
48 49
  }
}
50

51
const main = async () => {
52 53 54 55 56
  // Just be really verbose about this...
  console.log(
    `WARNING: DO NOT USE THIS FILE IN PRODUCTION! FOR LOCAL DEVELOPMENT ONLY!`
  )

57 58
  const config = parseEnv()

59
  await hre.run('deploy', {
60 61
    l1BlockTimeSeconds: config.l1BlockTimeSeconds,
    ctcMaxTransactionGasLimit: config.ctcMaxTransactionGasLimit,
62 63
    ctcL2GasDiscountDivisor: config.ctcL2GasDiscountDivisor,
    ctcEnqueueGasCost: config.ctcEnqueueGasCost,
64 65
    sccFraudProofWindow: config.sccFraudProofWindow,
    sccSequencerPublishWindow: config.sccFraudProofWindow,
66
    ovmSequencerAddress: sequencer.address,
67
    ovmProposerAddress: proposer.address,
68
    ovmAddressManagerOwner: deployer.address,
69
    numDeployConfirmations: 0,
70
    noCompile: process.env.NO_COMPILE ? true : false,
71 72 73 74 75 76
  })

  // Stuff below this line is currently required for CI to work properly. We probably want to
  // update our CI so this is no longer necessary. But I'm adding it for backwards compat so we can
  // get the hardhat-deploy stuff merged. Woot.
  const nicknames = {
77
    Lib_AddressManager: 'AddressManager',
78 79
  }

80
  const contracts: any = dirtree(
81
    path.resolve(__dirname, `../deployments/custom`)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  )
    .children.filter((child) => {
      return child.extension === '.json'
    })
    .reduce((contractsAccumulator, child) => {
      const contractName = child.name.replace('.json', '')
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      const artifact = require(path.resolve(
        __dirname,
        `../deployments/custom/${child.name}`
      ))
      contractsAccumulator[nicknames[contractName] || contractName] =
        artifact.address
      return contractsAccumulator
    }, {})
97

98 99 100
  contracts.OVM_Sequencer = await sequencer.getAddress()
  contracts.Deployer = await deployer.getAddress()

101
  const addresses = JSON.stringify(contracts, null, 2)
102
  const dumpsPath = path.resolve(__dirname, '../dist/dumps')
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  if (!fs.existsSync(dumpsPath)) {
    fs.mkdirSync(dumpsPath)
  }
  const addrsPath = path.resolve(dumpsPath, 'addresses.json')
  fs.writeFileSync(addrsPath, addresses)
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.log(
      JSON.stringify({ error: error.message, stack: error.stack }, null, 2)
    )
    process.exit(1)
  })