From 3e9a5d5e2913c25fa9edd535f707d3c2f2f311dc Mon Sep 17 00:00:00 2001 From: Mullapudi Pruthvik Date: Fri, 24 May 2024 18:00:19 +0530 Subject: [PATCH] feat(contracts): deploy v1 wallet factory contracts Ticket: COIN-114 --- hardhat.config.ts | 3 +- package.json | 2 +- scripts/deployV1Wallet.ts | 113 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 scripts/deployV1Wallet.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index d3820d5..0dbc3ba 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -15,6 +15,7 @@ const { PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT, QUICKNODE_ETH_MAINNET_API_KEY, PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP, + PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT, QUICKNODE_ARBITRUM_SEPOLIA_API_KEY, QUICKNODE_OPTIMISM_SEPOLIA_API_KEY, QUICKNODE_ARBITRUM_ONE_API_KEY, @@ -99,7 +100,7 @@ const config: HardhatUserConfig = { }, topeth: { url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`, - accounts: [`${TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT}`] + accounts: [`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`] }, opeth: { url: `${QUICKNODE_OPTIMISM_API_KEY}`, diff --git a/package.json b/package.json index f2fd0d2..f0ce140 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "scripts": { "deploy-prod": "hardhat run scripts/deploy.ts --network", - "deploy-test": "hardhat run scripts/deployV1Forwarder.ts --network", + "deploy-test": "hardhat run scripts/deployV1Wallet.ts --network", "test": "hardhat test", "coverage": "hardhat coverage", "solhint": "./node_modules/.bin/solhint --fix 'contracts/**/*.sol'", diff --git a/scripts/deployV1Wallet.ts b/scripts/deployV1Wallet.ts new file mode 100644 index 0000000..ad7f9d4 --- /dev/null +++ b/scripts/deployV1Wallet.ts @@ -0,0 +1,113 @@ +import { ethers } from 'hardhat'; +const hre = require('hardhat'); +const fs = require('fs'); + +async function main() { + const output = { + walletImplementation: '', + walletFactory: '' + }; + + const feeData = await ethers.provider.getFeeData(); + const gasParams = { + gasPrice: feeData.gasPrice! + }; + const [deployer] = await ethers.getSigners(); + const selfTransactions = 2; + + for (let i = 0; i < selfTransactions; i++) { + const tx = await deployer.sendTransaction({ + to: deployer.address, + value: ethers.utils.parseEther('0'), + gasPrice: gasParams.gasPrice + }); + await tx.wait(); + console.log(`Self transaction with nonce: ${i} complete`); + } + + const walletImplementationContractName = 'WalletSimple'; + const walletFactoryContractName = 'WalletFactory'; + + const WalletImplementation = await ethers.getContractFactory( + walletImplementationContractName + ); + const walletImplementation = await WalletImplementation.deploy(gasParams); + await walletImplementation.deployed(); + output.walletImplementation = walletImplementation.address; + console.log( + `${walletImplementationContractName} deployed at ` + + walletImplementation.address + ); + + const WalletFactory = await ethers.getContractFactory( + walletFactoryContractName + ); + const walletFactory = await WalletFactory.deploy( + walletImplementation.address, + gasParams + ); + await walletFactory.deployed(); + output.walletFactory = walletFactory.address; + console.log( + `${walletFactoryContractName} deployed at ` + walletFactory.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 walletImplementation.deployTransaction.wait(10); + await walletFactory.deployTransaction.wait(10); + + console.log('Done waiting, verifying'); + await verifyContract( + walletImplementationContractName, + walletImplementation.address, + [] + ); + await verifyContract('WalletFactory', walletFactory.address, [ + walletImplementation.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; +});