Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MickWang committed Apr 9, 2024
2 parents e965cb9 + 7360b5f commit bbb9ed3
Show file tree
Hide file tree
Showing 18 changed files with 1,439 additions and 186 deletions.
11 changes: 11 additions & 0 deletions components/common/input/TransactionWithdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
Insufficient balance
</template>
<template v-else-if="amountError === 'exceeds_balance' && !maxAmount">Amount exceeds balance</template>
<template v-else-if="amountError === 'exceeds_merge_limit'">
Input amount exceeds the merge limit.
</template>
<template v-else-if="amountError === 'exceeds_max_amount' || amountError === 'exceeds_balance'">
Max amount is
<button
Expand All @@ -66,6 +69,7 @@
<template v-else-if="amountError === 'exceeds_decimals'">
Max decimal length for {{ selectedToken?.symbol }} is {{ selectedToken?.decimals }}
</template>

</CommonInputErrorMessage>
<CommonButtonLabel v-else-if="inputted" as="div" variant="light" class="-mb-6 mt-1 text-right text-sm">
{{ totalAmountPrice }}
Expand Down Expand Up @@ -144,6 +148,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
mergeLimitExceeds: {
type: Boolean,
default: false
}
});

const emit = defineEmits<{
Expand Down Expand Up @@ -215,6 +223,9 @@ const setMaxAmount = () => {
};

const amountError = computed(() => {
if(props.mergeLimitExceeds) {
return 'exceeds_merge_limit'
}
if (!selectedToken.value) return;
if (tokenBalance.value && totalComputeAmount.value.gt(tokenBalance.value.amount)) {
return "exceeds_balance";
Expand Down
7 changes: 7 additions & 0 deletions components/transaction/summary/AddressEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ const props = defineProps({
type: Object as PropType<TransactionDestination>,
required: true,
},
addressLabel: {
type: String,
required: false
}
});
const { account } = storeToRefs(useOnboardStore());
const accountLabel = computed(() => {
if(props.addressLabel) {
return props.addressLabel;
}
if (props.address === account.value.address) {
return `Your ${props.destination.label} account`;
}
Expand Down
65 changes: 65 additions & 0 deletions composables/transaction/useMergeToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import MergeTokenPortal from "@/zksync-web3-nova/abi/MergeTokenPortal.json";
import { useOnboardStore } from "@/store/onboard";

import type { Hash } from "@/types";
import type { BigNumberish } from "ethers";
import type { PublicClient } from "viem";
import type { Ref } from "vue";

const nodeType = process.env.NODE_TYPE;

export type SourceTokenInfo = {
isSupported: boolean;
isLocked: boolean;
mergeToken: string;
balance: bigint;
depositLimit: bigint;
};
const NOVA_CHAIN_ID = nodeType === "nexus" ? 810180 : 810182;
const MERGE_TOKEN_PORTAL_ADDRESSES =
nodeType === "nexus" ? "0x83FD59FD58C6A5E6eA449e5400D02803875e1104" : "0x83FD59FD58C6A5E6eA449e5400D02803875e1104";
export default (tokenL2Address: Ref<string | undefined>) => {
const onboardStore = useOnboardStore();
const {
result,
inProgress,
error,
execute: getMergeTokenInfo,
reset,
} = usePromise(
async () => {
const publicClient = onboardStore.getPublicClient(NOVA_CHAIN_ID);
const info = (await publicClient!.readContract({
address: MERGE_TOKEN_PORTAL_ADDRESSES,
abi: MergeTokenPortal,
functionName: "getSourceTokenInfos",
args: [tokenL2Address.value],
})) as SourceTokenInfo;
return info;
},
{ cache: false }
);

const requestMergeTokenInfo = async () => {
if (tokenL2Address.value) {
await getMergeTokenInfo();
} else {
reset();
}
};

watch(
[tokenL2Address],
() => {
requestMergeTokenInfo();
},
{ immediate: true }
);

return {
result: computed(() => result.value),
inProgress: computed(() => inProgress.value),
error: computed(() => error.value),
requestMergeTokenInfo,
};
};
2 changes: 2 additions & 0 deletions composables/zksync/deposit/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default (getL1Signer: () => Promise<L1Signer | undefined>) => {
to: string;
tokenAddress: string;
amount: BigNumberish;
toMerge?: boolean;
},
fee: DepositFeeValues
) => {
Expand Down Expand Up @@ -48,6 +49,7 @@ export default (getL1Signer: () => Promise<L1Signer | undefined>) => {
to: transaction.to,
token: transaction.tokenAddress,
amount: transaction.amount,
toMerge: transaction.toMerge,
l2GasLimit: fee.l2GasLimit,
overrides,
});
Expand Down
3 changes: 3 additions & 0 deletions public/img/Shape.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 46 additions & 29 deletions store/zksync/ethereumBalance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getBalance } from "@wagmi/core";
import { getBalance, getPublicClient } from "@wagmi/core";

import type { Hash, TokenAmount } from "@/types";
import type { Config } from "@wagmi/core";
import type { Address } from "viem";

import { erc20Abi } from "viem";
import { l1Networks } from "@/data/networks";
import { useEthereumBalanceStore } from "@/store/ethereumBalance";
import { useNetworkStore } from "@/store/network";
Expand All @@ -17,7 +17,7 @@ export const useZkSyncEthereumBalanceStore = defineStore("zkSyncEthereumBalances
const tokensStore = useZkSyncTokensStore();
const { l1Network, selectedNetwork } = storeToRefs(useNetworkStore());
const wagmiConfig = onboardStore.wagmiConfig;
const { account } = storeToRefs(onboardStore);
const { account, network } = storeToRefs(onboardStore);
const { balance: ethereumBalance } = storeToRefs(ethereumBalancesStore);
const { l1Tokens } = storeToRefs(tokensStore);
const searchToken = useSearchtokenStore();
Expand Down Expand Up @@ -62,32 +62,49 @@ export const useZkSyncEthereumBalanceStore = defineStore("zkSyncEthereumBalances
nativeToken!.price = wmntToken?.price ?? 0;
nativeToken!.iconUrl = "/img/mantle.svg";
}
return await Promise.all([
...filterL1tokens.map(async (token) => {
const amount = await getBalance(wagmiConfig as Config, {
address: account.value.address!,
chainId: l1Network.value!.id,
token: token.address === ETH_TOKEN.l1Address ? undefined : (token.address! as Hash),
});
return {
...token,
amount: amount.value.toString(),
};
}),
...(searchTokenBalance.value ?? [])
.filter((token) => !Object.values(l1Tokens.value ?? []).find((e) => e.address === token.address))
.map(async (e) => {
const amount = await getBalance(wagmiConfig as Config, {
address: account.value.address!,
chainId: l1Network.value!.id,
token: e.address === ETH_TOKEN.l1Address ? undefined : (e.address! as Hash),
});
return {
...e,
amount: amount.value.toString(),
};
}),
]);
const publicClient = getPublicClient(wagmiConfig as Config, { chainId: l1Network.value?.id });

const ethBalance = await getBalance(wagmiConfig as Config, {
address: account.value.address!,
chainId: l1Network.value!.id,
token: undefined,
});
const erc20Tokens = filterL1tokens.filter((t) => t.address !== ETH_TOKEN.l1Address);
const filterTokenBalances =
(await publicClient?.multicall({
contracts: erc20Tokens.map((item) => ({
address: item.address as Hash,
abi: erc20Abi,
functionName: "balanceOf",
args: [account.value.address!],
})),
})) ?? [];

const searchTokens = (searchTokenBalance.value ?? []).filter(
(token) => !Object.values(l1Tokens.value ?? []).find((e) => e.address === token.address)
);
const searchTokenBalances =
(await publicClient?.multicall({
contracts: searchTokens.map((item) => ({
address: item.address as Hash,
abi: erc20Abi,
functionName: "balanceOf",
args: [account.value.address!],
})),
})) ?? [];

const ethToken = filterL1tokens.find((item) => item.address === ETH_TOKEN.l1Address);
return [
{ ...ethToken!, amount: ethBalance.value.toString() },
...filterTokenBalances.map((item, index) => ({
...erc20Tokens[index],
amount: item.result?.toString() ?? "0",
})),
...searchTokenBalances.map((item, index) => ({
...searchTokens[index],
amount: item.result?.toString() ?? "0",
})),
];
};
let isSaveToken = false,
oldBalance: TokenAmount[];
Expand Down
5 changes: 4 additions & 1 deletion store/zksync/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
return Object.fromEntries(
tokensRaw.value
.filter((e) => e.l1Address)
.map((token) => [token.l1Address!, { ...token, l1Address: undefined, address: token.l1Address! }])
.map((token) => [
token.l1Address!,
{ ...token, l1Address: undefined, address: token.l1Address!, l2Address: token.l2Address },
])
);
});

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Token = {
iconUrl?: string;
price?: TokenPrice;
networkKey?: string;
l2Address: string;
};
export type TokenAmount = Token & { amount: BigNumberish };

Expand Down
1 change: 1 addition & 0 deletions utils/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const mapApiToken = (token: Api.Response.Token): Token => {
}

return {
l2Address: token.l2Address,
l1Address: token.l1Address || undefined,
address: token.l2Address,
symbol: token.symbol || "unknown",
Expand Down
Loading

0 comments on commit bbb9ed3

Please sign in to comment.