From 9b9419acff502a9bf22c1a2c622e5ea903eaf820 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 10 Oct 2024 15:06:50 -0500 Subject: [PATCH 1/2] fix: add retry and check using new sdk method for finalization --- .../zksync/useWithdrawalFinalization.ts | 37 +++++++++++++++---- package.json | 2 +- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index a7ba59c7..a6dd49e5 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -122,6 +122,13 @@ export default (transactionInfo: ComputedRef) => { } const wallet = await onboardStore.getWallet(); const { transactionParams, gasLimit, gasPrice } = (await estimateFee())!; + + // Check if the batch has been processed before attempting finalization + const l1BatchNumber = finalizeWithdrawalParams.value?.l1BatchNumber; + if (l1BatchNumber && !(await isBatchProcessed(l1BatchNumber))) { + throw new Error("Batch not yet processed. Please wait and try again later."); + } + status.value = "waiting-for-signature"; transactionHash.value = await wallet.writeContract({ ...transactionParams, @@ -130,13 +137,16 @@ export default (transactionInfo: ComputedRef) => { }); status.value = "sending"; - const receipt = await retry(() => - onboardStore.getPublicClient().waitForTransactionReceipt({ - hash: transactionHash.value!, - onReplaced: (replacement) => { - transactionHash.value = replacement.transaction.hash; - }, - }) + const receipt = await retry( + async () => { + return await onboardStore.getPublicClient().waitForTransactionReceipt({ + hash: transactionHash.value!, + onReplaced: (replacement) => { + transactionHash.value = replacement.transaction.hash; + }, + }); + }, + { retries: 3, delay: 10000 } // Adjust retries and delay as needed ); trackEvent("withdrawal-finalized", { @@ -166,3 +176,16 @@ export default (transactionInfo: ComputedRef) => { commitTransaction, }; }; + +const isBatchProcessed = async (batchNumber: any) => { + const providerStore = useZkSyncProviderStore(); + try { + const totalBatchesExecuted = await providerStore.requestProvider().getTotalBatchesExecuted(); + + return batchNumber <= BigNumber.from(totalBatchesExecuted).toNumber(); + } catch (error) { + // eslint-disable-next-line no-console + console.error("Error fetching total batches executed:", error); + return false; + } +}; diff --git a/package.json b/package.json index 742334ac..079b0006 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "vite": "^3.0.0", "vue-tippy": "^6.0.0", "web3-avatar-vue": "^1.0.0", - "zksync-ethers": "^5.9.1" + "zksync-ethers": "../zksync-ethers/build" }, "overrides": { "vue": "latest" From ce0fd8b80162843f82e878d071cd127af51aa93f Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 10 Oct 2024 15:07:50 -0500 Subject: [PATCH 2/2] fix: add retry and check using new sdk method for finalization --- composables/zksync/useWithdrawalFinalization.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index a6dd49e5..c69592eb 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -146,7 +146,7 @@ export default (transactionInfo: ComputedRef) => { }, }); }, - { retries: 3, delay: 10000 } // Adjust retries and delay as needed + { retries: 3, delay: 10000 } ); trackEvent("withdrawal-finalized", {