@@ -3,9 +3,11 @@ import { JsonRpcProvider } from "@ethersproject/providers";
3
3
import {
4
4
VeaOutboxArbToEth__factory ,
5
5
VeaOutboxArbToEthDevnet__factory ,
6
- VeaOutboxArbToGnosisDevnet__factory ,
7
6
VeaInboxArbToEth__factory ,
7
+ VeaInboxArbToGnosis__factory ,
8
+ VeaOutboxArbToGnosis__factory ,
8
9
} from "@kleros/vea-contracts/typechain-types" ;
10
+ import { getBridgeConfig } from "consts/bridgeRoutes" ;
9
11
10
12
function getWallet ( privateKey : string , web3ProviderURL : string ) {
11
13
return new Wallet ( privateKey , new JsonRpcProvider ( web3ProviderURL ) ) ;
@@ -15,20 +17,61 @@ function getWalletRPC(privateKey: string, rpc: JsonRpcProvider) {
15
17
return new Wallet ( privateKey , rpc ) ;
16
18
}
17
19
18
- function getVeaInboxArbToEth ( veaInboxAddress : string , privateKey : string , web3ProviderURL : string ) {
19
- return VeaInboxArbToEth__factory . connect ( veaInboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
20
+ // Using destination chainId as identifier, Ex: Arbitrum One (42161) -> Ethereum Mainnet (1): Use "1" as chainId
21
+ function getVeaInbox ( veaInboxAddress : string , privateKey : string , web3ProviderURL : string , chainId : number ) {
22
+ const bridge = getBridgeConfig ( chainId ) ;
23
+ switch ( bridge . chain ) {
24
+ case "sepolia" :
25
+ case "mainnet" :
26
+ return VeaInboxArbToEth__factory . connect ( veaInboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
27
+ case "chiado" :
28
+ case "gnosis" :
29
+ return VeaInboxArbToGnosis__factory . connect ( veaInboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
30
+ default :
31
+ throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
32
+ }
20
33
}
21
34
22
- function getVeaInboxArbToEthProvider ( veaInboxAddress : string , privateKey : string , rpc : JsonRpcProvider ) {
23
- return VeaInboxArbToEth__factory . connect ( veaInboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
35
+ function getVeaInboxProvider ( veaInboxAddress : string , privateKey : string , rpc : JsonRpcProvider , chainId : number ) {
36
+ const bridges = getBridgeConfig ( chainId ) ;
37
+ switch ( bridges . chain ) {
38
+ case "sepolia" :
39
+ case "mainnet" :
40
+ return VeaInboxArbToEth__factory . connect ( veaInboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
41
+ case "chiado" :
42
+ case "gnosis" :
43
+ return VeaInboxArbToGnosis__factory . connect ( veaInboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
44
+ default :
45
+ throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
46
+ }
24
47
}
25
48
26
- function getVeaOutboxArbToEthProvider ( veaOutboxAddress : string , privateKey : string , rpc : JsonRpcProvider ) {
27
- return VeaOutboxArbToEth__factory . connect ( veaOutboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
49
+ function getVeaOutbox ( veaOutboxAddress : string , privateKey : string , web3ProviderURL : string , chainId : number ) {
50
+ const bridge = getBridgeConfig ( chainId ) ;
51
+ switch ( bridge . chain ) {
52
+ case "sepolia" :
53
+ case "mainnet" :
54
+ return VeaOutboxArbToEth__factory . connect ( veaInboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
55
+ case "chiado" :
56
+ case "gnosis" :
57
+ return VeaOutboxArbToGnosis__factory . connect ( veaInboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
58
+ default :
59
+ throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
60
+ }
28
61
}
29
62
30
- function getVeaOutboxArbToEth ( veaOutboxAddress : string , privateKey : string , web3ProviderURL : string ) {
31
- return VeaOutboxArbToEth__factory . connect ( veaOutboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
63
+ function getVeaOutboxProvider ( veaOutboxAddress : string , privateKey : string , rpc : JsonRpcProvider , chainId : number ) {
64
+ const bridges = getBridgeConfig ( chainId ) ;
65
+ switch ( bridges . chain ) {
66
+ case "sepolia" :
67
+ case "mainnet" :
68
+ return VeaOutboxArbToEth__factory . connect ( veaOutboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
69
+ case "chiado" :
70
+ case "gnosis" :
71
+ return VeaOutboxArbToGnosis__factory . connect ( veaOutboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
72
+ default :
73
+ throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
74
+ }
32
75
}
33
76
34
77
function getVeaOutboxArbToEthDevnetProvider ( veaOutboxAddress : string , privateKey : string , rpc : JsonRpcProvider ) {
@@ -39,19 +82,12 @@ function getVeaOutboxArbToEthDevnet(veaOutboxAddress: string, privateKey: string
39
82
return VeaOutboxArbToEthDevnet__factory . connect ( veaOutboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
40
83
}
41
84
42
- function getVeaOutboxArbToGnosisProvider ( veaOutboxAddress : string , privateKey : string , rpc : JsonRpcProvider ) {
43
- return VeaOutboxArbToGnosisDevnet__factory . connect ( veaOutboxAddress , getWalletRPC ( privateKey , rpc ) ) ;
44
- }
45
-
46
- function getVeaOutboxArbToGnosis ( veaOutboxAddress : string , privateKey : string , web3ProviderURL : string ) {
47
- return VeaOutboxArbToGnosisDevnet__factory . connect ( veaOutboxAddress , getWallet ( privateKey , web3ProviderURL ) ) ;
48
- }
49
-
50
85
export {
51
- getVeaOutboxArbToEth ,
52
86
getWalletRPC ,
53
87
getVeaOutboxArbToEthDevnetProvider ,
54
- getVeaInboxArbToEth ,
55
- getVeaInboxArbToEthProvider ,
56
- getVeaOutboxArbToEthProvider ,
88
+ getVeaOutbox ,
89
+ getVeaInbox ,
90
+ getVeaOutboxProvider ,
91
+ getVeaInboxProvider ,
92
+ getVeaOutboxArbToEthDevnet ,
57
93
} ;
0 commit comments