diff --git a/hardhat.config.ts b/hardhat.config.ts index 3f8ac7c..69c6636 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -27,9 +27,117 @@ const { BSCSCAN_API_KEY, ARBISCAN_API_KEY, OPTIMISTIC_ETHERSCAN_API_KEY, - ZKSYNC_EXPLORER_API_KEY + ZKSYNC_EXPLORER_API_KEY, + NETWORK_NAME } = process.env; +if (!NETWORK_NAME) { + console.error( + 'Error: No network specified. Please specify the network name in environment variable "NETWORK_NAME"' + ); + process.exit(1); +} + +interface NetworkConfig { + url: string; + accounts: string[]; +} + +interface ApiKeyConfig { + [key: string]: string; +} + +const networkConfigs: { [key: string]: NetworkConfig } = { + eth: { + url: `https://ethereum-rpc.publicnode.com`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + }, + hteth: { + url: `https://rpc.holesky.ethpandaops.io/`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`] + }, + polygon: { + url: `https://polygon-rpc.com/`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + }, + tpolygon: { + // https://polygon-amoy.g.alchemy.com + url: `https://polygon-amoy-bor-rpc.publicnode.com`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + }, + bsc: { + url: `https://bsc-dataseed1.binance.org/`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + }, + tbsc: { + url: `https://data-seed-prebsc-1-s1.binance.org:8545/`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + }, + tarbeth: { + url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`, + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] + }, + arbeth: { + url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`, + 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}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] + }, + opeth: { + url: `${QUICKNODE_OPTIMISM_API_KEY}`, + accounts: [ + `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, + `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` + ] + }, + tzketh: { + url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`, + accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] + } +}; + +const apiKeyConfigs: ApiKeyConfig = { + eth: `${ETHERSCAN_API_KEY}`, + hteth: `${ETHERSCAN_API_KEY}`, + polygon: `${POLYGONSCAN_API_KEY}`, + tpolygon: `${POLYGONSCAN_API_KEY}`, + bsc: `${BSCSCAN_API_KEY}`, + tbsc: `${BSCSCAN_API_KEY}`, + arbeth: `${ARBISCAN_API_KEY}`, + tarbeth: `${ARBISCAN_API_KEY}`, + opeth: `${OPTIMISTIC_ETHERSCAN_API_KEY}`, + topeth: `${OPTIMISTIC_ETHERSCAN_API_KEY}`, + zksync: `${ZKSYNC_EXPLORER_API_KEY}`, + tzksync: `${ZKSYNC_EXPLORER_API_KEY}` +}; + +const getNetworkConfig = (network: string): NetworkConfig => { + return networkConfigs[network]; +}; + +const getApiKeyConfig = (network: string): string => { + return apiKeyConfigs[network]; +}; + +const createDynamicNetworkConfig = ( + network: string +): { [key: string]: NetworkConfig } => { + const dynamicNetwork: { [key: string]: NetworkConfig } = {}; + dynamicNetwork[network] = getNetworkConfig(network); + return dynamicNetwork; +}; + const config: HardhatUserConfig = { solidity: { compilers: [ @@ -65,89 +173,14 @@ const config: HardhatUserConfig = { })), loggingEnabled: false }, - eth: { - url: `https://ethereum-rpc.publicnode.com`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - }, - hteth: { - url: `https://rpc.holesky.ethpandaops.io/`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`] - }, - matic: { - url: `https://polygon-rpc.com/`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - }, - tmatic: { - // https://polygon-amoy.g.alchemy.com - url: `https://polygon-amoy-bor-rpc.publicnode.com`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - }, - bsc: { - url: `https://bsc-dataseed1.binance.org/`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - }, - tbsc: { - url: `https://data-seed-prebsc-1-s1.binance.org:8545/`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - }, - tarbeth: { - url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`, - accounts: [ - `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, - `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` - ] - }, - arbeth: { - url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`, - 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}`, - `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` - ] - }, - opeth: { - url: `${QUICKNODE_OPTIMISM_API_KEY}`, - accounts: [ - `${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`, - `${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}` - ] - }, - tzketh: { - url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`, - accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`] - } + ...createDynamicNetworkConfig(NETWORK_NAME.toLowerCase()) }, gasReporter: { enabled: process.env.REPORT_GAS !== undefined, currency: 'USD' }, etherscan: { - apiKey: { - //ethereum - mainnet: `${ETHERSCAN_API_KEY}`, - goerli: `${ETHERSCAN_API_KEY}`, - holesky: `${ETHERSCAN_API_KEY}`, - //polygon - polygon: `${POLYGONSCAN_API_KEY}`, - polygonAmoy: `${POLYGONSCAN_API_KEY}`, - bscTestnet: `${BSCSCAN_API_KEY}`, - bsc: `${BSCSCAN_API_KEY}`, - // arbitrum - arbitrumOne: `${ARBISCAN_API_KEY}`, - arbitrumSepolia: `${ARBISCAN_API_KEY}`, - // optimism - optimisticEthereum: `${OPTIMISTIC_ETHERSCAN_API_KEY}`, - optimisticSepolia: `${OPTIMISTIC_ETHERSCAN_API_KEY}`, - // zksync - zksync: `${ZKSYNC_EXPLORER_API_KEY}`, - zksyncSepolia: `${ZKSYNC_EXPLORER_API_KEY}` - }, + apiKey: getApiKeyConfig(NETWORK_NAME.toLowerCase()), customChains: [ { network: 'holesky', diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 0abb239..848202e 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -11,6 +11,29 @@ async function main() { forwarderFactory: '' }; + const version = await new Promise((resolve) => { + console.log( + 'In case of new coins like arbeth, opeth, zketh, use version v4. \n' + + 'If we have to deploy contracts for the older coins like eth, avax, polygon, use version v1 or v2' + ); + const stdin = process.openStdin(); + console.log('Choose the version (v1/v2/v4): '); + stdin.addListener('data', function (d) { + const answer = d.toString().trim(); + if (answer.toLowerCase() === 'v1') { + resolve('v1'); + } else if (answer.toLowerCase() === 'v2') { + resolve('v2'); + } else if (answer.toLowerCase() === 'v2') { + resolve('v4'); + } else { + console.error('Please select the correct version'); + process.exit(1); + } + stdin.removeAllListeners('data'); + }); + }); + const feeData = await ethers.provider.getFeeData(); const gasParams = { gasPrice: feeData.gasPrice @@ -20,8 +43,12 @@ async function main() { let walletImplementationContractName = ''; let walletFactoryContractName = 'WalletFactory'; - let forwarderContractName = 'Forwarder'; - let forwarderFactoryContractName = 'ForwarderFactory'; + let forwarderContractName = + version === 'v1' || version === 'v2' ? 'Forwarder' : 'ForwarderV4'; + let forwarderFactoryContractName = + version === 'v1' || version === 'v2' + ? 'ForwarderFactory' + : 'ForwarderFactoryV4'; let contractPath = `contracts/WalletSimple.sol:WalletSimple`; const chainId = await deployer.getChainId(); switch (chainId) { @@ -31,8 +58,6 @@ async function main() { //hteth case 17000: walletImplementationContractName = 'WalletSimple'; - forwarderContractName = 'ForwarderV4'; - forwarderFactoryContractName = 'ForwarderFactoryV4'; contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`; break; //matic @@ -40,8 +65,6 @@ async function main() { //tmatic case 80002: walletImplementationContractName = 'WalletSimple'; - forwarderContractName = 'ForwarderV4'; - forwarderFactoryContractName = 'ForwarderFactoryV4'; contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`; break; // bsc @@ -49,8 +72,6 @@ async function main() { // tbsc case 97: walletImplementationContractName = 'WalletSimple'; - forwarderContractName = 'ForwarderV4'; - forwarderFactoryContractName = 'ForwarderFactoryV4'; contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`; break; // arbeth @@ -58,8 +79,6 @@ async function main() { // tarbeth case 421614: walletImplementationContractName = 'WalletSimple'; - forwarderContractName = 'Forwarder'; - forwarderFactoryContractName = 'ForwarderFactory'; contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`; break; // opeth @@ -67,8 +86,6 @@ async function main() { // topeth case 11155420: walletImplementationContractName = 'WalletSimple'; - forwarderContractName = 'Forwarder'; - forwarderFactoryContractName = 'ForwarderFactory'; contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`; break; // zketh diff --git a/scripts/deployDynamic.ts b/scripts/deployDynamic.ts new file mode 100644 index 0000000..e69de29