syncswap.mjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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://zksync2-testnet.zksync.dev/";
  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, "0xf2FD2bc2fBC12842aAb6FbB8b1159a6a83E72006");
  17. const res = await poolFactory.methods
  18. .getPool("0x20b28b1e4665fff290650586ad76e977eab90c5d", "0x0faF6df7054946141266420b43783387A78d82A9")
  19. .call();
  20. console.log("res: ", res);
  21. const router = new web3.eth.Contract(SyncSwapRouterAbi, "0xB3b7fCbb8Db37bC6f572634299A58f51622A847e");
  22. console.log(ethers.utils.parseEther("0.001", 18).toString())
  23. const addLiquidity = router.methods.addLiquidity2(
  24. "0xcFA3d5C02D827c0d1A48B4241700AEBF751458FA",
  25. [
  26. ["0x20b28b1e4665fff290650586ad76e977eab90c5d", ethers.utils.parseEther("0.001", 18).toString()],
  27. ["0x0faF6df7054946141266420b43783387A78d82A9", 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 gas = await addLiquidity.estimateGas({ from: walletAddress });
  36. console.log("gas: ", gas);