-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper-hardhat-config.ts
79 lines (69 loc) · 2.06 KB
/
helper-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
import dotenv from 'dotenv';
dotenv.config({});
export type Network = EthereumNetwork | PolygonNetwork | XDaiNetwork;
export enum EthereumNetwork {
kovan = 'kovan',
rinkeby = 'rinkeby',
main = 'main',
hardhat = 'hardhat',
tenderlyMain = 'tenderlyMain',
harhatevm = 'harhatevm',
goerli = 'goerli'
}
export enum PolygonNetwork {
main = 'polygon-mainnet',
mumbai = 'mumbai',
}
export enum XDaiNetwork {
xdai = 'xdai',
}
export type ParamsPerNetwork<T> =
| EthereumParamsPerNetwork<T>
| PolygonParamsPerNetwork<T>
| XDaiParamsPerNetwork<T>;
export interface EthereumParamsPerNetwork<Network> {
[EthereumNetwork.harhatevm]: Network;
[EthereumNetwork.rinkeby]: Network;
[EthereumNetwork.main]: Network;
[EthereumNetwork.hardhat]: Network;
[EthereumNetwork.tenderlyMain]: Network;
[EthereumNetwork.goerli]: Network;
}
export interface PolygonParamsPerNetwork<T> {
[PolygonNetwork.main]: T;
[PolygonNetwork.mumbai]: T;
}
export interface XDaiParamsPerNetwork<T> {
[XDaiNetwork.xdai]: T;
}
export interface ObjectString {
[key: string]: string;
}
export const alchemyUrlOrEnvVar = (defaultAlchemyUrl: string, rpcUrl?: string): string => {
const defaultUrl = `${defaultAlchemyUrl}/${process.env.ALCHEMY_KEY}`;
return rpcUrl ? rpcUrl : defaultUrl;
};
export const NETWORKS_RPC_URL: ParamsPerNetwork<string> = {
[EthereumNetwork.rinkeby]: alchemyUrlOrEnvVar(
'https://eth-rinkeby.alchemyapi.io/v2',
process.env.RINKEBY_RPC_URL
),
[EthereumNetwork.main]: alchemyUrlOrEnvVar(
'https://eth-mainnet.alchemyapi.io/v2',
process.env.MAINNET_RPC_URL
),
[EthereumNetwork.hardhat]: 'http://localhost:8545',
[PolygonNetwork.mumbai]: alchemyUrlOrEnvVar(
'https://polygon-mumbai.g.alchemy.com/v2',
process.env.MUMBAI_RPC_URL
),
[PolygonNetwork.main]: alchemyUrlOrEnvVar(
'https://polygon-mainnet.g.alchemy.com/v2',
process.env.POLYGON_RPC_URL
),
[XDaiNetwork.xdai]: 'https://rpc.xdaichain.com/',
[EthereumNetwork.goerli]: alchemyUrlOrEnvVar(
'https://eth-goerli.alchemyapi.io/v2',
process.env.GOERLI_RPC_URL
),
};