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

fix: add retry and check using new sdk method for finalization #194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
37 changes: 30 additions & 7 deletions composables/zksync/useWithdrawalFinalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
}
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.");
}
Comment on lines +125 to +130
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem necessary as it doesnt seem to be the root of the issue. Wallet.isWithdrawalFinalized() is used already and provides that check for withdrawal finalization


status.value = "waiting-for-signature";
transactionHash.value = await wallet.writeContract({
...transactionParams,
Expand All @@ -130,13 +137,16 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
});

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 }
);

trackEvent("withdrawal-finalized", {
Expand Down Expand Up @@ -166,3 +176,16 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
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;
}
};
Comment on lines +180 to +191
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading