浏览代码

异常交给顶层处理

龚成明 2 年之前
父节点
当前提交
8cdf6e8c73
共有 2 个文件被更改,包括 39 次插入48 次删除
  1. 5 4
      scripts/generate/index.js
  2. 34 44
      scripts/lib/lp-lib.js

+ 5 - 4
scripts/generate/index.js

@@ -30,9 +30,9 @@ class LpGenerate {
 
       // 3.2.2 从指定位置开始拉取lp
       for (let position = nextPosition; position < pairsLength; position++) {
-        // 3.2.2.1 拉取lp
-        const lp = await this.lpLib.getLpByPosition(factory, position)
-        if (lp) {
+        try {
+          // 3.2.2.1 拉取lp
+          const lp = await this.lpLib.getLpByPosition(factory, position)
           // 3.2.2.2 构造token0, token1
           const token0 = await this.tokenLib.parseToken(lp, true)
           const token1 = await this.tokenLib.parseToken(lp, false)
@@ -43,7 +43,8 @@ class LpGenerate {
           await this.tokenLib.saveToken(token1)
 
           logger.debug(`${position + 1} / ${pairsLength}, ${lp.name}-${lp.hash}-${this.chain.networkName}`)
-        } else {
+        } catch (e) {
+          logger.info(e)
           logger.debug(`lp get filed. ${position + 1} / ${pairsLength}, ${factory.name}-${factory.router}-${this.chain.networkName}`)
         }
       }

+ 34 - 44
scripts/lib/lp-lib.js

@@ -69,55 +69,45 @@ module.exports = class LpLib {
   }
 
   async getV2Pool(factory, position) {
-    try {
-      const info = await this.v2Tool.methods.getPairIdInfo(factory.hash, position).call()
-
-      const lp = {
-        hash: info['0'],
-        decimals0: info['3'],
-        decimals1: info['7'],
-        r0: info['4'],
-        r1: info['8'],
-        symbol0: info['2'],
-        symbol1: info['6'],
-        token0: info['1'],
-        token1: info['5']
-      }
-
-      return this.getEffectiveLp(factory, position, lp)
-    } catch (e) {
-      logger.info(e)
+    const info = await this.v2Tool.methods.getPairIdInfo(factory.hash, position).call()
+
+    const lp = {
+      hash: info['0'],
+      decimals0: info['3'],
+      decimals1: info['7'],
+      r0: info['4'],
+      r1: info['8'],
+      symbol0: info['2'],
+      symbol1: info['6'],
+      token0: info['1'],
+      token1: info['5']
     }
 
-    return undefined
+    return this.getEffectiveLp(factory, position, lp)
   }
 
   async getV3Pool(factory, position) {
-    try {
-      const positionManager = this.factoryLib.getPositionManager(factory.positionManager)
-      const positionInfo = await positionManager.methods.positions(position).call()
-      const info = await this.v3Tool.methods.getMoreInfo(positionInfo.token0, positionInfo.token1, positionInfo.fee).call()
-
-      const lp = {
-        hash: info.lp,
-        decimals0: info.decimals0,
-        decimals1: info.decimals1,
-        factory: factory.hash,
-        feei: positionInfo.fee,
-        id: position,
-        r0: info.r0,
-        r1: info.r1,
-        router: factory.router,
-        symbol0: symbol0,
-        symbol1: symbol1,
-        token0: positionInfo.token0,
-        token1: positionInfo.token1
-      }
-
-      return this.getEffectiveLp(factory, position, lp)
-    } catch (e) {}
-
-    return undefined
+    const positionManager = this.factoryLib.getPositionManager(factory.positionManager)
+    const positionInfo = await positionManager.methods.positions(position).call()
+    const info = await this.v3Tool.methods.getMoreInfo(positionInfo.token0, positionInfo.token1, positionInfo.fee).call()
+
+    const lp = {
+      hash: info.lp,
+      decimals0: info.decimals0,
+      decimals1: info.decimals1,
+      factory: factory.hash,
+      feei: positionInfo.fee,
+      id: position,
+      r0: info.r0,
+      r1: info.r1,
+      router: factory.router,
+      symbol0: symbol0,
+      symbol1: symbol1,
+      token0: positionInfo.token0,
+      token1: positionInfo.token1
+    }
+
+    return this.getEffectiveLp(factory, position, lp)
   }
 
   async getLpByPosition(factory, position) {