muteAddliquidity.mjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. const amountA = ethers.utils.parseEther("0.0015");
  19. const amountB = ethers.BigNumber.from(
  20. await muteRouter.methods.quote(amountA.toBigInt(), pairInfo.reserveA, pairInfo.reserveB).call()
  21. );
  22. console.log(ethers.utils.formatUnits(amountA, 18));
  23. console.log(ethers.utils.formatUnits(amountA.mul("985").div(1000), 18));
  24. console.log(ethers.utils.formatUnits(amountB, 6));
  25. const addLiquidity = await muteRouter.methods.addLiquidityETH(
  26. usdcAddress,
  27. amountB.toBigInt(),
  28. amountB.mul("985").div(1000).toBigInt(),
  29. amountA.mul("985").div(1000).toBigInt(),
  30. wallet.address,
  31. Math.floor(new Date().getTime() / 1000 + 60 * 30) + "",
  32. 0,
  33. false
  34. );
  35. const gasLimit = await addLiquidity.estimateGas({ from: wallet.address, value: amountA.toHexString() });
  36. const tx = await wallet.sendTransaction({
  37. to: muteRouterAddress,
  38. data: addLiquidity.encodeABI(),
  39. value: amountA.toHexString(),
  40. gasLimit: gasLimit,
  41. });
  42. console.log(tx);