|
| 1 | +import { use } from 'chai'; |
| 2 | +import { ethers } from 'hardhat'; |
| 3 | +const hre = require('hardhat'); |
| 4 | +const fs = require('fs'); |
| 5 | + |
| 6 | +async function main() { |
| 7 | + const output = { |
| 8 | + forwarderImplementation: '', |
| 9 | + forwarderFactory: '' |
| 10 | + }; |
| 11 | + |
| 12 | + const feeData = await ethers.provider.getFeeData(); |
| 13 | + const gasParams = { |
| 14 | + gasPrice: feeData.gasPrice |
| 15 | + }; |
| 16 | + |
| 17 | + const [deployer] = await ethers.getSigners(); |
| 18 | + |
| 19 | + let forwarderContractName = 'Forwarder'; |
| 20 | + let forwarderFactoryContractName = 'ForwarderFactory'; |
| 21 | + |
| 22 | + const Forwarder = await ethers.getContractFactory(forwarderContractName); |
| 23 | + const forwarder = await Forwarder.deploy(gasParams); |
| 24 | + await forwarder.deployed(); |
| 25 | + output.forwarderImplementation = forwarder.address; |
| 26 | + console.log(`${forwarderContractName} deployed at ` + forwarder.address); |
| 27 | + |
| 28 | + const ForwarderFactory = await ethers.getContractFactory( |
| 29 | + forwarderFactoryContractName |
| 30 | + ); |
| 31 | + const forwarderFactory = await ForwarderFactory.deploy( |
| 32 | + forwarder.address, |
| 33 | + gasParams |
| 34 | + ); |
| 35 | + await forwarderFactory.deployed(); |
| 36 | + output.forwarderFactory = forwarderFactory.address; |
| 37 | + console.log( |
| 38 | + `${forwarderFactoryContractName} deployed at ` + forwarderFactory.address |
| 39 | + ); |
| 40 | + |
| 41 | + fs.writeFileSync('output.json', JSON.stringify(output)); |
| 42 | + |
| 43 | + // Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract. |
| 44 | + console.log('Waiting for 5 minutes before verifying.....'); |
| 45 | + await new Promise((r) => setTimeout(r, 1000 * 300)); |
| 46 | + |
| 47 | + // We have to wait for a minimum of 10 block confirmations before we can call the etherscan api to verify |
| 48 | + await forwarder.deployTransaction.wait(10); |
| 49 | + await forwarderFactory.deployTransaction.wait(10); |
| 50 | + |
| 51 | + console.log('Done waiting, verifying'); |
| 52 | + await verifyContract(forwarderContractName, forwarder.address, []); |
| 53 | + await verifyContract(forwarderFactoryContractName, forwarderFactory.address, [ |
| 54 | + forwarder.address |
| 55 | + ]); |
| 56 | + console.log('Contracts verified'); |
| 57 | +} |
| 58 | + |
| 59 | +async function verifyContract( |
| 60 | + contractName: string, |
| 61 | + contractAddress: string, |
| 62 | + constructorArguments: string[], |
| 63 | + contract?: string |
| 64 | +) { |
| 65 | + try { |
| 66 | + const verifyContractArgs: { |
| 67 | + address: string; |
| 68 | + constructorArguments: string[]; |
| 69 | + contract?: string; |
| 70 | + } = { |
| 71 | + address: contractAddress, |
| 72 | + constructorArguments: constructorArguments |
| 73 | + }; |
| 74 | + |
| 75 | + if (contract) { |
| 76 | + verifyContractArgs.contract = contract; |
| 77 | + } |
| 78 | + |
| 79 | + await hre.run('verify:verify', verifyContractArgs); |
| 80 | + } catch (e) { |
| 81 | + // @ts-ignore |
| 82 | + // We get a failure API response if the source code has already been uploaded, don't throw in this case. |
| 83 | + if (!e.message.includes('Reason: Already Verified')) { |
| 84 | + throw e; |
| 85 | + } |
| 86 | + } |
| 87 | + console.log(`Verified ${contractName} on Etherscan!`); |
| 88 | +} |
| 89 | + |
| 90 | +main().catch((error) => { |
| 91 | + console.error(error); |
| 92 | + process.exitCode = 1; |
| 93 | +}); |
0 commit comments