瀏覽代碼

Merge remote-tracking branch 'origin/master'

million 1 年之前
父節點
當前提交
cbb601758c

+ 15 - 2
js-runtime/src/app.js

@@ -5,13 +5,26 @@ import muteSwapEthForUsdc from "./script/zksync2/mute/swap.js";
 import muteSwapUsdcForEth from "./script/zksync2/mute/swapUsdcForEth.js"
 import syncSwapEthForUsdc from "./script/zksync2/sync/swapEthForUsdc.js";
 import syncSwapUsdcForEth from "./script/zksync2/sync/swapUsdcForEth.js"
+import tiktokfiMint from "./script/zksync2/tiktokfi/mint.js";
 
 const app = express();
+
 app.use(bodyParser.json());
+
+const endMiddleware = (req, res, next) => {
+    console.log(`request url: ${req.url}`);
+    console.log(`request params: ${JSON.stringify(req.body.params)}`);
+    console.log(`request address: ${JSON.stringify(req.body.wallet.address)}`);
+    next();
+};
+
+app.use(endMiddleware)
 app.use("/zk-mute-swap-eth-usdc", muteSwapEthForUsdc)
-app.use("/zk-mute-swap-usdc-eth",muteSwapUsdcForEth)
+app.use("/zk-mute-swap-usdc-eth", muteSwapUsdcForEth)
 app.use("/zk-sync-swap-eth-usdc", syncSwapEthForUsdc)
