-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.ts
237 lines (208 loc) · 6.57 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { config as dotEnvConfig } from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import type { HttpNetworkUserConfig } from "hardhat/types";
import { BigNumber } from "ethers";
import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-ethers";
import "@openzeppelin/hardhat-upgrades";
import "hardhat-gas-reporter";
// Load the env configuration
dotEnvConfig();
const primarySolidityVersion = process.env.SOLIDITY_VERSION || "0.7.6";
const soliditySettings = process.env.SOLIDITY_SETTINGS
? JSON.parse(process.env.SOLIDITY_SETTINGS)
: undefined;
const DEFAULT_MNEMONIC =
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
const sharedNetworkConfig: HttpNetworkUserConfig = {};
if (process.env.PK) {
sharedNetworkConfig.accounts = [process.env.PK];
} else {
sharedNetworkConfig.accounts = {
mnemonic: process.env.MNEMONIC || DEFAULT_MNEMONIC,
};
}
const config: HardhatUserConfig = {
solidity: {
compilers: [
{ version: primarySolidityVersion, settings: soliditySettings },
{ version: "0.6.12" },
{ version: "0.5.17" },
],
},
networks: {
// Local networks
ganache: {
url: "http://127.0.0.1:7545",
from: process.env.FROM,
},
hardhat: {
from: process.env.FROM,
},
// Ethereum
mainnet: {
...sharedNetworkConfig,
url: `https://mainnet.infura.io/v3/${process.env.INFURA_KEY}`,
},
goerli: {
...sharedNetworkConfig,
url: `https://goerli.infura.io/v3/${process.env.INFURA_KEY}`,
},
sepolia: {
...sharedNetworkConfig,
url: `https://sepolia.infura.io/v3/${process.env.INFURA_KEY}`,
},
// Optimism
optimisticEthereum: {
...sharedNetworkConfig,
url: `https://optimism-mainnet.infura.io/v3/${process.env.INFURA_KEY}`,
},
optimisticGoerli: {
...sharedNetworkConfig,
url: `https://optimism-goerli.infura.io/v3/${process.env.INFURA_KEY}`,
},
// Arbitrum
arbitrum: {
...sharedNetworkConfig,
url: `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA_KEY}`,
},
arbitrumGoerli: {
...sharedNetworkConfig,
url: `https://arbitrum-goerli.infura.io/v3/${process.env.INFURA_KEY}`,
},
// Base
base: {
...sharedNetworkConfig,
url: "https://mainnet.base.org",
gasPrice: 1500000050,
},
baserli: {
...sharedNetworkConfig,
url: "https://goerli.base.org",
gasPrice: 150000000,
},
// WBTestnet
wbTestnet: {
...sharedNetworkConfig,
url: "https://rpc-testnet.whitebit.network",
},
// Polygon
polygon: {
...sharedNetworkConfig,
url: `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_KEY}`,
},
polygonMumbai: {
...sharedNetworkConfig,
url: `https://polygon-mumbai.infura.io/v3/${process.env.INFURA_KEY}`,
},
// BNB Chain
bsc: {
...sharedNetworkConfig,
url: "https://bsc-dataseed.binance.org/",
gasPrice: 5000000000,
},
bscTestnet: {
...sharedNetworkConfig,
url: "https://data-seed-prebsc-1-s1.binance.org:8545",
},
},
etherscan: {
apiKey: {
mainnet: process.env.ETHER_SCAN_KEY as string,
goerli: process.env.ETHER_SCAN_KEY as string,
sepolia: process.env.ETHER_SCAN_KEY as string,
bsc: process.env.BSC_SCAN_KEY as string,
bscTestnet: process.env.BSC_SCAN_KEY as string,
optimisticEthereum: process.env.OPTIMISTIC_SCAN_KEY as string,
optimisticGoerli: process.env.OPTIMISTIC_SCAN_KEY as string,
arbitrumOne: process.env.ARBI_SCAN_KEY as string,
arbitrumGoerli: process.env.ARBI_SCAN_KEY as string,
polygon: process.env.POLYGON_SCAN_KEY as string,
polygonMumbai: process.env.POLYGON_SCAN_KEY as string,
base: process.env.BASE_SCAN_KEY as string,
baserli: "NO NEED API KEY FOR THIS TESTNET",
},
customChains: [
{
network: "baserli",
chainId: 84531,
urls: {
apiURL: "https://api-goerli.basescan.org/api",
browserURL: "https://goerli.basescan.org",
},
},
{
network: "base",
chainId: 8453,
urls: {
apiURL: "https://api.basescan.org/api",
browserURL: "https://basescan.org",
},
},
],
},
gasReporter: {
enabled: process.env.REPORT_GAS ? true : false,
},
};
export default config;
declare var task: any;
task(
"signerBalance",
"Get the signer balance on specified network",
async () => {
const { ethers } = require("hardhat");
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);
await ethers.provider
.getBalance(wallet.address)
.then((balance: BigNumber) => {
console.log(
`${wallet.address} has ${ethers.utils.formatEther(
balance
)} in balance`
);
});
}
);
task("balance", "Prints an account's balance")
.addParam("address", "The account's address")
.setAction(async (taskArgs) => {
const { ethers } = require("hardhat");
const balance = await ethers.provider.getBalance(taskArgs.address);
console.log(ethers.utils.formatEther(balance), "ETH");
});
task("deploy", "Deploy contract")
.addFlag("upgradable", "The contract is upgradable as proxy and factory")
.addParam("contractName", "The contract's name")
.setAction(async (taskArgs) => {
const { ethers, upgrades } = require("hardhat");
const ContractFactory = await ethers.getContractFactory(
taskArgs.contractName
);
if (!taskArgs.upgradable) {
const contract = await ContractFactory.deploy();
await contract.deployed();
console.log(`Contract deployed at ${contract.address}`);
console.log(`Transaction: ${contract.deployTransaction.hash}`);
} else {
const contract = await upgrades.deployProxy(ContractFactory);
await contract.deployed();
console.log(`Contract deployed as proxy at ${contract.addres}`);
console.log(`Transaction: ${contract.deployTransaction.hash}`);
}
});
task("upgrade", "Upgrade factory contract")
.addParam("contractName", "The Factory contract name to deploy")
.addParam("proxyAddress", "The Proxy contract address to upgrade")
.setAction(async (taskArgs) => {
const { ethers, upgrades } = require("hardhat");
const ContractFactory = await ethers.getContractFactory(
taskArgs.contractName
);
const contract = await upgrades.upgradeProxy(
taskArgs.contractAddress,
ContractFactory
);
console.log(`Transaction: ${contract.deployTransaction.hash}`);
});