forked from SocketDotTech/socket-DL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardhat.config.ts
143 lines (134 loc) · 4.23 KB
/
hardhat.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import "@typechain/hardhat";
import "hardhat-preprocessor";
import "hardhat-deploy";
import "hardhat-abi-exporter";
import "hardhat-change-network";
import { config as dotenvConfig } from "dotenv";
import type { HardhatUserConfig } from "hardhat/config";
import type {
HardhatNetworkAccountUserConfig,
NetworkUserConfig,
} from "hardhat/types";
import { resolve } from "path";
import fs from "fs";
import "./tasks/accounts";
import { getJsonRpcUrl } from "./scripts/constants/networks";
import { ChainKey, chainKeyToSlug } from "./src";
const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
const isProduction = process.env.NODE_ENV === "production";
// Ensure that we have all the environment variables we need.
if (!process.env.SOCKET_SIGNER_KEY) throw new Error("No private key found");
const privateKey: HardhatNetworkAccountUserConfig = process.env
.SOCKET_SIGNER_KEY as unknown as HardhatNetworkAccountUserConfig;
function getChainConfig(chain: keyof typeof chainKeyToSlug): NetworkUserConfig {
return {
accounts: [`0x${privateKey}`],
chainId: chainKeyToSlug[chain],
url: getJsonRpcUrl(chain),
};
}
function getRemappings() {
return fs
.readFileSync("remappings.txt", "utf8")
.split("\n")
.filter(Boolean) // remove empty lines
.map((line) => line.trim().split("="));
}
let liveNetworks = {};
if (isProduction) {
liveNetworks = {
"arbitrum-goerli": getChainConfig(ChainKey.ARBITRUM_GOERLI),
"optimism-goerli": getChainConfig(ChainKey.OPTIMISM_GOERLI),
"polygon-mainnet": getChainConfig(ChainKey.POLYGON_MAINNET),
arbitrum: getChainConfig(ChainKey.ARBITRUM),
avalanche: getChainConfig(ChainKey.AVALANCHE),
bsc: getChainConfig(ChainKey.BSC),
goerli: getChainConfig(ChainKey.GOERLI),
mainnet: getChainConfig(ChainKey.MAINNET),
optimism: getChainConfig(ChainKey.OPTIMISM),
"polygon-mumbai": getChainConfig(ChainKey.POLYGON_MUMBAI),
"bsc-testnet": getChainConfig(ChainKey.BSC_TESTNET),
};
}
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
abiExporter: {
path: "artifacts/abi",
flat: true,
},
etherscan: {
apiKey: {
arbitrumOne: process.env.ARBISCAN_API_KEY || "",
arbitrumTestnet: process.env.ARBISCAN_API_KEY || "",
avalanche: process.env.SNOWTRACE_API_KEY || "",
bsc: process.env.BSCSCAN_API_KEY || "",
bscTestnet: process.env.BSCSCAN_API_KEY || "",
goerli: process.env.ETHERSCAN_API_KEY || "",
mainnet: process.env.ETHERSCAN_API_KEY || "",
optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
optimisticTestnet: process.env.OPTIMISM_API_KEY || "",
polygon: process.env.POLYGONSCAN_API_KEY || "",
polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
},
customChains: [
{
network: "optimisticTestnet",
chainId: chainKeyToSlug["optimism-goerli"],
urls: {
apiURL: "https://api-goerli-optimistic.etherscan.io/api",
browserURL: "https://goerli-optimism.etherscan.io/",
},
},
{
network: "arbitrumTestnet",
chainId: chainKeyToSlug["arbitrum-goerli"],
urls: {
apiURL: "https://api-goerli.arbiscan.io/api",
browserURL: "https://goerli.arbiscan.io/",
},
},
],
},
networks: {
hardhat: {
chainId: chainKeyToSlug.hardhat,
},
...liveNetworks,
},
paths: {
sources: "./contracts",
cache: "./cache_hardhat",
artifacts: "./artifacts",
tests: "./test",
},
// This fully resolves paths for imports in the ./lib directory for Hardhat
preprocess: {
eachLine: (hre) => ({
transform: (line: string) => {
if (line.match(/^\s*import /i)) {
getRemappings().forEach(([find, replace]) => {
if (line.match(find)) {
line = line.replace(find, replace);
}
});
}
return line;
},
}),
},
solidity: {
version: "0.8.7",
settings: {
optimizer: {
enabled: true,
runs: 999999,
},
// viaIR: true
},
},
};
export default config;