From e7df7a8a0311f5853b567b13551f97945e7f246c Mon Sep 17 00:00:00 2001
From: yuetloo <contact@yuetloo.com>
Date: Wed, 3 Apr 2024 20:56:38 -0400
Subject: [PATCH] map hardhat network name to etherscan name to retrieve the
 etherscan api key

---
 contracts/hardhat.config.ts                    |  2 +-
 contracts/tasks/runners/exportRound.ts         | 12 +++++++++++-
 contracts/utils/providers/EtherscanProvider.ts |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts
index 0a30c06b2..e9fcb6931 100644
--- a/contracts/hardhat.config.ts
+++ b/contracts/hardhat.config.ts
@@ -59,7 +59,7 @@ export default {
         'https://sepolia-rollup.arbitrum.io/rpc',
       accounts,
     },
-    optimisticEthereum: {
+    optimism: {
       url: process.env.JSONRPC_HTTP_URL || 'https://mainnet.optimism.io',
       accounts,
     },
diff --git a/contracts/tasks/runners/exportRound.ts b/contracts/tasks/runners/exportRound.ts
index 4eadf9818..da14269c1 100644
--- a/contracts/tasks/runners/exportRound.ts
+++ b/contracts/tasks/runners/exportRound.ts
@@ -29,6 +29,11 @@ type RoundListEntry = {
   isFinalized: boolean
 }
 
+// Map hardhat network name to the etherscan api network name in the hardhat.config
+const ETHERSCAN_NETWORKS: Record<string, string> = {
+  optimism: 'optimisticEthereum',
+}
+
 const toUndefined = () => undefined
 const toString = (val: bigint) => BigInt(val).toString()
 const toZero = () => BigInt(0)
@@ -41,13 +46,18 @@ function roundListFileName(directory: string): string {
   return path.join(directory, 'rounds.json')
 }
 
+function toEtherscanNetworkName(network: string): string {
+  return ETHERSCAN_NETWORKS[network] ?? network
+}
+
 function getEtherscanApiKey(config: any, network: string): string {
   let etherscanApiKey = ''
   if (config.etherscan?.apiKey) {
     if (typeof config.etherscan.apiKey === 'string') {
       etherscanApiKey = config.etherscan.apiKey
     } else {
-      etherscanApiKey = config.etherscan.apiKey[network]
+      const etherscanNetwork = toEtherscanNetworkName(network)
+      etherscanApiKey = config.etherscan.apiKey[etherscanNetwork]
     }
   }
 
diff --git a/contracts/utils/providers/EtherscanProvider.ts b/contracts/utils/providers/EtherscanProvider.ts
index efa0cadb0..5a35ac557 100644
--- a/contracts/utils/providers/EtherscanProvider.ts
+++ b/contracts/utils/providers/EtherscanProvider.ts
@@ -6,7 +6,7 @@ const EtherscanApiUrl: Record<string, string> = {
   arbitrum: 'https://api.arbiscan.io',
   'arbitrum-goerli': 'https://api-goerli.arbiscan.io',
   'arbitrum-sepolia': 'https://api-sepolia.arbiscan.io',
-  optimisticEthereum: 'https://api-optimistic.etherscan.io',
+  optimism: 'https://api-optimistic.etherscan.io',
   'optimism-sepolia': 'https://api-sepolia-optimistic.etherscan.io',
 }