| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const Web3Utils = require('../../utils/web3-utils')
- const logger = require("../../utils/logger")
- const BigNumber = require('ethers').BigNumber
- const ierc20abi = require('../../abi/IERC20_ABI.json')
- const contracts = require('../../config/contracts')
- const Time = require("../../utils/time")
- const ChainLib = require("../lib/chain-lib")
- const FactoryLib = require("../lib/factory-lib")
- const BaseModel = require("../../model/base-model")
- class LpGenerate {
- tokenInstance = {}
- lpInstance = {}
- constructor(web3, chain) {
- this.web3 = web3
- this.chain = chain
- // 初始化V2工具箱
- this.v2ToolAbi = require('../../abi/UNIV2_TOOLS_ABI.json')
- this.v2Tool = new this.web3.eth.Contract(this.v2ToolAbi, this.chain.v2ToolAddress)
- this.v2FactoryAbi = require('../../abi/UNIV2_FACTORY_ABI.json')
- // 初始化V3工具箱
- this.positionManagerAbi = require('../../abi/UNIV3_POSITION_MANAGER_ABI.json')
- this.v3ToolAbi = require('../../abi/UNIV3_TOOLS_ABI.json')
- this.v3Tool = new this.web3.eth.Contract(this.v3ToolAbi, this.chain.v3ToolAddress)
- // 初始化factory接口
- this.factoryModel = new BaseModel(this.chain.id, BaseModel.MODULES.FACTORY)
- }
- async tick() {
- // 3.1. 拉取指定链所有factory
- const factoryList = await FactoryLib.getFactoryList(this.factoryModel)
- logger.info(factoryList)
- // 3.2. 拉取指定factory的拉取情况
- // 3.3. 从指定位置开始拉取lp
- // 3.3.1 更新或新增lp
- // 3.3.2 更新或新增token
- }
- async run() {
- logger.debug(`${this.chain.networkName} liquidity pool generate 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(12000)
- }
- // while (true) {
- // for (const routerObj of routerList) {
- // try {
- // let pairsLength = 0
- //
- // const factoryAddress = routerObj.factory
- // // 获取当前pull状态
- // let position = await this.handlePosition(routerObj)
- // let v2Factory = undefined
- // // v2,v3分开处理
- // if (routerObj.type === 'univ2') {
- // // 获取工厂实例
- // v2Factory = this.parseFactory(routerObj, v2FactoryAbi, factoryAddress)
- // // 获取当前pairsLength
- // pairsLength = await v2Factory.methods.allPairsLength().call()
- // }
- // // 如果有未获取的池子
- // const haveNewLp = position < pairsLength
- //
- // // 打印信息
- // if (haveNewLp) {
- // logger.debug(`Router address: ${routerObj.router}`)
- // if (routerObj.type === 'univ2') {
- // logger.debug(`factory: ${factoryAddress}, ${position} / ${pairsLength}.`)
- // } else {
- // logger.debug(`position: ${routerObj.position}, ${position} / ${pairsLength}.`)
- // }
- // }
- //
- // // 挨个处理lp信息
- // for (; position < pairsLength; position++) {
- // await this.handleLp(position, pairsLength, routerObj, v2ToolBy410)
- // }
- //
- // if (haveNewLp) {
- // if (routerObj.type === 'univ2') {
- // await History.appendOrUpdate('UNIV2DEX', routerObj.factory, {"next": position})
- // }
- //
- // logger.debug('')
- // logger.debug('')
- // logger.debug('')
- // }
- // } catch (e) {
- // logger.debug(e)
- // }
- // }
- //
- // await Time.delay(12000)
- // }
- }
- }
- async function main() {
- const chain = await ChainLib.getChainFromCommand()
- const web3 = Web3Utils.autoCreate(chain)
- const generator = new LpGenerate(web3, chain)
- await generator.run()
- }
- main().catch((error) => {
- console.error(error);
- process.exitCode = 1;
- })
|