龚成明 3 лет назад
Родитель
Сommit
41949a7cad
2 измененных файлов с 48 добавлено и 55 удалено
  1. 2 1
      scripts/pullv2.ts
  2. 46 54
      scripts/pullv3.ts

+ 2 - 1
scripts/pullv2.ts

@@ -34,7 +34,7 @@ async function handleAFactory(router: String, factory: String, position: number,
 
   while (position <= pairsLength) {
     try {
-      const info = await v2_410_tool.methods.getPairIdInfo(factory, position++).call()
+      const info = await v2_410_tool.methods.getPairIdInfo(factory, position).call()
 
       // return (
       //  0   pairInfo.lp,
@@ -85,6 +85,7 @@ async function handleAFactory(router: String, factory: String, position: number,
       errorCount++
     }
 
+    position++
     if (errorCount >= 5) {
       position = position - 5
       break;

+ 46 - 54
scripts/pullv3.ts

@@ -29,64 +29,53 @@ async function handlePosition(router: String, factory: String) {
   return 0
 }
 
-async function handleAFactory(router: String, factory: String, position: number, v3_410_tool: any) {
+async function handleAFactory(router: String, factory: String, position: number, v3_tool: any, v3PositionManager: any) {
   let errorCount = 0
 
   while (true) {
     try {
-      const info = await v3_410_tool.methods.getPairIdInfo(factory, position++).call()
-
-      logger.debug(info)
-
-      // return (
-      //  0   pairInfo.lp,
-      //  1   pairInfo.token0,
-      //  2   pairInfo.symbol0,
-      //  3   pairInfo.decimals0,
-      //  4   pairInfo.r0,
-      //  5   pairInfo.token1,
-      //  6   pairInfo.symbol1,
-      //  7   pairInfo.decimals1,
-      //  8   pairInfo.r1
-      // );
-
-      // const symbol0 = info['2'].replace(/[^A-Za-z0-9 ]+/g, '').substring(0, 10)
-      // const symbol1 = info['6'].replace(/[^A-Za-z0-9 ]+/g, '').substring(0, 10)
-      // const name = `${router.slice(2, 4) + router.slice(-2)}_${symbol0}_${symbol1}`
-      // const sum2 = replaceAll(BigNumber.from(info['1']).add(BigNumber.from(info['5']))._hex, '0x0', '0x')
-
-    //   const data = {
-    //     LP: info['0'],
-    //     decimals0: info['3'],
-    //     decimals1: info['7'],
-    //     factory: factory,
-    //     feei: 30,
-    //     id: position,
-    //     name: name,
-    //     r0: info['4'],
-    //     r1: info['8'],
-    //     router: router,
-    //     sum2: sum2,
-    //     symbol0: symbol0,
-    //     symbol1: symbol1,
-    //     token0: info['1'],
-    //     token1: info['5']
-    //   }
-    //   const insertRst = await History.appendOrUpdate('0', info['0'], data)
-    //   logger.debug(insertRst.msg, `, hash: ${info['0']}, ${position} / ${pairsLength}`)
-    //
-    //   // 每十次更新一次position
-    //   if (position % 50 == 0) {
-    //     await History.appendOrUpdate('UNIV3DEX', factory, {"now": position})
-    //     logger.debug(`Position updated: ${position}`)
-    //   }
-    //
-    //   errorCount = 0
+      const positionInfo = await v3PositionManager.methods.positions(position).call()
+      const info = await v3_tool.methods.getMoreInfo(positionInfo.token0, positionInfo.token1, positionInfo.fee).call()
+
+      const symbol0 = info.symbol0.replace(/[^A-Za-z0-9 ]+/g, '').substring(0, 10)
+      const symbol1 = info.symbol1.replace(/[^A-Za-z0-9 ]+/g, '').substring(0, 10)
+      const name = `${router.slice(2, 4) + router.slice(-2)}_${symbol0}_${symbol1}`
+      const sum2 = replaceAll(BigNumber.from(positionInfo.token0).add(BigNumber.from(positionInfo.token1))._hex, '0x0', '0x')
+
+      const data = {
+        LP: info.lp,
+        decimals0: info.decimals0,
+        decimals1: info.decimals1,
+        factory: factory,
+        feei: positionInfo.fee,
+        id: position,
+        name: name,
+        r0: info.r0,
+        r1: info.r1,
+        router: router,
+        sum2: sum2,
+        symbol0: symbol0,
+        symbol1: symbol1,
+        token0: positionInfo.token0,
+        token1: positionInfo.token1
+      }
+
+      const insertRst = await History.appendOrUpdate('0', info.lp, data)
+      logger.debug(insertRst.msg, `, hash: ${info.lp}, ${position}`)
+
+      // 每十次更新一次position
+      if (position % 50 == 0) {
+        await History.appendOrUpdate('UNIV3DEX', factory, {"now": position})
+        logger.debug(`Position updated: ${position}`)
+      }
+
+      errorCount = 0
     } catch (e) {
       logger.error(JSON.stringify(e))
       errorCount++
     }
 
+    position++
     if (errorCount >= 5) {
       position = position - 5
       break;
@@ -100,10 +89,13 @@ async function main() {
   logger.debug('Pull v3 start.')
 
   const v3_router_abi = require('../abi/UNIV3_ROUTER_ABI.json')
-  const v3_tool_abi = require('../abi/410_V3_TOOLS.json')
+  const positionManagerAbi = require('../abi/UNIV3_POSITION_MANAGER_ABI.json')
+  const v3_tool_abi = require('../artifacts/contracts/V3Tool.sol/V3Tool.json').abi
 
-  // 初始化410 v3工具箱
-  const v3_410_tool = new web3.eth.Contract(v3_tool_abi, contracts.TOOLS_410_V3)
+  // 初始化 v3工具箱
+  const v3_tool = new web3.eth.Contract(v3_tool_abi, contracts.TOOLS_V3)
+  // 初始化PositionManager
+  const v3PositionManager = new web3.eth.Contract(positionManagerAbi, contracts.UNIV3_POSITION)
 
   for (let router_index = 0; router_index < v3_routers.length; router_index++) {
     const v3_router_address = v3_routers[router_index]
@@ -115,10 +107,10 @@ async function main() {
       const v3_router = new web3.eth.Contract(v3_router_abi, v3_router_address)
       const v3_factory_address = await v3_router.methods.factory().call()
       // 获取当前pull状态
-      const position = fromZero ? 0 : await handlePosition(v3_router_address, v3_factory_address)
+      const position = fromZero ? 1 : await handlePosition(v3_router_address, v3_factory_address)
 
       logger.debug(`factory: ${v3_factory_address}, ${position}.`)
-      await handleAFactory(v3_router_address, v3_factory_address, position, v3_410_tool)
+      await handleAFactory(v3_router_address, v3_factory_address, position, v3_tool, v3PositionManager)
     } catch (e) {
       logger.error(`New contract error, router: ${v3_router_address}`)
       logger.error(e)