From 1dabd761cba9b2dcccbaa16add2635352cbe7551 Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:05:07 -0500 Subject: [PATCH] chore(contracts): support op sepolia deployment --- contracts/.env.example | 3 ++- contracts/hardhat.config.ts | 25 +++++++++++++++++++++++-- contracts/package.json | 7 ++++++- contracts/tasks/helpers/constants.ts | 11 +++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/contracts/.env.example b/contracts/.env.example index 4b803b3e29..828a756865 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -1,5 +1,6 @@ MNEMONIC= -ETHERSCAN_API_KEY= +ETH_ETHERSCAN_API_KEY= +OPTIMISM_ETHERSCAN_API_KEY= INFURA_KEY= OP_RPC_URL= GAS_PRICE= diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index e0b7d07b07..a88f232555 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -9,7 +9,13 @@ import type { HardhatUserConfig } from "hardhat/config"; // Don't forget to import new tasks here import "./tasks/deploy"; -import { EChainId, ESupportedChains, NETWORKS_DEFAULT_GAS, getNetworkRpcUrls } from "./tasks/helpers/constants"; +import { + EChainId, + ESupportedChains, + NETWORKS_DEFAULT_GAS, + getEtherscanApiKeys, + getNetworkRpcUrls, +} from "./tasks/helpers/constants"; import "./tasks/runner/deployFull"; import "./tasks/runner/deployPoll"; import "./tasks/runner/merge"; @@ -22,6 +28,7 @@ const DEFAULT_BLOCK_GAS_LIMIT = 30_000_000; const DEFAULT_GAS_MUL = 2; const TEST_MNEMONIC = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"; const NETWORKS_RPC_URL = getNetworkRpcUrls(); +const ETHERSCAN_API_KEYS = getEtherscanApiKeys(); const getCommonNetworkConfig = (networkName: ESupportedChains, chainId: number, mnemonic?: string) => ({ url: NETWORKS_RPC_URL[networkName], @@ -51,6 +58,7 @@ const config: HardhatUserConfig = { defaultNetwork: "localhost", networks: { sepolia: getCommonNetworkConfig(ESupportedChains.Sepolia, EChainId.Sepolia), + optimism_sepolia: getCommonNetworkConfig(ESupportedChains.OptimismSepolia, EChainId.OptimismSepolia), coverage: getCommonNetworkConfig(ESupportedChains.Coverage, EChainId.Coverage, TEST_MNEMONIC), localhost: { url: "http://localhost:8545", @@ -90,7 +98,20 @@ const config: HardhatUserConfig = { disambiguatePaths: false, }, etherscan: { - apiKey: process.env.ETHERSCAN_API_KEY, + apiKey: { + [ESupportedChains.Sepolia]: ETHERSCAN_API_KEYS[ESupportedChains.Sepolia]!, + [ESupportedChains.OptimismSepolia]: ETHERSCAN_API_KEYS[ESupportedChains.OptimismSepolia]!, + }, + customChains: [ + { + network: ESupportedChains.OptimismSepolia, + chainId: EChainId.OptimismSepolia, + urls: { + apiURL: "https://api-sepolia-optimism.etherscan.io/api", + browserURL: "https://sepolia-optimism.etherscan.io", + }, + }, + ], }, sourcify: { enabled: true, diff --git a/contracts/package.json b/contracts/package.json index 96ea65c577..1a587699fe 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -56,13 +56,18 @@ "prove": "hardhat prove", "deploy:localhost": "pnpm run deploy", "deploy:sepolia": "pnpm run deploy --network sepolia", + "deploy:optimism-sepolia": "pnpm run deploy --network optimism_sepolia", "deploy-poll:localhost": "pnpm run deploy-poll", "deploy-poll:sepolia": "pnpm run deploy-poll --network sepolia", + "deploy-poll:optimism-sepolia": "pnpm run deploy-poll --network optimism_sepolia", "merge:localhost": "pnpm run merge", "merge:sepolia": "pnpm run merge --network sepolia", + "merge:optimism-sepolia": "pnpm run merge --network optimism_sepolia", "prove:localhost": "pnpm run prove", "prove:sepolia": "pnpm run prove --network sepolia", - "verify:sepolia": "pnpm run verify --network sepolia" + "prove:optimism-sepolia": "pnpm run prove --network optimism_sepolia", + "verify:sepolia": "pnpm run verify --network sepolia", + "verify:optimism-sepolia": "pnpm run verify --network optimism_sepolia" }, "dependencies": { "@nomicfoundation/hardhat-ethers": "^3.0.5", diff --git a/contracts/tasks/helpers/constants.ts b/contracts/tasks/helpers/constants.ts index 76dac42197..c79fb52114 100644 --- a/contracts/tasks/helpers/constants.ts +++ b/contracts/tasks/helpers/constants.ts @@ -3,6 +3,7 @@ */ export enum ESupportedChains { Sepolia = "sepolia", + OptimismSepolia = "optimism_sepolia", Coverage = "coverage", Hardhat = "hardhat", } @@ -12,6 +13,7 @@ export enum ESupportedChains { */ export enum EChainId { Hardhat = 31337, + OptimismSepolia = 11155420, Sepolia = 11155111, Coverage = 1337, } @@ -33,6 +35,7 @@ const gasPrice = (value: number) => value * GWEI; */ export const NETWORKS_DEFAULT_GAS: Record = { [ESupportedChains.Sepolia]: gasPrice(1), + [ESupportedChains.OptimismSepolia]: gasPrice(1), [ESupportedChains.Coverage]: gasPrice(1), [ESupportedChains.Hardhat]: gasPrice(1), }; @@ -47,7 +50,15 @@ export const getNetworkRpcUrls = (): Record => { return { [ESupportedChains.Sepolia]: `https://sepolia.infura.io/v3/${INFURA_KEY}`, + [ESupportedChains.OptimismSepolia]: `https://optimism-sepolia.infura.io/v3/${INFURA_KEY}`, [ESupportedChains.Coverage]: "http://localhost:8555", [ESupportedChains.Hardhat]: "http://localhost:8545", }; }; + +export const getEtherscanApiKeys = (): Record => ({ + [ESupportedChains.Sepolia]: process.env.ETH_ETHERSCAN_API_KEY, + [ESupportedChains.OptimismSepolia]: process.env.OPTIMISM_ETHERSCAN_API_KEY, + [ESupportedChains.Coverage]: undefined, + [ESupportedChains.Hardhat]: undefined, +});