forked from AugurProject/augur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkConfiguration.ts
137 lines (127 loc) · 5.56 KB
/
NetworkConfiguration.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
import { ethers } from 'ethers';
type NetworkOptions = {
isProduction: boolean;
http: string;
ws?: string;
ipc?: string;
privateKey?: string;
gasPrice: ethers.utils.BigNumber;
}
export const NETWORKS = [
'aura',
'clique',
'environment',
'rinkeby',
'ropsten',
'kovan',
'thunder',
'testrpc',
"mainnet",
'matic',
] as const;
export type NETWORKS = typeof NETWORKS[number];
export function isNetwork(x: any): x is NETWORKS {
return NETWORKS.includes(x);
}
type NetworksToOptions = {
[P in NETWORKS]?: NetworkOptions;
}
const networks: NetworksToOptions = {
thunder: {
isProduction: false,
http: "http://testnet-rpc.thundercore.com:8545",
privateKey: process.env.THUNDER_PRIVATE_KEY,
gasPrice: new ethers.utils.BigNumber(20*1000000000)
},
ropsten: {
isProduction: false,
http: "https://eth-ropsten.alchemyapi.io/jsonrpc/Kd37_uEmJGwU6pYq6jrXaJXXi8u9IoOM",
privateKey: process.env.ROPSTEN_PRIVATE_KEY,
gasPrice: new ethers.utils.BigNumber(20*1000000000)
},
kovan: {
isProduction: false,
http: "https://eth-kovan.alchemyapi.io/jsonrpc/1FomA6seLdWDvpIRvL9J5NhwPHLIGbWA",
privateKey: process.env.KOVAN_PRIVATE_KEY,
gasPrice: new ethers.utils.BigNumber(1)
},
rinkeby: {
isProduction: false,
http: "https://eth-rinkeby.alchemyapi.io/jsonrpc/Kd37_uEmJGwU6pYq6jrXaJXXi8u9IoOM",
ws: "wss://rinkeby.augur.net/ethereum-ws",
privateKey: process.env.RINKEBY_PRIVATE_KEY,
gasPrice: new ethers.utils.BigNumber(31*1000000000)
},
clique: {
isProduction: false,
http: "http://clique.ethereum.nodes.augur.net",
privateKey: process.env.CLIQUE_PRIVATE_KEY || "fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
gasPrice: new ethers.utils.BigNumber(1)
},
aura: {
isProduction: false,
http: "http://aura.ethereum.nodes.augur.net",
privateKey: process.env.AURA_PRIVATE_KEY || "fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
gasPrice: new ethers.utils.BigNumber(1)
},
environment: {
isProduction: process.env.PRODUCTION === "true" || false,
http: "http://localhost:8545",
ws: "ws://localhost:8546",
privateKey: process.env.ETHEREUM_PRIVATE_KEY || "fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
gasPrice: ((typeof process.env.ETHEREUM_GAS_PRICE_IN_NANOETH === "undefined") ? new ethers.utils.BigNumber(20) : new ethers.utils.BigNumber(process.env.ETHEREUM_GAS_PRICE_IN_NANOETH!)).mul(new ethers.utils.BigNumber(1000000000))
},
testrpc: {
isProduction: false,
http: "http://localhost:18545",
gasPrice: new ethers.utils.BigNumber(1),
privateKey: process.env.ETHEREUM_PRIVATE_KEY || "0xfae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
},
mainnet: {
isProduction: true,
http: "https://eth-mainnet.alchemyapi.io/jsonrpc/Kd37_uEmJGwU6pYq6jrXaJXXi8u9IoOM",
privateKey: process.env.ETHEREUM_PRIVATE_KEY || "fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
gasPrice: (
(typeof process.env.ETHEREUM_GAS_PRICE_IN_NANOETH === "undefined")
? new ethers.utils.BigNumber(20)
: new ethers.utils.BigNumber(process.env.ETHEREUM_GAS_PRICE_IN_NANOETH!)).mul(new ethers.utils.BigNumber(1e9)),
},
matic: {
isProduction: false,
http: "https://testnet2.matic.network",
privateKey: process.env.ETHEREUM_PRIVATE_KEY || "fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a",
gasPrice: new ethers.utils.BigNumber(0)
},
};
export class NetworkConfiguration {
public readonly networkName: string;
public readonly http: string;
public readonly ws?: string;
public readonly ipc?: string;
public readonly privateKey?: string;
public readonly gasPrice: ethers.utils.BigNumber;
public readonly isProduction: boolean;
public constructor(networkName: string, http: string, ws: string | undefined, ipc: string | undefined, gasPrice: ethers.utils.BigNumber, privateKey: string | undefined, isProduction: boolean) {
this.networkName = networkName;
this.http = http;
this.ws = ws;
this.ipc = ipc;
this.gasPrice = gasPrice;
this.privateKey = privateKey;
this.isProduction = isProduction;
}
public static create(networkName:NETWORKS=(typeof process.env.TESTRPC === 'undefined') ? "environment" : 'testrpc', validatePrivateKey: boolean=true): NetworkConfiguration {
const network = networks[networkName];
if (networkName === "environment" &&
(process.env.ETHEREUM_HTTP || process.env.ETHEREUM_WS || process.env.ETHEREUM_IPC)) {
Object.assign(network, {
http: process.env.ETHEREUM_HTTP,
ws: process.env.ETHEREUM_WS,
ipc: process.env.ETHEREUM_IPC,
});
}
if (network === undefined || network === null) throw new Error(`Network configuration ${networkName} not found`);
if (validatePrivateKey && (network.privateKey === undefined || network.privateKey === null)) throw new Error(`Network configuration for ${networkName} has no private key available. Check that this key is in the environment ${networkName == "environment" ? "ETHEREUM" : networkName.toUpperCase()}_PRIVATE_KEY`);
return new NetworkConfiguration(networkName, network.http, network.ws, network.ipc, network.gasPrice, network.privateKey, network.isProduction);
}
}