|
|
@@ -1,64 +1,58 @@
|
|
|
-const web3 = require('hardhat').web3
|
|
|
+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")
|
|
|
+const ChainLib = require("../lib/chain-lib")
|
|
|
+const FactoryLib = require("../lib/factory-lib")
|
|
|
+const BaseModel = require("../../model/base-model")
|
|
|
|
|
|
class LpGenerate {
|
|
|
tokenInstance = {}
|
|
|
lpInstance = {}
|
|
|
|
|
|
- async handlePosition(routerObj) {
|
|
|
- const block = routerObj.type === 'univ2' ? 'UNIV2DEX' : 'UNIV3DEX'
|
|
|
- const hash = routerObj.type === 'univ2' ? routerObj.factory : routerObj.router + '_router'
|
|
|
+ constructor(web3, chain) {
|
|
|
+ this.web3 = web3
|
|
|
+ this.chain = chain
|
|
|
|
|
|
- try {
|
|
|
- // 拉取当前pull状态信息
|
|
|
- const pullState = await History.findByHashOrBlockOrDataVague(block, hash, '', 0, 200)
|
|
|
- let nowPosition = 0
|
|
|
-
|
|
|
- // 没有状态信息的情况
|
|
|
- if (pullState.data.length === 0) {
|
|
|
- await History.appendOrUpdate(block, hash, {"next": 0})
|
|
|
- } else {
|
|
|
- nowPosition = pullState.data[0].dataObj.next
|
|
|
- }
|
|
|
-
|
|
|
- return nowPosition
|
|
|
- } catch (e) {
|
|
|
- logger.error(`Pull state error, router: ${routerObj.router}, factory: ${routerObj.factory}`)
|
|
|
- logger.error(e)
|
|
|
- }
|
|
|
-
|
|
|
- return 0
|
|
|
+ // 初始化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)
|
|
|
}
|
|
|
|
|
|
- parseFactory(router, factoryAbi, factoryAddress) {
|
|
|
- if (router.factoryObj === null) {
|
|
|
- router.factoryObj = new web3.eth.Contract(factoryAbi, factoryAddress)
|
|
|
- }
|
|
|
-
|
|
|
- return router.factoryObj
|
|
|
+ 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('Pull lp start.')
|
|
|
+ logger.debug(`${this.chain.networkName} liquidity pool generate is start.`)
|
|
|
+ logger.debug(`web3 is connected, block number: ${await this.web3.eth.getBlockNumber()}.`)
|
|
|
|
|
|
- // 1. 构造web3对象
|
|
|
- // 2. abi加载
|
|
|
// 3. 开始处理
|
|
|
- // 3.1. 拉取指定链所有factory(记得新增链工具合约配置信息)
|
|
|
- // 3.2. 拉取指定链所有factory的拉取情况
|
|
|
- // 3.3. 从指定位置开始拉取lp
|
|
|
- // 3.3.1 更新或新增lp
|
|
|
- // 3.3.2 更新或新增token
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ await this.tick()
|
|
|
+ } catch (e) {
|
|
|
+ logger.error(e)
|
|
|
+ }
|
|
|
+
|
|
|
+ await Time.delay(12000)
|
|
|
+ }
|
|
|
|
|
|
- // 初始化410 v2工具箱
|
|
|
- const v2ToolBy410Abi = require('../../abi/410_V2_TOOLS.json')
|
|
|
- const v2ToolBy410 = new web3.eth.Contract(v2ToolBy410Abi, contracts.V2_TOOLS_BY_410)
|
|
|
- const v2FactoryAbi = require('../../abi/UNIV2_FACTORY_ABI.json')
|
|
|
|
|
|
// while (true) {
|
|
|
// for (const routerObj of routerList) {
|
|
|
@@ -114,7 +108,11 @@ class LpGenerate {
|
|
|
}
|
|
|
|
|
|
async function main() {
|
|
|
- logger.info(await ChainLib.getChainFromCommand())
|
|
|
+ const chain = await ChainLib.getChainFromCommand()
|
|
|
+ const web3 = Web3Utils.autoCreate(chain)
|
|
|
+ const generator = new LpGenerate(web3, chain)
|
|
|
+
|
|
|
+ await generator.run()
|
|
|
}
|
|
|
|
|
|
main().catch((error) => {
|