-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.helpers.ts
208 lines (188 loc) · 6.26 KB
/
hardhat.helpers.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
import { resolve } from "path";
import { config as dotenvConfig } from "dotenv";
import { HardhatNetworkUserConfig, NetworkUserConfig } from "hardhat/types";
dotenvConfig({ path: resolve(__dirname, "./.env") });
type AutoOptions = {
goerli: "auto" | number;
hardhat: "auto" | number;
kovan: "auto" | number;
mainnet: "auto" | number;
rinkeby: "auto" | number;
ropsten: "auto" | number;
"arb-mainnet": "auto" | number;
"arb-rinkeby": "auto" | number;
"ply-mainnet": "auto" | number;
"ply-mumbai": "auto" | number;
"opt-mainnet": "auto" | number;
"opt-kovan": "auto" | number;
"palm-mainnet": "auto" | number;
"palm-rinkeby": "auto" | number;
};
enum EndpointProvider {
infura = "infura",
alchemy = "alchemy",
}
type EndpointsConfig = {
[key in EndpointProvider]: {
goerli: string;
hardhat: string;
kovan: string;
mainnet: string;
rinkeby: string;
ropsten: string;
"arb-mainnet": string;
"arb-rinkeby": string;
"ply-mainnet": string;
"ply-mumbai": string;
"opt-mainnet": string;
"opt-kovan": string;
"palm-mainnet"?: string;
"palm-rinkeby"?: string;
};
};
export const ChainIds = {
goerli: 5,
hardhat: 31337,
kovan: 42,
mainnet: 1,
rinkeby: 4,
ropsten: 3,
"arb-rinkeby": 421611,
"arb-mainnet": 42161,
"ply-mainnet": 137,
"ply-mumbai": 80001,
"opt-mainnet": 10,
"opt-kovan": 69,
"palm-mainnet": 11297108109,
"palm-rinkeby": 11297108099,
};
export const GasPrice: AutoOptions = {
goerli: "auto",
hardhat: "auto",
kovan: "auto",
mainnet: "auto",
rinkeby: 15000000000,
ropsten: "auto",
"arb-rinkeby": "auto",
"arb-mainnet": "auto",
"ply-mainnet": "auto",
"ply-mumbai": "auto",
"opt-mainnet": "auto",
"opt-kovan": "auto",
"palm-mainnet": "auto",
"palm-rinkeby": "auto",
};
export const Gas: AutoOptions = {
goerli: "auto",
hardhat: "auto",
kovan: "auto",
mainnet: "auto",
rinkeby: 20000000,
ropsten: "auto",
"arb-rinkeby": 1287983320,
"arb-mainnet": "auto",
"ply-mainnet": "auto",
"ply-mumbai": "auto",
"opt-mainnet": "auto",
"opt-kovan": "auto",
"palm-mainnet": "auto",
"palm-rinkeby": "auto",
};
export const EndpointURLs: EndpointsConfig = {
infura: {
goerli: "https://goerli.infura.io/v3/",
hardhat: "https://mainnet.infura.io/v3/",
kovan: "https://kovan.infura.io/v3/",
mainnet: "https://mainnet.infura.io/v3/",
rinkeby: "https://rinkeby.infura.io/v3/",
ropsten: "https://ropsten.infura.io/v3/",
"arb-mainnet": "https://arbitrum-mainnet.infura.io/v3/",
"arb-rinkeby": "https://arbitrum-rinkeby.infura.io/v3/",
"ply-mainnet": "https://polygon-mainnet.infura.io/v3/",
"ply-mumbai": "https://polygon-mumbai.infura.io/v3/",
"opt-mainnet": "https://optimism-mainnet.infura.io/v3/",
"opt-kovan": "https://optimism-kovan.infura.io/v3/",
"palm-mainnet": "https://palm-mainnet.infura.io/v3/",
"palm-rinkeby": "https://palm-rinkeby.infura.io/v3/",
},
alchemy: {
goerli: "https://eth-goerli.alchemyapi.io/v2/",
hardhat: "https://eth-mainnet.alchemyapi.io/v2/",
kovan: "https://eth-kovan.alchemyapi.io/v2/",
mainnet: "https://eth-mainnet.alchemyapi.io/v2/",
rinkeby: "https://eth-rinkeby.alchemyapi.io/v2/",
ropsten: "https://eth-ropsten.alchemyapi.io/v2/",
"arb-mainnet": "https://arb-mainnet.alchemyapi.io/v2/",
"arb-rinkeby": "https://arb-rinkeby.alchemyapi.io/v2/",
"ply-mainnet": "https://polygon-mainnet.alchemyapi.io/v2/",
"ply-mumbai": "https://polygon-mumbai.alchemyapi.io/v2/",
"opt-mainnet": "https://optimism-mainnet.alchemyapi.io/v2/",
"opt-kovan": "https://optimism-kovan.alchemyapi.io/v2/",
"palm-mainnet": "",
"palm-rinkeby": "",
},
};
export const Networks = Object.keys(ChainIds);
export type NetworksType = keyof typeof ChainIds;
// Ensure that we have all the environment variables we need.
if (!process.env.WALLET_SEED) {
throw new Error("Please set your WALLET_SEED in a .env file");
}
export const walletSeed: string = process.env.WALLET_SEED;
if (!process.env.ENDPOINT_API_KEY) {
throw new Error("Please set your ENDPOINT_API_KEY in a .env file");
}
const endpointApiKey: string = process.env.ENDPOINT_API_KEY;
const endpointProvider: string = process.env.ENDPOINT_PROVIDER != null ? process.env.ENDPOINT_PROVIDER : "";
if (endpointProvider !== "infura" && endpointProvider !== "alchemy") {
throw new Error("Please set your ENDPOINT_PROVIDER to a valid value in a .env file");
}
const configMaxGas: number | undefined = Number(process.env.MAX_GAS);
const configGasPrice: number | undefined = Number(process.env.GAS_PRICE);
export function getHardhatChainConfig(): HardhatNetworkUserConfig {
return {
accounts: {
mnemonic: "test test test test test test test test test test test junk",
path: "m/44'/60'/0'/0/",
initialIndex: 0,
count: 10,
},
chainId: ChainIds.hardhat,
};
}
export function getLocalhostChainConfig(): NetworkUserConfig {
return {
url: "http://127.0.0.1:8545",
accounts: {
mnemonic: "test test test test test test test test test test test junk",
path: "m/44'/60'/0'/0/",
initialIndex: 0,
count: 10,
},
};
}
export function getChainConfig(network: NetworksType): NetworkUserConfig {
const provider: EndpointProvider = <EndpointProvider>endpointProvider;
const url: string = EndpointURLs[provider][network] + endpointApiKey;
return {
accounts: {
count: 10,
mnemonic: walletSeed,
path: "m/44'/60'/0'/0",
},
chainId: ChainIds[network],
gas: configMaxGas || Gas[network] || "auto",
gasPrice: configGasPrice || GasPrice[network] || "auto",
url,
};
}
export function getEtherscanApiKey(): string {
if (!process.env.ETHERSCAN_API_KEY) {
return "";
}
try {
return JSON.parse(process.env.ETHERSCAN_API_KEY);
} catch (e) {
return process.env.ETHERSCAN_API_KEY;
}
}