xiongzhu hace 2 años
padre
commit
a170aa7286
Se han modificado 2 ficheros con 100 adiciones y 0 borrados
  1. 47 0
      muteAddliquidity.mjs
  2. 53 0
      muteRemoveliquidity.mjs

+ 47 - 0
muteAddliquidity.mjs

@@ -0,0 +1,47 @@
+import Web3, { eth } from "web3";
+import { BigNumber } from "bignumber.js";
+import { Wallet, Provider } from "zksync-web3";
+import { ethers } from "ethers";
+import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" };
+import mutePairAbi from "./mutePairAbi.json" assert { type: "json" };
+
+const rpc = "https://zksync2-testnet.zksync.dev/";
+const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
+const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8";
+const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9";
+
+const provider = new Provider(rpc);
+const wallet = new Wallet(privateKey).connect(provider);
+const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
+
+const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress);
+const wethAddress = await muteRouter.methods.WETH().call();
+console.log(`wethAddress: ${wethAddress}`);
+const pairInfo = await muteRouter.methods.getPairInfo([wethAddress, usdcAddress], false).call();
+
+const amountA = ethers.utils.parseEther("0.0015");
+const amountB = ethers.BigNumber.from(
+    await muteRouter.methods.quote(amountA.toBigInt(), pairInfo.reserveA, pairInfo.reserveB).call()
+);
+console.log(ethers.utils.formatUnits(amountA, 18));
+console.log(ethers.utils.formatUnits(amountA.mul("985").div(1000), 18));
+console.log(ethers.utils.formatUnits(amountB, 6));
+
+const addLiquidity = await muteRouter.methods.addLiquidityETH(
+    usdcAddress,
+    amountB.toBigInt(),
+    amountB.mul("985").div(1000).toBigInt(),
+    amountA.mul("985").div(1000).toBigInt(),
+    wallet.address,
+    Math.floor(new Date().getTime() / 1000 + 60 * 30) + "",
+    0,
+    false
+);
+const gasLimit = await addLiquidity.estimateGas({ from: wallet.address, value: amountA.toHexString() });
+const tx = await wallet.sendTransaction({
+    to: muteRouterAddress,
+    data: addLiquidity.encodeABI(),
+    value: amountA.toHexString(),
+    gasLimit: gasLimit,
+});
+console.log(tx);

+ 53 - 0
muteRemoveliquidity.mjs

@@ -0,0 +1,53 @@
+import Web3, { eth } from "web3";
+import { BigNumber } from "bignumber.js";
+import { Wallet, Provider } from "zksync-web3";
+import { ethers } from "ethers";
+import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" };
+import mutePairAbi from "./mutePairAbi.json" assert { type: "json" };
+
+const rpc = "https://zksync2-testnet.zksync.dev/";
+const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
+const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8";
+const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9";
+
+const provider = new Provider(rpc);
+const wallet = new Wallet(privateKey).connect(provider);
+const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
+
+const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress);
+const wethAddress = await muteRouter.methods.WETH().call();
+console.log(`wethAddress: ${wethAddress}`);
+const pairInfo = await muteRouter.methods.getPairInfo([wethAddress, usdcAddress], false).call();
+console.log(`pair: ${pairInfo.pair}`);
+const pair = new web3.eth.Contract(mutePairAbi, pairInfo.pair);
+const liquidity = await pair.methods.balanceOf(wallet.address).call();
+console.log(`liquidity: ${liquidity}`);
+
+const allowance = await pair.methods.allowance(wallet.address, muteRouterAddress).call();
+console.log(`allowance: ${allowance}`);
+
+if (allowance == 0) {
+    const approve = pair.methods.approve(muteRouterAddress, ethers.constants.MaxUint256.toBigInt());
+    await wallet.sendTransaction({
+        to: pairInfo.pair,
+        data: approve.encodeABI(),
+        gasLimit: await approve.estimateGas({ from: wallet.address }),
+    });
+}
+
+const removeLiquidity = await muteRouter.methods.removeLiquidityETHSupportingFeeOnTransferTokens(
+    usdcAddress,
+    ethers.BigNumber.from(liquidity).toHexString(),
+    1,
+    1,
+    wallet.address,
+    Math.floor(new Date().getTime() / 1000 + 60 * 30) + "",
+    false
+);
+const gasLimit = await removeLiquidity.estimateGas({ from: wallet.address });
+const tx = await wallet.sendTransaction({
+    to: muteRouterAddress,
+    data: removeLiquidity.encodeABI(),
+    gasLimit: gasLimit,
+});
+console.log(tx);