index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const ChainLib = require("../lib/chain-lib");
  2. const Web3Utils = require("../../utils/web3-utils");
  3. const logger = require("../../utils/logger");
  4. const Time = require("../../utils/time");
  5. const LpLib = require("../lib/lp-lib");
  6. class LpMaintenance {
  7. constructor(web3, chain) {
  8. this.web3 = web3
  9. this.chain = chain
  10. // 初始化依赖库
  11. this.lpLib = new LpLib(this.web3, this.chain)
  12. }
  13. async tick() {
  14. const v2LpList = await this.lpLib.getLpList(LpLib.VERSION.UNIV2)
  15. const v3LpList = await this.lpLib.getLpList(LpLib.VERSION.UNIV3)
  16. const lpList = v2LpList.concat(v3LpList)
  17. // 完善lp信息
  18. await this.lpLib.perfectLpInfo(lpList)
  19. }
  20. async run() {
  21. logger.debug(`${this.chain.networkName} liquidity pool maintenance is start.`)
  22. logger.debug(`web3 is connected, block number: ${await this.web3.eth.getBlockNumber()}.`)
  23. // 3. 开始处理
  24. while (true) {
  25. try {
  26. await this.tick()
  27. } catch (e) {
  28. logger.error(e)
  29. }
  30. await Time.delay(1000)
  31. }
  32. }
  33. }
  34. async function main() {
  35. const chain = await ChainLib.getChainFromCommand()
  36. const web3 = Web3Utils.autoCreate(chain)
  37. const generator = new LpMaintenance(web3, chain)
  38. await generator.run()
  39. }
  40. main().catch((error) => {
  41. console.error(error);
  42. process.exitCode = 1;
  43. })