muteRemoveliquidity.mjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Web3, { eth } from "web3";
  2. import { BigNumber } from "bignumber.js";
  3. import { Wallet, Provider } from "zksync-web3";
  4. import { ethers } from "ethers";
  5. import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" };
  6. import mutePairAbi from "./mutePairAbi.json" assert { type: "json" };
  7. const rpc = "https://zksync2-testnet.zksync.dev/";
  8. const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
  9. const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8";
  10. const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9";
  11. const provider = new Provider(rpc);
  12. const wallet = new Wallet(privateKey).connect(provider);
  13. const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
  14. const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress);
  15. const wethAddress = await muteRouter.methods.WETH().call();
  16. console.log(`wethAddress: ${wethAddress}`);
  17. const pairInfo = await muteRouter.methods.getPairInfo([wethAddress, usdcAddress], false).call();
  18. console.log(`pair: ${pairInfo.pair}`);
  19. const pair = new web3.eth.Contract(mutePairAbi, pairInfo.pair);
  20. const liquidity = await pair.methods.balanceOf(wallet.address).call();
  21. console.log(`liquidity: ${liquidity}`);
  22. const allowance = await pair.methods.allowance(wallet.address, muteRouterAddress).call();
  23. console.log(`allowance: ${allowance}`);
  24. if (allowance == 0) {
  25. const approve = pair.methods.approve(muteRouterAddress, ethers.constants.MaxUint256.toBigInt());
  26. await wallet.sendTransaction({
  27. to: pairInfo.pair,
  28. data: approve.encodeABI(),
  29. gasLimit: await approve.estimateGas({ from: wallet.address }),
  30. });
  31. }
  32. const removeLiquidity = await muteRouter.methods.removeLiquidityETHSupportingFeeOnTransferTokens(
  33. usdcAddress,
  34. ethers.BigNumber.from(liquidity).toHexString(),
  35. 1,
  36. 1,
  37. wallet.address,
  38. Math.floor(new Date().getTime() / 1000 + 60 * 30) + "",
  39. false
  40. );
  41. const gasLimit = await removeLiquidity.estimateGas({ from: wallet.address });
  42. const tx = await wallet.sendTransaction({
  43. to: muteRouterAddress,
  44. data: removeLiquidity.encodeABI(),
  45. gasLimit: gasLimit,
  46. });
  47. console.log(tx);