|
|
@@ -21,6 +21,7 @@ const ethTokenAddressList = baseTokenAddressList.filter(baseTokenAddress => {
|
|
|
export class LpMaintenance {
|
|
|
tokenAssembly: any = {}
|
|
|
memoryUtils: MemoryUtils = new MemoryUtils()
|
|
|
+ prevUpdateEthLpHours: number = -1
|
|
|
|
|
|
// 计算价格要用
|
|
|
allMaxValueLpGroupBySum: any = {}
|
|
|
@@ -125,7 +126,7 @@ export class LpMaintenance {
|
|
|
if (lpType != oldType) {
|
|
|
// 保存变更后的Lp
|
|
|
await this.saveLp(lp, lpType)
|
|
|
- logger.debug(`lp:${lp.LP},${oldType}->${lpType}.`)
|
|
|
+ logger.debug(`lp:${lp.LP}(${lp.r0}, ${lp.r1}),${oldType}->${lpType}.`)
|
|
|
}
|
|
|
|
|
|
await this.checkTokenByAddress(lp.token0, tokenType)
|
|
|
@@ -253,30 +254,47 @@ export class LpMaintenance {
|
|
|
return replaceAll(BigNumber.from(hex0).add(BigNumber.from(hex1))._hex, '0x0', '0x')
|
|
|
}
|
|
|
|
|
|
+ needToCheckEthLp() {
|
|
|
+ const hours = new Date().getHours()
|
|
|
+ if (this.prevUpdateEthLpHours != hours) {
|
|
|
+ this.prevUpdateEthLpHours = hours
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
async run() {
|
|
|
logger.debug('LP maintenance start.')
|
|
|
while (true) {
|
|
|
- await Time.delay(12000)
|
|
|
-
|
|
|
this.memoryUtils.logWithMemoryOnMemoryChange('a loop...')
|
|
|
|
|
|
try {
|
|
|
+ // toplp获取信息
|
|
|
const topLpPullRst = await History.findByBlock('topLp')
|
|
|
if (!topLpPullRst.state) continue
|
|
|
const topLpList = topLpPullRst.data
|
|
|
+ // lp获取信息
|
|
|
const lpPullRst = await History.findByBlock('lp')
|
|
|
if (!lpPullRst.state) continue
|
|
|
const lpList = lpPullRst.data
|
|
|
+ // normalLp获取息p
|
|
|
const normalLpPullRst = await History.findByBlock('normalLp')
|
|
|
if (!normalLpPullRst.state) continue
|
|
|
const normalLpList = normalLpPullRst.data
|
|
|
- // const ethLpPullRst = await History.findByBlock('ethLp')
|
|
|
- // if (!ethLpPullRst.state) continue
|
|
|
- // const ethLpList = ethLpPullRst.data
|
|
|
- const ethLpList: any = []
|
|
|
+ // 信息串联
|
|
|
+ let allTypeLpList: any = topLpList.concat(lpList).concat(normalLpList)
|
|
|
+
|
|
|
+ // 信息的ethLp获取需要是否
|
|
|
+ const needToCheckEthLp = this.needToCheckEthLp()
|
|
|
+ if (needToCheckEthLp) {
|
|
|
+ const ethLpPullRst = await History.findByBlock('ethLp')
|
|
|
+ if (!ethLpPullRst.state) continue
|
|
|
+ const ethLpList = ethLpPullRst.data
|
|
|
+ allTypeLpList = allTypeLpList.concat(ethLpList)
|
|
|
+ }
|
|
|
|
|
|
- const allTypeLpList: any = topLpList.concat(lpList).concat(normalLpList).concat(ethLpList)
|
|
|
- // const allTypeLpList: any = [].concat(normalLpList).concat(ethLpList)
|
|
|
const lpAddressList: any = this.generateAddressListByLpList(allTypeLpList)
|
|
|
// lp按sum分类
|
|
|
this.putAllLpGroupBySum(allTypeLpList)
|
|
|
@@ -284,10 +302,10 @@ export class LpMaintenance {
|
|
|
await this.pullAllToken(allTypeLpList)
|
|
|
|
|
|
// 集中拉取r0,r1并更新本地的
|
|
|
- const size = 2000
|
|
|
+ const size = needToCheckEthLp ? 200 : 2000
|
|
|
for (let from = 0; from < allTypeLpList.length; from += size) {
|
|
|
// logger.debug(`${from}, ${allTypeLpList.length}`)
|
|
|
- await Time.delay(168)
|
|
|
+ if (needToCheckEthLp) await Time.delay(168)
|
|
|
|
|
|
const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
|
|
|
const r0s = lpR0R1Info.amounts0
|
|
|
@@ -306,6 +324,8 @@ export class LpMaintenance {
|
|
|
} catch (e) {
|
|
|
logger.debug(e)
|
|
|
}
|
|
|
+
|
|
|
+ await Time.delay(12000)
|
|
|
}
|
|
|
}
|
|
|
}
|