From ab5e135775372847b4e823e7928f48fbec1f6c8b Mon Sep 17 00:00:00 2001 From: haymond-ZK Date: Wed, 3 Apr 2024 14:10:30 +0800 Subject: [PATCH 01/19] fix: Adding Page Elements --- public/img/Shape.svg | 3 +++ views/transactions/Deposit.vue | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 public/img/Shape.svg diff --git a/public/img/Shape.svg b/public/img/Shape.svg new file mode 100644 index 00000000..fa79b39b --- /dev/null +++ b/public/img/Shape.svg @@ -0,0 +1,3 @@ + + + diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 1600d134..b2746787 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -14,7 +14,7 @@
- Note: Your funds will be locked for a max of 30 days during the campaign. If you are participating in the OKX Cryptopedia, kindly visit https://app.zklink.io/bridge to deposit your assets to ensure successful task verification. + Note: Your funds will be locked for a max of 30 days during the campaign. If you are participating in the OKX Cryptopedia or Nova Parade, kindly visit https://app.zklink.io/bridge to deposit your assets to ensure successful task verification and and to earn Nova Points.
+
+ + Merge + + + Not Merge + +
+ { }; const step = ref<"form" | "confirm" | "submitted">("form"); +const isMerge = ref(true); const destination = computed(() => destinations.value.nova); const availableTokens = computed(() => { if (balance.value) return balance.value; @@ -831,4 +846,12 @@ onboardStore.subscribeOnNetworkChange((newchainId) => { right: 10px; top: -30px; } +.merge{ + border-radius: 16px; + background: rgba(3, 212, 152, 0.50)!important; +} +.notMerge{ + border-radius: 16px; + background: rgba(23, 85, 244, 0.25)!important; +} \ No newline at end of file From 6016475bb080fa1e7b9f6d6892daf9f2961e2ef6 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Wed, 3 Apr 2024 18:36:46 +0800 Subject: [PATCH 02/19] update deposit for merge token --- composables/transaction/useMergeToken.ts | 65 +++ composables/zksync/deposit/useTransaction.ts | 1 + store/onboard.ts | 2 +- store/zksync/tokens.ts | 5 +- types/index.d.ts | 1 + utils/mappers.ts | 1 + views/transactions/Deposit.vue | 87 ++-- zksync-web3-nova/abi/IL1Bridge.json | 137 ++++- zksync-web3-nova/abi/IL2Bridge.json | 87 +++- zksync-web3-nova/abi/MergeTokenPortal.json | 522 +++++++++++++++++++ zksync-web3-nova/src/adapters.ts | 22 +- zksync-web3-nova/typechain/IL1Bridge.d.ts | 278 +++++++--- zksync-web3-nova/typechain/IL2Bridge.d.ts | 178 ++++--- 13 files changed, 1218 insertions(+), 168 deletions(-) create mode 100644 composables/transaction/useMergeToken.ts create mode 100644 zksync-web3-nova/abi/MergeTokenPortal.json diff --git a/composables/transaction/useMergeToken.ts b/composables/transaction/useMergeToken.ts new file mode 100644 index 00000000..f18309ed --- /dev/null +++ b/composables/transaction/useMergeToken.ts @@ -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) => { + 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, + }; +}; diff --git a/composables/zksync/deposit/useTransaction.ts b/composables/zksync/deposit/useTransaction.ts index 69131ef1..3d840f1b 100644 --- a/composables/zksync/deposit/useTransaction.ts +++ b/composables/zksync/deposit/useTransaction.ts @@ -20,6 +20,7 @@ export default (getL1Signer: () => Promise) => { to: string; tokenAddress: string; amount: BigNumberish; + toMerge?: boolean; }, fee: DepositFeeValues ) => { diff --git a/store/onboard.ts b/store/onboard.ts index a19dd601..58e27924 100644 --- a/store/onboard.ts +++ b/store/onboard.ts @@ -154,7 +154,7 @@ export const useOnboardStore = defineStore("onboard", () => { "8a0ee50d1f22f6651afcae7eb4253e52a3310b90af5daef78a8c4929a9bb99d4", // binance web3 wallet "ad2eff108bf828a39e5cb41331d95861c9cc516aede9cb6a95d75d98c206e204", // Gate.io Wallet "c7708575a2c3c9e6a8ab493d56cdcc56748f03956051d021b8cd8d697d9a3fd2", // fox wallet - "aba1f652e61fd536e8a7a5cd5e0319c9047c435ef8f7e907717361ff33bb3588", + // "aba1f652e61fd536e8a7a5cd5e0319c9047c435ef8f7e907717361ff33bb3588", // "38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662",//bitget ], // termsConditionsUrl: "https://zksync.io/terms", diff --git a/store/zksync/tokens.ts b/store/zksync/tokens.ts index c8a40135..bf5fcd89 100644 --- a/store/zksync/tokens.ts +++ b/store/zksync/tokens.ts @@ -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 }, + ]) ); }); diff --git a/types/index.d.ts b/types/index.d.ts index 21aad246..220b403e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -10,6 +10,7 @@ export type Token = { iconUrl?: string; price?: TokenPrice; networkKey?: string; + l2Address: string; }; export type TokenAmount = Token & { amount: BigNumberish }; diff --git a/utils/mappers.ts b/utils/mappers.ts index abbde89e..e634dc9d 100644 --- a/utils/mappers.ts +++ b/utils/mappers.ts @@ -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", diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index b2746787..6bd05db4 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -11,10 +11,15 @@ > Confirm transaction - -
+ +
- Note: Your funds will be locked for a max of 30 days during the campaign. If you are participating in the OKX Cryptopedia or Nova Parade, kindly visit https://app.zklink.io/bridge to deposit your assets to ensure successful task verification and and to earn Nova Points. + Note: Your funds will be locked for a max of 30 days during the campaign. + If you are participating in the OKX Cryptopedia or Nova Parade, kindly visit + https://app.zklink.io/bridge to + deposit your assets to ensure successful task verification and and to earn Nova Points.
-
- - Merge +
+ + Merge - - Not Merge + + Not Merge
- ~ {{getWaitTime(eraNetwork.l1Network?.id)[1]}} minutes + ~ {{ getWaitTime(eraNetwork.l1Network?.id)[1] }} minutes
@@ -362,6 +369,7 @@ import { storeToRefs } from "pinia"; import EthereumTransactionFooter from "@/components/transaction/EthereumTransactionFooter.vue"; import useAllowance from "@/composables/transaction/useAllowance"; +import useMergeToken from "@/composables/transaction/useMergeToken"; import useInterval from "@/composables/useInterval"; import useNetworks from "@/composables/useNetworks"; import useEcosystemBanner from "@/composables/zksync/deposit/useEcosystemBanner"; @@ -375,6 +383,7 @@ import type { BigNumberish } from "ethers"; import { useRoute, useRouter } from "#app"; import { customBridgeTokens } from "@/data/customBridgeTokens"; +import { getWaitTime } from "@/data/networks"; import { useDestinationsStore } from "@/store/destinations"; import { useNetworkStore } from "@/store/network"; import { useOnboardStore } from "@/store/onboard"; @@ -391,7 +400,6 @@ import { silentRouterChange } from "@/utils/helpers"; import { TransitionAlertScaleInOutTransition, TransitionOpacity } from "@/utils/transitions"; import DepositSubmitted from "@/views/transactions/DepositSubmitted.vue"; import { ETH_ADDRESS } from "~/zksync-web3-nova/src/utils"; -import { getWaitTime } from "@/data/networks"; const route = useRoute(); const router = useRouter(); @@ -453,7 +461,7 @@ const selectedTokenAddress = ref( ); const selectedToken = computed(() => { if (!selectedTokenAddress.value) { - if(!selectedNetwork.value.isEthGasToken && defaultToken.value?.address === ETH_ADDRESS){ + if (!selectedNetwork.value.isEthGasToken && defaultToken.value?.address === ETH_ADDRESS) { return availableTokens.value[1]; } return defaultToken.value; @@ -461,9 +469,9 @@ const selectedToken = computed(() => { const res = availableTokens.value.find((e) => e.address === selectedTokenAddress.value) || availableBalances.value.find((e) => e.address === selectedTokenAddress.value) || - defaultToken.value - - if(!selectedNetwork.value.isEthGasToken && res.address === ETH_ADDRESS) { + defaultToken.value; + + if (!selectedNetwork.value.isEthGasToken && res.address === ETH_ADDRESS) { return availableTokens.value[1]; } return res; @@ -485,6 +493,9 @@ const amountInputTokenAddress = computed({ const tokenBalance = computed(() => { return balance.value?.find((e) => e.address === selectedToken.value?.address)?.amount; }); +const { result: mergeTokenInfo, inProgress: mergeTokenInfoInProgress } = useMergeToken( + computed(() => selectedToken.value?.l2Address) +); const { result: allowance, @@ -587,11 +598,24 @@ const totalComputeAmount = computed(() => { }); const enoughBalanceForTransaction = computed(() => !amountError.value); +const mergeSupported = computed(() => { + if (!selectedToken.value || !mergeTokenInfo.value || !amount.value) return false; + // console.log('mergeTokenInfo: ', mergeTokenInfo.value) + console.log(selectedToken.value); + const amountVal = decimalToBigNumber(amount.value, selectedToken.value.decimals); + return ( + mergeTokenInfo.value?.isSupported && + !mergeTokenInfo.value?.isLocked && + amountVal.add(mergeTokenInfo.value?.balance).lte(mergeTokenInfo.value?.depositLimit) + ); +}); + const transaction = computed< | { token: TokenAmount; from: { address: string; destination: TransactionDestinfonboardStoreation }; to: { address: string; destination: TransactionDestination }; + toMerge?: boolean; } | undefined >(() => { @@ -612,6 +636,7 @@ const transaction = computed< address: toAddress, destination: destination.value, }, + toMerge: isMerge.value }; }); const transactionHasGateway = ref(); @@ -718,6 +743,7 @@ const makeTransaction = async () => { to: transaction.value!.to.address, tokenAddress: transaction.value!.token.address, amount: transaction.value!.token.amount, + toMerge: transaction.value!.toMerge }, feeValues.value! ); @@ -794,7 +820,7 @@ const fetchBalances = async (force = false) => { }; fetchBalances(); -const unsubscribeFetchBalance = onboardStore.subscribeOnAccountChange((newAddress:any) => { +const unsubscribeFetchBalance = onboardStore.subscribeOnAccountChange((newAddress: any) => { if (!newAddress) return; estimate(); fetchBalances(); @@ -806,38 +832,37 @@ onBeforeUnmount(() => { }); onboardStore.subscribeOnNetworkChange((newchainId) => { - if(!newchainId) return; + if (!newchainId) return; resetFeeImmediately(); }); - \ No newline at end of file + diff --git a/zksync-web3-nova/abi/IL1Bridge.json b/zksync-web3-nova/abi/IL1Bridge.json index f0cb5759..ac6c1c7e 100644 --- a/zksync-web3-nova/abi/IL1Bridge.json +++ b/zksync-web3-nova/abi/IL1Bridge.json @@ -1,5 +1,13 @@ { + "_format": "hh-sol-artifact-1", + "contractName": "IL1Bridge", + "sourceName": "cache/solpp-generated-contracts/bridge/interfaces/IL1Bridge.sol", "abi": [ + { + "inputs": [], + "name": "FunctionNotSupported", + "type": "error" + }, { "anonymous": false, "inputs": [ @@ -28,6 +36,12 @@ { "anonymous": false, "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + }, { "indexed": true, "internalType": "address", @@ -41,7 +55,7 @@ "type": "address" }, { - "indexed": true, + "indexed": false, "internalType": "address", "name": "l1Token", "type": "address" @@ -56,6 +70,49 @@ "name": "DepositInitiated", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bool", + "name": "toMerge", + "type": "bool" + } + ], + "name": "DepositToMergeInitiated", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -100,7 +157,7 @@ }, { "internalType": "uint256", - "name": "_l2BlockNumber", + "name": "_l2BatchNumber", "type": "uint256" }, { @@ -110,7 +167,7 @@ }, { "internalType": "uint16", - "name": "_l2TxNumberInBlock", + "name": "_l2TxNumberInBatch", "type": "uint16" }, { @@ -150,6 +207,11 @@ "internalType": "uint256", "name": "_l2TxGasPerPubdataByte", "type": "uint256" + }, + { + "internalType": "address", + "name": "_refundRecipient", + "type": "address" } ], "name": "deposit", @@ -165,9 +227,53 @@ }, { "inputs": [ + { + "internalType": "address", + "name": "_l2Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, { "internalType": "uint256", - "name": "_l2BlockNumber", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasPerPubdataByte", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_refundRecipient", + "type": "address" + } + ], + "name": "depositToMerge", + "outputs": [ + { + "internalType": "bytes32", + "name": "txHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_l2BatchNumber", "type": "uint256" }, { @@ -177,7 +283,7 @@ }, { "internalType": "uint16", - "name": "_l2TxNumberInBlock", + "name": "_l2TxNumberInBatch", "type": "uint16" }, { @@ -200,7 +306,7 @@ "inputs": [ { "internalType": "uint256", - "name": "_l2BlockNumber", + "name": "_l2BatchNumber", "type": "uint256" }, { @@ -220,6 +326,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "l2Bridge", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -239,5 +358,9 @@ "stateMutability": "view", "type": "function" } - ] + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {} } diff --git a/zksync-web3-nova/abi/IL2Bridge.json b/zksync-web3-nova/abi/IL2Bridge.json index e62a099d..f1b9d3ca 100644 --- a/zksync-web3-nova/abi/IL2Bridge.json +++ b/zksync-web3-nova/abi/IL2Bridge.json @@ -1,5 +1,13 @@ { + "_format": "hh-zksolc-artifact-1", + "contractName": "IL2Bridge", + "sourceName": "cache-zk/solpp-generated-contracts/bridge/interfaces/IL2Bridge.sol", "abi": [ + { + "inputs": [], + "name": "FunctionNotSupported", + "type": "error" + }, { "anonymous": false, "inputs": [ @@ -31,6 +39,43 @@ "name": "FinalizeDeposit", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "l1Sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l2Receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l2Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "FinalizeDepositToMerge", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -92,7 +137,40 @@ ], "name": "finalizeDeposit", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_l1Sender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l2Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "finalizeDepositToMerge", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { @@ -169,5 +247,10 @@ "stateMutability": "nonpayable", "type": "function" } - ] + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "factoryDeps": {} } diff --git a/zksync-web3-nova/abi/MergeTokenPortal.json b/zksync-web3-nova/abi/MergeTokenPortal.json new file mode 100644 index 00000000..e0d29118 --- /dev/null +++ b/zksync-web3-nova/abi/MergeTokenPortal.json @@ -0,0 +1,522 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "depositLimit", + "type": "uint256" + } + ], + "name": "DepositLimitUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "DepositToMerge", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "depositLimit", + "type": "uint256" + } + ], + "name": "SourceTokenAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isLocked", + "type": "bool" + } + ], + "name": "SourceTokenLocked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + } + ], + "name": "SourceTokenRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sourceToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "WithdrawFromMerge", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + }, + { + "internalType": "address", + "name": "_mergeToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_depositLimit", + "type": "uint256" + } + ], + "name": "addSourceToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_receiver", + "type": "address" + } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + } + ], + "name": "getSourceTokenInfos", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isSupported", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isLocked", + "type": "bool" + }, + { + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "depositLimit", + "type": "uint256" + } + ], + "internalType": "struct IMergeTokenPortal.SourceTokenInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + } + ], + "name": "removeSourceToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_limit", + "type": "uint256" + } + ], + "name": "setDepositLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sourceToken", + "type": "address" + } + ], + "name": "sourceTokenInfoMap", + "outputs": [ + { + "internalType": "bool", + "name": "isSupported", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isLocked", + "type": "bool" + }, + { + "internalType": "address", + "name": "mergeToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "depositLimit", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + }, + { + "internalType": "bool", + "name": "_isLocked", + "type": "bool" + } + ], + "name": "updateDepositStatus", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sourceToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_receiver", + "type": "address" + } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] + \ No newline at end of file diff --git a/zksync-web3-nova/src/adapters.ts b/zksync-web3-nova/src/adapters.ts index d0a001ca..9b474b9e 100644 --- a/zksync-web3-nova/src/adapters.ts +++ b/zksync-web3-nova/src/adapters.ts @@ -159,6 +159,7 @@ export function AdapterL1>(Base: TBase) { async deposit(transaction: { token: Address; amount: BigNumberish; + toMerge?: boolean; to?: Address; operatorTip?: BigNumberish; bridgeAddress?: Address; @@ -296,6 +297,7 @@ export function AdapterL1>(Base: TBase) { async getDepositTx(transaction: { token: Address; amount: BigNumberish; + toMerge?: boolean; to?: Address; operatorTip?: BigNumberish; bridgeAddress?: Address; @@ -350,18 +352,21 @@ export function AdapterL1>(Base: TBase) { ...tx, }; } else { - const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish] = [ + const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address] = [ to, token, amount, tx.l2GasLimit, tx.gasPerPubdataByte, + to, ]; overrides.value ??= baseCost.add(operatorTip); await checkBaseCost(baseCost, overrides.value); - return await bridgeContracts.erc20.populateTransaction.deposit(...args, overrides); + return tx.toMerge + ? await bridgeContracts.erc20.populateTransaction.depositToMerge(...args, overrides) + : await bridgeContracts.erc20.populateTransaction.deposit(...args, overrides); } } @@ -517,7 +522,11 @@ export function AdapterL1>(Base: TBase) { //for mantle and manta async getL1FeeForOp(calldata: string): Promise { - if (!this._providerL2().isMantleChain() && !this._providerL2().isMantaChain() && !this._providerL2().isBlastChain()) { + if ( + !this._providerL2().isMantleChain() && + !this._providerL2().isMantaChain() && + !this._providerL2().isBlastChain() + ) { return BigNumber.from(0); } const abi = [ @@ -846,7 +855,12 @@ async function insertGasPrice( overrides: ethers.PayableOverrides ) { if (!overrides.gasPrice && !overrides.maxFeePerGas) { - if (l2Provider.isArbitrumChain() || l2Provider.isMantaChain() || l2Provider.isMantleChain() || l2Provider.isBlastChain()) { + if ( + l2Provider.isArbitrumChain() || + l2Provider.isMantaChain() || + l2Provider.isMantleChain() || + l2Provider.isBlastChain() + ) { //if arbitrum console.log("arbitrum chain"); console.log("manta chain, mantle chain, arbitrum chain, only support gasPrice"); diff --git a/zksync-web3-nova/typechain/IL1Bridge.d.ts b/zksync-web3-nova/typechain/IL1Bridge.d.ts index e770ca81..5e56608f 100644 --- a/zksync-web3-nova/typechain/IL1Bridge.d.ts +++ b/zksync-web3-nova/typechain/IL1Bridge.d.ts @@ -24,9 +24,11 @@ import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; interface IL1BridgeInterface extends ethers.utils.Interface { functions: { "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; - "deposit(address,address,uint256,uint256,uint256)": FunctionFragment; + "deposit(address,address,uint256,uint256,uint256,address)": FunctionFragment; + "depositToMerge(address,address,uint256,uint256,uint256,address)": FunctionFragment; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; "isWithdrawalFinalized(uint256,uint256)": FunctionFragment; + "l2Bridge()": FunctionFragment; "l2TokenAddress(address)": FunctionFragment; }; @@ -44,7 +46,11 @@ interface IL1BridgeInterface extends ethers.utils.Interface { ): string; encodeFunctionData( functionFragment: "deposit", - values: [string, string, BigNumberish, BigNumberish, BigNumberish] + values: [string, string, BigNumberish, BigNumberish, BigNumberish, string] + ): string; + encodeFunctionData( + functionFragment: "depositToMerge", + values: [string, string, BigNumberish, BigNumberish, BigNumberish, string] ): string; encodeFunctionData( functionFragment: "finalizeWithdrawal", @@ -54,6 +60,7 @@ interface IL1BridgeInterface extends ethers.utils.Interface { functionFragment: "isWithdrawalFinalized", values: [BigNumberish, BigNumberish] ): string; + encodeFunctionData(functionFragment: "l2Bridge", values?: undefined): string; encodeFunctionData( functionFragment: "l2TokenAddress", values: [string] @@ -64,6 +71,10 @@ interface IL1BridgeInterface extends ethers.utils.Interface { data: BytesLike ): Result; decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "depositToMerge", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "finalizeWithdrawal", data: BytesLike @@ -72,6 +83,7 @@ interface IL1BridgeInterface extends ethers.utils.Interface { functionFragment: "isWithdrawalFinalized", data: BytesLike ): Result; + decodeFunctionResult(functionFragment: "l2Bridge", data: BytesLike): Result; decodeFunctionResult( functionFragment: "l2TokenAddress", data: BytesLike @@ -79,12 +91,14 @@ interface IL1BridgeInterface extends ethers.utils.Interface { events: { "ClaimedFailedDeposit(address,address,uint256)": EventFragment; - "DepositInitiated(address,address,address,uint256)": EventFragment; + "DepositInitiated(bytes32,address,address,address,uint256)": EventFragment; + "DepositToMergeInitiated(bytes32,address,address,address,uint256,bool)": EventFragment; "WithdrawalFinalized(address,address,uint256)": EventFragment; }; getEvent(nameOrSignatureOrTopic: "ClaimedFailedDeposit"): EventFragment; getEvent(nameOrSignatureOrTopic: "DepositInitiated"): EventFragment; + getEvent(nameOrSignatureOrTopic: "DepositToMergeInitiated"): EventFragment; getEvent(nameOrSignatureOrTopic: "WithdrawalFinalized"): EventFragment; } @@ -106,9 +120,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -117,9 +131,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -130,38 +144,60 @@ export class IL1Bridge extends Contract { _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256)"( + depositToMerge( _l2Receiver: string, _l1Token: string, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositToMerge(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; finalizeWithdrawal( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; isWithdrawalFinalized( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise<{ @@ -169,13 +205,21 @@ export class IL1Bridge extends Contract { }>; "isWithdrawalFinalized(uint256,uint256)"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise<{ 0: boolean; }>; + l2Bridge(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "l2Bridge()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + l2TokenAddress( _l1Token: string, overrides?: CallOverrides @@ -195,9 +239,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -206,9 +250,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -219,48 +263,74 @@ export class IL1Bridge extends Contract { _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256)"( + "deposit(address,address,uint256,uint256,uint256,address)"( _l2Receiver: string, _l1Token: string, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositToMerge( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositToMerge(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; finalizeWithdrawal( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; isWithdrawalFinalized( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; "isWithdrawalFinalized(uint256,uint256)"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + l2TokenAddress(_l1Token: string, overrides?: CallOverrides): Promise; "l2TokenAddress(address)"( @@ -273,9 +343,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: CallOverrides ): Promise; @@ -284,9 +354,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: CallOverrides ): Promise; @@ -297,48 +367,74 @@ export class IL1Bridge extends Contract { _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: CallOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: CallOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256)"( + depositToMerge( _l2Receiver: string, _l1Token: string, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: CallOverrides + ): Promise; + + "depositToMerge(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: CallOverrides ): Promise; finalizeWithdrawal( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: CallOverrides ): Promise; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: CallOverrides ): Promise; isWithdrawalFinalized( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; "isWithdrawalFinalized(uint256,uint256)"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + l2TokenAddress( _l1Token: string, overrides?: CallOverrides @@ -358,12 +454,22 @@ export class IL1Bridge extends Contract { ): EventFilter; DepositInitiated( + l2DepositTxHash: BytesLike | null, from: string | null, to: string | null, - l1Token: string | null, + l1Token: null, amount: null ): EventFilter; + DepositToMergeInitiated( + l2DepositTxHash: BytesLike | null, + from: string | null, + to: string | null, + l1Token: null, + amount: null, + toMerge: null + ): EventFilter; + WithdrawalFinalized( to: string | null, l1Token: string | null, @@ -376,9 +482,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -387,9 +493,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -400,48 +506,74 @@ export class IL1Bridge extends Contract { _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositToMerge( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256)"( + "depositToMerge(address,address,uint256,uint256,uint256,address)"( _l2Receiver: string, _l1Token: string, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; finalizeWithdrawal( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; isWithdrawalFinalized( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; "isWithdrawalFinalized(uint256,uint256)"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + l2TokenAddress( _l1Token: string, overrides?: CallOverrides @@ -458,9 +590,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -469,9 +601,9 @@ export class IL1Bridge extends Contract { _depositSender: string, _l1Token: string, _l2TxHash: BytesLike, - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; @@ -482,48 +614,74 @@ export class IL1Bridge extends Contract { _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256)"( + depositToMerge( _l2Receiver: string, _l1Token: string, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositToMerge(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, overrides?: PayableOverrides ): Promise; finalizeWithdrawal( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, - _l2TxNumberInBlock: BigNumberish, + _l2TxNumberInBatch: BigNumberish, _message: BytesLike, _merkleProof: BytesLike[], overrides?: Overrides ): Promise; isWithdrawalFinalized( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; "isWithdrawalFinalized(uint256,uint256)"( - _l2BlockNumber: BigNumberish, + _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + l2TokenAddress( _l1Token: string, overrides?: CallOverrides @@ -534,4 +692,4 @@ export class IL1Bridge extends Contract { overrides?: CallOverrides ): Promise; }; -} \ No newline at end of file +} diff --git a/zksync-web3-nova/typechain/IL2Bridge.d.ts b/zksync-web3-nova/typechain/IL2Bridge.d.ts index 7e3e33ea..6e920fcf 100644 --- a/zksync-web3-nova/typechain/IL2Bridge.d.ts +++ b/zksync-web3-nova/typechain/IL2Bridge.d.ts @@ -14,6 +14,7 @@ import { Contract, ContractTransaction, Overrides, + PayableOverrides, CallOverrides, } from "@ethersproject/contracts"; import { BytesLike } from "@ethersproject/bytes"; @@ -23,7 +24,7 @@ import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; interface IL2BridgeInterface extends ethers.utils.Interface { functions: { "finalizeDeposit(address,address,address,uint256,bytes)": FunctionFragment; - "initialize(address,bytes32,address)": FunctionFragment; + "finalizeDepositToMerge(address,address,address,uint256,bytes)": FunctionFragment; "l1Bridge()": FunctionFragment; "l1TokenAddress(address)": FunctionFragment; "l2TokenAddress(address)": FunctionFragment; @@ -35,8 +36,8 @@ interface IL2BridgeInterface extends ethers.utils.Interface { values: [string, string, string, BigNumberish, BytesLike] ): string; encodeFunctionData( - functionFragment: "initialize", - values: [string, BytesLike, string] + functionFragment: "finalizeDepositToMerge", + values: [string, string, string, BigNumberish, BytesLike] ): string; encodeFunctionData(functionFragment: "l1Bridge", values?: undefined): string; encodeFunctionData( @@ -56,7 +57,10 @@ interface IL2BridgeInterface extends ethers.utils.Interface { functionFragment: "finalizeDeposit", data: BytesLike ): Result; - decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "finalizeDepositToMerge", + data: BytesLike + ): Result; decodeFunctionResult(functionFragment: "l1Bridge", data: BytesLike): Result; decodeFunctionResult( functionFragment: "l1TokenAddress", @@ -68,7 +72,15 @@ interface IL2BridgeInterface extends ethers.utils.Interface { ): Result; decodeFunctionResult(functionFragment: "withdraw", data: BytesLike): Result; - events: {}; + events: { + "FinalizeDeposit(address,address,address,uint256)": EventFragment; + "FinalizeDepositToMerge(address,address,address,address,uint256)": EventFragment; + "WithdrawalInitiated(address,address,address,uint256)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "FinalizeDeposit"): EventFragment; + getEvent(nameOrSignatureOrTopic: "FinalizeDepositToMerge"): EventFragment; + getEvent(nameOrSignatureOrTopic: "WithdrawalInitiated"): EventFragment; } export class IL2Bridge extends Contract { @@ -91,7 +103,7 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; "finalizeDeposit(address,address,address,uint256,bytes)"( @@ -100,21 +112,25 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; - initialize( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + finalizeDepositToMerge( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; - "initialize(address,bytes32,address)"( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + "finalizeDepositToMerge(address,address,address,uint256,bytes)"( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; l1Bridge(overrides?: CallOverrides): Promise<{ @@ -174,7 +190,7 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; "finalizeDeposit(address,address,address,uint256,bytes)"( @@ -183,21 +199,25 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; - initialize( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + finalizeDepositToMerge( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; - "initialize(address,bytes32,address)"( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + "finalizeDepositToMerge(address,address,address,uint256,bytes)"( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; l1Bridge(overrides?: CallOverrides): Promise; @@ -251,17 +271,21 @@ export class IL2Bridge extends Contract { overrides?: CallOverrides ): Promise; - initialize( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, + finalizeDepositToMerge( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, overrides?: CallOverrides ): Promise; - "initialize(address,bytes32,address)"( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, + "finalizeDepositToMerge(address,address,address,uint256,bytes)"( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, overrides?: CallOverrides ): Promise; @@ -304,7 +328,29 @@ export class IL2Bridge extends Contract { ): Promise; }; - filters: {}; + filters: { + FinalizeDeposit( + l1Sender: string | null, + l2Receiver: string | null, + l2Token: string | null, + amount: null + ): EventFilter; + + FinalizeDepositToMerge( + l1Sender: string | null, + l2Receiver: string | null, + l2Token: string | null, + mergeToken: null, + amount: null + ): EventFilter; + + WithdrawalInitiated( + l2Sender: string | null, + l1Receiver: string | null, + l2Token: string | null, + amount: null + ): EventFilter; + }; estimateGas: { finalizeDeposit( @@ -313,7 +359,7 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; "finalizeDeposit(address,address,address,uint256,bytes)"( @@ -322,21 +368,25 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; - initialize( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + finalizeDepositToMerge( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; - "initialize(address,bytes32,address)"( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + "finalizeDepositToMerge(address,address,address,uint256,bytes)"( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; l1Bridge(overrides?: CallOverrides): Promise; @@ -385,7 +435,7 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; "finalizeDeposit(address,address,address,uint256,bytes)"( @@ -394,21 +444,25 @@ export class IL2Bridge extends Contract { _l1Token: string, _amount: BigNumberish, _data: BytesLike, - overrides?: Overrides + overrides?: PayableOverrides ): Promise; - initialize( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + finalizeDepositToMerge( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; - "initialize(address,bytes32,address)"( - _l1Bridge: string, - _l2TokenProxyBytecodeHash: BytesLike, - _governor: string, - overrides?: Overrides + "finalizeDepositToMerge(address,address,address,uint256,bytes)"( + _l1Sender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides ): Promise; l1Bridge(overrides?: CallOverrides): Promise; From 7adef7ebfa943d1b263e7b365b2cda10a9f0eed0 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Wed, 3 Apr 2024 22:40:23 +0800 Subject: [PATCH 03/19] add depositToMerge --- composables/zksync/deposit/useTransaction.ts | 1 + zksync-web3-nova/src/adapters.ts | 2 +- .../typechain/IL1BridgeFactory.ts | 135 ++++++++++++++++-- 3 files changed, 126 insertions(+), 12 deletions(-) diff --git a/composables/zksync/deposit/useTransaction.ts b/composables/zksync/deposit/useTransaction.ts index 3d840f1b..09b854f2 100644 --- a/composables/zksync/deposit/useTransaction.ts +++ b/composables/zksync/deposit/useTransaction.ts @@ -49,6 +49,7 @@ export default (getL1Signer: () => Promise) => { to: transaction.to, token: transaction.tokenAddress, amount: transaction.amount, + toMerge: transaction.toMerge, l2GasLimit: fee.l2GasLimit, overrides, }); diff --git a/zksync-web3-nova/src/adapters.ts b/zksync-web3-nova/src/adapters.ts index 9b474b9e..b6e7c3d3 100644 --- a/zksync-web3-nova/src/adapters.ts +++ b/zksync-web3-nova/src/adapters.ts @@ -360,7 +360,7 @@ export function AdapterL1>(Base: TBase) { tx.gasPerPubdataByte, to, ]; - + debugger; overrides.value ??= baseCost.add(operatorTip); await checkBaseCost(baseCost, overrides.value); diff --git a/zksync-web3-nova/typechain/IL1BridgeFactory.ts b/zksync-web3-nova/typechain/IL1BridgeFactory.ts index 42511866..d789df84 100644 --- a/zksync-web3-nova/typechain/IL1BridgeFactory.ts +++ b/zksync-web3-nova/typechain/IL1BridgeFactory.ts @@ -8,15 +8,17 @@ import { Provider } from "@ethersproject/providers"; import type { IL1Bridge } from "./IL1Bridge"; export class IL1BridgeFactory { - static connect( - address: string, - signerOrProvider: Signer | Provider - ): IL1Bridge { + static connect(address: string, signerOrProvider: Signer | Provider): IL1Bridge { return new Contract(address, _abi, signerOrProvider) as IL1Bridge; } } const _abi = [ + { + inputs: [], + name: "FunctionNotSupported", + type: "error", + }, { anonymous: false, inputs: [ @@ -45,6 +47,12 @@ const _abi = [ { anonymous: false, inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, { indexed: true, internalType: "address", @@ -58,7 +66,7 @@ const _abi = [ type: "address", }, { - indexed: true, + indexed: false, internalType: "address", name: "l1Token", type: "address", @@ -73,6 +81,49 @@ const _abi = [ name: "DepositInitiated", type: "event", }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "bool", + name: "toMerge", + type: "bool", + }, + ], + name: "DepositToMergeInitiated", + type: "event", + }, { anonymous: false, inputs: [ @@ -117,7 +168,7 @@ const _abi = [ }, { internalType: "uint256", - name: "_l2BlockNumber", + name: "_l2BatchNumber", type: "uint256", }, { @@ -127,7 +178,7 @@ const _abi = [ }, { internalType: "uint16", - name: "_l2TxNumberInBlock", + name: "_l2TxNumberInBatch", type: "uint16", }, { @@ -168,6 +219,11 @@ const _abi = [ name: "_l2TxGasPerPubdataByte", type: "uint256", }, + { + internalType: "address", + name: "_refundRecipient", + type: "address", + }, ], name: "deposit", outputs: [ @@ -182,9 +238,53 @@ const _abi = [ }, { inputs: [ + { + internalType: "address", + name: "_l2Receiver", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, { internalType: "uint256", - name: "_l2BlockNumber", + name: "_amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasPerPubdataByte", + type: "uint256", + }, + { + internalType: "address", + name: "_refundRecipient", + type: "address", + }, + ], + name: "depositToMerge", + outputs: [ + { + internalType: "bytes32", + name: "txHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_l2BatchNumber", type: "uint256", }, { @@ -194,7 +294,7 @@ const _abi = [ }, { internalType: "uint16", - name: "_l2TxNumberInBlock", + name: "_l2TxNumberInBatch", type: "uint16", }, { @@ -217,7 +317,7 @@ const _abi = [ inputs: [ { internalType: "uint256", - name: "_l2BlockNumber", + name: "_l2BatchNumber", type: "uint256", }, { @@ -237,6 +337,19 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [], + name: "l2Bridge", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [ { @@ -256,4 +369,4 @@ const _abi = [ stateMutability: "view", type: "function", }, -]; \ No newline at end of file +]; From 8d06c3453ede2327c49374058e8b1a879fab56c4 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 4 Apr 2024 16:46:08 +0800 Subject: [PATCH 04/19] fix: update okx tips icon --- views/transactions/Deposit.vue | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 36f3a636..a58c9206 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -1,7 +1,7 @@ + + {{ totalAmountPrice }} @@ -144,6 +148,10 @@ const props = defineProps({ type: Boolean, default: false, }, + mergeLimitExceeds: { + type: Boolean, + default: false + } }); const emit = defineEmits<{ @@ -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"; diff --git a/components/transaction/summary/AddressEntry.vue b/components/transaction/summary/AddressEntry.vue index 33c7662f..533fee9d 100644 --- a/components/transaction/summary/AddressEntry.vue +++ b/components/transaction/summary/AddressEntry.vue @@ -46,11 +46,18 @@ const props = defineProps({ type: Object as PropType, 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`; } diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 0901bc09..d04368a4 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -7,7 +7,7 @@ OKX Cryptopedia @@ -72,6 +72,7 @@ :max-amount="maxAmount" :approve-required="!enoughAllowance" :loading="tokensRequestInProgress || balanceInProgress" + :merge-limit-exceeds="mergeLimitExceeds" class="mb-block-padding-1/2 sm:mb-block-gap" > -
- - Merge - - - Not Merge - -
Receive funds
+ Checking allowance error: {{ allowanceRequestError.message }} @@ -957,4 +960,22 @@ onboardStore.subscribeOnNetworkChange((newchainId) => { border-radius: 16px; background: rgba(23, 85, 244, 0.25) !important; } +.showTip:hover{ + .tooltip{ + display: block; + } +} +.tooltip{ + display: none; + position: absolute; + padding: 12px 20px 12px 24px; + top: -4.5rem; + width: 35rem; + left: -10rem; + border-radius: 8px; + background: #1F2127; + a{ + color: #1755F4; + } +} From 738aa3aeeebada93b20ea5395c6bd06e253b966d Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Sun, 7 Apr 2024 17:24:05 +0800 Subject: [PATCH 10/19] fix:refresh balance after deposit --- views/transactions/Deposit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index d31e823e..21c92f81 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -811,7 +811,7 @@ const makeTransaction = async () => { transactionInfo.value = completedTransaction; setTimeout(() => { transfersHistoryStore.reloadRecentTransfers().catch(() => undefined); - eraWalletStore.requestBalance({ force: true }).catch(() => undefined); + fetchBalances(true).catch(() => undefined); }, 2000); }) .catch((err) => { From 41fd69f2795a7eedd3e57ef982504a937f21679f Mon Sep 17 00:00:00 2001 From: haymond-ZK Date: Sun, 7 Apr 2024 17:40:22 +0800 Subject: [PATCH 11/19] fix: change switch style --- public/img/Shape.svg | 2 +- views/transactions/Deposit.vue | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/img/Shape.svg b/public/img/Shape.svg index fa79b39b..d39ed105 100644 --- a/public/img/Shape.svg +++ b/public/img/Shape.svg @@ -1,3 +1,3 @@ - + diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 9991a1e1..702dece9 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -212,7 +212,7 @@ Receive funds -
+
Merge Token
@@ -220,7 +220,16 @@
- {{ isMerge?'Merge':'Not Merge' }} Switch + Merge + +
@@ -424,6 +433,7 @@ import { silentRouterChange } from "@/utils/helpers"; import { TransitionAlertScaleInOutTransition, TransitionOpacity } from "@/utils/transitions"; import DepositSubmitted from "@/views/transactions/DepositSubmitted.vue"; import { ETH_ADDRESS } from "~/zksync-web3-nova/src/utils"; +import { Switch } from "@headlessui/vue"; const okxIcon = "/img/okx-cryptopedia.svg"; const launchIcon = "/img/launch.svg"; From 84d5e6dabd296e8b7253c7e957297556420fec91 Mon Sep 17 00:00:00 2001 From: haymond-ZK Date: Sun, 7 Apr 2024 17:47:59 +0800 Subject: [PATCH 12/19] fix: change switch add limit --- views/transactions/Deposit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 702dece9..762a04d5 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -212,7 +212,7 @@ Receive funds -
+
Merge Token
From ed870c701c85d9b2222d80d658f424d128292031 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Sun, 7 Apr 2024 20:14:34 +0800 Subject: [PATCH 13/19] use multicall to getBalance --- store/zksync/ethereumBalance.ts | 85 +++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/store/zksync/ethereumBalance.ts b/store/zksync/ethereumBalance.ts index d1f5eef0..b8626a87 100644 --- a/store/zksync/ethereumBalance.ts +++ b/store/zksync/ethereumBalance.ts @@ -1,9 +1,9 @@ -import { getBalance } from "@wagmi/core"; +import { getBalance, multicall } 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"; @@ -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(); @@ -55,32 +55,75 @@ export const useZkSyncEthereumBalanceStore = defineStore("zkSyncEthereumBalances const filterL1tokens = Object.values(l1Tokens.value ?? []).filter( (e) => e.networkKey === selectedNetwork.value.key || e.address === ETH_TOKEN.l1Address ); - 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) => { + console.log("chain: ", l1Network.value, network.value); + if (l1Network.value?.id === network.value.chainId) { + 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 multicall(wagmiConfig as Config, { + contracts: erc20Tokens.map((item) => ({ + address: item.address as Hash, + abi: erc20Abi, + functionName: "balanceOf", + args: [account.value.address!], + })), + }); + console.log("filterTokenBalances: ", filterTokenBalances); + const searchTokens = (searchTokenBalance.value ?? []).filter( + (token) => !Object.values(l1Tokens.value ?? []).find((e) => e.address === token.address) + ); + const searchTokenBalances = await multicall(wagmiConfig as Config, { + contracts: searchTokens.map((item) => ({ + address: item.address as Hash, + abi: erc20Abi, + functionName: "balanceOf", + args: [account.value.address!], + })), + }); + console.log("searchTokenBalances: ", searchTokenBalances); + 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", + })), + ]; + } else { + return await Promise.all([ + ...filterL1tokens.map(async (token) => { 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), + token: token.address === ETH_TOKEN.l1Address ? undefined : (token.address! as Hash), }); return { - ...e, + ...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(), + }; + }), + ]); + } }; let isSaveToken = false, oldBalance: TokenAmount[]; From 57d66753325d044a5471d99334fff522832349a1 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Mon, 8 Apr 2024 10:42:53 +0800 Subject: [PATCH 14/19] update multicall for get balance --- store/zksync/ethereumBalance.ts | 91 ++++++++++++--------------------- 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/store/zksync/ethereumBalance.ts b/store/zksync/ethereumBalance.ts index b8626a87..34a8d14a 100644 --- a/store/zksync/ethereumBalance.ts +++ b/store/zksync/ethereumBalance.ts @@ -1,4 +1,4 @@ -import { getBalance, multicall } from "@wagmi/core"; +import { getBalance, getPublicClient } from "@wagmi/core"; import type { Hash, TokenAmount } from "@/types"; import type { Config } from "@wagmi/core"; @@ -55,75 +55,50 @@ export const useZkSyncEthereumBalanceStore = defineStore("zkSyncEthereumBalances const filterL1tokens = Object.values(l1Tokens.value ?? []).filter( (e) => e.networkKey === selectedNetwork.value.key || e.address === ETH_TOKEN.l1Address ); - console.log("chain: ", l1Network.value, network.value); - if (l1Network.value?.id === network.value.chainId) { - 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 multicall(wagmiConfig as Config, { + + 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!], })), - }); - console.log("filterTokenBalances: ", filterTokenBalances); - const searchTokens = (searchTokenBalance.value ?? []).filter( - (token) => !Object.values(l1Tokens.value ?? []).find((e) => e.address === token.address) - ); - const searchTokenBalances = await multicall(wagmiConfig as Config, { + })) ?? []; + + 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!], })), - }); - console.log("searchTokenBalances: ", searchTokenBalances); - 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", - })), - ]; - } else { - 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 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[]; From 9420db82618375775cd69b965838a85c30ff66b6 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 14:11:09 +0800 Subject: [PATCH 15/19] fix error when check l2 txhash --- store/zksync/wallet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/zksync/wallet.ts b/store/zksync/wallet.ts index 1258766f..1516c96c 100644 --- a/store/zksync/wallet.ts +++ b/store/zksync/wallet.ts @@ -69,7 +69,7 @@ export const useZkSyncWalletStore = defineStore("zkSyncWallet", () => { const getPrimaryL1VoidSigner = () => { const web3Provider = new ethers.providers.Web3Provider( - getPublicClient({ chainId: primaryNetwork.l1Network?.id }) as any, + onboardStore.getPublicClient(primaryNetwork.l1Network?.id) as any, "any" ); const voidSigner = new VoidSigner(account.value.address || ETH_TOKEN.address, web3Provider); From 24cecf9795ebc61bd70fb604bdbea57212ba5c65 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 17:38:24 +0800 Subject: [PATCH 16/19] update ui for merge token --- views/transactions/Deposit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index e183ca35..f4bcc605 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -227,7 +227,7 @@ > From 2f322f52092138c1e8896df991111bc302cd8216 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 17:48:53 +0800 Subject: [PATCH 17/19] update text --- views/transactions/Deposit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index f4bcc605..99c83644 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -216,7 +216,7 @@ Merge Token
- All supported source tokens with the same entity from different networks can be merged into a single merged token. Learn More. + All supported source tokens with the same entity from different networks can be merged into a single merged token. Holding or using merged token to engage with supported dApps could receive higher multipliers. Learn More.
From aa5b7817fe247dfa6843d70624265c75f738cedb Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 17:52:38 +0800 Subject: [PATCH 18/19] update text --- store/zksync/wallet.ts | 2 +- views/transactions/Deposit.vue | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/store/zksync/wallet.ts b/store/zksync/wallet.ts index 1258766f..1516c96c 100644 --- a/store/zksync/wallet.ts +++ b/store/zksync/wallet.ts @@ -69,7 +69,7 @@ export const useZkSyncWalletStore = defineStore("zkSyncWallet", () => { const getPrimaryL1VoidSigner = () => { const web3Provider = new ethers.providers.Web3Provider( - getPublicClient({ chainId: primaryNetwork.l1Network?.id }) as any, + onboardStore.getPublicClient(primaryNetwork.l1Network?.id) as any, "any" ); const voidSigner = new VoidSigner(account.value.address || ETH_TOKEN.address, web3Provider); diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index 99c83644..fcf13187 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -973,6 +973,7 @@ onboardStore.subscribeOnNetworkChange((newchainId) => { .showTip:hover{ .tooltip{ display: block; + z-index: 100; } } .tooltip{ From 58097d5e38b171567b90f5143f8f29b498e05c29 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 20:20:50 +0800 Subject: [PATCH 19/19] add exception catch for amount exceeds decimals --- views/transactions/Deposit.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/views/transactions/Deposit.vue b/views/transactions/Deposit.vue index fcf13187..1805c642 100644 --- a/views/transactions/Deposit.vue +++ b/views/transactions/Deposit.vue @@ -640,10 +640,14 @@ const mergeSupported = computed(() => { const mergeLimitExceeds = computed(() => { if (!selectedToken.value || !mergeTokenInfo.value || !amount.value) return false; - const amountVal = decimalToBigNumber(amount.value, selectedToken.value.decimals); - const exceeds = amountVal.add(mergeTokenInfo.value?.balance).gt(mergeTokenInfo.value?.depositLimit); - console.log("exceeds: ", exceeds); - return mergeSupported.value && isMerge.value && exceeds; + try { + const amountVal = decimalToBigNumber(amount.value, selectedToken.value.decimals); + const exceeds = amountVal.add(mergeTokenInfo.value?.balance).gt(mergeTokenInfo.value?.depositLimit); + console.log("exceeds: ", exceeds); + return mergeSupported.value && isMerge.value && exceeds; + } catch (e) { // may throw exception when amount exceeds decimals + return false; +} }); const transaction = computed<