|
|
@@ -3,6 +3,7 @@ import History from "../interface/history";
|
|
|
import contracts from "../../config/contracts";
|
|
|
import logger from "../../utils/logger";
|
|
|
import {BigNumber} from "ethers";
|
|
|
+import {replaceAll} from "hardhat/internal/util/strings";
|
|
|
|
|
|
// 初始化410 v2工具箱
|
|
|
const v2ToolBy410Abi = require('../../abi/410_V2_TOOLS.json')
|
|
|
@@ -36,28 +37,36 @@ export class LpMaintenance {
|
|
|
// 2.两token之一能直接与baseToken做池子的
|
|
|
// 这两种情况直接带入baseTokenConvertEthValueMap计算
|
|
|
for (const baseTokenAddress of baseTokenAddressList) {
|
|
|
- const token0AndBaseTokenLp = this.allMaxValueLpGroupBySum[this.getHexSum(token0, baseTokenAddress.toLowerCase())]
|
|
|
+ const token0AndBaseTokenSum = this.getHexSum(token0, baseTokenAddress.toLowerCase())
|
|
|
+ const token0AndBaseTokenLp = this.allMaxValueLpGroupBySum[token0AndBaseTokenSum]
|
|
|
|
|
|
if (token0AndBaseTokenLp) {
|
|
|
- return {
|
|
|
- '0': token0AndBaseTokenLp.zeroToOnePrice * this.baseTokenConvertEthValueMap[baseTokenAddress],
|
|
|
- '1': 1 / token0AndBaseTokenLp.zeroToOnePrice * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
+ const priceMap: any = {}
|
|
|
+ if (token0AndBaseTokenLp.token0.toLowerCase() == token0) {
|
|
|
+ priceMap['0'] = token0AndBaseTokenLp.in1Token0OutToken1 * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
+ } else {
|
|
|
+ priceMap['0'] = token0AndBaseTokenLp.in1Token1OutToken0 * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
}
|
|
|
+ priceMap['1'] = 0
|
|
|
+
|
|
|
+ return priceMap
|
|
|
}
|
|
|
|
|
|
- const token1AndBaseTokenLp = this.allMaxValueLpGroupBySum[this.getHexSum(token1, baseTokenAddress.toLowerCase())]
|
|
|
+ const token1AndBaseTokenSum = this.getHexSum(token1, baseTokenAddress.toLowerCase())
|
|
|
+ const token1AndBaseTokenLp = this.allMaxValueLpGroupBySum[token1AndBaseTokenSum]
|
|
|
if (token1AndBaseTokenLp) {
|
|
|
- return {
|
|
|
- '0': 1 / token1AndBaseTokenLp.oneToZeroPrice * this.baseTokenConvertEthValueMap[baseTokenAddress],
|
|
|
- '1': token1AndBaseTokenLp.oneToZeroPrice * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
+ const priceMap: any = {}
|
|
|
+ if (token1AndBaseTokenLp.token0.toLowerCase() == token1) {
|
|
|
+ priceMap['1'] = token1AndBaseTokenLp.in1Token0OutToken1 * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
+ } else {
|
|
|
+ priceMap['1'] = token1AndBaseTokenLp.in1Token1OutToken0 * this.baseTokenConvertEthValueMap[baseTokenAddress]
|
|
|
}
|
|
|
- }
|
|
|
+ priceMap['0'] = 0
|
|
|
|
|
|
- if (ethTokenAddressList.indexOf(baseTokenAddress.toLowerCase()) == -1) {
|
|
|
- logger.debug(`${JSON.stringify(lp)}`)
|
|
|
- logger.debug(`0, ${token0AndBaseTokenLp.zeroToOnePrice}, ${this.baseTokenConvertEthValueMap[baseTokenAddress]}`)
|
|
|
- logger.debug(`1, ${token1AndBaseTokenLp.zeroToOnePrice}, ${this.baseTokenConvertEthValueMap[baseTokenAddress]}`)
|
|
|
+ return priceMap
|
|
|
}
|
|
|
+
|
|
|
+ // lp.LP.toLowerCase() === '0x23103F8a0A9B8585762Ab3cD79e1667A1f5C163a'.toLowerCase()
|
|
|
}
|
|
|
|
|
|
// 3.两token都不能与baseToken做池子的
|
|
|
@@ -72,23 +81,16 @@ export class LpMaintenance {
|
|
|
{ type: 'normalLp', limit: 0.1 },
|
|
|
{ type: 'lp', limit: 0 },
|
|
|
]
|
|
|
- // token折合成eth的价格
|
|
|
- let tokenConvertEthPrice: any = {
|
|
|
- '0': 1,
|
|
|
- '1': 1
|
|
|
- }
|
|
|
-
|
|
|
- // token0和token1都不是eth的,分三种情况探讨
|
|
|
- if (ethTokenAddressList.indexOf(lp.token0.toLowerCase()) == -1
|
|
|
- && ethTokenAddressList.indexOf(lp.token1.toLowerCase()) == -1) {
|
|
|
- tokenConvertEthPrice = this.getLpEthValue(lp)
|
|
|
- }
|
|
|
+ // token折合成eth的价格,分三种情况探讨
|
|
|
+ // 0: token0与eth的价格
|
|
|
+ // 1: token1与eth的价格
|
|
|
+ let tokenConvertEthPrice: any = this.getLpEthValue(lp)
|
|
|
|
|
|
// 从高到低遍历过滤条件
|
|
|
const decimals0 = parseInt(lp.decimals0)
|
|
|
- const decimals1 = parseInt(lp.decimals0)
|
|
|
- const realAmount0 = parseInt(lp.r0) * tokenConvertEthPrice['0'] / Math.pow(10, -decimals0)
|
|
|
- const realAmount1 = parseInt(lp.r1) * tokenConvertEthPrice['1'] / Math.pow(10, -decimals1)
|
|
|
+ const decimals1 = parseInt(lp.decimals1)
|
|
|
+ const realAmount0 = parseInt(lp.r0) * tokenConvertEthPrice['0'] / Math.pow(10, decimals0)
|
|
|
+ const realAmount1 = parseInt(lp.r1) * tokenConvertEthPrice['1'] / Math.pow(10, decimals1)
|
|
|
|
|
|
for (const filterType of filterTypeList) {
|
|
|
const amountLimit = filterType.limit
|
|
|
@@ -157,6 +159,7 @@ export class LpMaintenance {
|
|
|
|
|
|
for (const lpDbObj of lpList) {
|
|
|
const lp = lpDbObj.dataObj
|
|
|
+ lp.sum2 = this.getHexSum(lp.token0, lp.token1)
|
|
|
|
|
|
const notExist = !this.allMaxValueLpGroupBySum[lp.sum2]
|
|
|
const moreValueThanNowMax = !notExist && (parseInt(lp.r0) > this.allMaxValueLpGroupBySum[lp.sum2].r0)
|
|
|
@@ -165,8 +168,8 @@ export class LpMaintenance {
|
|
|
const r1RealAmount = parseInt(lp.r1) / Math.pow(10, parseInt(lp.decimals1))
|
|
|
|
|
|
// 计算0换1的价格和1换0的价格
|
|
|
- lp.zeroToOnePrice = r1RealAmount / r0RealAmount // 一个token0 = zeroToOnePrice个token1
|
|
|
- lp.oneToZeroPrice = r0RealAmount / r1RealAmount // 一个token1 = oneForZeroPrice个token0
|
|
|
+ lp.in1Token0OutToken1 = r1RealAmount / r0RealAmount // 一个token0 = in1Token0OutToken1个token1
|
|
|
+ lp.in1Token1OutToken0 = r0RealAmount / r1RealAmount // 一个token1 = oneForZeroPrice个token0
|
|
|
|
|
|
this.allMaxValueLpGroupBySum[lp.sum2] = lp
|
|
|
}
|
|
|
@@ -189,9 +192,9 @@ export class LpMaintenance {
|
|
|
const token1 = maxValueLp.token1.toLowerCase()
|
|
|
|
|
|
if (baseTokenAddress.toLowerCase() == token0) {
|
|
|
- this.baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.zeroToOnePrice
|
|
|
+ this.baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.in1Token0OutToken1
|
|
|
} else if (baseTokenAddress.toLowerCase() == token1) {
|
|
|
- this.baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.oneToZeroPrice
|
|
|
+ this.baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.in1Token1OutToken0
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -199,7 +202,7 @@ export class LpMaintenance {
|
|
|
}
|
|
|
|
|
|
getHexSum(hex0: string, hex1: string) {
|
|
|
- return BigNumber.from(hex0).add(BigNumber.from(hex1))._hex
|
|
|
+ return replaceAll(BigNumber.from(hex0).add(BigNumber.from(hex1))._hex, '0x0', '0x')
|
|
|
}
|
|
|
|
|
|
async run() {
|
|
|
@@ -223,6 +226,7 @@ export class LpMaintenance {
|
|
|
// const ethLpList: any = []
|
|
|
|
|
|
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)
|
|
|
@@ -245,7 +249,9 @@ export class LpMaintenance {
|
|
|
for (const lpDbObj of allTypeLpList) {
|
|
|
await this.handleLp(lpDbObj.dataObj, lpDbObj.block)
|
|
|
}
|
|
|
- } catch (e) {}
|
|
|
+ } catch (e) {
|
|
|
+ logger.debug(e)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|