diff --git a/integration/testConfig.ts b/integration/testConfig.ts index e0ee9fc..b27a214 100644 --- a/integration/testConfig.ts +++ b/integration/testConfig.ts @@ -3,12 +3,12 @@ import type { NativeEtherlinkToken, NativeTezosToken, ERC20EtherlinkToken, FA12T export interface TestTokens { readonly tezos: { tez: NativeTezosToken; - ctez: FA12TezosToken; + tzbtc: FA12TezosToken; usdt: FA2TezosToken; }; readonly etherlink: { tez: NativeEtherlinkToken - ctez: ERC20EtherlinkToken; + tzbtc: ERC20EtherlinkToken; usdt: ERC20EtherlinkToken; }; } @@ -62,27 +62,27 @@ const createTestTokens = (): TestTokens => { tez: { type: 'native' }, - ctez: { + tzbtc: { type: 'fa1.2', - address: 'KT1LpdETWYvPWCQTR2FEW6jE6dVqJqxYjdeW' + address: 'KT1Vq1toL9mQquJhCvVRbbcC8PbZJWM4bPui' }, usdt: { type: 'fa2', - address: 'KT195Eb8T524v5VJ99ZzH2wpnPfQ2wJfMi6h', - tokenId: '42' + address: 'KT1K6uyg7cjNRoPkYw6SfyCm1f2tPLHfVUez', + tokenId: '0' } }, etherlink: { tez: { type: 'native' }, - ctez: { + tzbtc: { type: 'erc20', address: '0x87dcBf128677ba36E79D47dAf4eb4e51610e0150' }, usdt: { type: 'erc20', - address: '0xcB5d40c6B1bdf5Cd51b3801351b0A68D101a561b' + address: '0x8554cD57C0C3E5Ab9d1782c9063279fA9bFA4680' } } }; diff --git a/integration/testHelpers.ts b/integration/testHelpers.ts index b5bfa65..9440a55 100644 --- a/integration/testHelpers.ts +++ b/integration/testHelpers.ts @@ -47,7 +47,7 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk { tezos: { ...testConfig.tokens.tezos.tez, - ticketHelperContractAddress: 'KT1DWVsu4Jtu2ficZ1qtNheGPunm5YVniegT' + ticketHelperContractAddress: 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9' }, etherlink: { ...testConfig.tokens.etherlink.tez, @@ -55,19 +55,19 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk }, { tezos: { - ...testConfig.tokens.tezos.ctez, - ticketerContractAddress: 'KT1RvSp4yDKUABqWmv3pKGE9fA6iCGy7bqGh', - ticketHelperContractAddress: 'KT1DHLWJorW9WB6ztkx1XcoaJKWXeTu9yoR1' + ...testConfig.tokens.tezos.tzbtc, + ticketerContractAddress: 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo', + ticketHelperContractAddress: 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1' }, etherlink: { - ...testConfig.tokens.etherlink.ctez + ...testConfig.tokens.etherlink.tzbtc } }, { tezos: { ...testConfig.tokens.tezos.usdt, - ticketerContractAddress: 'KT1VybveLaWhpQHKph28WcGwSy1ud22KSEan', - ticketHelperContractAddress: 'KT1DNtHLr9T9zksZjZvQwgtx5XJwrW9wzETB' + ticketerContractAddress: 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp', + ticketHelperContractAddress: 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH' }, etherlink: { ...testConfig.tokens.etherlink.usdt @@ -194,7 +194,7 @@ export const expectFinishedDeposit = ( etherlinkOperation: { blockId: expect.any(Number), hash: expect.stringMatching(etherlinkOperationRegex), - logIndex: expect.any(Number), + logIndex: params.etherlinkToken.type === 'native' ? null : expect.any(Number), amount: params.outAmount, token: params.etherlinkToken, timestamp: expect.any(String), diff --git a/integration/tests/balances.test.ts b/integration/tests/balances.test.ts index 8eed43b..034c057 100644 --- a/integration/tests/balances.test.ts +++ b/integration/tests/balances.test.ts @@ -40,10 +40,10 @@ describe('Balances', () => { test.each([ () => [testTezosAccountAddress, tokens.tezos.tez] as const, - () => [testTezosAccountAddress, tokens.tezos.ctez] as const, + () => [testTezosAccountAddress, tokens.tezos.tzbtc] as const, () => [testTezosAccountAddress, tokens.tezos.usdt] as const, () => [testEtherlinkAccountAddress, tokens.etherlink.tez] as const, - () => [testEtherlinkAccountAddress, tokens.etherlink.ctez] as const, + () => [testEtherlinkAccountAddress, tokens.etherlink.tzbtc] as const, () => [testEtherlinkAccountAddress, tokens.etherlink.usdt] as const, ])('Get the balance for a specific address and token: %#', async getTestData => { const [address, token] = getTestData(); @@ -59,30 +59,30 @@ describe('Balances', () => { test.each([ () => [testTezosAccountAddress, [tokens.tezos.tez], [tokens.tezos.tez]] as const, - () => [testTezosAccountAddress, [tokens.tezos.ctez], [tokens.tezos.ctez]] as const, - () => [testTezosAccountAddress, [tokens.tezos.ctez, tokens.tezos.usdt], [tokens.tezos.ctez, tokens.tezos.usdt]] as const, + () => [testTezosAccountAddress, [tokens.tezos.tzbtc], [tokens.tezos.tzbtc]] as const, + () => [testTezosAccountAddress, [tokens.tezos.tzbtc, tokens.tezos.usdt], [tokens.tezos.tzbtc, tokens.tezos.usdt]] as const, () => [ testTezosAccountAddress, - [tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt], - [tokens.tezos.tez, tokens.tezos.ctez, tokens.tezos.usdt] + [tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt], + [tokens.tezos.tez, tokens.tezos.tzbtc, tokens.tezos.usdt] ] as const, () => [ testTezosAccountAddress, - [tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.tezos.usdt], - [tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt] + [tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.tezos.usdt], + [tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt] ] as const, () => [ testTezosAccountAddress, - [tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt], - [tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt] + [tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt], + [tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt] ] as const, () => [testEtherlinkAccountAddress, [tokens.etherlink.tez], [tokens.etherlink.tez]] as const, - () => [testEtherlinkAccountAddress, [tokens.etherlink.ctez], [tokens.etherlink.ctez],] as const, - () => [testEtherlinkAccountAddress, [tokens.etherlink.ctez, tokens.etherlink.usdt], [tokens.etherlink.ctez, tokens.etherlink.usdt]] as const, + () => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc], [tokens.etherlink.tzbtc]] as const, + () => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc, tokens.etherlink.usdt], [tokens.etherlink.tzbtc, tokens.etherlink.usdt]] as const, () => [ testEtherlinkAccountAddress, - [tokens.etherlink.ctez, tokens.tezos.ctez, tokens.tezos.tez, tokens.etherlink.usdt], - [tokens.etherlink.ctez, tokens.etherlink.tez, tokens.etherlink.usdt] + [tokens.etherlink.tzbtc, tokens.tezos.tzbtc, tokens.tezos.tez, tokens.etherlink.usdt], + [tokens.etherlink.tzbtc, tokens.etherlink.tez, tokens.etherlink.usdt] ] as const, ])('Get the balance for a specific address and tokens: %#', async getTestData => { const [address, tokens, expectedTokens] = getTestData(); @@ -113,7 +113,7 @@ describe('Balances', () => { balance: expect.any(BigInt) }, { - token: tokens.tezos.ctez, + token: tokens.tezos.tzbtc, balance: expect.any(BigInt) }, { @@ -137,7 +137,7 @@ describe('Balances', () => { balance: expect.any(BigInt) }, { - token: tokens.etherlink.ctez, + token: tokens.etherlink.tzbtc, balance: expect.any(BigInt) }, { diff --git a/integration/tests/deposit.test.ts b/integration/tests/deposit.test.ts index 4c34008..e092978 100644 --- a/integration/tests/deposit.test.ts +++ b/integration/tests/deposit.test.ts @@ -75,8 +75,8 @@ describe('Deposit', () => { }); test('Deposit FA1.2 token', async () => { - const amount = 7n; - const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez]; + const amount = 7_000_000n; + const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc]; const depositResult = await tokenBridge.deposit(amount, tezosToken); expectPendingDeposit(depositResult.tokenTransfer, { @@ -102,7 +102,7 @@ describe('Deposit', () => { }); test('Deposit FA2 token', async () => { - const amount = 20n; + const amount = 20_000_000n; const [tezosToken, etherlinkToken] = [tokens.tezos.usdt, tokens.etherlink.usdt]; const depositResult = await tokenBridge.deposit(amount, tezosToken); @@ -129,8 +129,8 @@ describe('Deposit', () => { }); test('Deposit FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => { - const amount = 5n; - const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez]; + const amount = 5_000_000n; + const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc]; let readyForDone = false; tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => { @@ -174,8 +174,8 @@ describe('Deposit', () => { }); test('Deposit FA1.2 token, check the transfer status using events (subscribeToAccountTransfers)', done => { - const amount = 5n; - const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez]; + const amount = 5_000_000n; + const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc]; let readyForDone = false; let tokenTransferOperationHash: string | undefined; diff --git a/integration/tests/withdrawal.test.ts b/integration/tests/withdrawal.test.ts index 357682a..4ca4e4d 100644 --- a/integration/tests/withdrawal.test.ts +++ b/integration/tests/withdrawal.test.ts @@ -46,9 +46,9 @@ describe('Withdrawal', () => { tokenBridge[Symbol.dispose](); }); - test('Withdraw FA1.2 token', async () => { - const amount = 17n; - const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez]; + test.only('Withdraw FA1.2 token', async () => { + const amount = 1_700_000n; + const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc]; const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken); expectPendingWithdrawal(startWithdrawResult.tokenTransfer, { @@ -96,7 +96,7 @@ describe('Withdrawal', () => { }, withdrawalTimeout); test('Withdraw FA2 token', async () => { - const amount = 20n; + const amount = 20_000_000n; const [tezosToken, etherlinkToken] = [tokens.tezos.usdt, tokens.etherlink.usdt]; const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken); @@ -144,9 +144,9 @@ describe('Withdrawal', () => { }); }, withdrawalTimeout); - test('Withdraw FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => { - const amount = 3n; - const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez]; + test.skip('Withdraw FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => { + const amount = 3_000_000n; + const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc]; let readyForDone = false; tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => { diff --git a/src/bridgeBlockchainService/web3EtherlinkBridgeBlockchainService/web3EtherlinkBridgeBlockchainService.ts b/src/bridgeBlockchainService/web3EtherlinkBridgeBlockchainService/web3EtherlinkBridgeBlockchainService.ts index 6d9af93..72c92d7 100644 --- a/src/bridgeBlockchainService/web3EtherlinkBridgeBlockchainService/web3EtherlinkBridgeBlockchainService.ts +++ b/src/bridgeBlockchainService/web3EtherlinkBridgeBlockchainService/web3EtherlinkBridgeBlockchainService.ts @@ -28,7 +28,7 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc { receipt: TransactionReceipt }, NonPayableMethodObject, NonPayableMethodObject -> { +> { protected readonly web3: Web3; protected readonly withdrawNativeTokenPrecompiledAddress: string; protected readonly withdrawNonNativeTokenPrecompiledAddress: string; @@ -67,11 +67,16 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc this.getSignerAddress() ]); const data = nonNativeTokenOperation.encodeABI(); - // TODO: need to calculate the value or hardcode it in config + + const estimatedGas = await this.web3.eth.estimateGas({ + from: signerAddress, + to: this.withdrawNonNativeTokenPrecompiledAddress, + data, + }); const receipt = await this.web3.eth.sendTransaction({ from: signerAddress, to: this.withdrawNonNativeTokenPrecompiledAddress, - gas: 30000n, + gas: estimatedGas + (estimatedGas * 5n / 100n), gasPrice, data, });