From 980fd88c5dada9d767d2ea17dd675c5fbfb10c60 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 14:09:14 +0530 Subject: [PATCH 1/6] feat(bridge-ui): retry tx with gasLimit on unpredictable gas error --- packages/bridge-ui/src/bridge/ERC20Bridge.ts | 20 ++++++++++++++++-- packages/bridge-ui/src/bridge/ETHBridge.ts | 22 +++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/bridge-ui/src/bridge/ERC20Bridge.ts b/packages/bridge-ui/src/bridge/ERC20Bridge.ts index 71bb863da77..309e8a541df 100644 --- a/packages/bridge-ui/src/bridge/ERC20Bridge.ts +++ b/packages/bridge-ui/src/bridge/ERC20Bridge.ts @@ -1,4 +1,4 @@ -import { BigNumber, Contract, Signer } from 'ethers'; +import { BigNumber, Contract, ethers, Signer } from 'ethers'; import type { Transaction } from 'ethers'; import type { ApproveOpts, @@ -190,7 +190,23 @@ export class ERC20Bridge implements Bridge { }); } - return await contract.processMessage(opts.message, proof); + let processMessageTx; + try { + processMessageTx = await contract.processMessage(opts.message, proof); + } catch (error) { + if (error.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) { + processMessageTx = await contract.processMessage( + opts.message, + proof, + { + gasLimit: 1e6, + }, + ); + } else { + throw new Error(error); + } + } + return processMessageTx; } else { return await contract.retryMessage(opts.message, false); } diff --git a/packages/bridge-ui/src/bridge/ETHBridge.ts b/packages/bridge-ui/src/bridge/ETHBridge.ts index 5b3ea01f2ba..0f188372842 100644 --- a/packages/bridge-ui/src/bridge/ETHBridge.ts +++ b/packages/bridge-ui/src/bridge/ETHBridge.ts @@ -1,4 +1,4 @@ -import { BigNumber, Contract } from 'ethers'; +import { BigNumber, Contract, ethers } from 'ethers'; import type { Transaction } from 'ethers'; import type { ApproveOpts, @@ -41,7 +41,7 @@ export class ETHBridge implements Bridge { callValue: 0, processingFee: opts.processingFeeInWei ?? BigNumber.from(0), gasLimit: opts.processingFeeInWei - ? BigNumber.from(140000) + ? BigNumber.from(900000) : BigNumber.from(0), memo: opts.memo ?? '', }; @@ -133,7 +133,23 @@ export class ETHBridge implements Bridge { }; const proof = await this.prover.GenerateProof(proofOpts); - return await contract.processMessage(opts.message, proof); + let processMessageTx; + try { + processMessageTx = await contract.processMessage(opts.message, proof); + } catch (error) { + if (error.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) { + processMessageTx = await contract.processMessage( + opts.message, + proof, + { + gasLimit: 1e6, + }, + ); + } else { + throw new Error(error); + } + } + return processMessageTx; } else { return await contract.retryMessage(opts.message, true); } From e307f54e3c1a23ed172080c77749a175dd6d3616 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 15:04:40 +0530 Subject: [PATCH 2/6] feat(bridge-ui): add message status for when claim tx is in progress --- packages/bridge-ui/src/domain/message.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/bridge-ui/src/domain/message.ts b/packages/bridge-ui/src/domain/message.ts index 0b7c1350d1a..2d01befb0c4 100644 --- a/packages/bridge-ui/src/domain/message.ts +++ b/packages/bridge-ui/src/domain/message.ts @@ -6,6 +6,7 @@ export enum MessageStatus { Done, Failed, FailedReleased, + ClaimInProgress, } export type Message = { From 6add30349134f86da46218146b0f1eb8203797d3 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 15:05:09 +0530 Subject: [PATCH 3/6] feat(bridge-ui): show insufficient balance message when user has zero balance --- .../InsufficientBalanceTooltip.svelte | 14 ++++++++++ .../src/components/Transaction.svelte | 28 ++++++++++++++----- .../src/components/Transactions.svelte | 13 +++++++-- 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 packages/bridge-ui/src/components/InsufficientBalanceTooltip.svelte diff --git a/packages/bridge-ui/src/components/InsufficientBalanceTooltip.svelte b/packages/bridge-ui/src/components/InsufficientBalanceTooltip.svelte new file mode 100644 index 00000000000..1f1bc82d949 --- /dev/null +++ b/packages/bridge-ui/src/components/InsufficientBalanceTooltip.svelte @@ -0,0 +1,14 @@ + + + + +
+ You have insufficient balance to claim this transaction. Please wait for + the relayer to claim the transaction for you. +
+
+
diff --git a/packages/bridge-ui/src/components/Transaction.svelte b/packages/bridge-ui/src/components/Transaction.svelte index 89e36b64ca8..d845a2b905f 100644 --- a/packages/bridge-ui/src/components/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transaction.svelte @@ -4,7 +4,11 @@ import { ArrowTopRightOnSquare } from 'svelte-heros-v2'; import { MessageStatus } from '../domain/message'; import { Contract, ethers } from 'ethers'; - import { bridges, chainIdToTokenVaultAddress } from '../store/bridge'; + import { + activeBridge, + bridges, + chainIdToTokenVaultAddress, + } from '../store/bridge'; import { signer } from '../store/signer'; import { pendingTransactions } from '../store/transactions'; import { errorToast, successToast } from '../utils/toast'; @@ -19,7 +23,7 @@ import { LottiePlayer } from '@lottiefiles/svelte-lottie-player'; import HeaderSync from '../constants/abi/HeaderSync'; import { providers } from '../store/providers'; - import { fetchSigner, switchNetwork } from '@wagmi/core'; + import { fetchFeeData, fetchSigner, switchNetwork } from '@wagmi/core'; import Bridge from '../constants/abi/Bridge'; import ButtonWithTooltip from './ButtonWithTooltip.svelte'; import TokenVault from '../constants/abi/TokenVault'; @@ -29,7 +33,7 @@ export let fromChain: Chain; export let toChain: Chain; - export let onTooltipClick: () => void; + export let onTooltipClick: (showInsufficientBalanceMessage: boolean) => void; export let onShowTransactionDetailsClick: () => void; let loading: boolean; @@ -76,6 +80,14 @@ await switchChainAndSetSigner(chain); } + // For now just handling this case for when the user has 0 balance during their first bridge transaction to L2 + // TODO: estimate Claim transaction + const userBalance = await $signer.getBalance('latest'); + if (!userBalance.gt(0)) { + onTooltipClick(true); + return; + } + const tx = await $bridges .get( bridgeTx.message?.data === '0x' || !bridgeTx.message?.data @@ -96,6 +108,7 @@ }); successToast($_('toast.transactionSent')); + transaction.status = MessageStatus.ClaimInProgress; } catch (e) { console.error(e); errorToast($_('toast.errorSendingTransaction')); @@ -226,7 +239,7 @@ - + onTooltipClick(false)}> {#if !processable} Pending @@ -243,10 +256,11 @@ width={26} controlsLayout={[]} /> - {:else if transaction.receipt && transaction.status === MessageStatus.New} + {:else if transaction.receipt && [MessageStatus.New, MessageStatus.ClaimInProgress].includes(transaction.status)} {:else if transaction.status === MessageStatus.Retriable} diff --git a/packages/bridge-ui/src/components/Transactions.svelte b/packages/bridge-ui/src/components/Transactions.svelte index 2bc5b882c08..80f33a74735 100644 --- a/packages/bridge-ui/src/components/Transactions.svelte +++ b/packages/bridge-ui/src/components/Transactions.svelte @@ -3,11 +3,13 @@ import Transaction from './Transaction.svelte'; import TransactionDetail from './TransactionDetail.svelte'; import MessageStatusTooltip from './MessageStatusTooltip.svelte'; + import InsufficientBalanceTooltip from './InsufficientBalanceTooltip.svelte'; import type { BridgeTransaction } from '../domain/transactions'; import { chainsRecord } from '../chain/chains'; let selectedTransaction: BridgeTransaction; let showMessageStatusTooltip: boolean; + let showInsufficientBalance: boolean;
@@ -25,8 +27,12 @@ {#each $transactions as transaction} { - showMessageStatusTooltip = true; + onTooltipClick={(showInsufficientBalanceMessage = false) => { + if (showInsufficientBalanceMessage) { + showInsufficientBalance = true; + } else { + showMessageStatusTooltip = true; + } }} onShowTransactionDetailsClick={() => { selectedTransaction = transaction; @@ -47,5 +53,6 @@ onClose={() => (selectedTransaction = null)} /> {/if} - + +
From d3c32d1d5fa5c5c342c8975d20a09ace6be15769 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 15:12:55 +0530 Subject: [PATCH 4/6] fix(bridge-ui): tx dedup if receipt does not exist --- packages/bridge-ui/src/App.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index a6e8fe64ca2..efcacff5f57 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -159,7 +159,7 @@ const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => { const blockInfo = blockInfoMap.get(tx.fromChainId); - if (blockInfo?.latestProcessedBlock >= tx.receipt.blockNumber) { + if (blockInfo?.latestProcessedBlock >= tx.receipt?.blockNumber) { return false; } return true; From 18d286ffd929b23a2e93036b7e0370dba5b87da6 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 15:21:27 +0530 Subject: [PATCH 5/6] fix(bridge-ui): check balance less than 0.0001 --- packages/bridge-ui/src/components/Transaction.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bridge-ui/src/components/Transaction.svelte b/packages/bridge-ui/src/components/Transaction.svelte index d845a2b905f..a718bea7066 100644 --- a/packages/bridge-ui/src/components/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transaction.svelte @@ -80,10 +80,10 @@ await switchChainAndSetSigner(chain); } - // For now just handling this case for when the user has 0 balance during their first bridge transaction to L2 + // For now just handling this case for when the user has near 0 balance during their first bridge transaction to L2 // TODO: estimate Claim transaction const userBalance = await $signer.getBalance('latest'); - if (!userBalance.gt(0)) { + if (!userBalance.gt(ethers.utils.parseEther('0.0001'))) { onTooltipClick(true); return; } From f2f25bf7b791e1e6a39f0256ecd8bd0bf2778ab9 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 20 Mar 2023 16:38:55 +0530 Subject: [PATCH 6/6] fix(bridge-ui): revert processing fee change --- packages/bridge-ui/src/bridge/ETHBridge.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bridge-ui/src/bridge/ETHBridge.ts b/packages/bridge-ui/src/bridge/ETHBridge.ts index 0f188372842..74d4610ab62 100644 --- a/packages/bridge-ui/src/bridge/ETHBridge.ts +++ b/packages/bridge-ui/src/bridge/ETHBridge.ts @@ -41,7 +41,7 @@ export class ETHBridge implements Bridge { callValue: 0, processingFee: opts.processingFeeInWei ?? BigNumber.from(0), gasLimit: opts.processingFeeInWei - ? BigNumber.from(900000) + ? BigNumber.from(140000) : BigNumber.from(0), memo: opts.memo ?? '', };