-app.use("/zk-sync-swap-usdc-eth",syncSwapUsdcForEth)
+app.use("/zk-sync-swap-usdc-eth", syncSwapUsdcForEth)
+app.use("/zk-sync-tiktokfi-mint", tiktokfiMint)
+
 
 app.use((err, req, res, next) => {
     // 处理错误逻辑

+ 1 - 1
js-runtime/src/script/zksync2/mute/swapUsdcForEth.js

@@ -14,7 +14,7 @@ async function sendSwapTx(amountNumber, router, signer, provider, wallet, approv
     let timestamp = new Date().getTime();
     timestamp = (timestamp / 1000 + 20 * 60).toFixed(0);
     const amountsOut = await router.getAmountsOut(amountIn, path, stable);
-    const amountOut = (amountsOut[1].toNumber() * 995 / 1000).toFixed(0);
+    const amountOut = (amountsOut[1].mul(995).div(1000));
     const swapTx = await router.swapExactTokensForETHSupportingFeeOnTransferTokens(amountIn, amountOut, path, signer.address, timestamp, stable)
     await swapTx.wait();
     const swapReceipt = await provider.getTransactionReceipt(swapTx.hash);

+ 73 - 0
js-runtime/src/script/zksync2/tiktokfi/mint.js

@@ -0,0 +1,73 @@
+import express from "express";
+import {ethers, utils, Wallet} from "ethers"
+
+const router = express.Router();
+
+// 0x84bb1e42
+// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe
+// 0000000000000000000000000000000000000000000000000000000000000001
+// 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+// 00000000000000000000000000000000000000000000000000038d7ea4c68000
+// 00000000000000000000000000000000000000000000000000000000000000c0
+// 0000000000000000000000000000000000000000000000000000000000000180
+// 0000000000000000000000000000000000000000000000000000000000000080
+// 0000000000000000000000000000000000000000000000000000000000000003
+// 00000000000000000000000000000000000000000000000000038d7ea4c68000
+// 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+// 0000000000000000000000000000000000000000000000000000000000000001
+// 0000000000000000000000000000000000000000000000000000000000000000
+// 0000000000000000000000000000000000000000000000000000000000000000
+router.post("/", async (req, res) => {
+    let input = `0x84bb1e42
+    {address}
+    0000000000000000000000000000000000000000000000000000000000000001
+    000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+    00000000000000000000000000000000000000000000000000038d7ea4c68000
+    00000000000000000000000000000000000000000000000000000000000000c0
+    0000000000000000000000000000000000000000000000000000000000000180
+    0000000000000000000000000000000000000000000000000000000000000080
+    0000000000000000000000000000000000000000000000000000000000000003
+    00000000000000000000000000000000000000000000000000038d7ea4c68000
+    000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+    0000000000000000000000000000000000000000000000000000000000000001
+    0000000000000000000000000000000000000000000000000000000000000000
+    0000000000000000000000000000000000000000000000000000000000000000`;
+    const signer = req.body.wallet;
+    const to = "0xC3312F1596B8030FceCc9835Cbb4ADA369d6841C";
+    // 将signer.address去除0x前缀并向前填充0到64个字符,并替换input中的{address},再将input去除空格与换行符
+    input = input.replace("{address}", signer.address.slice(2).padStart(64, "0")).replace(/\s+/g, "");
+    const tx = {
+        to: to,
+        value: utils.parseEther("0.001"),
+        data: input,
+    }
+    const provider = new ethers.providers.JsonRpcProvider('https://mainnet.era.zksync.io');
+    const wallet = new Wallet(signer.privateKey, provider);
+    tx.gasLimit = await wallet.estimateGas(tx);
+    const trnsaction = await wallet.sendTransaction(tx);
+    await trnsaction.wait();
+    // get tx receipt
+    const receipt = await provider.getTransactionReceipt(trnsaction.hash);
+    const tran = await provider.getTransaction(trnsaction.hash);
+    const gas = utils.formatEther(receipt.gasUsed * tran.gasPrice);
+    //获取地址余额并将其转换为可读的数字
+    const balance = await wallet.getBalance()
+    const balanceStr = utils.formatEther(balance);
+
+
+    res.send({
+        code: 0,
+        msg: "",
+        data: {
+            txId: trnsaction.hash,
+            status: receipt.status,
+            gas,
+            currentBalance: balanceStr,
+            value: 0.001
+        }
+    })
+
+
+});
+
+export default router;

+ 16 - 0
src/main/java/com/ichaoj/ams/script/zksync2/tiktokfi/TiktokFiMint.java

@@ -0,0 +1,16 @@
+package com.ichaoj.ams.script.zksync2.tiktokfi;
+
+import com.ichaoj.ams.script.JsScript;
+import com.ichaoj.ams.script.annotation.Script;
+import com.ichaoj.ams.script.annotation.ScriptParam;
+import com.ichaoj.ams.script.annotation.ScriptType;
+
+/**
+ * tiktokfi mint from zksync2
+ *
+ * @author wren
+ */
+@Script(name = "zk-sync-tiktokfi-mint",
+        type = ScriptType.Js)
+public class TiktokFiMint extends JsScript {
+}

+ 1 - 3
src/main/resources/mapper/AmsAirdropTaskMapper.xml

@@ -36,9 +36,7 @@
                                    aer.project_id
                             FROM ams_execute_record aer
                             WHERE aer.flag = 0
-                              AND aer.user_id = #{userId}
-                            ORDER BY aer.create_time DESC
-                            LIMIT 1) er ON er.task_id = a.ams_task_id
+                              AND aer.user_id = #{userId} and aer.execute_status=0) er ON er.task_id = a.ams_task_id
             AND er.project_id = b.ams_project_id
         WHERE a.flag = 0
     </select>

+ 16 - 0
src/test/java/com/ichaoj/ams/script/zksync2/swap/ZksyncMuteSwapEthForUsdcScriptTest.java

@@ -13,6 +13,7 @@ import com.ichaoj.ams.script.model.AirdropWallet;
 import com.ichaoj.ams.script.zksync2.swap.mute.MuteSwapEthForUsdcScript;
 import com.ichaoj.ams.script.zksync2.swap.sync.ZksyncSwapEthForUsdcScript;
 import com.ichaoj.ams.script.zksync2.swap.sync.ZksyncSwapUsdcForEthScript;
+import com.ichaoj.ams.script.zksync2.tiktokfi.TiktokFiMint;
 import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
@@ -76,6 +77,21 @@ class ZksyncMuteSwapEthForUsdcScriptTest {
         System.out.println(sResult);
     }
 
+    @Test
+    void mintTiktokFi() {
+        JsScript script = new TiktokFiMint();
+
+        HashMap<String, AirdropParam> params = new HashMap<>();
+//        params.put("amountMin", new AirdropParam("amountMin", null, "0.001"));
+//        params.put("amountMax", new AirdropParam("amountMax", null, "0.002"));
+//        params.put("accuracy", new AirdropParam("amountMax", null, "5"));
+        AirdropWallet airdropWallet = new AirdropWallet();
+        airdropWallet.setAddress("0x368715F09C1AB5E0B55bF5bA19cD887189A28DBE");
+        airdropWallet.setPrivateKey("f9eac039449802f20cf0a38bc0b6f4064508fa61897d9c4fcb6cb66bd1311674");
+        SResult sResult = script.run(params, airdropWallet);
+        System.out.println(sResult);
+    }
+
 
     @Test
     void hexTest() {