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/withdraw claimable status #192

Merged
merged 25 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4b6bec0
remove wallet loading
MickWang Apr 20, 2024
bc5829a
Merge pull request #153 from zkLinkProtocol/feat/remove_wallet_loading
leochw Apr 20, 2024
6a6a375
Merge pull request #158 from zkLinkProtocol/feat/failed_deposit_history
leochw Apr 22, 2024
63f4330
Merge branch 'main' into feat/merge_main_dev
MickWang Apr 22, 2024
2e32558
Merge branch 'dev' into feat/merge_main_dev
MickWang Apr 22, 2024
f8a23c7
Merge pull request #162 from zkLinkProtocol/feat/merge_main_dev
haymond-ZK Apr 22, 2024
06e4a79
Merge branch 'main' into feat/withdraw_claimable_status
MickWang Apr 22, 2024
c32ea58
update claimable status for withdrawal
MickWang Apr 22, 2024
a7e4cd6
update for withdrawal cliamable and claimed status
MickWang Apr 23, 2024
fc6d845
update withdrawal history chain name issue
MickWang Apr 23, 2024
0615ff9
fix estimate fee for claim
MickWang Apr 23, 2024
93db654
fix estimate fee issue for claim
MickWang Apr 23, 2024
d5962a6
check claimable status for tx in storage
MickWang Apr 23, 2024
242137c
display claimed withdrawal tx in completed transfers
MickWang Apr 23, 2024
f3b8bcc
add delay limit for check claimable status
MickWang Apr 23, 2024
e270c7b
add zklink contract eth balance check for claimable status
MickWang Apr 24, 2024
6981f82
fix estimate fee for claim withdrawal
MickWang Apr 24, 2024
60d1189
add wait receipt for withdraw tx
MickWang Apr 24, 2024
0a96560
fix publicent error
MickWang Apr 24, 2024
80139f9
update merge token portal contract
MickWang Apr 24, 2024
eb408f6
remove wallet connect loading
MickWang Apr 25, 2024
e778159
update withdrawal tx for local storage missing
MickWang Apr 25, 2024
45dd3d4
add reload merge token info
MickWang Apr 25, 2024
6949287
fix conflicts
MickWang Apr 25, 2024
a204d74
update conmment
MickWang Apr 25, 2024
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
2 changes: 1 addition & 1 deletion components/loaders/Connecting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</template>

<script lang="ts" setup>
import { computed } from "vue";
import { computed, onMounted } from "vue";

import { storeToRefs } from "pinia";

Expand Down
12 changes: 6 additions & 6 deletions components/transaction/TransferWithdrawalLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ const props = defineProps({
},
});

