1
1
import { InMemorySigner } from '@taquito/signer' ;
2
2
import { TezosToolkit } from '@taquito/taquito' ;
3
+ import { ethers as ethers } from 'ethers' ;
4
+ import { ethers as ethersV5 } from 'ethers-v5' ;
3
5
import Web3 from 'web3' ;
4
6
5
7
import { TestConfig } from './testConfig' ;
@@ -8,6 +10,8 @@ import {
8
10
TokenBridge ,
9
11
TaquitoContractTezosBridgeBlockchainService ,
10
12
Web3EtherlinkBridgeBlockchainService ,
13
+ EthersV5EtherlinkBridgeBlockchainService ,
14
+ EthersEtherlinkBridgeBlockchainService ,
11
15
DefaultDataProvider ,
12
16
BridgeTokenTransferKind , BridgeTokenTransferStatus , LogLevel ,
13
17
type TezosToken , type EtherlinkToken ,
@@ -23,10 +27,15 @@ const withdrawalIdRegex = /^0x[0-9a-f]{64}_\d+$/;
23
27
const tezosOperationRegex = / ^ o [ 0 - 9 a - z A - Z ] { 50 } $ / ;
24
28
const etherlinkOperationRegex = / ^ 0 x [ 0 - 9 a - f ] { 64 } $ / ;
25
29
30
+ export type EtherlinkToolkit =
31
+ | { type : 'web3' , web3 : Web3 }
32
+ | { type : 'ethers-v6' , ethers : typeof ethers , signer : ethers . Signer }
33
+ | { type : 'ethers-v5' , ethers : typeof ethersV5 , signer : ethersV5 . Signer } ;
34
+
26
35
interface CreateTestTokenBridgeParams {
27
36
testConfig : TestConfig ,
28
37
tezosToolkit ?: TezosToolkit ,
29
- etherlinkToolkit ?: Web3 ,
38
+ etherlinkToolkit ?: EtherlinkToolkit ,
30
39
overriddenDefaultDataProviderOptions ?: Partial < DefaultDataProviderOptions >
31
40
}
32
41
@@ -47,7 +56,7 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
47
56
{
48
57
tezos : {
49
58
...testConfig . tokens . tezos . tez ,
50
- ticketHelperContractAddress : 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9 '
59
+ ticketHelperContractAddress : 'KT1VEjeQfDBSfpDH5WeBM5LukHPGM2htYEh3 '
51
60
} ,
52
61
etherlink : {
53
62
...testConfig . tokens . etherlink . tez ,
@@ -56,8 +65,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
56
65
{
57
66
tezos : {
58
67
...testConfig . tokens . tezos . tzbtc ,
59
- ticketerContractAddress : 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo ' ,
60
- ticketHelperContractAddress : 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1 '
68
+ ticketerContractAddress : 'KT1H7if3gSZE1pZSK48W3NzGpKmbWyBxWDHe ' ,
69
+ ticketHelperContractAddress : 'KT1KUAaaRMeMS5TJJyGTQJANcpSR4egvHBUk '
61
70
} ,
62
71
etherlink : {
63
72
...testConfig . tokens . etherlink . tzbtc
@@ -66,8 +75,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
66
75
{
67
76
tezos : {
68
77
...testConfig . tokens . tezos . usdt ,
69
- ticketerContractAddress : 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp ' ,
70
- ticketHelperContractAddress : 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH '
78
+ ticketerContractAddress : 'KT1S6Nf9MnafAgSUWLKcsySPNFLUxxqSkQCw ' ,
79
+ ticketHelperContractAddress : 'KT1JLZe4qTa76y6Us2aDoRNUgZyssSDUr6F5 '
71
80
} ,
72
81
etherlink : {
73
82
...testConfig . tokens . etherlink . usdt
@@ -82,9 +91,18 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
82
91
tezosToolkit,
83
92
smartRollupAddress : testConfig . tezosRollupAddress
84
93
} ) ,
85
- etherlinkBridgeBlockchainService : new Web3EtherlinkBridgeBlockchainService ( {
86
- web3 : etherlinkToolkit
87
- } ) ,
94
+ etherlinkBridgeBlockchainService : etherlinkToolkit . type === 'web3'
95
+ ? new Web3EtherlinkBridgeBlockchainService ( {
96
+ web3 : etherlinkToolkit . web3
97
+ } )
98
+ : etherlinkToolkit . type === 'ethers-v6' ? new EthersEtherlinkBridgeBlockchainService ( {
99
+ ethers : etherlinkToolkit . ethers ,
100
+ signer : etherlinkToolkit . signer
101
+ } )
102
+ : new EthersV5EtherlinkBridgeBlockchainService ( {
103
+ ethers : etherlinkToolkit . ethers ,
104
+ signer : etherlinkToolkit . signer
105
+ } ) ,
88
106
bridgeDataProviders : {
89
107
transfers : defaultDataProvider ,
90
108
balances : defaultDataProvider ,
@@ -103,16 +121,41 @@ export const createTezosToolkitWithSigner = (rpcUrl: string, privateKey: string)
103
121
return toolkit ;
104
122
} ;
105
123
106
- export const createEtherlinkToolkitWithSigner = ( rpcUrl : string , privateKey : string ) : Web3 => {
124
+ const createWeb3EtherlinkToolkitWithSigner = ( rpcUrl : string , privateKey : string ) => {
125
+ const web3 = new Web3 ( rpcUrl ) ;
126
+ const account = web3 . eth . accounts . privateKeyToAccount ( privateKey ) ;
127
+ web3 . eth . accounts . wallet . add ( account ) ;
128
+ web3 . eth . defaultAccount = account . address ;
129
+
130
+ return { type : 'web3' , web3 } satisfies EtherlinkToolkit ;
131
+ } ;
132
+
133
+ const createEthersEtherlinkToolkitWithSigner = ( rpcUrl : string , privateKey : string ) => {
134
+ const provider = new ethers . JsonRpcProvider ( rpcUrl ) ;
135
+ const wallet = new ethers . Wallet ( privateKey , provider ) ;
136
+
137
+ return { type : 'ethers-v6' , ethers, signer : wallet } satisfies EtherlinkToolkit ;
138
+ } ;
139
+
140
+ const createEthersV5EtherlinkToolkitWithSigner = ( rpcUrl : string , privateKey : string ) => {
141
+ const provider = new ethersV5 . providers . JsonRpcProvider ( rpcUrl ) ;
142
+ const wallet = new ethersV5 . Wallet ( privateKey , provider ) ;
143
+
144
+ return { type : 'ethers-v5' , ethers : ethersV5 , signer : wallet } satisfies EtherlinkToolkit ;
145
+ } ;
146
+
147
+ export const createEtherlinkToolkitWithSigner = ( rpcUrl : string , privateKey : string , type : EtherlinkToolkit [ 'type' ] = 'web3' ) => {
107
148
if ( ! privateKey . startsWith ( '0x' ) )
108
149
privateKey = '0x' + privateKey ;
109
150
110
- const toolkit = new Web3 ( rpcUrl ) ;
111
- const account = toolkit . eth . accounts . privateKeyToAccount ( privateKey ) ;
112
- toolkit . eth . accounts . wallet . add ( account ) ;
113
- toolkit . eth . defaultAccount = account . address ;
114
-
115
- return toolkit ;
151
+ switch ( type ) {
152
+ case 'web3' :
153
+ return createWeb3EtherlinkToolkitWithSigner ( rpcUrl , privateKey ) ;
154
+ case 'ethers-v6' :
155
+ return createEthersEtherlinkToolkitWithSigner ( rpcUrl , privateKey ) ;
156
+ case 'ethers-v5' :
157
+ return createEthersV5EtherlinkToolkitWithSigner ( rpcUrl , privateKey ) ;
158
+ }
116
159
} ;
117
160
118
161
export const expectPendingDeposit = (
0 commit comments