skyfffire 3 lat temu
rodzic
commit
9ad6d9d7f0

Plik diff jest za duży
+ 0 - 0
abi/UNIV2_FACTORY_ABI.json


+ 1 - 1
config/routers.ts → config/v2_routers.ts

@@ -1 +1 @@
-export default ['0x7a250d5630b4cf539739df2c5dacb4c659f2488d', '0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f', '0xf6a86eaa9ea0f38f66b3718114ae79acaf35e02f', '0x03f7724180aa6b939894b5ca4314783b0b36b329', '0x53e0e51b5ed9202110d7ecd637a4581db8b9879f', '0x0c17e776cd218252adfca8d4e761d3fe757e9778', '0x25553828f22bdd19a20e4f12f052903cb474a335', '0x45815d3d2cd2a1cfbcf08dcfbdc6e11774ed9e39', '0x8cda39226daf33ae1aba0c92c34d1a1982cf0210', '0x59fe14af3ce9f15b06fb23dad670f3e68f885024', '0xea566e16af328085e75c7b4d3a007cf23f3f208d', '0x1fdd76e18dd21046b7e7d54c8254bf08b239e4d9', '0xdc6844ced486ec04803f02f2ee40bbdbef615f21', '0x07f72839d7a71a117fa859cba643c9291eeba921', '0x3e445e3280c5747a188db8d0ab7762838a50e4ff', '0x05f6bb6b96ca657a3666d2f1bca302b999a671b4', '0x3018234c038d524147ff47148baa8381306f28cf', '0x39d660d507f1bc34dbce94831081d6cf9131c3b9', '0xceb90e4c17d626be0facd78b79c9c87d7ca181b3', '0xb5e9f6c58f548cee53257304e287b23757effca1', '0xb9960d9bca016e9748be75dd52f02188b9d0829f', '0xe6e90bc9f3b95cdb69f48c7bfdd0ede1386b135a', '0xff062471eaf07b50fc1b77e61787301867610f80', '0xfe1f5bb11db3a9dead9d00ceb6f4e607b847d08e', '0xc14d550632db8592d1243edc8b95b0ad06703867', '0x5f509a3c3f16df2fba7bf84dee1efbce6bb85587', '0x6c78d71ce7300343e3633e0c45d6c7a79fee4650', '0xfcdf5cc307964ffabfc14fbd2dc4fad8e0fe9f45', '0xf73ba36cf5466abf1cfbc16ce4096eea135b5ea1', '0xcf7d4b75b7bccdb8b4f992fe05970680e2ee1a02', '0x463672ffded540f7613d3e8248e3a8a51baf7217', '0x3b505af97031b75e2be39e7f8fa1fa634857f29d', '0x1d5c6f1607a171ad52efb270121331b3039dd83e', '0x37d7f26405103c9bc9d8f9352cf32c5b655cbe02', '0x3bc722f252c7bae2f55647e49adcb9d33ff6ebcc', '0x8f589dcef8bc9564c17fba05ab6204e9793c9223', '0xdafb251f372d040f0da0f9b787623aae9cf1acb6', '0xbcc59f7397e78133d0b7ad0e044aaa26015292a1', '0x57556d10e6e9de56d72b9b322d433b9ed06741d0']
+export default ['0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f', '0x7a250d5630b4cf539739df2c5dacb4c659f2488d', '0xf6a86eaa9ea0f38f66b3718114ae79acaf35e02f', '0x03f7724180aa6b939894b5ca4314783b0b36b329', '0x53e0e51b5ed9202110d7ecd637a4581db8b9879f', '0x0c17e776cd218252adfca8d4e761d3fe757e9778', '0x25553828f22bdd19a20e4f12f052903cb474a335', '0x45815d3d2cd2a1cfbcf08dcfbdc6e11774ed9e39', '0x8cda39226daf33ae1aba0c92c34d1a1982cf0210', '0x59fe14af3ce9f15b06fb23dad670f3e68f885024', '0xea566e16af328085e75c7b4d3a007cf23f3f208d', '0x1fdd76e18dd21046b7e7d54c8254bf08b239e4d9', '0xdc6844ced486ec04803f02f2ee40bbdbef615f21', '0x07f72839d7a71a117fa859cba643c9291eeba921', '0x3e445e3280c5747a188db8d0ab7762838a50e4ff', '0x05f6bb6b96ca657a3666d2f1bca302b999a671b4', '0x3018234c038d524147ff47148baa8381306f28cf', '0x39d660d507f1bc34dbce94831081d6cf9131c3b9', '0xceb90e4c17d626be0facd78b79c9c87d7ca181b3', '0xb5e9f6c58f548cee53257304e287b23757effca1', '0xb9960d9bca016e9748be75dd52f02188b9d0829f', '0xe6e90bc9f3b95cdb69f48c7bfdd0ede1386b135a', '0xff062471eaf07b50fc1b77e61787301867610f80', '0xfe1f5bb11db3a9dead9d00ceb6f4e607b847d08e', '0xc14d550632db8592d1243edc8b95b0ad06703867', '0x5f509a3c3f16df2fba7bf84dee1efbce6bb85587', '0x6c78d71ce7300343e3633e0c45d6c7a79fee4650', '0xfcdf5cc307964ffabfc14fbd2dc4fad8e0fe9f45', '0xf73ba36cf5466abf1cfbc16ce4096eea135b5ea1', '0xcf7d4b75b7bccdb8b4f992fe05970680e2ee1a02', '0x463672ffded540f7613d3e8248e3a8a51baf7217', '0x3b505af97031b75e2be39e7f8fa1fa634857f29d', '0x1d5c6f1607a171ad52efb270121331b3039dd83e', '0x37d7f26405103c9bc9d8f9352cf32c5b655cbe02', '0x3bc722f252c7bae2f55647e49adcb9d33ff6ebcc', '0x8f589dcef8bc9564c17fba05ab6204e9793c9223', '0xdafb251f372d040f0da0f9b787623aae9cf1acb6', '0xbcc59f7397e78133d0b7ad0e044aaa26015292a1', '0x57556d10e6e9de56d72b9b322d433b9ed06741d0']

