Skip to content

Commit

Permalink
deployer: ledger support, no sequencer private key (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
tynes authored Nov 5, 2020
1 parent 08455c2 commit 0bb89f9
Show file tree
Hide file tree
Showing 3 changed files with 488 additions and 24 deletions.
35 changes: 25 additions & 10 deletions packages/contracts/bin/deploy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node

const contracts = require('../build/src/contract-deployment/deploy');
const { providers, Wallet } = require('ethers');
const { providers, Wallet, utils } = require('ethers');
const { LedgerSigner } = require('@ethersproject/hardware-wallets');
const { JsonRpcProvider } = providers;

const env = process.env;
const key = env.DEPLOYER_PRIVATE_KEY;
const sequencerKey = env.SEQUENCER_PRIVATE_KEY;
let SEQUENCER_ADDRESS = env.SEQUENCER_ADDRESS;
const web3Url = env.L1_NODE_WEB3_URL || 'http://127.0.0.1:8545';
const MIN_TRANSACTION_GAS_LIMIT = env.MIN_TRANSACTION_GAS_LIMIT || 0;
const MAX_TRANSACTION_GAS_LIMIT = env.MAX_TRANSACTION_GAS_LIMIT || 1000000000;
Expand All @@ -16,17 +18,30 @@ let WHITELIST_OWNER = env.WHITELIST_OWNER;
const WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT = env.WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT || true;
const FORCE_INCLUSION_PERIOD_SECONDS = env.FORCE_INCLUSION_PERIOD_SECONDS || (30 * 60);
const CHAIN_ID = env.CHAIN_ID || 420; // layer 2 chainid
const USE_LEDGER = env.USE_LEDGER || false;
const HD_PATH = env.HD_PATH || utils.defaultPath;

(async () => {
if (typeof key === 'undefined')
throw new Error('Must pass deployer key as DEPLOYER_PRIVATE_KEY');
const provider = new JsonRpcProvider(web3Url);
let signer;

if (typeof sequencerKey === 'undefined')
throw new Error('Must pass sequencer key as SEQUENCER_PRIVATE_KEY');
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);
}

const provider = new JsonRpcProvider(web3Url);
const signer = new Wallet(key, provider);
const sequencer = new Wallet(sequencerKey, provider);
if (SEQUENCER_ADDRESS) {
if (!utils.isAddress(SEQUENCER_ADDRESS))
throw new Error(`Invalid Sequencer Address: ${SEQUENCER_ADDRESS}`)
} else {
if (!sequencerKey)
throw new Error('Must pass sequencer key as SEQUENCER_PRIVATE_KEY');
const sequencer = new Wallet(sequencerKey, provider);
SEQUENCER_ADDRESS = await sequencer.getAddress()
}

if (typeof WHITELIST_OWNER === 'undefined')
WHITELIST_OWNER = signer;
Expand All @@ -35,7 +50,7 @@ const CHAIN_ID = env.CHAIN_ID || 420; // layer 2 chainid
deploymentSigner: signer,
transactionChainConfig: {
forceInclusionPeriodSeconds: FORCE_INCLUSION_PERIOD_SECONDS,
sequencer,
sequencer: SEQUENCER_ADDRESS,
},
ovmGlobalContext: {
ovmCHAINID: CHAIN_ID
Expand All @@ -58,7 +73,7 @@ const CHAIN_ID = env.CHAIN_ID || 420; // layer 2 chainid

const out = {};
out.AddressManager = AddressManager.address;
out.OVM_Sequencer = await sequencer.getAddress()
out.OVM_Sequencer = SEQUENCER_ADDRESS;
out.Deployer = await signer.getAddress()
for (const [name, contract] of Object.entries(result.contracts)) {
out[name] = contract.address;
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"deploy": "./bin/deploy.js"
},
"dependencies": {
"@ethersproject/hardware-wallets": "^5.0.8",
"ethers": "5.0.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 0bb89f9

Please sign in to comment.