Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the ethers.js. Update README. Fix eslint issues #3

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
547 changes: 61 additions & 486 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion integration/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ TEZOS_RPC_URL=
ETHERLINK_RPC_URL=
DIPDUP_BASE_URL=
TZKT_API_BASE_URL=
TEZOS_ROLLUP_BASE_URL=
TEZOS_ACCOUNT_PRIVATE_KEY=
ETHERLINK_ACCOUNT_PRIVATE_KEY=
TEZOS_ROLLUP_ADDRESS=
Expand Down
11 changes: 4 additions & 7 deletions integration/testConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface TestConfig {
readonly etherlinkRpcUrl: string;
readonly dipDupBaseUrl: string;
readonly tzKTApiBaseUrl: string;
readonly tezosRollupBaseUrl: string;
readonly tezosRollupAddress: string;
readonly etherlinkKernelAddress: string;
readonly etherlinkWithdrawPrecompileAddress: string;
Expand All @@ -32,7 +31,6 @@ const envInfos = [
['ETHERLINK_RPC_URL', 'the RPC URL for Etherlink'],
['DIPDUP_BASE_URL', 'the base URL of the DipDup Bridge Data Provider'],
['TZKT_API_BASE_URL', 'the base URL of the TzKT API'],
['TEZOS_ROLLUP_BASE_URL', 'the base URL of the Tezos Rollup Node'],
['TEZOS_ACCOUNT_PRIVATE_KEY', 'the private key of the test Tezos account'],
['ETHERLINK_ACCOUNT_PRIVATE_KEY', 'the private key of the test Etherlink account'],
['TEZOS_ROLLUP_ADDRESS', 'the address of the Bridge Rollup in Tezos'],
Expand Down Expand Up @@ -64,11 +62,11 @@ const createTestTokens = (): TestTokens => {
},
tzbtc: {
type: 'fa1.2',
address: 'KT1Vq1toL9mQquJhCvVRbbcC8PbZJWM4bPui'
address: 'KT1HmyazXfKDbo8XjwtWPXcoyHcmNPDCvZyb'
},
usdt: {
type: 'fa2',
address: 'KT1K6uyg7cjNRoPkYw6SfyCm1f2tPLHfVUez',
address: 'KT1V2ak1MfNd3w4oyKD64ehYU7K4CrpUcDGR',
tokenId: '0'
}
},
Expand All @@ -78,11 +76,11 @@ const createTestTokens = (): TestTokens => {
},
tzbtc: {
type: 'erc20',
address: '0x87dcBf128677ba36E79D47dAf4eb4e51610e0150'
address: '0x8e73aE3CF688Fbd8368c99520d26F9eF1B4d3BCa'
},
usdt: {
type: 'erc20',
address: '0x8554cD57C0C3E5Ab9d1782c9063279fA9bFA4680'
address: '0xf68997eCC03751cb99B5B36712B213f11342452b'
}
}
};
Expand All @@ -100,7 +98,6 @@ export const getTestConfig = (): TestConfig => {
etherlinkRpcUrl: env.ETHERLINK_RPC_URL,
dipDupBaseUrl: env.DIPDUP_BASE_URL,
tzKTApiBaseUrl: env.TZKT_API_BASE_URL,
tezosRollupBaseUrl: env.TEZOS_ROLLUP_BASE_URL,
tezosAccountPrivateKey: env.TEZOS_ACCOUNT_PRIVATE_KEY,
etherlinkAccountPrivateKey: env.ETHERLINK_ACCOUNT_PRIVATE_KEY,
tezosRollupAddress: env.TEZOS_ROLLUP_ADDRESS,
Expand Down
75 changes: 59 additions & 16 deletions integration/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';
import { ethers as ethers } from 'ethers';
import { ethers as ethersV5 } from 'ethers-v5';
import Web3 from 'web3';

import { TestConfig } from './testConfig';
Expand All @@ -8,6 +10,8 @@ import {
TokenBridge,
TaquitoContractTezosBridgeBlockchainService,
Web3EtherlinkBridgeBlockchainService,
EthersV5EtherlinkBridgeBlockchainService,
EthersEtherlinkBridgeBlockchainService,
DefaultDataProvider,
BridgeTokenTransferKind, BridgeTokenTransferStatus, LogLevel,
type TezosToken, type EtherlinkToken,
Expand All @@ -23,10 +27,15 @@ const withdrawalIdRegex = /^0x[0-9a-f]{64}_\d+$/;
const tezosOperationRegex = /^o[0-9a-zA-Z]{50}$/;
const etherlinkOperationRegex = /^0x[0-9a-f]{64}$/;

export type EtherlinkToolkit =
| { type: 'web3', web3: Web3 }
| { type: 'ethers-v6', ethers: typeof ethers, signer: ethers.Signer }
| { type: 'ethers-v5', ethers: typeof ethersV5, signer: ethersV5.Signer };

interface CreateTestTokenBridgeParams {
testConfig: TestConfig,
tezosToolkit?: TezosToolkit,
etherlinkToolkit?: Web3,
etherlinkToolkit?: EtherlinkToolkit,
overriddenDefaultDataProviderOptions?: Partial<DefaultDataProviderOptions>
}

Expand All @@ -47,7 +56,7 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
{
tezos: {
...testConfig.tokens.tezos.tez,
ticketHelperContractAddress: 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9'
ticketHelperContractAddress: 'KT1VEjeQfDBSfpDH5WeBM5LukHPGM2htYEh3'
},
etherlink: {
...testConfig.tokens.etherlink.tez,
Expand All @@ -56,8 +65,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
{
tezos: {
...testConfig.tokens.tezos.tzbtc,
ticketerContractAddress: 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo',
ticketHelperContractAddress: 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1'
ticketerContractAddress: 'KT1H7if3gSZE1pZSK48W3NzGpKmbWyBxWDHe',
ticketHelperContractAddress: 'KT1KUAaaRMeMS5TJJyGTQJANcpSR4egvHBUk'
},
etherlink: {
...testConfig.tokens.etherlink.tzbtc
Expand All @@ -66,8 +75,8 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
{
tezos: {
...testConfig.tokens.tezos.usdt,
ticketerContractAddress: 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp',
ticketHelperContractAddress: 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH'
ticketerContractAddress: 'KT1S6Nf9MnafAgSUWLKcsySPNFLUxxqSkQCw',
ticketHelperContractAddress: 'KT1JLZe4qTa76y6Us2aDoRNUgZyssSDUr6F5'
},
etherlink: {
...testConfig.tokens.etherlink.usdt
Expand All @@ -82,9 +91,18 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
tezosToolkit,
smartRollupAddress: testConfig.tezosRollupAddress
}),
etherlinkBridgeBlockchainService: new Web3EtherlinkBridgeBlockchainService({
web3: etherlinkToolkit
}),
etherlinkBridgeBlockchainService: etherlinkToolkit.type === 'web3'
? new Web3EtherlinkBridgeBlockchainService({
web3: etherlinkToolkit.web3
})
: etherlinkToolkit.type === 'ethers-v6' ? new EthersEtherlinkBridgeBlockchainService({
ethers: etherlinkToolkit.ethers,
signer: etherlinkToolkit.signer
})
: new EthersV5EtherlinkBridgeBlockchainService({
ethers: etherlinkToolkit.ethers,
signer: etherlinkToolkit.signer
}),
bridgeDataProviders: {
transfers: defaultDataProvider,
balances: defaultDataProvider,
Expand All @@ -103,16 +121,41 @@ export const createTezosToolkitWithSigner = (rpcUrl: string, privateKey: string)
return toolkit;
};

export const createEtherlinkToolkitWithSigner = (rpcUrl: string, privateKey: string): Web3 => {
const createWeb3EtherlinkToolkitWithSigner = (rpcUrl: string, privateKey: string) => {
const web3 = new Web3(rpcUrl);
const account = web3.eth.accounts.privateKeyToAccount(privateKey);
web3.eth.accounts.wallet.add(account);
web3.eth.defaultAccount = account.address;

return { type: 'web3', web3 } satisfies EtherlinkToolkit;
};

const createEthersEtherlinkToolkitWithSigner = (rpcUrl: string, privateKey: string) => {
const provider = new ethers.JsonRpcProvider(rpcUrl);
const wallet = new ethers.Wallet(privateKey, provider);

return { type: 'ethers-v6', ethers, signer: wallet } satisfies EtherlinkToolkit;
};

const createEthersV5EtherlinkToolkitWithSigner = (rpcUrl: string, privateKey: string) => {
const provider = new ethersV5.providers.JsonRpcProvider(rpcUrl);
const wallet = new ethersV5.Wallet(privateKey, provider);

return { type: 'ethers-v5', ethers: ethersV5, signer: wallet } satisfies EtherlinkToolkit;
};

export const createEtherlinkToolkitWithSigner = (rpcUrl: string, privateKey: string, type: EtherlinkToolkit['type'] = 'web3') => {
if (!privateKey.startsWith('0x'))
privateKey = '0x' + privateKey;

const toolkit = new Web3(rpcUrl);
const account = toolkit.eth.accounts.privateKeyToAccount(privateKey);
toolkit.eth.accounts.wallet.add(account);
toolkit.eth.defaultAccount = account.address;

return toolkit;
switch (type) {
case 'web3':
return createWeb3EtherlinkToolkitWithSigner(rpcUrl, privateKey);
case 'ethers-v6':
return createEthersEtherlinkToolkitWithSigner(rpcUrl, privateKey);
case 'ethers-v5':
return createEthersV5EtherlinkToolkitWithSigner(rpcUrl, privateKey);
}
};

export const expectPendingDeposit = (
Expand Down
7 changes: 2 additions & 5 deletions integration/tests/balances.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { TezosToolkit } from '@taquito/taquito';
import Web3 from 'web3';

import type { AccountTokenBalance, AccountTokenBalances } from '../../src';
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
import {
createTezosToolkitWithSigner, createEtherlinkToolkitWithSigner, createTestTokenBridge
} from '../testHelpers';
import { createTezosToolkitWithSigner, createEtherlinkToolkitWithSigner, createTestTokenBridge, type EtherlinkToolkit } from '../testHelpers';

describe('Balances', () => {
let testConfig: TestConfig;
let tokens: TestTokens;
let tezosToolkit: TezosToolkit;
let etherlinkToolkit: Web3;
let etherlinkToolkit: EtherlinkToolkit;
let tokenBridge: ReturnType<typeof createTestTokenBridge>;
let testTezosAccountAddress: string;
let testEtherlinkAccountAddress: string;
Expand Down
11 changes: 4 additions & 7 deletions integration/tests/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { TezosToolkit } from '@taquito/taquito';
import Web3 from 'web3';

import {
BridgeTokenTransferStatus,
type NativeEtherlinkToken, type NativeTezosToken
} from '../../src';
import { BridgeTokenTransferStatus } from '../../src';
import { bridgeUtils } from '../../src/utils';
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
import {
Expand All @@ -13,14 +9,15 @@ import {
expectPendingDeposit,
expectCreatedDeposit,
expectFinishedDeposit,
createTestTokenBridge
createTestTokenBridge,
type EtherlinkToolkit
} from '../testHelpers';

describe('Deposit', () => {
let testConfig: TestConfig;
let tokens: TestTokens;
let tezosToolkit: TezosToolkit;
let etherlinkToolkit: Web3;
let etherlinkToolkit: EtherlinkToolkit;
let tokenBridge: ReturnType<typeof createTestTokenBridge>;
let testTezosAccountAddress: string;
let testEtherlinkAccountAddress: string;
Expand Down
6 changes: 3 additions & 3 deletions integration/tests/withdrawal.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TezosToolkit } from '@taquito/taquito';
import Web3 from 'web3';

import { BridgeTokenTransferStatus, type TokenBridge } from '../../src';
import { getTestConfig, type TestConfig, type TestTokens } from '../testConfig';
Expand All @@ -10,7 +9,8 @@ import {
expectCreatedWithdrawal,
expectSealedWithdrawal,
expectFinishedWithdrawal,
createTestTokenBridge
createTestTokenBridge,
type EtherlinkToolkit
} from '../testHelpers';

const withdrawalTimeout = process.env.WITHDRAWAL_TIMEOUT ? parseInt(process.env.WITHDRAWAL_TIMEOUT, 10) : 15 * 60 * 1000;
Expand All @@ -19,7 +19,7 @@ describe('Withdrawal', () => {
let testConfig: TestConfig;
let tokens: TestTokens;
let tezosToolkit: TezosToolkit;
let etherlinkToolkit: Web3;
let etherlinkToolkit: EtherlinkToolkit;
let tokenBridge: TokenBridge;
let testTezosAccountAddress: string;
let testEtherlinkAccountAddress: string;
Expand Down
Loading
Loading