Browse Source

上线测试,非直连ETH的LP测试

龚成明 3 years ago
parent
commit
d4adc2eeab
2 changed files with 74 additions and 31 deletions
  1. 28 12
      config/base-token.json
  2. 46 19
      scripts/lp/lpMaintenance.ts

+ 28 - 12
config/base-token.json

@@ -1,14 +1,30 @@
 {
-  "0x7bf88d2c0e32de92cdaf2d43ccdc23e8edfd5990": "WETHW",
-  "0xaf3ccfd9b59b36628cc2f659a09d6440795b2520": "ETH",
-  "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "WETH",
-  "0xdac17f958d2ee523a2206206994597c13d831ec7": "USDT",
-  "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": "USDC",
-  "0x6b175474e89094c44da98b954eedeac495271d0f": "DAI",
-  "0xf61eb8999f2f222f425d41da4c2ff4b6d8320c87": "BUSD",
-  "0x2ad7868ca212135c6119fd7ad1ce51cfc5702892": "USDTW",
-  "0xc675fdbe260e1ee93106ee596b916952a9344f44": "USDCW",
-  "0x25de68ef588cb0c2c8f3537861e828ae699cd0db": "USDCPOW",
-  "0x11bbb41b3e8baf7f75773db7428d5acee25fec75": "USDCUNIW",
-  "0x8a496486f4c7cb840555bc2be327cba1447027c3": "USDTUNIW"
+  "0x7bf88d2c0e32de92cdaf2d43ccdc23e8edfd5990": {
+    "name": "WETHW",
+    "decimals": 18
+  },
+  "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": {
+    "name": "WETH",
+    "decimals": 18
+  },
+  "0x2ad7868ca212135c6119fd7ad1ce51cfc5702892": {
+    "name": "USDTW",
+    "decimals": 6
+  },
+  "0xc675fdbe260e1ee93106ee596b916952a9344f44": {
+    "name": "USDCW",
+    "decimals": 18
+  },
+  "0x25de68ef588cb0c2c8f3537861e828ae699cd0db": {
+    "name": "USDCPOW",
+    "decimals": 6
+  },
+  "0x11bbb41b3e8baf7f75773db7428d5acee25fec75": {
+    "name": "USDCUNIW",
+    "decimals": 6
+  },
+  "0x8a496486f4c7cb840555bc2be327cba1447027c3": {
+    "name": "USDTUNIW",
+    "decimals": 6
+  }
 }

+ 46 - 19
scripts/lp/lpMaintenance.ts

@@ -2,13 +2,18 @@ import { web3 } from "hardhat";
 import History from "../interface/history";
 import contracts from "../../config/contracts";
 import logger from "../../utils/logger";
-import history from "../interface/history";
-const ierc20abi = require('../../abi/IERC20_ABI.json')
 
 // 初始化410 v2工具箱
 const v2ToolBy410Abi = require('../../abi/410_V2_TOOLS.json')
 const v2ToolBy410 = new web3.eth.Contract(v2ToolBy410Abi, contracts.V2_TOOLS_BY_410)
 
+// basetoken
+const baseTokenMap = require('../../config/base-token.json')
+const baseTokenAddressList = Object.keys(baseTokenMap)
+const ethTokenAddressList = baseTokenAddressList.filter(baseTokenAddress => {
+  return baseTokenMap[baseTokenAddress].name.indexOf('ETH') != -1
+})
+
 export class LpMaintenance {
   tokenInstance: any = {}
   maxMemoryOfByte: number = 0
@@ -19,27 +24,48 @@ export class LpMaintenance {
   }
 
   async checkLpType(lp: any) {
-    const ethTokenList = [
-      '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
-      '0x7bf88d2c0e32de92cdaf2d43ccdc23e8edfd5990'  // WETHW
-    ]
-
+    // lp过滤后类型表
     const filterTypeList = [
-      { type: 'topLp', limit: 10 * 1e18 },
-      { type: 'normalLp', limit: 1 * 1e18 },
+      { type: 'topLp', limit: 10 },
+      { type: 'normalLp', limit: 1 },
       { type: 'lp', limit: 0 },
     ]
+    // token折合成eth的价格
+    let tokenConvertEthPrice = 1
+
+    // token0和token1都不是baseToken的。视为lp
+    if (baseTokenAddressList.indexOf(lp.token0.toLowerCase()) == -1
+      && baseTokenAddressList.indexOf(lp.token1.toLowerCase()) == -1) {
+      return 'lp'
+    }
 
-    if (ethTokenList.indexOf(lp.token0.toLowerCase()) == -1
-      && ethTokenList.indexOf(lp.token1.toLowerCase()) == -1) {
-      return 'normalLp'
+    // token0和token1都不是eth的,视为usdx
+    if (ethTokenAddressList.indexOf(lp.token0.toLowerCase()) == -1
+      && ethTokenAddressList.indexOf(lp.token1.toLowerCase()) == -1) {
+      tokenConvertEthPrice = 0.142
     }
 
+    // 从高到低遍历过滤条件
     for (const filterType of filterTypeList) {
-      if (ethTokenList.indexOf(lp.token0.toLowerCase()) != -1) {
-        if (parseInt(lp.r0) >= filterType.limit) return filterType.type
-      } else if (ethTokenList.indexOf(lp.token1.toLowerCase()) != -1) {
-        if (parseInt(lp.r1) >= filterType.limit) return filterType.type
+      // 从头到尾搜索baseToken
+      for (const baseTokenAddress of baseTokenAddressList) {
+        const baseToken = baseTokenMap[baseTokenAddress]
+        const amountLimit = filterType.limit * Math.pow(10, baseToken.decimals)
+
+        // 如果是token0是baseToken,则将token1根据价格折合成eth数量计算
+        if (lp.token0.toLowerCase() === baseTokenAddress) {
+          const convertedEthAmount = parseInt(lp.r0) * tokenConvertEthPrice
+          if (convertedEthAmount >= amountLimit) {
+            return filterType.type
+          }
+        }
+        // 如果是token1是baseToken,则将token1根据价格折合成eth数量计算
+        if (lp.token1.toLowerCase() === baseTokenAddress) {
+          const convertedEthAmount = parseInt(lp.r1) * tokenConvertEthPrice
+          if (convertedEthAmount >= amountLimit) {
+            return filterType.type
+          }
+        }
       }
     }
   }
@@ -98,17 +124,18 @@ export class LpMaintenance {
   }
 
   async run() {
+    logger.debug(ethTokenAddressList)
     logger.debug('LP maintenance start.')
     while (true) {
       this.showMemory('a loop...')
 
-      const topLpPullRst = await history.findByBlock('topLp')
+      const topLpPullRst = await History.findByBlock('topLp')
       if (!topLpPullRst.state) continue
       const topLpList = topLpPullRst.data
-      const lpPullRst = await history.findByBlock('lp')
+      const lpPullRst = await History.findByBlock('lp')
       if (!lpPullRst.state) continue
       const lpList = lpPullRst.data
-      const normalLpPullRst = await history.findByBlock('normalLp')
+      const normalLpPullRst = await History.findByBlock('normalLp')
       if (!normalLpPullRst.state) continue
       const normalLpList = normalLpPullRst.data