Skip to content

Commit 83cd71a

Browse files
authored
Merge pull request #3 from baking-bad/feature/etherjs
Support the ethers.js. Update README. Fix eslint issues
2 parents 87867fa + ed4a370 commit 83cd71a

16 files changed

+1374
-542
lines changed

README.md

+61-486
Large diffs are not rendered by default.

integration/.env

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ TEZOS_RPC_URL=
22
ETHERLINK_RPC_URL=
33
DIPDUP_BASE_URL=
44
TZKT_API_BASE_URL=
5-
TEZOS_ROLLUP_BASE_URL=
65
TEZOS_ACCOUNT_PRIVATE_KEY=
76
ETHERLINK_ACCOUNT_PRIVATE_KEY=
87
TEZOS_ROLLUP_ADDRESS=

integration/testConfig.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export interface TestConfig {
1818
readonly etherlinkRpcUrl: string;
1919
readonly dipDupBaseUrl: string;
2020
readonly tzKTApiBaseUrl: string;
21-
readonly tezosRollupBaseUrl: string;
2221
readonly tezosRollupAddress: string;
2322
readonly etherlinkKernelAddress: string;
2423
readonly etherlinkWithdrawPrecompileAddress: string;
@@ -32,7 +31,6 @@ const envInfos = [
3231
['ETHERLINK_RPC_URL', 'the RPC URL for Etherlink'],
3332
['DIPDUP_BASE_URL', 'the base URL of the DipDup Bridge Data Provider'],
3433
['TZKT_API_BASE_URL', 'the base URL of the TzKT API'],
35-
['TEZOS_ROLLUP_BASE_URL', 'the base URL of the Tezos Rollup Node'],
3634
['TEZOS_ACCOUNT_PRIVATE_KEY', 'the private key of the test Tezos account'],
3735
['ETHERLINK_ACCOUNT_PRIVATE_KEY', 'the private key of the test Etherlink account'],
3836
['TEZOS_ROLLUP_ADDRESS', 'the address of the Bridge Rollup in Tezos'],
@@ -64,11 +62,11 @@ const createTestTokens = (): TestTokens => {
6462
},
6563
tzbtc: {
6664
type: 'fa1.2',
67-
address: 'KT1Vq1toL9mQquJhCvVRbbcC8PbZJWM4bPui'
65+
address: 'KT1HmyazXfKDbo8XjwtWPXcoyHcmNPDCvZyb'
6866
},
6967
usdt: {
7068
type: 'fa2',
71-
address: 'KT1K6uyg7cjNRoPkYw6SfyCm1f2tPLHfVUez',
69+
address: 'KT1V2ak1MfNd3w4oyKD64ehYU7K4CrpUcDGR',
7270
tokenId: '0'
7371
}
7472
},
@@ -78,11 +76,11 @@ const createTestTokens = (): TestTokens => {
7876
},
7977
tzbtc: {
8078
type: 'erc20',
81-
address: '0x87dcBf128677ba36E79D47dAf4eb4e51610e0150'
79+
address: '0x8e73aE3CF688Fbd8368c99520d26F9eF1B4d3BCa'
8280
},
8381
usdt: {
8482
type: 'erc20',
85-
address: '0x8554cD57C0C3E5Ab9d1782c9063279fA9bFA4680'
83+
address: '0xf68997eCC03751cb99B5B36712B213f11342452b'
8684
}
8785
}
8886
};
@@ -100,7 +98,6 @@ export const getTestConfig = (): TestConfig => {
10098
etherlinkRpcUrl: env.ETHERLINK_RPC_URL,
10199
dipDupBaseUrl: env.DIPDUP_BASE_URL,
102100
tzKTApiBaseUrl: env.TZKT_API_BASE_URL,
103-
tezosRollupBaseUrl: env.TEZOS_ROLLUP_BASE_URL,
104101
tezosAccountPrivateKey: env.TEZOS_ACCOUNT_PRIVATE_KEY,
105102
etherlinkAccountPrivateKey: env.ETHERLINK_ACCOUNT_PRIVATE_KEY,
106103
tezosRollupAddress: env.TEZOS_ROLLUP_ADDRESS,

integration/testHelpers.ts

+59-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { InMemorySigner } from '@taquito/signer';
22
import { TezosToolkit } from '@taquito/taquito';
3+
import { ethers as ethers } from 'ethers';
4+
import { ethers as ethersV5 } from 'ethers-v5';
35
import Web3 from 'web3';
46

57
import { TestConfig } from './testConfig';
@@ -8,6 +10,8 @@ import {
810
TokenBridge,
911
TaquitoContractTezosBridgeBlockchainService,
1012
Web3EtherlinkBridgeBlockchainService,
13+
EthersV5EtherlinkBridgeBlockchainService,
14+
EthersEtherlinkBridgeBlockchainService,
1115
DefaultDataProvider,
1216
BridgeTokenTransferKind, BridgeTokenTransferStatus, LogLevel,
1317
type TezosToken, type EtherlinkToken,
@@ -23,10 +27,15 @@ const withdrawalIdRegex = /^0x[0-9a-f]{64}_\d+$/;
2327
const tezosOperationRegex = /^o[0-9a-zA-Z]{50}$/;
2428
const etherlinkOperationRegex = /^0x[0-9a-f]{64}$/;
2529

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+
2635
interface CreateTestTokenBridgeParams {
2736
testConfig: TestConfig,
2837
tezosToolkit?: TezosToolkit,
29-
etherlinkToolkit?: Web3,
38+
etherlinkToolkit?: EtherlinkToolkit,
3039
overriddenDefaultDataProviderOptions?: Partial<DefaultDataProviderOptions>
3140
}
3241

@@ -47,7 +56,7 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
4756
{
4857
tezos: {
4958
...testConfig.tokens.tezos.tez,
50-
ticketHelperContractAddress: 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9'
59+
ticketHelperContractAddress: 'KT1VEjeQfDBSfpDH5WeBM5LukHPGM2htYEh3'
5160
},
5261
etherlink: {
5362
...testConfig.tokens.etherlink.tez,
@@ -56,8 +65,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
5665
{
5766
tezos: {
5867
...testConfig.tokens.tezos.tzbtc,
59-
ticketerContractAddress: 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo',
60-
ticketHelperContractAddress: 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1'
68+
ticketerContractAddress: 'KT1H7if3gSZE1pZSK48W3NzGpKmbWyBxWDHe',
69+
ticketHelperContractAddress: 'KT1KUAaaRMeMS5TJJyGTQJANcpSR4egvHBUk'
6170
},
6271
etherlink: {
6372
...testConfig.tokens.etherlink.tzbtc
@@ -66,8 +75,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
6675
{
6776
tezos: {
6877
...testConfig.tokens.tezos.usdt,
69-
ticketerContractAddress: 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp',
70-
ticketHelperContractAddress: 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH'
78+
ticketerContractAddress: 'KT1S6Nf9MnafAgSUWLKcsySPNFLUxxqSkQCw',
79+
ticketHelperContractAddress: 'KT1JLZe4qTa76y6Us2aDoRNUgZyssSDUr6F5'
7180
},
7281
etherlink: {
7382
...testConfig.tokens.etherlink.usdt
@@ -82,9 +91,18 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
8291
tezosToolkit,
8392
smartRollupAddress: testConfig.tezosRollupAddress
8493
}),
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+
}),
88106
bridgeDataProviders: {
89107
transfers: defaultDataProvider,
90108
balances: defaultDataProvider,
@@ -103,16 +121,41 @@ export const createTezosToolkitWithSigner = (rpcUrl: string, privateKey: string)
103121
return toolkit;
104122
};
105123

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') => {
107148
if (!privateKey.startsWith('0x'))
108149
privateKey = '0x' + privateKey;
109150

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+
}
116159
};
117160

118161
export const expectPendingDeposit = (

integration/tests/balances.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { TezosToolkit } from '@taquito/taquito';
2-
import Web3 from 'web3';
32

43
import type { AccountTokenBalance, AccountTokenBalances } from '../../src';
54
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
6-
import {
7-
createTezosToolkitWithSigner, createEtherlinkToolkitWithSigner, createTestTokenBridge
8-
} from '../testHelpers';
5+
import { createTezosToolkitWithSigner, createEtherlinkToolkitWithSigner, createTestTokenBridge, type EtherlinkToolkit } from '../testHelpers';
96

107
describe('Balances', () => {
118
let testConfig: TestConfig;
129
let tokens: TestTokens;
1310
let tezosToolkit: TezosToolkit;
14-
let etherlinkToolkit: Web3;
11+
let etherlinkToolkit: EtherlinkToolkit;
1512
let tokenBridge: ReturnType<typeof createTestTokenBridge>;
1613
let testTezosAccountAddress: string;
1714
let testEtherlinkAccountAddress: string;

integration/tests/deposit.test.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { TezosToolkit } from '@taquito/taquito';
2-
import Web3 from 'web3';
32

4-
import {
5-
BridgeTokenTransferStatus,
6-
type NativeEtherlinkToken, type NativeTezosToken
7-
} from '../../src';
3+
import { BridgeTokenTransferStatus } from '../../src';
84
import { bridgeUtils } from '../../src/utils';
95
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
106
import {
@@ -13,14 +9,15 @@ import {
139
expectPendingDeposit,
1410
expectCreatedDeposit,
1511
expectFinishedDeposit,
16-
createTestTokenBridge
12+
createTestTokenBridge,
13+
type EtherlinkToolkit
1714
} from '../testHelpers';
1815

1916
describe('Deposit', () => {
2017
let testConfig: TestConfig;
2118
let tokens: TestTokens;
2219
let tezosToolkit: TezosToolkit;
23-
let etherlinkToolkit: Web3;
20+
let etherlinkToolkit: EtherlinkToolkit;
2421
let tokenBridge: ReturnType<typeof createTestTokenBridge>;
2522
let testTezosAccountAddress: string;
2623
let testEtherlinkAccountAddress: string;

integration/tests/withdrawal.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TezosToolkit } from '@taquito/taquito';
2-
import Web3 from 'web3';
32

43
import { BridgeTokenTransferStatus, type TokenBridge } from '../../src';
54
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
@@ -10,7 +9,8 @@ import {
109
expectCreatedWithdrawal,
1110
expectSealedWithdrawal,
1211
expectFinishedWithdrawal,
13-
createTestTokenBridge
12+
createTestTokenBridge,
13+
type EtherlinkToolkit
1414
} from '../testHelpers';
1515

1616
const withdrawalTimeout = process.env.WITHDRAWAL_TIMEOUT ? parseInt(process.env.WITHDRAWAL_TIMEOUT, 10) : 15 * 60 * 1000;
@@ -19,7 +19,7 @@ describe('Withdrawal', () => {
1919
let testConfig: TestConfig;
2020
let tokens: TestTokens;
2121
let tezosToolkit: TezosToolkit;
22-
let etherlinkToolkit: Web3;
22+
let etherlinkToolkit: EtherlinkToolkit;
2323
let tokenBridge: TokenBridge;
2424
let testTezosAccountAddress: string;
2525
let testEtherlinkAccountAddress: string;

0 commit comments

Comments
 (0)