forked from thirdweb-dev/contracts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat.config.ts
128 lines (115 loc) · 3.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
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import dotenv from "dotenv";
import "hardhat-abi-exporter";
import "hardhat-contract-sizer";
import "hardhat-gas-reporter";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
dotenv.config();
const chainIds = {
hardhat: 31337,
ganache: 1337,
mainnet: 1,
ropsten: 3,
rinkeby: 4,
goerli: 5,
kovan: 42,
avax: 43114,
avax_testnet: 43113,
fantom: 250,
fantom_testnet: 4002,
polygon: 137,
mumbai: 80001,
};
// Ensure that we have all the environment variables we need.
let testPrivateKey: string = process.env.TEST_PRIVATE_KEY || "";
let alchemyKey: string = process.env.ALCHEMY_KEY || "";
let explorerScanKey: string = process.env.SCAN_API_KEY || "";
function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
if (!alchemyKey) {
throw new Error("Missing ALCHEMY_KEY");
}
const polygonNetworkName = network === "polygon" ? "mainnet" : "mumbai";
let nodeUrl =
chainIds[network] == 137 || chainIds[network] == 80001
? `https://polygon-${polygonNetworkName}.g.alchemy.com/v2/${alchemyKey}`
: `https://eth-${network}.alchemyapi.io/v2/${alchemyKey}`;
if (network === "avax") {
nodeUrl = "https://api.avax.network/ext/bc/C/rpc";
} else if (network === "avax_testnet") {
nodeUrl = "https://api.avax-test.network/ext/bc/C/rpc";
} else if (network === "fantom") {
nodeUrl = "https://rpc.ftm.tools";
} else if (network === "fantom_testnet") {
nodeUrl = "https://rpc.testnet.fantom.network";
}
return {
chainId: chainIds[network],
url: nodeUrl,
accounts: [`${testPrivateKey}`],
};
}
interface ConfigWithEtherscan extends HardhatUserConfig {
etherscan: { apiKey: string };
}
const config: ConfigWithEtherscan = {
paths: {
artifacts: "./artifacts",
cache: "./cache",
sources: "./contracts",
tests: "./test",
},
solidity: {
version: "0.8.9",
settings: {
metadata: {
// Not including the metadata hash
// https://github.com/paulrberg/solidity-template/issues/31
bytecodeHash: "none",
},
// You should disable the optimizer when debugging
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
optimizer: {
enabled: true,
runs: 800,
// runs: 400,
},
},
},
abiExporter: {
flat: true,
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
etherscan: {
apiKey: explorerScanKey,
},
gasReporter: {
coinmarketcap: process.env.REPORT_GAS_COINMARKETCAP_API_KEY,
currency: "USD",
enabled: process.env.REPORT_GAS ? true : false,
},
};
if (testPrivateKey) {
config.networks = {
mainnet: createTestnetConfig("mainnet"),
rinkeby: createTestnetConfig("rinkeby"),
polygon: createTestnetConfig("polygon"),
mumbai: createTestnetConfig("mumbai"),
fantom: createTestnetConfig("fantom"),
fantom_testnet: createTestnetConfig("fantom_testnet"),
avax: createTestnetConfig("avax"),
avax_testnet: createTestnetConfig("avax_testnet"),
};
}
config.networks = {
...config.networks,
hardhat: {
chainId: 1337,
},
};
export default config;