|
| 1 | +import { ethers } from 'hardhat'; |
| 2 | +const hre = require('hardhat'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +async function main() { |
| 6 | + const output = { |
| 7 | + walletImplementation: '', |
| 8 | + walletFactory: '', |
| 9 | + forwarderImplementation: '', |
| 10 | + forwarderFactory: '', |
| 11 | + batcher: '' |
| 12 | + }; |
| 13 | + |
| 14 | + const contractName = 'Batcher'; |
| 15 | + const transferGasLimit = '200000'; |
| 16 | + |
| 17 | + const Batcher = await ethers.getContractFactory(contractName); |
| 18 | + const batcher = await Batcher.deploy(transferGasLimit); |
| 19 | + await batcher.deployed(); |
| 20 | + output.batcher = batcher.address; |
| 21 | + console.log('Batcher deployed at ' + batcher.address); |
| 22 | + |
| 23 | + fs.writeFileSync('output.json', JSON.stringify(output)); |
| 24 | + |
| 25 | + // Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract. |
| 26 | + console.log('Waiting for 5 minutes before verifying.....'); |
| 27 | + await new Promise((r) => setTimeout(r, 1000 * 300)); |
| 28 | + |
| 29 | + console.log('Done waiting, verifying'); |
| 30 | + await verifyContract(contractName, batcher.address, [transferGasLimit]); |
| 31 | + console.log('Contracts verified'); |
| 32 | +} |
| 33 | + |
| 34 | +async function verifyContract( |
| 35 | + contractName: string, |
| 36 | + contractAddress: string, |
| 37 | + constructorArguments: string[], |
| 38 | + contract?: string |
| 39 | +) { |
| 40 | + try { |
| 41 | + const verifyContractArgs: { |
| 42 | + address: string; |
| 43 | + constructorArguments: string[]; |
| 44 | + contract?: string; |
| 45 | + } = { |
| 46 | + address: contractAddress, |
| 47 | + constructorArguments: constructorArguments |
| 48 | + }; |
| 49 | + |
| 50 | + if (contract) { |
| 51 | + verifyContractArgs.contract = contract; |
| 52 | + } |
| 53 | + |
| 54 | + await hre.run('verify:verify', verifyContractArgs); |
| 55 | + } catch (e) { |
| 56 | + // @ts-ignore |
| 57 | + // We get a failure API response if the source code has already been uploaded, don't throw in this case. |
| 58 | + if (!e.message.includes('Reason: Already Verified')) { |
| 59 | + throw e; |
| 60 | + } |
| 61 | + } |
| 62 | + console.log(`Verified ${contractName} on Etherscan!`); |
| 63 | +} |
| 64 | + |
| 65 | +main().catch((error) => { |
| 66 | + console.error(error); |
| 67 | + process.exitCode = 1; |
| 68 | +}); |
0 commit comments