diff --git a/hardhat.config.ts b/hardhat.config.ts index 0dbc3ba..b9b76fa 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -92,19 +92,31 @@ const config: HardhatUserConfig = { }, tarbeth: { url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`, - accounts: [`${TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT}`] + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] }, arbeth: { url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`, - accounts: [`${MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT}`] + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] }, topeth: { url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`, - accounts: [`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`] + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] }, opeth: { url: `${QUICKNODE_OPTIMISM_API_KEY}`, - accounts: [`${MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT}`] + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] }, tzketh: { url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`, diff --git a/package.json b/package.json index f0ce140..b0d6257 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "test": "test" }, "scripts": { - "deploy-prod": "hardhat run scripts/deploy.ts --network", - "deploy-test": "hardhat run scripts/deployV1Wallet.ts --network", + "deploy-prod": "hardhat run scripts/deployV1FactoryContracts.ts --network", + "deploy-test": "hardhat run scripts/deployV1FactoryContracts.ts --network", "test": "hardhat test", "coverage": "hardhat coverage", "solhint": "./node_modules/.bin/solhint --fix 'contracts/**/*.sol'", diff --git a/scripts/deployV1Wallet.ts b/scripts/deployV1FactoryContracts.ts similarity index 55% rename from scripts/deployV1Wallet.ts rename to scripts/deployV1FactoryContracts.ts index ad7f9d4..c1fa075 100644 --- a/scripts/deployV1Wallet.ts +++ b/scripts/deployV1FactoryContracts.ts @@ -5,19 +5,24 @@ const fs = require('fs'); async function main() { const output = { walletImplementation: '', - walletFactory: '' + walletFactory: '', + forwarderImplementation: '', + forwarderFactory: '' }; const feeData = await ethers.provider.getFeeData(); + + const [walletDeployer, forwarderDeployer] = await ethers.getSigners(); + const gasParams = { - gasPrice: feeData.gasPrice! + gasPrice: feeData.gasPrice!.mul('2') }; - const [deployer] = await ethers.getSigners(); - const selfTransactions = 2; - for (let i = 0; i < selfTransactions; i++) { - const tx = await deployer.sendTransaction({ - to: deployer.address, + console.log('Deploying wallet contracts....'); + const walletSelfTransactions = 2; + for (let i = 0; i < walletSelfTransactions; i++) { + const tx = await walletDeployer.sendTransaction({ + to: walletDeployer.address, value: ethers.utils.parseEther('0'), gasPrice: gasParams.gasPrice }); @@ -29,7 +34,8 @@ async function main() { const walletFactoryContractName = 'WalletFactory'; const WalletImplementation = await ethers.getContractFactory( - walletImplementationContractName + walletImplementationContractName, + walletDeployer ); const walletImplementation = await WalletImplementation.deploy(gasParams); await walletImplementation.deployed(); @@ -40,7 +46,8 @@ async function main() { ); const WalletFactory = await ethers.getContractFactory( - walletFactoryContractName + walletFactoryContractName, + walletDeployer ); const walletFactory = await WalletFactory.deploy( walletImplementation.address, @@ -52,6 +59,54 @@ async function main() { `${walletFactoryContractName} deployed at ` + walletFactory.address ); + const forwarderSelfTransactions = 234; + console.log('Deploying forwarder contracts....'); + + for (let i = 0; i < forwarderSelfTransactions; i++) { + const tx = await forwarderDeployer.sendTransaction({ + to: forwarderDeployer.address, + value: ethers.utils.parseEther('0'), + gasPrice: gasParams.gasPrice + }); + await tx.wait(); + console.log(`Self transaction with nonce: ${i} complete`); + } + + const forwarderImplementationContractName = 'Forwarder'; + const forwarderFactoryContractName = 'ForwarderFactory'; + + const ForwarderImplementation = await ethers.getContractFactory( + forwarderImplementationContractName, + forwarderDeployer + ); + + const forwarderImplementation = await ForwarderImplementation.deploy( + gasParams + ); + await forwarderImplementation.deployed(); + output.forwarderImplementation = forwarderImplementation.address; + + console.log( + `${forwarderImplementationContractName} deployed at ` + + forwarderImplementation.address, + forwarderDeployer + ); + + const ForwarderFactory = await ethers.getContractFactory( + forwarderFactoryContractName + ); + + const forwarderFactory = await ForwarderFactory.deploy( + forwarderImplementation.address, + gasParams + ); + + await forwarderFactory.deployed(); + output.forwarderFactory = forwarderFactory.address; + console.log( + `${forwarderFactoryContractName} deployed at ` + forwarderFactory.address + ); + fs.writeFileSync('output.json', JSON.stringify(output)); // Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract. @@ -62,6 +117,8 @@ async function main() { await walletImplementation.deployTransaction.wait(10); await walletFactory.deployTransaction.wait(10); + await forwarderImplementation.deployTransaction.wait(10); + await forwarderFactory.deployTransaction.wait(10); console.log('Done waiting, verifying'); await verifyContract( @@ -73,6 +130,16 @@ async function main() { walletImplementation.address ]); + await verifyContract( + forwarderImplementationContractName, + forwarderImplementation.address, + [] + ); + + await verifyContract('ForwarderFactory', forwarderFactory.address, [ + forwarderImplementation.address + ]); + console.log('Contracts verified'); } diff --git a/scripts/deployV1Forwarder.ts b/scripts/deployV1Forwarder.ts deleted file mode 100644 index 1c5c76f..0000000 --- a/scripts/deployV1Forwarder.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { use } from 'chai'; -import { ethers } from 'hardhat'; -const hre = require('hardhat'); -const fs = require('fs'); - -async function main() { - const output = { - forwarderImplementation: '', - forwarderFactory: '' - }; - - const feeData = await ethers.provider.getFeeData(); - const gasParams = { - gasPrice: feeData.gasPrice - }; - - const [deployer] = await ethers.getSigners(); - - let forwarderContractName = 'Forwarder'; - let forwarderFactoryContractName = 'ForwarderFactory'; - - const Forwarder = await ethers.getContractFactory(forwarderContractName); - const forwarder = await Forwarder.deploy(gasParams); - await forwarder.deployed(); - output.forwarderImplementation = forwarder.address; - console.log(`${forwarderContractName} deployed at ` + forwarder.address); - - const ForwarderFactory = await ethers.getContractFactory( - forwarderFactoryContractName - ); - const forwarderFactory = await ForwarderFactory.deploy( - forwarder.address, - gasParams - ); - await forwarderFactory.deployed(); - output.forwarderFactory = forwarderFactory.address; - console.log( - `${forwarderFactoryContractName} deployed at ` + forwarderFactory.address - ); - - fs.writeFileSync('output.json', JSON.stringify(output)); - - // Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract. - console.log('Waiting for 5 minutes before verifying.....'); - await new Promise((r) => setTimeout(r, 1000 * 300)); - - // We have to wait for a minimum of 10 block confirmations before we can call the etherscan api to verify - await forwarder.deployTransaction.wait(10); - await forwarderFactory.deployTransaction.wait(10); - - console.log('Done waiting, verifying'); - await verifyContract(forwarderContractName, forwarder.address, []); - await verifyContract(forwarderFactoryContractName, forwarderFactory.address, [ - forwarder.address - ]); - console.log('Contracts verified'); -} - -async function verifyContract( - contractName: string, - contractAddress: string, - constructorArguments: string[], - contract?: string -) { - try { - const verifyContractArgs: { - address: string; - constructorArguments: string[]; - contract?: string; - } = { - address: contractAddress, - constructorArguments: constructorArguments - }; - - if (contract) { - verifyContractArgs.contract = contract; - } - - await hre.run('verify:verify', verifyContractArgs); - } catch (e) { - // @ts-ignore - // We get a failure API response if the source code has already been uploaded, don't throw in this case. - if (!e.message.includes('Reason: Already Verified')) { - throw e; - } - } - console.log(`Verified ${contractName} on Etherscan!`); -} - -main().catch((error) => { - console.error(error); - process.exitCode = 1; -});