From 18ceebf843bafe052fe450682469ddd76eb5fd0d Mon Sep 17 00:00:00 2001 From: "Ramon \"9Tails\" Canales" Date: Thu, 23 May 2024 15:31:58 +0100 Subject: [PATCH 01/10] feat: updating zksync-ethers --- composables/zksync/useWithdrawalFinalization.ts | 11 ++--------- package-lock.json | 11 +++++++---- package.json | 2 +- store/zksync/transactionStatus.ts | 14 ++------------ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index 3d91bf7b1..e23b06958 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -2,7 +2,7 @@ import { useMemoize } from "@vueuse/core"; import { BigNumber, type BigNumberish } from "ethers"; import { Wallet } from "zksync-ethers"; import ZkSyncL1BridgeAbi from "zksync-ethers/abi/IL1Bridge.json"; -import ZkSyncContractAbi from "zksync-ethers/abi/IZkSync.json"; +import ZkSyncContractAbi from "zksync-ethers/abi/IZkSyncStateTransition.json"; import type { Hash } from "@/types"; @@ -22,7 +22,6 @@ export default (transactionInfo: ComputedRef) => { .getDefaultBridgeAddresses() .then((e) => e.erc20L1) ); - const retrieveMainContractAddress = useMemoize(() => providerStore.requestProvider().getMainContractAddress()); const gasLimit = ref(); const gasPrice = ref(); @@ -70,7 +69,7 @@ export default (transactionInfo: ComputedRef) => { finalizeWithdrawalParams.value = await getFinalizationParams(); if (usingMainContract.value) { return { - address: (await retrieveMainContractAddress()) as Hash, + address: (await retrieveBridgeAddress()) as Hash, abi: ZkSyncContractAbi, account: onboardStore.account.address!, functionName: "finalizeEthWithdrawal", @@ -147,12 +146,6 @@ export default (transactionInfo: ComputedRef) => { }, }); - trackEvent("withdrawal-finalized", { - token: transactionInfo.value!.token.symbol, - amount: transactionInfo.value!.token.amount, - to: transactionInfo.value!.to.address, - }); - status.value = "done"; return receipt; } catch (err) { diff --git a/package-lock.json b/package-lock.json index c4d5608cf..937e03812 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "vite": "^3.0.0", "vue-tippy": "^6.0.0", "web3-avatar-vue": "^1.0.0", - "zksync-ethers": "^5.5.0" + "zksync-ethers": "^5.8.0-beta.5" }, "devDependencies": { "@commitlint/cli": "^17.4.2", @@ -34517,12 +34517,15 @@ } }, "node_modules/zksync-ethers": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/zksync-ethers/-/zksync-ethers-5.5.0.tgz", - "integrity": "sha512-sH77qSRSa1iEzy9abK2d5yaKA30QIpztbLUtjRJ34kWujdlVre8Sd0uUzLu+zW56AksU3AHGDl/iMtr/eHhDwg==", + "version": "5.8.0-beta.5", + "resolved": "https://registry.npmjs.org/zksync-ethers/-/zksync-ethers-5.8.0-beta.5.tgz", + "integrity": "sha512-saT/3OwLgifqzrBG7OujvUMapzXnshAaLzAZMycUtdV20eLSSVkyLIARVwh1M6hMQIUvX2htV0JN82QRMyM3Ig==", "dependencies": { "ethers": "~5.7.0" }, + "engines": { + "node": ">=16.0.0" + }, "peerDependencies": { "ethers": "~5.7.0" } diff --git a/package.json b/package.json index bdad0dda3..295e1fb54 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "vite": "^3.0.0", "vue-tippy": "^6.0.0", "web3-avatar-vue": "^1.0.0", - "zksync-ethers": "^5.5.0" + "zksync-ethers": "^5.8.0-beta.5" }, "overrides": { "vue": "latest" diff --git a/store/zksync/transactionStatus.ts b/store/zksync/transactionStatus.ts index bb760b149..bb6d4c384 100644 --- a/store/zksync/transactionStatus.ts +++ b/store/zksync/transactionStatus.ts @@ -1,6 +1,6 @@ import { useStorage } from "@vueuse/core"; import { decodeEventLog } from "viem"; -import ZkSyncContractInterface from "zksync-ethers/abi/IZkSync.json"; +import ZkSyncContractInterface from "zksync-ethers/abi/IZkSyncStateTransition.json"; import type { FeeEstimationParams } from "@/composables/zksync/useFee"; import type { TokenAmount, Hash } from "@/types"; @@ -30,14 +30,6 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta const { account } = storeToRefs(onboardStore); const { eraNetwork } = storeToRefs(providerStore); - const failedTransaction = useStorage("zksync-bridge-failed-transaction", []); - const addFailedTransaction = (transaction: TransactionInfo) => { - if (failedTransaction.value.some((tx) => tx.transactionHash === transaction.transactionHash)) { - return; - } - failedTransaction.value = [...failedTransaction.value, transaction]; - }; - const storageSavedTransactions = useStorage<{ [networkKey: string]: TransactionInfo[] }>( "zksync-bridge-transactions", {} @@ -96,7 +88,6 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta transaction.info.withdrawalFinalizationAvailable = false; transaction.info.failed = true; transaction.info.completed = true; - addFailedTransaction(transaction); return transaction; } if (transactionDetails.status !== "verified") { @@ -115,11 +106,10 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta const transactionReceipt = await providerStore.requestProvider().getTransactionReceipt(transaction.transactionHash); if (!transactionReceipt) return transaction; const transactionDetails = await providerStore.requestProvider().getTransactionDetails(transaction.transactionHash); - transaction.info.completed = true; if (transactionDetails.status === "failed") { transaction.info.failed = true; - addFailedTransaction(transaction); } + transaction.info.completed = true; return transaction; }; const waitForCompletion = async (transaction: TransactionInfo) => { From 48c740a2fccd9b9d5e0246b22eb0420173ce375b Mon Sep 17 00:00:00 2001 From: "Ramon \"9Tails\" Canales" Date: Thu, 23 May 2024 15:38:11 +0100 Subject: [PATCH 02/10] feat: fixing chain convertion for wagmi --- data/wagmi.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/data/wagmi.ts b/data/wagmi.ts index 8839332a8..2e36f648e 100644 --- a/data/wagmi.ts +++ b/data/wagmi.ts @@ -19,7 +19,7 @@ const useExistingEraChain = (network: ZkSyncNetwork) => { const existingNetworks = [zkSync, zkSyncSepoliaTestnet, zkSyncTestnet]; return existingNetworks.find((existingNetwork) => existingNetwork.id === network.id); }; -const createEraChain = (network: ZkSyncNetwork) => { +const createZKChain = (network: ZkSyncNetwork) => { return { id: network.id, name: network.name, @@ -29,8 +29,17 @@ const createEraChain = (network: ZkSyncNetwork) => { default: { http: [network.rpcUrl] }, public: { http: [network.rpcUrl] }, }, + blockExplorers: network.blockExplorerUrl + ? { + default: { + name: "Explorer", + url: network.blockExplorerUrl, + }, + } + : undefined, }; }; + const getAllChains = () => { const chains: Chain[] = []; const addUniqueChain = (chain: Chain) => { @@ -42,7 +51,7 @@ const getAllChains = () => { if (network.l1Network) { addUniqueChain(network.l1Network); } - addUniqueChain(useExistingEraChain(network) ?? createEraChain(network)); + addUniqueChain(useExistingEraChain(network) ?? createZKChain(network)); } return chains; From 28271730eda5c937913f51fd58a578d653e34cca Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Mon, 3 Jun 2024 18:21:44 +0200 Subject: [PATCH 03/10] fix: using shared bridge for ETH based chain withdrawal --- .../zksync/useWithdrawalFinalization.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index e23b06958..260ba9a40 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -2,7 +2,7 @@ import { useMemoize } from "@vueuse/core"; import { BigNumber, type BigNumberish } from "ethers"; import { Wallet } from "zksync-ethers"; import ZkSyncL1BridgeAbi from "zksync-ethers/abi/IL1Bridge.json"; -import ZkSyncContractAbi from "zksync-ethers/abi/IZkSyncStateTransition.json"; +import IL1SharedBridge from "zksync-ethers/abi/IL1SharedBridge.json"; import type { Hash } from "@/types"; @@ -16,11 +16,13 @@ export default (transactionInfo: ComputedRef) => { const { isCorrectNetworkSet } = storeToRefs(onboardStore); const { tokens } = storeToRefs(tokensStore); - const retrieveBridgeAddress = useMemoize(() => + const retrieveBridgeAddresses = useMemoize(() => providerStore.requestProvider().getDefaultBridgeAddresses()); + + const retrieveChainId = useMemoize(() => providerStore .requestProvider() - .getDefaultBridgeAddresses() - .then((e) => e.erc20L1) + .getNetwork() + .then((network) => network.chainId) ); const gasLimit = ref(); @@ -57,6 +59,7 @@ export default (transactionInfo: ComputedRef) => { transactionInfo.value.transactionHash ); return { + chainId: await retrieveChainId(), l1BatchNumber, l2MessageIndex, l2TxNumberInBlock, @@ -69,15 +72,15 @@ export default (transactionInfo: ComputedRef) => { finalizeWithdrawalParams.value = await getFinalizationParams(); if (usingMainContract.value) { return { - address: (await retrieveBridgeAddress()) as Hash, - abi: ZkSyncContractAbi, + address: (await retrieveBridgeAddresses()).sharedL1 as Hash, + abi: IL1SharedBridge, account: onboardStore.account.address!, - functionName: "finalizeEthWithdrawal", + functionName: "finalizeWithdrawal", args: Object.values(finalizeWithdrawalParams.value!), }; } else { return { - address: (await retrieveBridgeAddress()) as Hash, + address: (await retrieveBridgeAddresses()).erc20L1 as Hash, abi: ZkSyncL1BridgeAbi, account: onboardStore.account.address!, functionName: "finalizeWithdrawal", @@ -146,6 +149,12 @@ export default (transactionInfo: ComputedRef) => { }, }); + trackEvent("withdrawal-finalized", { + token: transactionInfo.value!.token.symbol, + amount: transactionInfo.value!.token.amount, + to: transactionInfo.value!.to.address, + }); + status.value = "done"; return receipt; } catch (err) { From 5909553e3effebf4f2d0019ad204025b6e252a93 Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Wed, 5 Jun 2024 03:39:40 +0200 Subject: [PATCH 04/10] erc20 deposit and withdraw fix --- composables/zksync/deposit/useTransaction.ts | 1 + composables/zksync/useTransaction.ts | 2 +- composables/zksync/useWithdrawalFinalization.ts | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composables/zksync/deposit/useTransaction.ts b/composables/zksync/deposit/useTransaction.ts index 1b8811878..7cd33a109 100644 --- a/composables/zksync/deposit/useTransaction.ts +++ b/composables/zksync/deposit/useTransaction.ts @@ -44,6 +44,7 @@ export default (getL1Signer: () => Promise) => { token: transaction.tokenAddress, amount: transaction.amount, l2GasLimit: fee.l2GasLimit, + approveERC20: true, overrides, }); diff --git a/composables/zksync/useTransaction.ts b/composables/zksync/useTransaction.ts index 19ca672aa..d8662c93b 100644 --- a/composables/zksync/useTransaction.ts +++ b/composables/zksync/useTransaction.ts @@ -40,7 +40,7 @@ export default (getSigner: () => Promise, getProvider: () => const getRequiredBridgeAddress = async () => { if (transaction.tokenAddress === ETH_TOKEN.address) return undefined; const bridgeAddresses = await retrieveBridgeAddresses(); - return bridgeAddresses.erc20L2; + return bridgeAddresses.sharedL2; }; const bridgeAddress = transaction.type === "withdrawal" ? await getRequiredBridgeAddress() : undefined; diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index 260ba9a40..a9dca2428 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -1,7 +1,6 @@ import { useMemoize } from "@vueuse/core"; import { BigNumber, type BigNumberish } from "ethers"; import { Wallet } from "zksync-ethers"; -import ZkSyncL1BridgeAbi from "zksync-ethers/abi/IL1Bridge.json"; import IL1SharedBridge from "zksync-ethers/abi/IL1SharedBridge.json"; import type { Hash } from "@/types"; @@ -80,8 +79,8 @@ export default (transactionInfo: ComputedRef) => { }; } else { return { - address: (await retrieveBridgeAddresses()).erc20L1 as Hash, - abi: ZkSyncL1BridgeAbi, + address: (await retrieveBridgeAddresses()).sharedL1 as Hash, + abi: IL1SharedBridge, account: onboardStore.account.address!, functionName: "finalizeWithdrawal", args: Object.values(finalizeWithdrawalParams.value!), From 0068f4584c999e500b203c9dbb76882eeb163a28 Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Wed, 5 Jun 2024 10:03:24 +0200 Subject: [PATCH 05/10] fix: approve ERC-20 with UI --- composables/zksync/deposit/useTransaction.ts | 1 - views/transactions/Deposit.vue | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composables/zksync/deposit/useTransaction.ts b/composables/zksync/deposit/useTransaction.ts index 7cd33a109..1b8811878 100644 --- a/composables/zksync/deposit/useTransaction.ts +++ b/composables/zksync/deposit/useTransaction.ts @@ -44,7 +44,6 @@ export default (getL1Signer: () => Promise) => { token: transaction.tokenAddress, amount: transaction.amount, l2GasLimit: fee.l2GasLimit, - approveERC20: true, overrides, }); diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index ccfc0151a..fd43f9cc8 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -486,7 +486,7 @@ const { } = useAllowance( computed(() => account.value.address), computed(() => selectedToken.value?.address), - async () => (await providerStore.requestProvider().getDefaultBridgeAddresses()).erc20L1 + async () => (await providerStore.requestProvider().getDefaultBridgeAddresses()).sharedL1 ); const enoughAllowance = computed(() => { if (!allowance.value || !selectedToken.value) { From 039bd1eca4ee3f91b60b03c6914abd8c6c9f4622 Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Wed, 5 Jun 2024 10:06:54 +0200 Subject: [PATCH 06/10] chore: redundant if statement removed --- .../zksync/useWithdrawalFinalization.ts | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index a9dca2428..06ea67a3f 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -44,7 +44,6 @@ export default (transactionInfo: ComputedRef) => { const feeToken = computed(() => { return tokens.value?.[ETH_TOKEN.address]; }); - const usingMainContract = computed(() => transactionInfo.value.token.address === ETH_TOKEN.address); const getFinalizationParams = async () => { const provider = providerStore.requestProvider(); @@ -69,23 +68,13 @@ export default (transactionInfo: ComputedRef) => { const getTransactionParams = async () => { finalizeWithdrawalParams.value = await getFinalizationParams(); - if (usingMainContract.value) { - return { - address: (await retrieveBridgeAddresses()).sharedL1 as Hash, - abi: IL1SharedBridge, - account: onboardStore.account.address!, - functionName: "finalizeWithdrawal", - args: Object.values(finalizeWithdrawalParams.value!), - }; - } else { - return { - address: (await retrieveBridgeAddresses()).sharedL1 as Hash, - abi: IL1SharedBridge, - account: onboardStore.account.address!, - functionName: "finalizeWithdrawal", - args: Object.values(finalizeWithdrawalParams.value!), - }; - } + return { + address: (await retrieveBridgeAddresses()).sharedL1 as Hash, + abi: IL1SharedBridge, + account: onboardStore.account.address!, + functionName: "finalizeWithdrawal", + args: Object.values(finalizeWithdrawalParams.value!), + }; }; const { From 02a2804628e9d1f486016296e70be3775cc951b8 Mon Sep 17 00:00:00 2001 From: Jack Hamer Date: Wed, 5 Jun 2024 13:19:27 +0300 Subject: [PATCH 07/10] fix: enable manual finalization by default --- views/transactions/Deposit.vue | 9 +-------- views/transactions/Transfer.vue | 3 +-- views/transactions/WithdrawalSubmitted.vue | 8 +------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index fd43f9cc8..819e3e5dd 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -130,14 +130,7 @@ I understand, proceed to bridge - + Don't show again diff --git a/views/transactions/Transfer.vue b/views/transactions/Transfer.vue index e842f7258..c402ab67f 100644 --- a/views/transactions/Transfer.vue +++ b/views/transactions/Transfer.vue @@ -491,8 +491,7 @@ const withdrawalManualFinalizationRequired = computed(() => { if (!transaction.value) return false; return ( props.type === "withdrawal" && - (isCustomNode || - isWithdrawalManualFinalizationRequired(transaction.value.token, eraNetwork.value.l1Network?.id || -1)) + isWithdrawalManualFinalizationRequired(transaction.value.token, eraNetwork.value.l1Network?.id || -1) ); }); diff --git a/views/transactions/WithdrawalSubmitted.vue b/views/transactions/WithdrawalSubmitted.vue index c3b0ccabe..07a958c83 100644 --- a/views/transactions/WithdrawalSubmitted.vue +++ b/views/transactions/WithdrawalSubmitted.vue @@ -149,9 +149,7 @@