From e965cb93ac8e6ade98a728aa19d46582c4dab6c5 Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 9 Apr 2024 14:04:56 +0800 Subject: [PATCH] add weth contracts --- data/networks.ts | 13 ++++++++++--- store/zksync/wallet.ts | 2 +- zksync-web3-nova/src/adapters.ts | 14 +++++++++----- zksync-web3-nova/src/provider.ts | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/data/networks.ts b/data/networks.ts index e993f666..f0301971 100644 --- a/data/networks.ts +++ b/data/networks.ts @@ -149,7 +149,7 @@ export type ZkSyncNetwork = { l1Gateway?: Address; isEthGasToken?: boolean; getTokens?: () => Token[] | Promise; // If blockExplorerApi is specified, tokens will be fetched from there. Otherwise, this function will be used. - wethContract?: Address; + wethContract?: Address[]; }; export const nexusNode: ZkSyncNetwork[] = [ @@ -168,7 +168,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x83Bc7394738A7A084081aF22EEC0051908c0055c", isEthGasToken: true, l1Network: l1Networks.mainnet, - wethContract: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + wethContract: ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"], }, { id: 810180, @@ -184,6 +184,7 @@ export const nexusNode: ZkSyncNetwork[] = [ erc20BridgeL2: "0x01c3f51294494e350AD69B999Db6B382b3B510b9", isEthGasToken: true, l1Network: l1Networks.linea, + wethContract: ["0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f"], }, { id: 810180, @@ -200,6 +201,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0xeCD189e0f390826E137496a4e4a23ACf76c942Ab", isEthGasToken: true, l1Network: l1Networks.zkSync, + wethContract: ["0x5aea5775959fbc2557cc8789bc1bf90a239d9a91", "0x8Ebe4A94740515945ad826238Fc4D56c6B8b0e60"], }, { id: 810180, @@ -216,7 +218,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x273D59aed2d793167c162E64b9162154B07583C0", isEthGasToken: true, l1Network: l1Networks.arbitrum, - wethContract: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", + wethContract: ["0x82af49447d8a07e3bd95bd0d56f35241523fbab1"], }, { id: 810180, @@ -233,6 +235,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0xdE1Ce751405Fe6D836349226EEdCDFFE1C3BE269", isEthGasToken: true, l1Network: l1Networks.mantle, + wethContract: ["0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111"], }, { id: 810180, @@ -249,6 +252,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x649Dfa2c4d09D877419fA1eDC4005BfbEF7CD82D", isEthGasToken: true, l1Network: l1Networks.manta, + wethContract: ["0x0Dc808adcE2099A9F62AA87D9670745AbA741746"], }, { id: 810180, @@ -265,6 +269,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x41FaF46Ca4Dfd912B65B66D29BdD432782BB1158", isEthGasToken: true, l1Network: l1Networks.blast, + wethContract: ["0x4300000000000000000000000000000000000004"], }, { id: 810180, @@ -281,6 +286,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x668e8F67adB8219e1816C2E5bBEa055A78AF3026", isEthGasToken: true, l1Network: l1Networks.optimism, + wethContract: ["0x4200000000000000000000000000000000000006"], }, { id: 810180, @@ -297,6 +303,7 @@ export const nexusNode: ZkSyncNetwork[] = [ l1Gateway: "0x4eEA93966AA5cd658225E0D43b665A5a491d2b7E", isEthGasToken: true, l1Network: l1Networks.base, + wethContract: ["0x4200000000000000000000000000000000000006"], }, ]; 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/zksync-web3-nova/src/adapters.ts b/zksync-web3-nova/src/adapters.ts index 3870331a..842e68b2 100644 --- a/zksync-web3-nova/src/adapters.ts +++ b/zksync-web3-nova/src/adapters.ts @@ -166,9 +166,12 @@ export function AdapterL1>(Base: TBase) { console.log("approve mnt res: ", res); } - async unwrapWETH(amount: BigNumberish) { - const weth = await this._providerL2().getWETHContractAddress(); - const wethContract = new ethers.Contract(weth, WethAbi, this._signerL1()); + async unwrapWETH(token: Address, amount: BigNumberish) { + const weths = await this._providerL2().getWETHContractAddress(); + if (!weths.map((item) => item.toLowerCase().includes(token.toLowerCase()))) { + return; + } + const wethContract = new ethers.Contract(token, WethAbi, this._signerL1()); const { hash } = await wethContract.withdraw(amount); await this._providerL1().waitForTransaction(hash); } @@ -193,8 +196,9 @@ export function AdapterL1>(Base: TBase) { transaction.token = WMNT_CONTRACT; transaction.approveERC20 = true; } - if (isSameAddress(transaction.token, await this._providerL2().getWETHContractAddress())) { - await this.unwrapWETH(transaction.amount); + const weths = await this._providerL2().getWETHContractAddress(); + if (weths.map((item) => item.toLowerCase()).includes(transaction.token.toLowerCase())) { + await this.unwrapWETH(transaction.token, transaction.amount); transaction.token = ETH_ADDRESS; } const depositTx = await this.getDepositTx(transaction); diff --git a/zksync-web3-nova/src/provider.ts b/zksync-web3-nova/src/provider.ts index 82805de1..a9c2f614 100644 --- a/zksync-web3-nova/src/provider.ts +++ b/zksync-web3-nova/src/provider.ts @@ -43,7 +43,7 @@ export type ContractAddresses = { erc20BridgeL1?: Address; erc20BridgeL2?: Address; l1Gateway?: Address; - wethContract?: Address; + wethContract?: Address[]; }; export class Provider extends ethers.providers.JsonRpcProvider { protected contractAddressesMap: Map; @@ -378,7 +378,7 @@ export class Provider extends ethers.providers.JsonRpcProvider { return contractAddresses.mainContract!; } - async getWETHContractAddress(): Promise
{ + async getWETHContractAddress(): Promise { let contractAddresses = this.contractAddressesMap.get(this.networkKey); if (!contractAddresses) { throw new Error("networkKey: " + this.networkKey + " is undefined");