const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();
const { account } = storeToRefs(useOnboardStore());
const eraNetwork = getNetworkInfo(props.transfer);
const label = computed(() => {
if(props.transfer.status === 'failed') {
return 'Failed Deposit'
if (props.transfer.status === "failed") {
return "Failed Deposit";
}
const article = 'Withdraw';
const article = "Withdraw";
if (props.transfer.to === account.value.address) {
return article;
}
Expand Down Expand Up @@ -139,8 +139,8 @@ const getl1NetworkName = () => {
};
} else {
return {
from: primaryNetwork.l1Network?.name,
to: primaryNetwork.l1Network?.name,
from: eraNetwork.l1Network?.name,
to: eraNetwork.l1Network?.name,
};
}
}
Expand Down
10 changes: 5 additions & 5 deletions components/transaction/WithdrawalsAvailableForClaimAlert.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<CommonHeightTransition :opened="!!withdrawalsAvailableForClaiming.length">
<CommonAlert variant="warning" :icon="ExclamationTriangleIcon" class="mb-block-gap">
<p>You have withdrawals available for claiming on {{ newNetwork?.l1Network?.name }} network</p>
<p class="mr-4">You have withdrawals available for claiming on {{ newNetwork?.l1Network?.name }} network</p>
<CommonButton as="RouterLink" :to="{ name: 'transfers' }" variant="primary">
<span class="whitespace-nowrap">See withdrawals</span>
</CommonButton>
Expand All @@ -19,10 +19,10 @@ import useNetworks from "@/composables/useNetworks";

const { eraNetwork } = storeToRefs(useZkSyncProviderStore());
const { withdrawalsAvailableForClaiming } = storeToRefs(useZkSyncWithdrawalsStore());
const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();
const newNetwork = computed(() => {
if (withdrawalsAvailableForClaiming.value.length> 0) {
return getNetworkInfo(withdrawalsAvailableForClaiming.value[0])
if (withdrawalsAvailableForClaiming.value.length > 0) {
return getNetworkInfo(withdrawalsAvailableForClaiming.value[0]);
}
})
});
</script>
4 changes: 3 additions & 1 deletion composables/transaction/useMergeToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export type SourceTokenInfo = {
};
const NOVA_CHAIN_ID = nodeType === "nexus" ? 810180 : 810181;
const MERGE_TOKEN_PORTAL_ADDRESSES =
nodeType === "nexus" ? "0x83FD59FD58C6A5E6eA449e5400D02803875e1104" : "0x83FD59FD58C6A5E6eA449e5400D02803875e1104";
nodeType === "nexus" ? "0x83FD59FD58C6A5E6eA449e5400D02803875e1104" : "0x400993142059ddF34636c58Bb066aAD2d21ec273";
export default (tokenL2Address: Ref<string | undefined>) => {
const onboardStore = useOnboardStore();
const {
result,
inProgress,
error,
execute: getMergeTokenInfo,
reload: reloadMergeTokenInfo,
reset,
} = usePromise(
async () => {
Expand Down Expand Up @@ -59,5 +60,6 @@ export default (tokenL2Address: Ref<string | undefined>) => {
inProgress: computed(() => inProgress.value),
error: computed(() => error.value),
requestMergeTokenInfo,
reloadMergeTokenInfo
};
};
12 changes: 12 additions & 0 deletions composables/zksync/useTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useMemoize } from "@vueuse/core";
import { type BigNumberish } from "ethers";

Expand All @@ -6,8 +7,11 @@ import useScreening from "@/composables/useScreening";
import type { TokenAmount } from "@/types";
import type { Provider, Signer } from "@/zksync-web3-nova/src";

import { useOnboardStore } from "@/store/onboard";
import { useZkSyncWalletStore } from "@/store/zksync/wallet";
import { formatError } from "@/utils/formatters";
import { sleep } from "@/utils/helpers";
import { NOVA_CHAIN_ID } from "@/utils/constants";

type TransactionParams = {
type: "transfer" | "withdrawal";
Expand All @@ -29,6 +33,8 @@ export default (getSigner: () => Promise<Signer | undefined>, getProvider: () =>
const error = ref<Error | undefined>();
const transactionHash = ref<string | undefined>();
const eraWalletStore = useZkSyncWalletStore();
const onboardStore = useOnboardStore();
const publicClient = onboardStore.getPublicClient(NOVA_CHAIN_ID);

const retrieveBridgeAddresses = useMemoize(() => getProvider().getDefaultBridgeAddresses());
const { validateAddress } = useScreening();
Expand Down Expand Up @@ -68,6 +74,12 @@ export default (getSigner: () => Promise<Signer | undefined>, getProvider: () =>
});

transactionHash.value = tx.hash;
await sleep(1500);
try {
await publicClient?.getTransactionReceipt({ hash: tx.hash as `0x${string}` });
} catch (e) {
error.value = formatError(e as Error);
}
status.value = "done";

return tx;
Expand Down
6 changes: 4 additions & 2 deletions composables/zksync/useWithdrawalFinalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
const tokensStore = useZkSyncTokensStore();
const { network } = storeToRefs(onboardStore);
const { tokens } = storeToRefs(tokensStore);
const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();

const { selectedNetwork } = storeToRefs(useNetworkStore());
let provider: Provider | undefined;
Expand Down Expand Up @@ -119,10 +119,12 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
inProgress: estimationInProgress,
error: estimationError,
execute: estimateFee,
reload: reloadEstimateFee,
} = usePromise(
async () => {
const eraNetwork = getNetworkInfo(transactionInfo.value) || selectedNetwork.value;
tokensStore.requestTokens();
const publicClient = onboardStore.getPublicClient();
const publicClient = onboardStore.getPublicClient(eraNetwork.l1Network?.id);
if (!publicClient) return;
const transactionParams = await getTransactionParams();
const [price, limit] = await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<LoadersConnecting />
<!-- <LoadersConnecting /> -->
<ModalConnectingWalletError />
<!-- <ModalNetworkChangedWarning v-if="!isConnectingWallet" /> -->
<ModalLegalNotice />
Expand Down
5 changes: 2 additions & 3 deletions pages/transfers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
Loading transfers error: {{ recentTransfersRequestError.message }}
</CommonErrorBlock>
</CommonCardWithLineButtons>
<div v-else-if="displayedTransfers.length">
<div v-else-if="displayedTransfers.length" class="mt-6">
<CommonCardWithLineButtons>
<TransactionTransferLineItem v-for="(item, index) in displayedTransfers" :key="index" :transfer="item" />
</CommonCardWithLineButtons>
Expand Down Expand Up @@ -135,8 +135,7 @@ type RecentBridgeOperation = Transfer & {
const recentBridgeOperations = computed<RecentBridgeOperation[]>(() => {
const recent = userTransactions.value.filter(
(tx) =>
(tx.type === "withdrawal" &&
(!tx.info.completed || new Date(tx.timestamp).getTime() + WITHDRAWAL_DELAY * 2 > new Date().getTime())) ||
(tx.type === "withdrawal" && !tx.info.completed) ||
(tx.type === "deposit" &&
new Date(tx.timestamp).getTime() + getWaitTime(eraNetwork.value.l1Network?.id)[0] > new Date().getTime())
);
Expand Down
28 changes: 20 additions & 8 deletions store/zksync/transactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import ZkSyncContractInterface from "@/zksync-web3-nova/abi/IZkSync.json";

import type { FeeEstimationParams } from "@/composables/zksync/useFee";
import type { TransactionDestination } from "@/store/destinations";

import { useZkSyncWithdrawalsStore } from "@/store/zksync/withdrawals";

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

Expand Down Expand Up @@ -44,6 +47,9 @@ export const getEstmatdDepositDelay = (networkKey: string): number => {
return ESTIMATED_DEPOSIT_DELAY_SECONDARY;
}
};

export const WITHDRAWAL_CHECK_DELAY_DAYS = process.env.NODE_TYPE === "nexus-sepolia" ? 0.5 : 7;

export const WITHDRAWAL_DELAY = 7 * 24 * 60 * 60 * 1000; // 7 * 24 hours
export type Address = Hash;
export type ForwardL2Request = {
Expand All @@ -64,7 +70,7 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
const onboardStore = useOnboardStore();
const { account } = storeToRefs(onboardStore);
const eraWalletStore = useZkSyncWalletStore();

const zkSyncWithdrawalsStore = useZkSyncWithdrawalsStore();
const storageSavedTransactions = useStorage<{ [networkKey: string]: TransactionInfo[] }>(
"zksync-bridge-transactions",
{}
Expand Down Expand Up @@ -183,7 +189,7 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
transaction.info.completed = true;
return transaction;
};
const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();
const { selectedNetwork } = storeToRefs(useNetworkStore());
let provider: Provider | undefined;
const request = (transaction: any) => {
Expand All @@ -205,15 +211,21 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
};
const getWithdrawalStatus = async (transaction: TransactionInfo) => {
if (!transaction.info.withdrawalFinalizationAvailable) {
const transactionDetails = await request(transaction).getTransactionDetails(transaction.transactionHash);
if (transactionDetails.status !== "verified") {
const claimable = await zkSyncWithdrawalsStore.checkWithdrawalFinalizeAvailable(transaction);
if (!claimable) {
return transaction;
}
// const transactionDetails = await request(transaction).getTransactionDetails(transaction.transactionHash);
// if (transactionDetails.status !== "verified") {
// return transaction;
// }
}
const isFinalized = await useZkSyncWalletStore()
.getL1VoidSigner(true)
?.isWithdrawalFinalized(transaction.transactionHash)
.catch(() => false);

// const isFinalized = await useZkSyncWalletStore()
// .getL1VoidSigner(true)
// ?.isWithdrawalFinalized(transaction.transactionHash)
// .catch(() => false);
const isFinalized = await zkSyncWithdrawalsStore.setStatus(transaction);
transaction.info.withdrawalFinalizationAvailable = true;
transaction.info.completed = isFinalized;
return transaction;
Expand Down
49 changes: 48 additions & 1 deletion store/zksync/transfersHistory.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import useNetworks from "@/composables/useNetworks";
import usePaginatedRequest from "@/composables/zksync/usePaginatedRequest";

import type { Api } from "@/types";
import type { Transfer } from "@/utils/mappers";

import { useDestinationsStore } from "@/store/destinations";
import { useOnboardStore } from "@/store/onboard";
import { useZkSyncProviderStore } from "@/store/zksync/provider";
import { mapApiTransfer } from "@/utils/mappers";
import {
useZkSyncTransactionStatusStore,
WITHDRAWAL_CHECK_DELAY_DAYS,
WITHDRAWAL_DELAY,
} from "@/store/zksync/transactionStatus";
import { useZkSyncWithdrawalsStore } from "@/store/zksync/withdrawals";
import { mapApiTransfer } from "@/utils/mappers";

const TRANSACTIONS_FETCH_LIMIT = 50;

export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistory", () => {
const onboardStore = useOnboardStore();
const { eraNetwork } = storeToRefs(useZkSyncProviderStore());
const { account } = storeToRefs(onboardStore);
const transactionStatusStore = useZkSyncTransactionStatusStore();
const { userTransactions } = storeToRefs(transactionStatusStore);
const { destinations } = storeToRefs(useDestinationsStore());
const { getNetworkInfo } = useNetworks();

const filterOutDuplicateTransfers = (transfers: Transfer[]) => {
/*
Expand Down Expand Up @@ -81,6 +92,42 @@ export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistor
const mappedTransfers = response.items.map(mapApiTransfer);
useZkSyncWithdrawalsStore().updateWithdrawals();
transfers.value = filterOutDuplicateTransfers(mappedTransfers);
//TODO put withdrawals into local storage
for (const withdrawal of transfers.value.filter((e) => e.type === "withdrawal")) {
if (!userTransactions.value.find((e) => e.transactionHash === withdrawal.transactionHash)) {
const eraNetworks = getNetworkInfo(withdrawal);
const obj = {
iconUrl: eraNetworks.logoUrl,
key: "nova",
label: eraNetworks?.l1Network?.name,
};
transactionStatusStore.saveTransaction({
type: "withdrawal",
transactionHash: withdrawal.transactionHash!,
timestamp: withdrawal.timestamp,
token: {
...withdrawal.token!,
amount: withdrawal.amount!,
},
from: {
address: withdrawal.from,
destination: destinations.value.nova,
},
to: {
address: withdrawal.to,
destination: obj,
},
info: {
expectedCompleteTimestamp: new Date(
new Date(withdrawal.timestamp).getTime() + WITHDRAWAL_DELAY
).toISOString(),
completed: false, // will check internally
withdrawalFinalizationAvailable: false, // will check internally
},
gateway: withdrawal.gateway,
});
}
}
},
{ cache: 30000 }
);
Expand Down
Loading
Loading