From 0a93f131ca3ee2ad6dd4b807f84f82e7eec42d02 Mon Sep 17 00:00:00 2001 From: poma Date: Fri, 26 Mar 2021 23:06:46 +0300 Subject: [PATCH] arbitrum deployment --- instances.js | 69 ++--------------------------- src/execute.js | 39 ++++++++++++++--- src/generate.js | 113 +++++++++++++++++++++++++++++------------------- src/utils.js | 9 ++++ 4 files changed, 115 insertions(+), 115 deletions(-) diff --git a/instances.js b/instances.js index e6e071d..a8bee2f 100644 --- a/instances.js +++ b/instances.js @@ -1,70 +1,9 @@ module.exports = [ { - tokenAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F", - denomination: "10000000000000000000000", - domain: "dai-10000.tornadocash.eth", - symbol: "DAI", + isETH: true, + denomination: "1000000000000000000", + domain: "eth-1.tornadocash.eth", + symbol: "ETH", decimals: 18 }, - { - tokenAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F", - denomination: "100000000000000000000000", - domain: "dai-100000.tornadocash.eth", - symbol: "DAI", - decimals: 18 - }, - { - isCToken: true, - tokenAddress: "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643", - denomination: "5000000000000", - domain: "cdai-50000.tornadocash.eth", - symbol: "cDAI", - decimals: 8 - }, - { - isCToken: true, - tokenAddress: "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643", - denomination: "50000000000000", - domain: "cdai-500000.tornadocash.eth", - symbol: "cDAI", - decimals: 8 - }, - { - isCToken: true, - tokenAddress: "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643", - denomination: "500000000000000", - domain: "cdai-5000000.tornadocash.eth", - symbol: "cDAI", - decimals: 8 - }, - { - tokenAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", - denomination: "10000000", - domain: "wbtc-01.tornadocash.eth", - symbol: "wBTC", - decimals: 8 - }, - { - tokenAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", - denomination: "100000000", - domain: "wbtc-1.tornadocash.eth", - symbol: "wBTC", - decimals: 8 - }, - { - tokenAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", - denomination: "1000000000", - domain: "wbtc-10.tornadocash.eth", - symbol: "wBTC", - decimals: 8 - }, - // { - // isETH: false, - // isCToken: true, - // tokenAddress: "0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc", - // denomination: "1000000000000000000", - // domain: "fau-2.tornadocash.eth", - // symbol: "FAU", - // decimals: 18 - // }, ] diff --git a/src/execute.js b/src/execute.js index 5e6975f..d872c81 100644 --- a/src/execute.js +++ b/src/execute.js @@ -15,25 +15,52 @@ async function main() { const privateKey = process.env.PRIVATE_KEY const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL) const wallet = new ethers.Wallet(privateKey, provider) - const deployer = new ethers.Contract(actions.deployer, abi, wallet) + let deployer = new ethers.Contract(actions.deployer, abi, wallet) + + let code = await provider.getCode(actions.eipDeployer.expectedAddress) + if (!code || code === '0x') { + console.log('Deploying EIP-2470 deployer') + const balance = await provider.getBalance(actions.eipDeployer.from) + if (balance < ethers.utils.parseEther('0.0247')) { + console.log('Insufficient balance on deploy address, sending some eth') + const tx = await wallet.sendTransaction({ + to: actions.eipDeployer.from, + value: ethers.utils.parseEther('0.0247').sub(balance).toHexString(), + gasLimit: ethers.BigNumber.from(21000).toHexString(), + gasPrice: 1e6, + }) + console.log('Tx hash:', tx.hash) + } + const serialized = ethers.utils.serializeTransaction( + actions.eipDeployer.tx, + actions.eipDeployer.signature, + ) + const tx = await provider.sendTransaction(serialized) + console.log('Tx hash:', tx.hash) + } for (const action of actions.actions) { - let code = await provider.getCode(action.expectedAddress) + 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: 7e6, gasPrice: 1e6 }) + const tx = await deployer.deploy(action.bytecode, actions.salt, { gasLimit: 7e7, gasPrice: 1e6 }) console.log(`TX hash ${explorer}/tx/${tx.hash}`) try { await tx.wait() console.log(`Deployed ${action.contract} to ${explorer}/address/${action.expectedAddress}\n`) + if (action.contract === 'Deployer.sol') { + deployer = deployer.attach(action.expectedAddress) + } } catch (e) { console.error(`Failed to deploy ${action.contract}, sending debug tx`) - const tx = await wallet.sendTransaction({ gasLimit: 8e6, data: action.bytecode }) - console.log(`TX hash ${explorer}/tx/${tx.hash}`) - await tx.wait() + // const trace = await provider.send('debug_traceTransaction', [ tx.hash ]) + // console.log(trace) + const tx2 = await wallet.sendTransaction({ gasLimit: 8e6, data: action.bytecode }) + console.log(`TX hash ${explorer}/tx/${tx2.hash}`) + await tx2.wait() console.log('Mined, check revert reason on etherscan') return // throw new Error(`Failed to deploy ${action.contract}`) diff --git a/src/generate.js b/src/generate.js index 2e29a6f..9b035bc 100644 --- a/src/generate.js +++ b/src/generate.js @@ -2,60 +2,82 @@ require('dotenv').config() const fs = require('fs') const ethers = require('ethers') const { formatUnits, commify } = ethers.utils -const { deploy, getContractData } = require('./utils') +const { deploy, getContractData, expectedAddress } = require('./utils') const { DEPLOYER, SALT, HASHER, VERIFIER, COMP_ADDRESS } = process.env const instances = require('../instances') -// const deployer = getContractData('../deployer/build/contracts/Deployer.json') -// const verifier = getContractData('../tornado-core/build/contracts/Verifier.json') -// const hasher = getContractData('../tornado-core/build/contracts/Hasher.json') +const deployer = getContractData('../deployer/build/contracts/Deployer.json') +const verifier = getContractData('../tornado-core/build/contracts/Verifier.json') +const hasher = getContractData('../tornado-core/build/contracts/Hasher.json') const ethTornado = getContractData('../tornado-core/build/contracts/ETHTornado.json') const ercTornado = getContractData('../tornado-core/build/contracts/ERC20Tornado.json') const compTornado = getContractData('../tornado-core/build/contracts/cTornado.json') const actions = [] +// eip-2470 +const eipDeployer = { + tx: { + nonce: 0, + gasPrice: 100000000000, + value: 0, + data: + '0x608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c63430006020033', + gasLimit: 247000, + }, + signature: { + v: 27, + r: '0x247000', + s: '0x2470', + }, + from: '0xBb6e024b9cFFACB947A71991E386681B1Cd1477D', // needs to have 0.0247 ETH + expectedAddress: '0xce0042B868300000d44A59004Da54A005ffdcf9f', +} + // Actions needed for new blockchains // Assumes that EIP-2470 deployer is already present on the chain -// actions.push( -// deploy({ -// domain: config.deployer.address, -// 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.', -// }), -// ) -// -// // Deploy Hasher -// actions.push( -// deploy({ -// domain: 'hasher.contract.tornadocash.eth', -// contract: hasher, -// title: 'Hasher', -// description: 'MiMC hasher contract', -// dependsOn: [ -// -// ] -// }), -// ) -// -// // Deploy verifier -// actions.push( -// deploy({ -// domain: 'verifier.contract.tornadocash.eth', -// contract: verifier, -// title: 'Verifier', -// description: 'zkSNARK verifier contract for withdrawals', -// }), -// ) +actions.push( + deploy({ + domain: 'deployer.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.', + }), +) + +// Deploy Hasher +actions.push( + deploy({ + domain: 'hasher.contract.tornadocash.eth', + contract: hasher, + title: 'Hasher', + description: 'MiMC hasher contract', + dependsOn: [], + }), +) + +// Deploy verifier +actions.push( + deploy({ + domain: 'verifier.contract.tornadocash.eth', + contract: verifier, + title: 'Verifier', + description: 'zkSNARK verifier contract for withdrawals', + }), +) // Deploy instances for (const instance of instances) { - const args = [VERIFIER, HASHER, instance.denomination, 20] + const args = [ + expectedAddress(actions, 'verifier.contract.tornadocash.eth'), + expectedAddress(actions, 'hasher.contract.tornadocash.eth'), + instance.denomination, + 20, + ] if (!instance.isETH) { args.push(instance.tokenAddress) } @@ -67,18 +89,21 @@ for (const instance of instances) { domain: instance.domain, contract: instance.isETH ? ethTornado : instance.isCToken ? compTornado : ercTornado, args, - title: `Tornado.cash instance for ${commify(formatUnits(instance.denomination, instance.decimals)).replace(/\.0$/, '')} of ${ - instance.symbol + title: `Tornado.cash instance for ${commify( + formatUnits(instance.denomination, instance.decimals), + ).replace(/\.0$/, '')} of ${instance.symbol}`, + description: `Tornado cash instance for ${commify( + formatUnits(instance.denomination, instance.decimals), + ).replace(/\.0$/, '')} of ${instance.symbol}${ + instance.isETH ? '' : ` at address ${instance.tokenAddress}` }`, - description: `Tornado cash instance for ${commify(formatUnits(instance.denomination, instance.decimals)).replace(/\.0$/, '')} of ${ - instance.symbol - }${instance.isETH ? '' : ` at address ${instance.tokenAddress}`}`, }), ) } // Write output const result = { + eipDeployer, deployer: DEPLOYER, salt: SALT, actions: actions, diff --git a/src/utils.js b/src/utils.js index 882eb15..f753567 100644 --- a/src/utils.js +++ b/src/utils.js @@ -51,7 +51,16 @@ function deploy({ } } +function expectedAddress(actions, action) { + const result = actions.find((a) => a.domain === action) + if (!result) { + throw new Error(`Address not found: ${action}`) + } + return result.expectedAddress +} + module.exports = { deploy, getContractData, + expectedAddress, }