|
@@ -17,7 +17,7 @@ const ethTokenAddressList = baseTokenAddressList.filter(baseTokenAddress => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
export class LpMaintenance {
|
|
export class LpMaintenance {
|
|
|
- tokenInstance: any = {}
|
|
|
|
|
|
|
+ tokenAssembly: any = {}
|
|
|
maxMemoryOfByte: number = 0
|
|
maxMemoryOfByte: number = 0
|
|
|
maxMemoryChanged: boolean = true
|
|
maxMemoryChanged: boolean = true
|
|
|
|
|
|
|
@@ -101,21 +101,34 @@ export class LpMaintenance {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async checkTokenByAddress(tokenAddress: any, newType: string) {
|
|
|
|
|
+ const tokenDbOBj = this.tokenAssembly[tokenAddress]
|
|
|
|
|
+
|
|
|
|
|
+ if (this.needUpdate(tokenDbOBj.type, tokenDbOBj.type)) {
|
|
|
|
|
+ tokenDbOBj.type = newType
|
|
|
|
|
+ await History.appendOrUpdate(tokenDbOBj.type, tokenDbOBj.hash, tokenDbOBj.data)
|
|
|
|
|
+ logger.debug(`token:${tokenAddress},${tokenDbOBj.type}->${tokenDbOBj.type}.`)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async handleLp(lp: any, oldType: any) {
|
|
async handleLp(lp: any, oldType: any) {
|
|
|
// 过滤Lp
|
|
// 过滤Lp
|
|
|
- let lpType = await this.checkLpType(lp)
|
|
|
|
|
|
|
+ let lpType: any = await this.checkLpType(lp)
|
|
|
|
|
+ let tokenType = 'token'
|
|
|
|
|
+ if (lpType != 'lp') tokenType = replaceAll(lpType, 'Lp', '') + 'Token'
|
|
|
// 一共12w个池子,非ethw的垃圾池子就不拉了
|
|
// 一共12w个池子,非ethw的垃圾池子就不拉了
|
|
|
if (lpType == 'lp' && !lp.isEthW) {
|
|
if (lpType == 'lp' && !lp.isEthW) {
|
|
|
lpType = 'ethLp'
|
|
lpType = 'ethLp'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (lpType != oldType) {
|
|
if (lpType != oldType) {
|
|
|
- // 保存变更之后的的Token
|
|
|
|
|
- // await this.saveToken(lp, lpType)
|
|
|
|
|
// 保存变更后的Lp
|
|
// 保存变更后的Lp
|
|
|
await this.saveLp(lp, lpType)
|
|
await this.saveLp(lp, lpType)
|
|
|
logger.debug(`lp:${lp.LP},${oldType}->${lpType}.`)
|
|
logger.debug(`lp:${lp.LP},${oldType}->${lpType}.`)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ await this.checkTokenByAddress(lp.token0, tokenType)
|
|
|
|
|
+ await this.checkTokenByAddress(lp.token1, tokenType)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
showMemory (mainInfo: string) {
|
|
showMemory (mainInfo: string) {
|
|
@@ -176,6 +189,47 @@ export class LpMaintenance {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ needUpdate(oldType: string, newType: string) {
|
|
|
|
|
+ const tokenTypeMap: any = {
|
|
|
|
|
+ 'token': 1,
|
|
|
|
|
+ 'normalToken': 2,
|
|
|
|
|
+ 'topToken': 3
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return tokenTypeMap[newType] > tokenTypeMap[oldType]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async pullAllToken(lpList: any) {
|
|
|
|
|
+ for (const lpDbObj of lpList) {
|
|
|
|
|
+ const lp = lpDbObj.dataObj
|
|
|
|
|
+ const lpType = lpDbObj.block
|
|
|
|
|
+ let tokenType = 'token'
|
|
|
|
|
+
|
|
|
|
|
+ if (lpType != 'lp') tokenType = replaceAll(lpType, 'Lp', '') + 'Token'
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.tokenAssembly[lp.token0]) {
|
|
|
|
|
+ const token0Rst = await History.findByHash(lp.token0)
|
|
|
|
|
+ const token0DbObj = token0Rst.data
|
|
|
|
|
+
|
|
|
|
|
+ this.tokenAssembly[lp.token0] = {
|
|
|
|
|
+ type: token0DbObj.block,
|
|
|
|
|
+ hash: token0DbObj.hash,
|
|
|
|
|
+ data: token0DbObj.dataObj
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this.tokenAssembly[lp.token1]) {
|
|
|
|
|
+ const token1Rst = await History.findByHash(lp.token1)
|
|
|
|
|
+ const token1DbObj = token1Rst.data
|
|
|
|
|
+
|
|
|
|
|
+ this.tokenAssembly[lp.token1] = {
|
|
|
|
|
+ type: token1DbObj.block,
|
|
|
|
|
+ hash: token1DbObj.hash,
|
|
|
|
|
+ data: token1DbObj.dataObj
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
calcBaseTokenCovertEthValue() {
|
|
calcBaseTokenCovertEthValue() {
|
|
|
for (const baseTokenAddress of baseTokenAddressList) {
|
|
for (const baseTokenAddress of baseTokenAddressList) {
|
|
|
const isEthToken = ethTokenAddressList.indexOf(baseTokenAddress) != -1
|
|
const isEthToken = ethTokenAddressList.indexOf(baseTokenAddress) != -1
|
|
@@ -230,6 +284,8 @@ export class LpMaintenance {
|
|
|
const lpAddressList: any = this.generateAddressListByLpList(allTypeLpList)
|
|
const lpAddressList: any = this.generateAddressListByLpList(allTypeLpList)
|
|
|
// lp按sum分类
|
|
// lp按sum分类
|
|
|
this.putAllLpGroupBySum(allTypeLpList)
|
|
this.putAllLpGroupBySum(allTypeLpList)
|
|
|
|
|
+ // 获取所有lp的未拉取的token
|
|
|
|
|
+ await this.pullAllToken(allTypeLpList)
|
|
|
|
|
|
|
|
// 集中拉取r0,r1并更新本地的
|
|
// 集中拉取r0,r1并更新本地的
|
|
|
const size = 2000
|
|
const size = 2000
|