import Web3, { eth } from "web3"; import { BigNumber } from "bignumber.js"; import { Wallet, Provider } from "zksync-web3"; import { ethers } from "ethers"; import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" }; import mutePairAbi from "./mutePairAbi.json" assert { type: "json" }; const rpc = "https://zksync2-testnet.zksync.dev/"; const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e"; const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8"; const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9"; const provider = new Provider(rpc); const wallet = new Wallet(privateKey).connect(provider); const web3 = new Web3(new Web3.providers.HttpProvider(rpc)); const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress); const wethAddress = await muteRouter.methods.WETH().call(); console.log(`wethAddress: ${wethAddress}`); const pairInfo = await muteRouter.methods.getPairInfo([wethAddress, usdcAddress], false).call(); const amountA = ethers.utils.parseEther("0.0015"); const amountB = ethers.BigNumber.from( await muteRouter.methods.quote(amountA.toBigInt(), pairInfo.reserveA, pairInfo.reserveB).call() ); console.log(ethers.utils.formatUnits(amountA, 18)); console.log(ethers.utils.formatUnits(amountA.mul("985").div(1000), 18)); console.log(ethers.utils.formatUnits(amountB, 6)); const addLiquidity = await muteRouter.methods.addLiquidityETH( usdcAddress, amountB.toBigInt(), amountB.mul("985").div(1000).toBigInt(), amountA.mul("985").div(1000).toBigInt(), wallet.address, Math.floor(new Date().getTime() / 1000 + 60 * 30) + "", 0, false ); const gasLimit = await addLiquidity.estimateGas({ from: wallet.address, value: amountA.toHexString() }); const tx = await wallet.sendTransaction({ to: muteRouterAddress, data: addLiquidity.encodeABI(), value: amountA.toHexString(), gasLimit: gasLimit, }); console.log(tx);