skyfffire 3 gadi atpakaļ
vecāks
revīzija
c348b01777
2 mainītis faili ar 17 papildinājumiem un 18 dzēšanām
  1. 0 0
      config/v2RouterInfo.json
  2. 17 18
      scripts/pushv2.ts

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
config/v2RouterInfo.json


+ 17 - 18
scripts/pushv2.ts

@@ -29,12 +29,12 @@ async function handlePosition(router: String, factory: String) {
   return 0
 }
 
-async function handleAFactory(router: String, factory: String, position: number, pairsLength: number, v2_410_tool: any) {
+async function handleAFactory(routerObj: any, position: number, pairsLength: number, v2_410_tool: any) {
   let errorCount = 0
 
   while (position <= pairsLength) {
     try {
-      const info = await v2_410_tool.methods.getPairIdInfo(factory, position).call()
+      const info = await v2_410_tool.methods.getPairIdInfo(routerObj.factory, position).call()
 
       // return (
       //  0   pairInfo.lp,
@@ -50,32 +50,33 @@ async function handleAFactory(router: String, factory: String, position: number,
 
       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 name = `${routerObj.name}_${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,
+        factory: routerObj.factory,
+        feei: routerObj.fee,
         id: position,
         name: name,
         r0: info['4'],
         r1: info['8'],
-        router: router,
+        router: routerObj.router,
         sum2: sum2,
         symbol0: symbol0,
         symbol1: symbol1,
         token0: info['1'],
-        token1: info['5']
+        token1: info['5'],
+        isEthW: routerObj.type == 'ETHW'
       }
       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('UNIV2DEX', factory, {"now": position})
+        await History.appendOrUpdate('UNIV2DEX', routerObj.factory, {"now": position})
         logger.debug(`Position updated: ${position}`)
       }
 
@@ -98,33 +99,31 @@ async function main() {
 
   logger.debug('Pull v2 start.')
 
-  const v2_router_abi = require('../abi/UNIV2_ROUTER_ABI.json')
   const v2_factory_abi = require('../abi/UNIV2_FACTORY_ABI.json')
   const v2_tool_abi = require('../abi/410_V2_TOOLS.json')
 
   // 初始化410 v2工具箱
   const v2_410_tool = new web3.eth.Contract(v2_tool_abi, contracts.TOOLS_410_V2)
+  const v2RouterInfo = require('../config/v2RouterInfo.json')
 
-  for (let router_index = 0; router_index < v2_routers.length; router_index++) {
-    const v2_router_address = v2_routers[router_index]
+  for (let router_index = 0; router_index < v2RouterInfo.length; router_index++) {
+    const v2Router = v2RouterInfo[router_index]
 
     try {
-      logger.debug(`Router address: ${v2_router_address}`)
+      logger.debug(`Router address: ${v2Router.router}`)
 
-      // 获取工厂地址
-      const v2_router = new web3.eth.Contract(v2_router_abi, v2_router_address)
-      const v2_factory_address = await v2_router.methods.factory().call()
+      const v2_factory_address = v2Router.factory
       // 获取工厂实例
       const v2_factory = new web3.eth.Contract(v2_factory_abi, v2_factory_address)
       // 获取当前pairsLength
       const pairsLength = await v2_factory.methods.allPairsLength().call()
       // 获取当前pull状态
-      const position = fromZero ? 0 : await handlePosition(v2_router_address, v2_factory_address)
+      const position = fromZero ? 0 : await handlePosition(v2Router.router, v2_factory_address)
 
       logger.debug(`factory: ${v2_factory_address}, ${position} / ${pairsLength}.`)
-      await handleAFactory(v2_router_address, v2_factory_address, position, pairsLength, v2_410_tool)
+      await handleAFactory(v2Router, position, pairsLength, v2_410_tool)
     } catch (e) {
-      logger.error(`New contract error, router: ${v2_router_address}`)
+      logger.error(`New contract error, router: ${v2Router.router}`)
       logger.error(e)
     }
   }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels