|
|
@@ -68,7 +68,7 @@ export class LpMaintenance {
|
|
|
|
|
|
if (ethTokenList.indexOf(lp.token0.toLowerCase()) == -1
|
|
|
&& ethTokenList.indexOf(lp.token1.toLowerCase()) == -1) {
|
|
|
- return 'topLp'
|
|
|
+ return 'normalLp'
|
|
|
}
|
|
|
|
|
|
for (const filterType of filterTypeList) {
|
|
|
@@ -80,17 +80,16 @@ export class LpMaintenance {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async handleLp(lp: any) {
|
|
|
- // 保存Lp信息
|
|
|
- await this.saveLp(lp, '0')
|
|
|
- // 保存Lp的Token到Token表
|
|
|
- await this.saveToken(lp, 'token')
|
|
|
+ async handleLp(lp: any, oldType: any) {
|
|
|
// 过滤Lp
|
|
|
const lpType = await this.checkLpType(lp)
|
|
|
- // 保存筛选之后的的Token到TopToken表
|
|
|
- await this.saveToken(lp, lpType)
|
|
|
- // 保存过滤后的Lp到TopLp
|
|
|
- await this.saveLp(lp, lpType)
|
|
|
+ if (lpType != oldType) {
|
|
|
+ // 保存变更之后的的Token
|
|
|
+ // await this.saveToken(lp, lpType)
|
|
|
+ // 保存变更后的Lp
|
|
|
+ await this.saveLp(lp, lpType)
|
|
|
+ logger.debug(`lp:${lp.LP},${oldType}->${lpType}.`)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
showMemory (mainInfo: string) {
|
|
|
@@ -105,14 +104,49 @@ export class LpMaintenance {
|
|
|
return (bytes / 1024 / 1024).toFixed(2) + ' MB';
|
|
|
}
|
|
|
|
|
|
+ generateAddressListByLpList (lpList: any) {
|
|
|
+ const lpAddressList: any = []
|
|
|
+
|
|
|
+ for (const lp of lpList) {
|
|
|
+ lpAddressList.push(lp.dataObj.LP)
|
|
|
+ }
|
|
|
+
|
|
|
+ return lpAddressList
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLocalLpListR0R1(lpList: any, r0s: any, r1s: any) {
|
|
|
+ for (let index = 0; index < lpList.length; index++) {
|
|
|
+ lpList[index].dataObj.r0 = r0s[index]
|
|
|
+ lpList[index].dataObj.r1 = r1s[index]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async run() {
|
|
|
logger.debug('LP maintenance start.')
|
|
|
-
|
|
|
while (true) {
|
|
|
- const lpList: any = []
|
|
|
+ this.showMemory('pull db lp data...')
|
|
|
+ const lpPullRst = await history.findByHashOrBlockOrDataVague('topLp', '', '', 0, 20000)
|
|
|
+ if (!lpPullRst.state) continue
|
|
|
+ const topLpList = lpPullRst.data
|
|
|
+ logger.debug(`lp length:${topLpList.length}, generate address list...`)
|
|
|
+ const lpList: any = [].concat(topLpList)
|
|
|
+ const lpAddressList: any = this.generateAddressListByLpList(lpList)
|
|
|
+
|
|
|
+ // 集中拉取r0,r1并更新本地的
|
|
|
+ const size = 2000
|
|
|
+ logger.debug(`update lp r0,r1 by 410 tools...`)
|
|
|
+ for (let from = 0; from < topLpList.length; from += size) {
|
|
|
+ logger.debug(`get lp info from ${from} to ${from + size}...`)
|
|
|
+ const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
|
|
|
+ const r0s = lpR0R1Info.amounts0
|
|
|
+ const r1s = lpR0R1Info.amounts1
|
|
|
+
|
|
|
+ this.updateLocalLpListR0R1(lpList.slice(from, from + size), r0s, r1s)
|
|
|
+ }
|
|
|
|
|
|
- for (const lp of lpList) {
|
|
|
- await this.handleLp(lp)
|
|
|
+ // 将lp类型有变动的全部更新
|
|
|
+ for (const lpDbObj of lpList) {
|
|
|
+ await this.handleLp(lpDbObj.dataObj, lpDbObj.block)
|
|
|
}
|
|
|
}
|
|
|
}
|