import Web3, { eth } from "web3"; import { BigNumber } from "bignumber.js"; import { Wallet, Provider } from "zksync-web3"; import SyncSwapPoolFactoryAbi from "./SyncSwapClassicPoolFactory.json" assert { type: "json" }; import SyncSwapRouterAbi from "./SyncSwapRouter.json" assert { type: "json" }; import { ethers } from "ethers"; const rpc = "https://zksync2-testnet.zksync.dev/"; const walletAddress = "0x93626e5d46772652a8100a3ffc34d7bad8b29e00"; const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e"; const poolFactoryAddress = "0xf2FD2bc2fBC12842aAb6FbB8b1159a6a83E72006"; const routerAddress = "0xB3b7fCbb8Db37bC6f572634299A58f51622A847e"; const wethAddress = "0x20b28b1e4665fff290650586ad76e977eab90c5d"; const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9"; 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(SyncSwapPoolFactoryAbi, poolFactoryAddress); const poolAddress = await poolFactory.methods.getPool(wethAddress, usdcAddress).call(); console.log("poolAddress: ", res); const router = new web3.eth.Contract(SyncSwapRouterAbi, routerAddress); console.log(ethers.utils.parseEther("0.001", 18).toString()); const addLiquidity = router.methods.addLiquidity2( poolAddress, [ [ethers.constants.AddressZero, ethers.utils.parseEther("0.01", 18).toString()], [usdcAddress, ethers.utils.parseEther("0", 6).toString()], ], //encode abi ethers.utils.defaultAbiCoder.encode(["uint256"], [walletAddress]), 0, "0x0000000000000000000000000000000000000000", "0x" ); console.log(addLiquidity.encodeABI()); const gasLimit = await addLiquidity.estimateGas({ from: walletAddress, value: ethers.utils.parseEther("0.01", 18).toString(), }); console.log("gasLimit: ", gasLimit); const tx = await wallet.sendTransaction({ // from: wallet.address, to: routerAddress, data: addLiquidity.encodeABI(), gasLimit, }); console.log("tx: ", tx);