deploy.js 4.81 KB
Newer Older
1
#!/usr/bin/env node
2

3
const contracts = require('../build/src/contract-deployment/deploy');
4
const { providers, Wallet, utils, ethers } = require('ethers');
5
const { LedgerSigner } = require('@ethersproject/hardware-wallets');
6 7 8 9 10
const { JsonRpcProvider } = providers;

const env = process.env;
const key = env.DEPLOYER_PRIVATE_KEY;
const sequencerKey = env.SEQUENCER_PRIVATE_KEY;
11
let SEQUENCER_ADDRESS = env.SEQUENCER_ADDRESS;
12
const web3Url = env.L1_NODE_WEB3_URL || 'http://127.0.0.1:8545';
13
const DEPLOY_TX_GAS_LIMIT = env.DEPLOY_TX_GAS_LIMIT || 5000000;
14
const MIN_TRANSACTION_GAS_LIMIT = env.MIN_TRANSACTION_GAS_LIMIT || 50000;
15
const MAX_TRANSACTION_GAS_LIMIT = env.MAX_TRANSACTION_GAS_LIMIT || 9000000;
16
const MAX_GAS_PER_QUEUE_PER_EPOCH = env.MAX_GAS_PER_QUEUE_PER_EPOCH || 250000000;
17
const SECONDS_PER_EPOCH = env.SECONDS_PER_EPOCH || 0;
18
const WAIT_FOR_RECEIPTS = env.WAIT_FOR_RECEIPTS === 'true';
19 20
let WHITELIST_OWNER = env.WHITELIST_OWNER;
const WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT = env.WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT || true;
21
const FORCE_INCLUSION_PERIOD_SECONDS = env.FORCE_INCLUSION_PERIOD_SECONDS || 2592000; // 30 days
22 23
const FRAUD_PROOF_WINDOW_SECONDS = env.FRAUD_PROOF_WINDOW_SECONDS || (60 * 60 * 24 * 7); // 7 days
const SEQUENCER_PUBLISH_WINDOW_SECONDS = env.SEQUENCER_PUBLISH_WINDOW_SECONDS || (60 * 30); // 30 min
24
const CHAIN_ID = env.CHAIN_ID || 422; // layer 2 chainid
25 26
const USE_LEDGER = env.USE_LEDGER || false;
const HD_PATH = env.HD_PATH || utils.defaultPath;
27
const BLOCK_TIME_SECONDS = env.BLOCK_TIME_SECONDS || 15;
28
const L2_CROSS_DOMAIN_MESSENGER_ADDRESS =
29
  env.L2_CROSS_DOMAIN_MESSENGER_ADDRESS || '0x4200000000000000000000000000000000000007';
30 31
let RELAYER_ADDRESS = env.RELAYER_ADDRESS || '0x0000000000000000000000000000000000000000';
const RELAYER_PRIVATE_KEY = env.RELAYER_PRIVATE_KEY;
32

33
(async () => {
34 35
  const provider = new JsonRpcProvider(web3Url);
  let signer;
36

37
  // Use the ledger for the deployer
38 39 40 41 42 43 44
  if (USE_LEDGER) {
    signer = new LedgerSigner(provider, 'default', HD_PATH);
  } else  {
    if (typeof key === 'undefined')
      throw new Error('Must pass deployer key as DEPLOYER_PRIVATE_KEY');
    signer = new Wallet(key, provider);
  }
45

46 47
  if (SEQUENCER_ADDRESS) {
    if (!utils.isAddress(SEQUENCER_ADDRESS))
48
      throw new Error(`Invalid Sequencer Address: ${SEQUENCER_ADDRESS}`);
49 50 51 52
  } else {
    if (!sequencerKey)
      throw new Error('Must pass sequencer key as SEQUENCER_PRIVATE_KEY');
    const sequencer = new Wallet(sequencerKey, provider);
53
    SEQUENCER_ADDRESS = await sequencer.getAddress();
54
  }
55 56 57 58

  if (typeof WHITELIST_OWNER === 'undefined')
    WHITELIST_OWNER = signer;

59 60 61 62 63 64 65 66 67 68
  // Use the address derived from RELAYER_PRIVATE_KEY if a private key
  // is passed. Using the zero address as the relayer address will mean
  // there is no relayer authentication.
  if (RELAYER_PRIVATE_KEY) {
    if (!utils.isAddress(RELAYER_ADDRESS))
      throw new Error(`Invalid Relayer Address: ${RELAYER_ADDRESS}`);
    const relayer = new Wallet(RELAYER_PRIVATE_KEY, provider);
    RELAYER_ADDRESS = await relayer.getAddress();
  }

69 70 71 72
  const result = await contracts.deploy({
    deploymentSigner: signer,
    transactionChainConfig: {
      forceInclusionPeriodSeconds: FORCE_INCLUSION_PERIOD_SECONDS,
73
      sequencer: SEQUENCER_ADDRESS,
74
      forceInclusionPeriodBlocks: Math.ceil(FORCE_INCLUSION_PERIOD_SECONDS/BLOCK_TIME_SECONDS),
75
    },
76 77 78 79
    stateChainConfig: {
      fraudProofWindowSeconds: FRAUD_PROOF_WINDOW_SECONDS,
      sequencerPublishWindowSeconds: SEQUENCER_PUBLISH_WINDOW_SECONDS,
    },
80
    ovmGlobalContext: {
81 82
      ovmCHAINID: CHAIN_ID,
      L2CrossDomainMessengerAddress: L2_CROSS_DOMAIN_MESSENGER_ADDRESS
83
    },
84
    l1CrossDomainMessengerConfig: {
85
      relayerAddress: RELAYER_ADDRESS,
86
    },
87 88 89 90 91 92 93 94 95 96
    ovmGasMeteringConfig: {
      minTransactionGasLimit: MIN_TRANSACTION_GAS_LIMIT,
      maxTransactionGasLimit: MAX_TRANSACTION_GAS_LIMIT,
      maxGasPerQueuePerEpoch: MAX_GAS_PER_QUEUE_PER_EPOCH,
      secondsPerEpoch: SECONDS_PER_EPOCH
    },
    whitelistConfig: {
      owner: WHITELIST_OWNER,
      allowArbitraryContractDeployment: WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT
    },
97 98 99
    ethConfig: {
      initialAmount: 0,
    },
100 101 102 103
    deployOverrides: {
      gasLimit: DEPLOY_TX_GAS_LIMIT
    },
    waitForReceipts: WAIT_FOR_RECEIPTS,
104 105 106 107 108 109 110
  });

  const { failedDeployments, AddressManager } = result;
  if (failedDeployments.length !== 0)
    throw new Error(`Contract deployment failed: ${failedDeployments.join(',')}`);

  const out = {};
111
  out.AddressManager = AddressManager.address;
112
  out.OVM_Sequencer = SEQUENCER_ADDRESS;
113
  out.Deployer = await signer.getAddress()
114
  for (const [name, contract] of Object.entries(result.contracts)) {
115
    out[name] = contract.address;
116 117 118 119 120 121
  }
  console.log(JSON.stringify(out, null, 2));
})().catch(err => {
  console.log(JSON.stringify({error: err.message, stack: err.stack}, null, 2));
  process.exit(1);
});