Skip to content

Commit

Permalink
add weth contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
MickWang committed Apr 9, 2024
1 parent 4d9cd13 commit e965cb9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 10 additions & 3 deletions data/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export type ZkSyncNetwork = {
l1Gateway?: Address;
isEthGasToken?: boolean;
getTokens?: () => Token[] | Promise<Token[]>; // If blockExplorerApi is specified, tokens will be fetched from there. Otherwise, this function will be used.
wethContract?: Address;
wethContract?: Address[];
};

export const nexusNode: ZkSyncNetwork[] = [
Expand All @@ -168,7 +168,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x83Bc7394738A7A084081aF22EEC0051908c0055c",
isEthGasToken: true,
l1Network: l1Networks.mainnet,
wethContract: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
wethContract: ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"],
},
{
id: 810180,
Expand All @@ -184,6 +184,7 @@ export const nexusNode: ZkSyncNetwork[] = [
erc20BridgeL2: "0x01c3f51294494e350AD69B999Db6B382b3B510b9",
isEthGasToken: true,
l1Network: l1Networks.linea,
wethContract: ["0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f"],
},
{
id: 810180,
Expand All @@ -200,6 +201,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0xeCD189e0f390826E137496a4e4a23ACf76c942Ab",
isEthGasToken: true,
l1Network: l1Networks.zkSync,
wethContract: ["0x5aea5775959fbc2557cc8789bc1bf90a239d9a91", "0x8Ebe4A94740515945ad826238Fc4D56c6B8b0e60"],
},
{
id: 810180,
Expand All @@ -216,7 +218,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x273D59aed2d793167c162E64b9162154B07583C0",
isEthGasToken: true,
l1Network: l1Networks.arbitrum,
wethContract: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
wethContract: ["0x82af49447d8a07e3bd95bd0d56f35241523fbab1"],
},
{
id: 810180,
Expand All @@ -233,6 +235,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0xdE1Ce751405Fe6D836349226EEdCDFFE1C3BE269",
isEthGasToken: true,
l1Network: l1Networks.mantle,
wethContract: ["0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111"],
},
{
id: 810180,
Expand All @@ -249,6 +252,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x649Dfa2c4d09D877419fA1eDC4005BfbEF7CD82D",
isEthGasToken: true,
l1Network: l1Networks.manta,
wethContract: ["0x0Dc808adcE2099A9F62AA87D9670745AbA741746"],
},
{
id: 810180,
Expand All @@ -265,6 +269,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x41FaF46Ca4Dfd912B65B66D29BdD432782BB1158",
isEthGasToken: true,
l1Network: l1Networks.blast,
wethContract: ["0x4300000000000000000000000000000000000004"],
},
{
id: 810180,
Expand All @@ -281,6 +286,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x668e8F67adB8219e1816C2E5bBEa055A78AF3026",
isEthGasToken: true,
l1Network: l1Networks.optimism,
wethContract: ["0x4200000000000000000000000000000000000006"],
},
{
id: 810180,
Expand All @@ -297,6 +303,7 @@ export const nexusNode: ZkSyncNetwork[] = [
l1Gateway: "0x4eEA93966AA5cd658225E0D43b665A5a491d2b7E",
isEthGasToken: true,
l1Network: l1Networks.base,
wethContract: ["0x4200000000000000000000000000000000000006"],
},
];

Expand Down
2 changes: 1 addition & 1 deletion store/zksync/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions zksync-web3-nova/src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(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);
}
Expand All @@ -193,8 +196,9 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(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);
Expand Down
4 changes: 2 additions & 2 deletions zksync-web3-nova/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ContractAddresses>;
Expand Down Expand Up @@ -378,7 +378,7 @@ export class Provider extends ethers.providers.JsonRpcProvider {
return contractAddresses.mainContract!;
}

async getWETHContractAddress(): Promise<Address> {
async getWETHContractAddress(): Promise<Address[]> {
let contractAddresses = this.contractAddressesMap.get(this.networkKey);
if (!contractAddresses) {
throw new Error("networkKey: " + this.networkKey + " is undefined");
Expand Down

0 comments on commit e965cb9

Please sign in to comment.