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(); console.log(`pair: ${pairInfo.pair}`); const pair = new web3.eth.Contract(mutePairAbi, pairInfo.pair); const liquidity = await pair.methods.balanceOf(wallet.address).call(); console.log(`liquidity: ${liquidity}`); const allowance = await pair.methods.allowance(wallet.address, muteRouterAddress).call(); console.log(`allowance: ${allowance}`); if (allowance == 0) { const approve = pair.methods.approve(muteRouterAddress, ethers.constants.MaxUint256.toBigInt()); await wallet.sendTransaction({ to: pairInfo.pair, data: approve.encodeABI(), gasLimit: await approve.estimateGas({ from: wallet.address }), }); } const removeLiquidity = await muteRouter.methods.removeLiquidityETHSupportingFeeOnTransferTokens( usdcAddress, ethers.BigNumber.from(liquidity).toHexString(), 1, 1, wallet.address, Math.floor(new Date().getTime() / 1000 + 60 * 30) + "", false ); const gasLimit = await removeLiquidity.estimateGas({ from: wallet.address }); const tx = await wallet.sendTransaction({ to: muteRouterAddress, data: removeLiquidity.encodeABI(), gasLimit: gasLimit, }); console.log(tx);