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

feat: shared bridge support #178

Merged
merged 13 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions composables/zksync/deposit/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default (getL1Signer: () => Promise<L1Signer | undefined>) => {
token: transaction.tokenAddress,
amount: transaction.amount,
l2GasLimit: fee.l2GasLimit,
approveERC20: true,
benceharomi marked this conversation as resolved.
Show resolved Hide resolved
overrides,
});

Expand Down
2 changes: 1 addition & 1 deletion composables/zksync/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default (getSigner: () => Promise<Signer | undefined>, 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;

Expand Down
23 changes: 12 additions & 11 deletions composables/zksync/useWithdrawalFinalization.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,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 IL1SharedBridge from "zksync-ethers/abi/IL1SharedBridge.json";

import type { Hash } from "@/types";

Expand All @@ -16,13 +15,14 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
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 retrieveMainContractAddress = useMemoize(() => providerStore.requestProvider().getMainContractAddress());

const gasLimit = ref<BigNumberish | undefined>();
const gasPrice = ref<BigNumberish | undefined>();
Expand Down Expand Up @@ -58,6 +58,7 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
transactionInfo.value.transactionHash
);
return {
chainId: await retrieveChainId(),
l1BatchNumber,
l2MessageIndex,
l2TxNumberInBlock,
Expand All @@ -70,16 +71,16 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
finalizeWithdrawalParams.value = await getFinalizationParams();
if (usingMainContract.value) {
benceharomi marked this conversation as resolved.
Show resolved Hide resolved
return {
address: (await retrieveMainContractAddress()) 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,
abi: ZkSyncL1BridgeAbi,
address: (await retrieveBridgeAddresses()).sharedL1 as Hash,
abi: IL1SharedBridge,
account: onboardStore.account.address!,
functionName: "finalizeWithdrawal",
args: Object.values(finalizeWithdrawalParams.value!),
Expand Down
1 change: 1 addition & 0 deletions data/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const formatZkSyncChain = (network: ZkSyncNetwork) => {
: undefined,
};
};

const getAllChains = () => {
const chains: Chain[] = [];
const addUniqueChain = (chain: Chain) => {
Expand Down
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 2 additions & 12 deletions store/zksync/transactionStatus.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -30,14 +30,6 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
const { account } = storeToRefs(onboardStore);
const { eraNetwork } = storeToRefs(providerStore);

const failedTransaction = useStorage<TransactionInfo[]>("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",
{}
Expand Down Expand Up @@ -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") {
Expand All @@ -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) => {
Expand Down
Loading