From 077588ceceaaefc2cd237902a3f19cb41c498581 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 20 Oct 2021 12:01:31 +0300 Subject: [PATCH] execute --- .env.example | 10 +++++++--- package.json | 2 +- src/execute.js | 34 +++++++++++++++++++++++----------- src/generate.js | 17 +++++++++++++++-- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example index 0429309..a8fb83b 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ GOVERNANCE=0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce L2_OMNIBRIDGE=0x59447362798334d3485c64D1e4870Fde2DDC0d75 L2_TOKEN=0xCa8d20f3e0144a72C6B5d576e9Bd3Fd8557E2B04 L2_AMB=0x162e898bd0aacb578c8d5f8d6ca588c13d2a383f +L1_CHAIN_ID=100 L1_OMNIBRIDGE=0xf0b456250dc9990662a6f25808cc74a6d1131ea9 L1_TOKEN=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c @@ -13,8 +14,11 @@ L1_CHAIN_ID=56 MINIMUM_WITHDRAWAL_AMOUNT=0.05 MAXIMUM_DEPOSIT_AMOUNT=1 - PRIVATE_KEY=0x -RPC_URL= -NET_ID=42 + +L1_RPC_URL= +L2_RPC_URL= +L1_EXPLORER= +L2_EXPLORER= + GAS_PRICE_IN_WEI=123000000000 diff --git a/package.json b/package.json index b80e3b3..dcbc2bf 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "ens": "node src/ens.js", "execute": "node src/execute.js", "build": "./build.sh && yarn generate", - "deploy": "yarn build && yarn ens && yarn execute", + "deploy": "yarn build && yarn execute", "eslint": "eslint --ext .js --ignore-path .gitignore src", "prettier:check": "prettier --check src --config .prettierrc", "prettier:fix": "prettier --write src --config .prettierrc", diff --git a/src/execute.js b/src/execute.js index cf3dc6b..d63eddf 100644 --- a/src/execute.js +++ b/src/execute.js @@ -3,17 +3,13 @@ const ethers = require('ethers') const actions = require('../actions.json') const abi = require('../abi/deployer.abi.json') -const prefix = { - 1: '', - 42: 'kovan.', - 5: 'goerli.', -} +const { L1_EXPLORER, L2_EXPLORER, L1_RPC_URL, L2_RPC_URL, GAS_PRICE_IN_WEI } = process.env -const explorer = `https://${prefix[process.env.NET_ID]}etherscan.io` - -async function main() { +async function execute(isL1) { + const RPC_URL = isL1 ? L1_RPC_URL : L2_RPC_URL + const explorer = isL1 ? L1_EXPLORER : L2_EXPLORER const privateKey = process.env.PRIVATE_KEY - const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL) + const provider = new ethers.providers.JsonRpcProvider(RPC_URL) const wallet = new ethers.Wallet(privateKey, provider) let deployer = new ethers.Contract(actions.deployer, abi, wallet) console.log('actions.deployer', actions.deployer) @@ -41,13 +37,20 @@ async function main() { } for (const action of actions.actions) { + if ((isL1 && !action.isL1Contract) || (!isL1 && action.isL1Contract)) { + continue + } + code = await provider.getCode(action.expectedAddress) if (code && code !== '0x') { console.log(`${action.contract} is already deployed at ${explorer}/address/${action.expectedAddress}`) continue } console.log(`Deploying ${action.contract} to ${action.domain} (${action.expectedAddress})`) - const tx = await deployer.deploy(action.bytecode, actions.salt, { gasLimit: 70e6, gasPrice: 1e9 }) + const tx = await deployer.deploy(action.bytecode, actions.salt, { + gasLimit: 5e6, + gasPrice: GAS_PRICE_IN_WEI, + }) console.log(`TX hash ${explorer}/tx/${tx.hash}`) try { await tx.wait() @@ -59,7 +62,11 @@ async function main() { console.error(`Failed to deploy ${action.contract}, sending debug tx`) // const trace = await provider.send('debug_traceTransaction', [ tx.hash ]) // console.log(trace) - const tx2 = await wallet.sendTransaction({ gasLimit: 70e6, gasPrice: 1e9, data: action.bytecode }) + const tx2 = await wallet.sendTransaction({ + gasLimit: 5e6, + gasPrice: GAS_PRICE_IN_WEI, + data: action.bytecode, + }) console.log(`TX hash ${explorer}/tx/${tx2.hash}`) await tx2.wait() console.log('Mined, check revert reason on etherscan') @@ -69,4 +76,9 @@ async function main() { } } +async function main() { + await execute(true) + await execute(false) +} + main() diff --git a/src/generate.js b/src/generate.js index 6af8dff..c3f96d4 100644 --- a/src/generate.js +++ b/src/generate.js @@ -52,19 +52,20 @@ const eipDeployer = { // Actions needed for new blockchains // Assumes that EIP-2470 deployer is already present on the chain +// L1 actions.push( deploy({ - domain: 'deployer.contract.tornadocash.eth', + domain: 'deployerL1.contract.tornadocash.eth', contract: deployer, args: ['0x0000000000000000000000000000000000000000'], dependsOn: [], title: 'Deployment proxy', description: 'This a required contract to initialize all other contracts. It is simple wrapper around EIP-2470 Singleton Factory that emits an event of contract deployment. The wrapper also validates if the deployment was successful.', + isL1Contract: true, }), ) -// L1 actions.push( deploy({ domain: 'l1Helper.contract.tornadocash.eth', @@ -79,6 +80,18 @@ actions.push( // L2 // Deploy Hasher +actions.push( + deploy({ + domain: 'deployerL2.contract.tornadocash.eth', + contract: deployer, + args: ['0x0000000000000000000000000000000000000000'], + dependsOn: [], + title: 'Deployment proxy', + description: + 'This a required contract to initialize all other contracts. It is simple wrapper around EIP-2470 Singleton Factory that emits an event of contract deployment. The wrapper also validates if the deployment was successful.', + }), +) + actions.push( deploy({ domain: 'hasher.contract.tornadocash.eth',