syncswap1.mjs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import Web3, { eth } from "web3";
  2. import { BigNumber } from "bignumber.js";
  3. import { Wallet, Provider } from "zksync-web3";
  4. import SyncSwapPoolAbi from "./SyncSwapClassicPoolFactory.json" assert { type: "json" };
  5. import SyncSwapRouterAbi from "./SyncSwapRouter.json" assert { type: "json" };
  6. import { ethers } from "ethers";
  7. const rpc = "https://mainnet.era.zksync.io";
  8. const walletAddress = "0x93626e5d46772652a8100a3ffc34d7bad8b29e00";
  9. const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
  10. const provider = new Provider(rpc);
  11. const wallet = new Wallet(privateKey).connect(provider);
  12. console.log("rpc: ", rpc);
  13. const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
  14. const account = web3.eth.accounts.privateKeyToAccount(privateKey);
  15. console.log("address: ", account.address);
  16. const poolFactory = new web3.eth.Contract(SyncSwapPoolAbi, "0xf2DAd89f2788a8CD54625C60b55cD3d2D0ACa7Cb");
  17. const res = await poolFactory.methods
  18. .getPool("0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91")
  19. .call();
  20. console.log("res: ", res);
  21. const router = new web3.eth.Contract(SyncSwapRouterAbi, "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295");
  22. console.log(ethers.utils.parseEther("0.01", 18).toString());
  23. const addLiquidity = router.methods.addLiquidity2(
  24. "0x80115c708E12eDd42E504c1cD52Aea96C547c05c",
  25. [
  26. [ethers.constants.AddressZero, ethers.utils.parseEther("0.001", 18).toString()],
  27. ["0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", ethers.utils.parseEther("0", 6).toString()],
  28. ],
  29. //encode abi
  30. ethers.utils.defaultAbiCoder.encode(["uint256"], [walletAddress]),
  31. 0,
  32. "0x0000000000000000000000000000000000000000",
  33. "0x"
  34. );
  35. const gasLimit = await addLiquidity.estimateGas({
  36. from: walletAddress,
  37. value: ethers.utils.parseEther("0.001", 18).toString(),
  38. });
  39. console.log("gasLimit: ", gasLimit);
  40. const tx = await wallet.sendTransaction({
  41. // from: wallet.address,
  42. to: "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295",
  43. data: router.methods.addLiquidity2(
  44. "0x80115c708E12eDd42E504c1cD52Aea96C547c05c",
  45. [
  46. [ethers.constants.AddressZero, ethers.utils.parseEther("0.01", 18).toString()],
  47. ["0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", ethers.utils.parseEther("0", 6).toString()],
  48. ],
  49. //encode abi
  50. ethers.utils.defaultAbiCoder.encode(["uint256"], [walletAddress]),
  51. 0,
  52. "0x0000000000000000000000000000000000000000",
  53. "0x"
  54. ).encodeABI(),
  55. // value: ethers.utils.parseEther("0.001", 18).toString(),
  56. gasLimit,
  57. });
  58. console.log("tx: ", tx);
  59. await tx.wait()