@@ -2,72 +2,113 @@ import { RenNetwork } from "@renproject/utils";
2
2
3
3
import { EthereumBaseChain } from "./base" ;
4
4
import { resolveEVMNetworkConfig } from "./utils/generic" ;
5
+ import { EVMNetworkConfig } from "./utils/types" ;
5
6
6
- const configMap : EthereumBaseChain [ "configMap" ] = {
7
- [ RenNetwork . Mainnet ] : {
8
- selector : "Ethereum" ,
9
-
10
- nativeAsset : { name : "Ether" , symbol : "ETH" , decimals : 18 } ,
11
- averageConfirmationTime : 15 ,
12
-
13
- config : {
14
- chainId : "0x1" ,
15
- chainName : "Ethereum Mainnet" ,
16
- nativeCurrency : { name : "Ether" , symbol : "ETH" , decimals : 18 } ,
17
- rpcUrls : [
18
- "https://cloudflare-eth.com" ,
19
- "https://mainnet.infura.io/v3/${INFURA_API_KEY}" ,
20
- "wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}" ,
21
- "https://api.mycryptoapi.com/eth" ,
22
- ] ,
23
- blockExplorerUrls : [ "https://etherscan.io" ] ,
24
- } ,
7
+ const ethereumMainnetConfig : EVMNetworkConfig = {
8
+ selector : "Ethereum" ,
25
9
26
- addresses : {
27
- GatewayRegistry : "0xf36666C230Fa12333579b9Bd6196CB634D6BC506" ,
28
- BasicBridge : "0x82DF02A52E2e76C0c233367f2fE6c9cfe51578c5" ,
29
- } ,
10
+ nativeAsset : { name : "Ether" , symbol : "ETH" , decimals : 18 } ,
11
+ averageConfirmationTime : 15 ,
12
+
13
+ config : {
14
+ chainId : "0x1" ,
15
+ chainName : "Ethereum Mainnet" ,
16
+ nativeCurrency : { name : "Ether" , symbol : "ETH" , decimals : 18 } ,
17
+ rpcUrls : [
18
+ "https://cloudflare-eth.com" ,
19
+ "https://mainnet.infura.io/v3/${INFURA_API_KEY}" ,
20
+ "wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}" ,
21
+ "https://api.mycryptoapi.com/eth" ,
22
+ ] ,
23
+ blockExplorerUrls : [ "https://etherscan.io" ] ,
30
24
} ,
31
25
32
- [ RenNetwork . Testnet ] : {
33
- selector : "Ethereum" ,
34
- isTestnet : true ,
35
-
36
- nativeAsset : { name : "Kovan Ether" , symbol : "ETH" , decimals : 18 } ,
37
- averageConfirmationTime : 15 ,
38
-
39
- config : {
40
- chainId : "0x2a" ,
41
- chainName : "Kovan" ,
42
- nativeCurrency : {
43
- name : "Kovan Ether" ,
44
- symbol : "KOV" ,
45
- decimals : 18 ,
46
- } ,
47
- rpcUrls : [
48
- "https://kovan.poa.network" ,
49
- "http://kovan.poa.network:8545" ,
50
- "https://kovan.infura.io/v3/${INFURA_API_KEY}" ,
51
- "wss://kovan.infura.io/ws/v3/${INFURA_API_KEY}" ,
52
- "ws://kovan.poa.network:8546" ,
53
- ] ,
54
- blockExplorerUrls : [ "https://kovan.etherscan.io" ] ,
26
+ addresses : {
27
+ GatewayRegistry : "0xf36666C230Fa12333579b9Bd6196CB634D6BC506" ,
28
+ BasicBridge : "0x82DF02A52E2e76C0c233367f2fE6c9cfe51578c5" ,
29
+ } ,
30
+ } ;
31
+
32
+ const kovanConfig : EVMNetworkConfig = {
33
+ selector : "Ethereum" ,
34
+ isTestnet : true ,
35
+
36
+ nativeAsset : { name : "Kovan Ether" , symbol : "ETH" , decimals : 18 } ,
37
+ averageConfirmationTime : 15 ,
38
+
39
+ config : {
40
+ chainId : "0x2a" ,
41
+ chainName : "Kovan" ,
42
+ nativeCurrency : {
43
+ name : "Kovan Ether" ,
44
+ symbol : "KOV" ,
45
+ decimals : 18 ,
55
46
} ,
47
+ rpcUrls : [
48
+ "https://kovan.poa.network" ,
49
+ "http://kovan.poa.network:8545" ,
50
+ "https://kovan.infura.io/v3/${INFURA_API_KEY}" ,
51
+ "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" ,
52
+ "wss://kovan.infura.io/ws/v3/${INFURA_API_KEY}" ,
53
+ "wss://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" ,
54
+ "ws://kovan.poa.network:8546" ,
55
+ ] ,
56
+ blockExplorerUrls : [ "https://kovan.ethplorer.io" ] ,
57
+ } ,
58
+
59
+ addresses : {
60
+ GatewayRegistry : "0x5076a1F237531fa4dC8ad99bb68024aB6e1Ff701" ,
61
+ BasicBridge : "0xcb6bD6B6c7D7415C0157e393Bb2B6Def7555d518" ,
62
+ } ,
63
+ } ;
64
+
65
+ const goerliConfig : EVMNetworkConfig = {
66
+ selector : "Goerli" ,
67
+
68
+ nativeAsset : { name : "Görli Ether" , symbol : "gETH" , decimals : 18 } ,
69
+ averageConfirmationTime : 15 ,
56
70
57
- addresses : {
58
- GatewayRegistry : "0x5076a1F237531fa4dC8ad99bb68024aB6e1Ff701" ,
59
- BasicBridge : "0xcb6bD6B6c7D7415C0157e393Bb2B6Def7555d518" ,
71
+ config : {
72
+ chainId : "0x5" ,
73
+ chainName : "Görli" ,
74
+ nativeCurrency : {
75
+ name : "Görli Ether" ,
76
+ symbol : "GOR" ,
77
+ decimals : 18 ,
60
78
} ,
79
+ rpcUrls : [
80
+ "https://rpc.goerli.mudit.blog/" ,
81
+ "https://goerli.infura.io/v3/${INFURA_API_KEY}" ,
82
+ "https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}" ,
83
+ "wss://goerli.infura.io/v3/${INFURA_API_KEY}" ,
84
+ "wss://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}" ,
85
+ ] ,
86
+ blockExplorerUrls : [ "https://goerli.etherscan.io" ] ,
87
+ } ,
88
+
89
+ addresses : {
90
+ GatewayRegistry : "0x5076a1F237531fa4dC8ad99bb68024aB6e1Ff701" ,
91
+ BasicBridge : "0xcb6bD6B6c7D7415C0157e393Bb2B6Def7555d518" ,
61
92
} ,
62
93
} ;
63
94
95
+ export const defaultConfigMap : EthereumBaseChain [ "configMap" ] = {
96
+ [ RenNetwork . Mainnet ] : ethereumMainnetConfig ,
97
+ [ RenNetwork . Testnet ] : kovanConfig ,
98
+ } ;
99
+
100
+ export const goerliConfigMap : EthereumBaseChain [ "configMap" ] = {
101
+ [ RenNetwork . Mainnet ] : ethereumMainnetConfig ,
102
+ [ RenNetwork . Testnet ] : goerliConfig ,
103
+ } ;
104
+
64
105
/**
65
106
* The Ethereum RenJS implementation.
66
107
*/
67
108
export class Ethereum extends EthereumBaseChain {
68
109
// Static members.
69
110
public static chain = "Ethereum" as const ;
70
- public static configMap = configMap ;
111
+ public static configMap = defaultConfigMap ;
71
112
public static assets = {
72
113
ETH : "ETH" as const ,
73
114
DAI : "DAI" as const ,
@@ -85,6 +126,16 @@ export class Ethereum extends EthereumBaseChain {
85
126
ROOK : "ROOK" as const ,
86
127
BADGER : "BADGER" as const ,
87
128
KNC : "KNC" as const ,
129
+
130
+ // Goerli only
131
+ gETH : "gETH" as const ,
132
+ REN_Goerli : "REN_Goerli" as const ,
133
+ DAI_Goerli : "DAI_Goerli" as const ,
134
+ USDC_Goerli : "USDC_Goerli" as const ,
135
+ USDT_Goerli : "USDT_Goerli" as const ,
136
+
137
+ // Aliases
138
+ ETH_Goerli : "gETH" as const ,
88
139
} ;
89
140
90
141
public configMap = Ethereum . configMap ;
@@ -95,17 +146,26 @@ export class Ethereum extends EthereumBaseChain {
95
146
*
96
147
* @param params Ethereum constructor parameters
97
148
* @param params.network A RenVM network string or an EVM config object.
149
+ * @param params.testnet Optionally specify a default Ethereum testnet.
98
150
* @param params.provider A Web3 or Ethers.js provider.
99
151
* @param params.signer A Web3 or Ethers.js signer.
100
152
* @param params.config Pass optional configurations, e.g. a logger
101
153
*/
102
154
public constructor ( {
103
155
network,
156
+ testnet,
104
157
...params
105
- } : ConstructorParameters < typeof EthereumBaseChain > [ 0 ] ) {
158
+ } : ConstructorParameters < typeof EthereumBaseChain > [ 0 ] & {
159
+ testnet ?: "Kovan" | "Goerli" | "Görli" ;
160
+ } ) {
106
161
super ( {
107
162
...params ,
108
- network : resolveEVMNetworkConfig ( configMap , network ) ,
163
+ network : resolveEVMNetworkConfig (
164
+ testnet === "Goerli" || testnet === "Görli"
165
+ ? goerliConfigMap
166
+ : defaultConfigMap ,
167
+ network ,
168
+ ) ,
109
169
} ) ;
110
170
}
111
171
}
0 commit comments