فهرست منبع

维护进城测试

龚成明 3 سال پیش
والد
کامیت
94b12278ba
4فایلهای تغییر یافته به همراه55 افزوده شده و 21 حذف شده
  1. 2 2
      hardhat.config.ts
  2. 2 2
      package.json
  3. 3 3
      scripts/interface/history.ts
  4. 48 14
      scripts/lp/lpMaintenance.ts

+ 2 - 2
hardhat.config.ts

@@ -7,8 +7,8 @@ import {HardhatRuntimeEnvironment} from "hardhat/types";
 
 const ETH_RPC = 'http://3.227.34.41:8545'
 const ETH_W_RPC = 'http://3.227.34.41:18545'
-const ETH_W_WS = 'ws://127.0.0.1:18546'
-const ETH_W_IPC = '/ethereum_pow_800/data/geth.ipc'
+const ETH_W_WS = 'ws://3.227.34.41:18546'
+// const ETH_W_IPC = '/ethereum_pow_800/data/geth.ipc'
 
 const config: HardhatUserConfig = {
   defaultNetwork: 'eth_w',

+ 2 - 2
package.json

@@ -1,8 +1,8 @@
 {
   "scripts": {
     "hardhat": "hardhat",
-    "push": "npm run hardhat -- run ./scripts/push.ts",
-    "pushFromHead": "npm run hardhat -- run ./scripts/pushFromHead.ts"
+    "lpGenerate": "npm run hardhat -- run ./scripts/lp/lpGenerate.ts",
+    "lpMaintenance": "npm run hardhat -- run ./scripts/lp/lpMaintenance.ts"
   },
   "devDependencies": {
     "@nomicfoundation/hardhat-toolbox": "^2.0.0",

+ 3 - 3
scripts/interface/history.ts

@@ -2,14 +2,14 @@ import http from '../../utils/http'
 
 export default class History {
   static async findByHashOrBlockOrDataVague(block: String, hashCode: String, dataVague: String,
-                                            limit1: Number, limit2: Number) {
+                                            start: Number, size: Number) {
     let url = '/ethmev/findByHashOrBlockOrDataVague'
     const rst = await http.post(url, {
       block: block,
       hash: hashCode,
       dataVague: dataVague,
-      limit1: limit1,
-      limit2: limit2
+      limit1: start,
+      limit2: size
     })
     return rst.data
   }

+ 48 - 14
scripts/lp/lpMaintenance.ts

@@ -68,7 +68,7 @@ export class LpMaintenance {
 
     if (ethTokenList.indexOf(lp.token0.toLowerCase()) == -1
       && ethTokenList.indexOf(lp.token1.toLowerCase()) == -1) {
-      return 'topLp'
+      return 'normalLp'
     }
 
     for (const filterType of filterTypeList) {
@@ -80,17 +80,16 @@ export class LpMaintenance {
     }
   }
 
-  async handleLp(lp: any) {
-    // 保存Lp信息
-    await this.saveLp(lp, '0')
-    // 保存Lp的Token到Token表
-    await this.saveToken(lp, 'token')
+  async handleLp(lp: any, oldType: any) {
     // 过滤Lp
     const lpType = await this.checkLpType(lp)
-    // 保存筛选之后的的Token到TopToken表
-    await this.saveToken(lp, lpType)
-    // 保存过滤后的Lp到TopLp
-    await this.saveLp(lp, lpType)
+    if (lpType != oldType) {
+      // 保存变更之后的的Token
+      // await this.saveToken(lp, lpType)
+      // 保存变更后的Lp
+      await this.saveLp(lp, lpType)
+      logger.debug(`lp:${lp.LP},${oldType}->${lpType}.`)
+    }
   }
 
   showMemory (mainInfo: string) {
@@ -105,14 +104,49 @@ export class LpMaintenance {
     return (bytes / 1024 / 1024).toFixed(2) + ' MB';
   }
 
+  generateAddressListByLpList (lpList: any) {
+    const lpAddressList: any = []
+
+    for (const lp of lpList) {
+      lpAddressList.push(lp.dataObj.LP)
+    }
+
+    return lpAddressList
+  }
+
+  updateLocalLpListR0R1(lpList: any, r0s: any, r1s: any) {
+    for (let index = 0; index < lpList.length; index++) {
+      lpList[index].dataObj.r0 = r0s[index]
+      lpList[index].dataObj.r1 = r1s[index]
+    }
+  }
+
   async run() {
     logger.debug('LP maintenance start.')
-
     while (true) {
-      const lpList: any = []
+      this.showMemory('pull db lp data...')
+      const lpPullRst = await history.findByHashOrBlockOrDataVague('topLp', '', '', 0, 20000)
+      if (!lpPullRst.state) continue
+      const topLpList = lpPullRst.data
+      logger.debug(`lp length:${topLpList.length}, generate address list...`)
+      const lpList: any = [].concat(topLpList)
+      const lpAddressList: any = this.generateAddressListByLpList(lpList)
+
+      // 集中拉取r0,r1并更新本地的
+      const size = 2000
+      logger.debug(`update lp r0,r1 by 410 tools...`)
+      for (let from = 0; from < topLpList.length; from += size) {
+        logger.debug(`get lp info from ${from} to ${from + size}...`)
+        const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
+        const r0s = lpR0R1Info.amounts0
+        const r1s = lpR0R1Info.amounts1
+
+        this.updateLocalLpListR0R1(lpList.slice(from, from + size), r0s, r1s)
+      }
 
-      for (const lp of lpList) {
-        await this.handleLp(lp)
+      // 将lp类型有变动的全部更新
+      for (const lpDbObj of lpList) {
+        await this.handleLp(lpDbObj.dataObj, lpDbObj.block)
       }
     }
   }