+ 1 - 0
config/v3_routers.ts

@@ -0,0 +1 @@
+export default ['0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45']

+ 1 - 1
scripts/interface/history.ts

@@ -1,4 +1,4 @@
-import http from './http'
+import http from '../../utils/http'
 
 export default class History {
   static async findByHashOrBlockOrDataVague(block: String, hashCode: String, dataVague: String) {

+ 115 - 11
scripts/pullv2.ts

@@ -1,20 +1,124 @@
 import { web3 } from "hardhat";
 import History from "./interface/history";
 import contracts from "../config/contracts";
+import logger from "../utils/logger";
+import v2_routers from "../config/v2_routers";
+import {BigNumber} from "ethers";
+import {replaceAll} from "hardhat/internal/util/strings";
 
-import log4js from 'log4js'
-const logger = log4js.getLogger()
-logger.level = "debug";
+async function handlePosition(router: String, factory: String) {
+  try {
+    // 拉取当前pull状态信息
+    const pullState = await History.findByHashOrBlockOrDataVague('UNIV2DEX', factory, '')
+    let nowPosition = 0
+
+    // 没有状态信息的情况
+    if (pullState.data.length == 0) {
+      const appendRst = await History.appendOrUpdate('UNIV2DEX', factory, {"now": nowPosition})
+      logger.debug(appendRst)
+    } else {
+      nowPosition = pullState.data[0].dataObj.now
+    }
+
+    return nowPosition
+  } catch (e) {
+    logger.error(`Pull state error, router: ${router}, factory: ${factory}`)
+    logger.error(e)
+  }
+
+  return 0
+}
+
+async function handleAFactory(router: String, factory: String, position: number, v2_410_tool: any) {
+  let errorCount = 0
+
+  while (true) {
+    try {
+      const info = await v2_410_tool.methods.getPairIdInfo(factory, position++).call()
+
+      // 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 data = {
+        LP: info['0'],
+        decimals0: info['4'],
+        decimals1: info['7'],
+        factory: factory,
+        feei: 30,
+        id: position,
+        name: `${router.slice(2, 4) + router.slice(-2)}_${info['2']}_${info['6']}`,
+        r0: 0,
+        r1: 0,
+        router: router,
+        sum2: replaceAll(BigNumber.from(info['1']).add(BigNumber.from(info['5']))._hex, '0x0', '0x'),
+        symbol0: info['2'],
+        symbol1: info['6'],
+        token0: info['1'],
+        token1: info['5']
+      }
+      logger.debug(await History.appendOrUpdate('0', info['0'], data), `, hash: ${info['0']}`)
+
+      // 每十次更新一次position
+      if (position % 50 == 0) {
+        await History.appendOrUpdate('UNIV2DEX', factory, {"now": position})
+        logger.debug(`Position updated: ${position}`)
+      }
+
+      errorCount = 0
+    } catch (e) {
+      logger.error(e)
+      errorCount++
+    }
+
+    if (errorCount >= 5) {
+      position = position - 5
+      break;
+    }
+  }
+}
 
 async function main() {
-  // const appendRst = await History.appendOrUpdate('UNIV2DEX', '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f', {"now": 0})
-  // console.log(appendRst)
-  // console.log(JSON.stringify(await History.findByHashOrBlockOrDataVague('UNIV2DEX', '', '')))
-
-  // const univ2_tool_abi = require('../abi/410_V2_TOOLS.json')
-  // const univ2_tool_410 = new web3.eth.Contract(univ2_tool_abi, contracts.TOOLS_410_V2)
-  // const pairIdInfo = await univ2_tool_410.methods.getPairIdInfo('0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f', 0).call()
-  // console.log(pairIdInfo)
+  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)
+
+  for (let router_index = 0; router_index < v2_routers.length; router_index++) {
+    const v2_router_address = v2_routers[router_index]
+
+    try {
+      logger.debug(`Router address: ${v2_router_address}`)
+
+      // 获取工厂地址
+      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 = new web3.eth.Contract(v2_factory_abi, v2_factory_address)
+      // 获取当前pairsLength
+      const pairsLength = await v2_factory.methods.allPairsLength().call()
+      // 获取当前pull状态
+      const position = await handlePosition(v2_router_address, v2_factory_address)
+
+      logger.debug(`factory: ${v2_factory}, ${position} / ${pairsLength}.`)
+      await handleAFactory(v2_router_address, v2_factory_address, position, v2_410_tool)
+    } catch (e) {
+      logger.error(`New contract error, router: ${v2_router_address}`)
+      logger.error(e)
+    }
+  }
 }
 
 main().catch((error) => {

+ 0 - 0
scripts/interface/http.ts → utils/http.ts


+ 5 - 0
utils/logger.ts

@@ -0,0 +1,5 @@
+import log4js from 'log4js'
+const logger = log4js.getLogger()
+logger.level = "debug";
+
+export default logger

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików