take-dump.ts 3.64 KB
Newer Older
1 2 3 4 5
/* External Imports */
import * as fs from 'fs'
import * as path from 'path'
import * as mkdirp from 'mkdirp'

6 7 8 9 10 11
const ensure = (value, key) => {
  if (typeof value === 'undefined' || value === null || Number.isNaN(value)) {
    throw new Error(`${key} is undefined, null or NaN`)
  }
}

12
/* Internal Imports */
13
import { makeL2GenesisFile } from '../src/make-genesis'
14 15 16 17 18
;(async () => {
  const outdir = path.resolve(__dirname, '../dist/dumps')
  const outfile = path.join(outdir, 'state-dump.latest.json')
  mkdirp.sync(outdir)

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 63 64 65 66
  const env = process.env

  // An account that represents the owner of the whitelist
  const whitelistOwner = env.WHITELIST_OWNER
  // The gas price oracle owner, can update values is GasPriceOracle L2 predeploy
  const gasPriceOracleOwner = env.GAS_PRICE_ORACLE_OWNER
  // The initial overhead value for the GasPriceOracle
  const gasPriceOracleOverhead = parseInt(
    env.GAS_PRICE_ORACLE_OVERHEAD || '2750',
    10
  )
  // The initial scalar value for the GasPriceOracle. The actual
  // scalar is scaled downwards by the number of decimals
  const gasPriceOracleScalar = parseInt(
    env.GAS_PRICE_ORACLE_SCALAR || '1500000',
    10
  )
  // The initial decimals that scale down the scalar in the GasPriceOracle
  const gasPriceOracleDecimals = parseInt(
    env.GAS_PRICE_ORACLE_DECIMALS || '6',
    10
  )
  // The initial L1 base fee in the GasPriceOracle. This determines how
  // expensive the L1 portion of the transaction fee is.
  const gasPriceOracleL1BaseFee = parseInt(
    env.GAS_PRICE_ORACLE_L1_BASE_FEE || '1',
    10
  )
  // The initial L2 gas price set in the GasPriceOracle
  const gasPriceOracleGasPrice = parseInt(
    env.GAS_PRICE_ORACLE_GAS_PRICE || '1',
    10
  )
  // The L2 block gas limit, used in the L2 block headers as well to limit
  // the amount of execution for a single block.
  const l2BlockGasLimit = parseInt(env.L2_BLOCK_GAS_LIMIT, 10)
  // The L2 chain id, added to the chain config
  const l2ChainId = parseInt(env.L2_CHAIN_ID, 10)
  // The block signer address, added to the block extradata for clique consensus
  const blockSignerAddress = env.BLOCK_SIGNER_ADDRESS
  // The L1 standard bridge address for cross domain messaging
  const l1StandardBridgeAddress = env.L1_STANDARD_BRIDGE_ADDRESS
  // The L1 fee wallet address, used to restrict the account that fees on L2 can
  // be withdrawn to on L1
  const l1FeeWalletAddress = env.L1_FEE_WALLET_ADDRESS
  // The L1 cross domain messenger address, used for cross domain messaging
  const l1CrossDomainMessengerAddress = env.L1_CROSS_DOMAIN_MESSENGER_ADDRESS

67 68
  ensure(whitelistOwner, 'WHITELIST_OWNER')
  ensure(gasPriceOracleOwner, 'GAS_PRICE_ORACLE_OWNER')
69 70 71 72 73 74 75
  ensure(l2BlockGasLimit, 'L2_BLOCK_GAS_LIMIT')
  ensure(l2ChainId, 'L2_CHAIN_ID')
  ensure(blockSignerAddress, 'BLOCK_SIGNER_ADDRESS')
  ensure(l1StandardBridgeAddress, 'L1_STANDARD_BRIDGE_ADDRESS')
  ensure(l1FeeWalletAddress, 'L1_FEE_WALLET_ADDRESS')
  ensure(l1CrossDomainMessengerAddress, 'L1_CROSS_DOMAIN_MESSENGER_ADDRESS')

76
  // Basic warning so users know that the whitelist will be disabled if the owner is the zero address.
77
  if (env.WHITELIST_OWNER === '0x' + '00'.repeat(20)) {
78 79 80 81 82
    console.log(
      'WARNING: whitelist owner is address(0), whitelist will be disabled'
    )
  }

83
  const genesis = await makeL2GenesisFile({
84 85 86 87 88 89 90 91 92 93 94 95 96
    whitelistOwner,
    gasPriceOracleOwner,
    gasPriceOracleOverhead,
    gasPriceOracleScalar,
    gasPriceOracleL1BaseFee,
    gasPriceOracleGasPrice,
    gasPriceOracleDecimals,
    l2BlockGasLimit,
    l2ChainId,
    blockSignerAddress,
    l1StandardBridgeAddress,
    l1FeeWalletAddress,
    l1CrossDomainMessengerAddress,
97
  })
98

99
  fs.writeFileSync(outfile, JSON.stringify(genesis, null, 4))
100
})()