forked from rmourey26/SKYBIT-Keyless-Deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.js
201 lines (172 loc) · 7.39 KB
/
hardhat.config.js
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
require(`@nomicfoundation/hardhat-toolbox`)
require(`@openzeppelin/hardhat-upgrades`)
require(`dotenv`).config()
require(`@skybit/hardhat-yul`)
BigInt.prototype[`toJSON`] = () => this.toString() // To prevent TypeError: Do not know how to serialize a BigInt
// SET YOUR ACCOUNT HERE
const accounts = { mnemonic: process.env.MNEMONIC || `test test test test test test test test test test test junk` }
// const accounts = [process.env.PRIVATE_KEY0]
// const accounts = [process.env.PRIVATE_KEY1, process.env.PRIVATE_KEY2]
// You can add more blockchains to this list if they don't already exist in viem/chains
const additionalNetworks = { // See https://github.com/wevm/viem/blob/main/src/chains/index.ts
bttc: {
chainId: 199,
url: `https://rpc.bittorrentchain.io`,
accounts,
network: `bttc`,
urls: {
apiURL: `https://api.bttcscan.com/api`,
browserURL: `https://bttcscan.com`
}
},
bttcTestnet: {
chainId: 1028,
url: `https://testrpc.bittorrentchain.io`,
accounts,
network: `bttcTestnet`,
urls: {
apiURL: `https://api-testnet.bttcscan.com/api`,
browserURL: `https://testnet.bttcscan.com`
}
},
heco: {
chainId: 128,
url: `https://http-mainnet.hecochain.com`,
accounts,
// use built-in hardhat-verify details
},
hecoTestnet: {
chainId: 256,
url: `https://http-testnet.hecochain.com`,
accounts,
// use built-in hardhat-verify details
},
harmonyTest: {
chainId: 1666700000,
url: `https://api.s0.b.hmny.io`,
accounts,
// use built-in hardhat-verify details
},
bobaTestnet: {
chainId: 2888,
url: `https://goerli.boba.network`,
accounts,
network: `bobaTestnet`,
urls: {
apiURL: `https://api-testnet.bobascan.com/api`,
browserURL: `https://testnet.bobascan.com`
}
},
}
const hardhatVerifyBuiltinChains = [`mainnet`, `goerli`, `optimisticEthereum`, `bsc`, `sokol`, `bscTestnet`, `xdai`, `gnosis`, `heco`, `polygon`, `opera`, `hecoTestnet`, `optimisticGoerli`, `polygonZkEVM`, `moonbeam`, `moonriver`, `moonbaseAlpha`, `polygonZkEVMTestnet`, `ftmTestnet`, `base`, `chiado`, `holesky`, `arbitrumOne`, `avalancheFujiTestnet`, `avalanche`, `polygonMumbai`, `polygonAmoy`, `baseGoerli`, `baseSepolia`, `arbitrumSepolia`, `sepolia`, `aurora`, `auroraTestnet`, `harmony`, `harmonyTest`] // https://github.com/NomicFoundation/hardhat/blob/main/packages/hardhat-verify/src/internal/chain-config.ts
const viemChainsToHardhatVerifyTranslation = { // because some names don't match. So we'll use the name in hardhat-verify.
arbitrum: `arbitrumOne`,
avalancheFuji: `avalancheFujiTestnet`,
fantom: `opera`,
fantomTestnet: `ftmTestnet`,
gnosisChiado: `chiado`,
harmonyOne: `harmony`,
optimism: `optimisticEthereum`,
optimismGoerli: `optimisticGoerli`,
polygonZkEvm: `polygonZkEVM`,
polygonZkEvmTestnet: `polygonZkEVMTestnet`,
}
let networks = {}
const chains = require(`viem/chains`)
for (let [chainName, chainData] of Object.entries(chains)) {
if (![`hardhat`, `localhost`].includes(chainName)) { // "HardhatConfig.networks.hardhat can't have an url"
chainName = viemChainsToHardhatVerifyTranslation[chainName] === undefined ? chainName : viemChainsToHardhatVerifyTranslation[chainName] // change to what hardhat-verify uses
// console.log(chainName.trim())
networks[chainName] = {
chainId: chainData.id,
url: chainData.rpcUrls.default.http[0],
accounts,
}
// add keys for hardhat-verify if blockchain isn't built in hardhat-verify and has explorer
if (!hardhatVerifyBuiltinChains.includes(chainName) && Object.hasOwn(chainData, `blockExplorers`)) {
const browserURL = chainData.blockExplorers[Object.hasOwn(chainData.blockExplorers, `etherscan`) ? `etherscan` : `default`].url
networks[chainName] = {
...networks[chainName],
...{
network: chainName,
urls: {
apiURL: `${browserURL.slice(0, 8)}api${browserURL.split(`.`).length === 2 ? `.` : `-`}${browserURL.slice(8)}/api`,
browserURL
}
}
}
}
} else {
networks[chainName] = { // to prevent undefined chainId
chainId: 31337,
}
}
}
networks = { ...networks, ...additionalNetworks }
// RPC URL overrides in case you dont want to use the one in viem/chains:
// networks.mainnet.url = `https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
networks.bscTestnet.url = `https://data-seed-prebsc-2-s2.bnbchain.org:8545`
networks.sepolia.url = `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// networks.chiado.url = `https://endpoints.omniatech.io/v1/gnosis/chiado/public`
const customChains = Object.values(networks).filter(network => Object.hasOwn(network, `urls`))
/** @type import(`hardhat/config`).HardhatUserConfig */
module.exports = {
solidity: { // changing these values changes bytecode, so can affect deployment address if not using CREATE3
compilers: [
{
version: `0.8.26`,
settings: {
optimizer: {
enabled: true,
runs: 15000
},
evmVersion: `cancun`,
}
},
],
},
networks,
etherscan: {
apiKey: { // ADD LINES FOR YOUR DESIRED BLOCKCHAINS HERE FOR CONTRACT VERIFICATION ON BLOCKCHAIN EXPLORER. If it's in viemChainsToHardhatVerifyTranslation then write the translated value.
mainnet: process.env.ETHERSCAN_API_KEY,
goerli: process.env.ETHERSCAN_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
celo: process.env.CELOSCAN_API_KEY,
celoAlfajores: process.env.CELOSCAN_API_KEY,
polygonZkEVM: process.env.ZKEVM_POLYGONSCAN_API_KEY,
polygonZkEVMTestnet: process.env.ZKEVM_POLYGONSCAN_API_KEY,
bsc: process.env.BSCSCAN_API_KEY,
bscTestnet: process.env.BSCSCAN_API_KEY,
avalanche: process.env.SNOWTRACE_API_KEY,
avalancheFujiTestnet: process.env.SNOWTRACE_API_KEY,
polygon: process.env.POLYGONSCAN_API_KEY,
polygonMumbai: process.env.POLYGONSCAN_API_KEY,
},
customChains,
timeout: 60000 // 1min (default is 20s)
}
}
/* Not needed anymore after forking https://github.com/ZeframLou/create3-factory
// override hardhat compilation subtask
const { TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH } = require(`hardhat/builtin-tasks/task-names`)
subtask(TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH)
.setAction(
async (args, hre, runSuper) => {
let filePath = `node_modules/@ZeframLou/create3-factory/package.json` // to create package.json required to import solidity file for compilation
const fileContent = `{ "name": "create3-factory", "version": "18cfad8d118b25a5092cdfed6bea9c932ca5b6eb" }`
const fs = require(`fs`)
const path = require(`path`)
fs.writeFileSync(path.join(__dirname, filePath), fileContent)
// console.log(`Created ${filePath}`)
filePath = `node_modules/@transmissions11/solmate/src/utils/Bytes32AddressLib.sol` // to handle "import {CREATE3} from "solmate/utils/CREATE3.sol";"
let fileDest = `solmate/utils/Bytes32AddressLib.sol`
fs.cpSync(filePath, fileDest, { recursive: true })
// console.log(`Copied ${filePath} to ${fileDest}`)
filePath = `node_modules/@transmissions11/solmate/src/utils/CREATE3.sol`
fileDest = `solmate/utils/CREATE3.sol`
fs.cpSync(filePath, fileDest, { recursive: true })
// console.log(`Copied ${filePath} to ${fileDest}`)
return await runSuper(args) // run the original subtask
}
)
*/