Kaynağa Gözat

维护的基本框架OK

skyfffire 2 yıl önce
ebeveyn
işleme
1f70d50d8e

+ 1 - 1
scripts/generate/index.js

@@ -15,7 +15,7 @@ class LpGenerate {
     // 初始化依赖库
     this.factoryLib = new FactoryLib(this.web3, this.chain)
     this.tokenLib = new TokenLib(this.web3, this.chain)
-    this.lpLib = new LpLib(this.web3, this.chain, this.factoryLib, this.tokenLib)
+    this.lpLib = new LpLib(this.web3, this.chain)
   }
 
   async tick() {

+ 10 - 3
scripts/lib/lp-lib.js

@@ -2,6 +2,8 @@ const logger = require("../../utils/logger");
 const BaseModel = require("../../model/base-model");
 const V2ToolAbi = require('../../abi/UNIV2_TOOLS_ABI.json')
 const V3ToolAbi = require('../../abi/UNIV3_TOOLS_ABI.json')
+const FactoryLib = require("./factory-lib");
+const TokenLib = require("./token-lib");
 
 module.exports = class LpLib {
   static LEVEL = {
@@ -12,11 +14,12 @@ module.exports = class LpLib {
     TOP: 'top'
   }
 
-  constructor(web3, chain, factoryLib, tokenLib) {
+  constructor(web3, chain) {
     this.web3 = web3
     this.chain = chain
-    this.factoryLib = factoryLib
-    this.tokenLib = tokenLib
+
+    this.factoryLib = new FactoryLib(this.web3, this.chain)
+    this.tokenLib = new TokenLib(this.web3, this.chain)
     
     this.v2LpModel = new BaseModel(this.chain.id, BaseModel.MODULES.V2_LP)
     this.v3LpModel = new BaseModel(this.chain.id, BaseModel.MODULES.V3_LP)
@@ -119,4 +122,8 @@ module.exports = class LpLib {
       throw Error(`Unknown factory version: ${factory.version}, hash is: ${factory.hash}.`)
     }
   }
+
+  async getV2LpList() {
+
+  }
 }

+ 48 - 0
scripts/maintenance/index.js

@@ -0,0 +1,48 @@
+const ChainLib = require("../lib/chain-lib");
+const Web3Utils = require("../../utils/web3-utils");
+const logger = require("../../utils/logger");
+const Time = require("../../utils/time");
+const LpLib = require("../lib/lp-lib");
+
+class LpMaintenance {
+  constructor(web3, chain) {
+    this.web3 = web3
+    this.chain = chain
+
+    // 初始化依赖库
+    this.lpLib = new LpLib(this.web3, this.chain)
+  }
+
+  async tick() {
+
+  }
+
+  async run() {
+    logger.debug(`${this.chain.networkName} liquidity pool maintenance is start.`)
+    logger.debug(`web3 is connected, block number: ${await this.web3.eth.getBlockNumber()}.`)
+
+    // 3. 开始处理
+    while (true) {
+      try {
+        await this.tick()
+      } catch (e) {
+        logger.error(e)
+      }
+
+      await Time.delay(1000)
+    }
+  }
+}
+
+async function main() {
+  const chain = await ChainLib.getChainFromCommand()
+  const web3 = Web3Utils.autoCreate(chain)
+  const generator = new LpMaintenance(web3, chain)
+
+  await generator.run()
+}
+
+main().catch((error) => {
+  console.error(error);
+  process.exitCode = 1;
+})