import Web3, { eth } from "web3"; import { BigNumber } from "bignumber.js"; import { Wallet, Provider } from "zksync-web3"; import SyncSwapPoolAbi from "./SyncSwapClassicPoolFactory.json" assert { type: "json" }; import SyncSwapRouterAbi from "./SyncSwapRouter.json" assert { type: "json" }; import { ethers } from "ethers"; const rpc = "https://mainnet.era.zksync.io"; const walletAddress = "0x93626e5d46772652a8100a3ffc34d7bad8b29e00"; const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e"; const provider = new Provider(rpc); const wallet = new Wallet(privateKey).connect(provider); console.log("rpc: ", rpc); const web3 = new Web3(new Web3.providers.HttpProvider(rpc)); const account = web3.eth.accounts.privateKeyToAccount(privateKey); console.log("address: ", account.address); const poolFactory = new web3.eth.Contract(SyncSwapPoolAbi, "0xf2DAd89f2788a8CD54625C60b55cD3d2D0ACa7Cb"); const res = await poolFactory.methods .getPool("0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91") .call(); console.log("res: ", res); const router = new web3.eth.Contract(SyncSwapRouterAbi, "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295"); console.log(ethers.utils.parseEther("0.01", 18).toString()); const addLiquidity = router.methods.addLiquidity2( "0x80115c708E12eDd42E504c1cD52Aea96C547c05c", [ [ethers.constants.AddressZero, ethers.utils.parseEther("0.001", 18).toString()], ["0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", ethers.utils.parseEther("0", 6).toString()], ], //encode abi ethers.utils.defaultAbiCoder.encode(["uint256"], [walletAddress]), 0, "0x0000000000000000000000000000000000000000", "0x" ); const gasLimit = await addLiquidity.estimateGas({ from: walletAddress, value: ethers.utils.parseEther("0.001", 18).toString(), }); console.log("gasLimit: ", gasLimit); const tx = await wallet.sendTransaction({ // from: wallet.address, to: "0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295", data: router.methods.addLiquidity2( "0x80115c708E12eDd42E504c1cD52Aea96C547c05c", [ [ethers.constants.AddressZero, ethers.utils.parseEther("0.01", 18).toString()], ["0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", ethers.utils.parseEther("0", 6).toString()], ], //encode abi ethers.utils.defaultAbiCoder.encode(["uint256"], [walletAddress]), 0, "0x0000000000000000000000000000000000000000", "0x" ).encodeABI(), // value: ethers.utils.parseEther("0.001", 18).toString(), gasLimit, }); console.log("tx: ", tx); await tx.wait()