|
@@ -6,6 +6,13 @@ const V3ToolAbi = require('../../abi/UNIV3_TOOLS_ABI.json')
|
|
|
const FactoryLib = require("./factory-lib");
|
|
const FactoryLib = require("./factory-lib");
|
|
|
const TokenLib = require("./token-lib");
|
|
const TokenLib = require("./token-lib");
|
|
|
|
|
|
|
|
|
|
+// basetoken
|
|
|
|
|
+const baseTokenMap = require('../../config/base-token.json')
|
|
|
|
|
+const baseTokenAddressList = Object.keys(baseTokenMap)
|
|
|
|
|
+const ethTokenAddressList = baseTokenAddressList.filter(baseTokenAddress => {
|
|
|
|
|
+ return baseTokenMap[baseTokenAddress].name.indexOf('ETH') !== -1
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
module.exports = class LpLib {
|
|
module.exports = class LpLib {
|
|
|
static LEVEL = {
|
|
static LEVEL = {
|
|
|
NOT: 'not',
|
|
NOT: 'not',
|
|
@@ -166,7 +173,7 @@ module.exports = class LpLib {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- calcSwapPrice(lpList) {
|
|
|
|
|
|
|
+ putSwapPrice(lpList) {
|
|
|
for (const lp of lpList) {
|
|
for (const lp of lpList) {
|
|
|
const r0RealAmount = parseInt(lp.r0) / Math.pow(10, parseInt(lp.decimals0))
|
|
const r0RealAmount = parseInt(lp.r0) / Math.pow(10, parseInt(lp.decimals0))
|
|
|
const r1RealAmount = parseInt(lp.r1) / Math.pow(10, parseInt(lp.decimals1))
|
|
const r1RealAmount = parseInt(lp.r1) / Math.pow(10, parseInt(lp.decimals1))
|
|
@@ -177,7 +184,45 @@ module.exports = class LpLib {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- calcLpValue(lpList) {
|
|
|
|
|
|
|
+ getBaseTokenCovertEthValue(maxValueLpMap) {
|
|
|
|
|
+ const baseTokenConvertEthValueMap = {}
|
|
|
|
|
+
|
|
|
|
|
+ for (const baseTokenAddress of baseTokenAddressList) {
|
|
|
|
|
+ const isEthToken = ethTokenAddressList.indexOf(baseTokenAddress) !== -1
|
|
|
|
|
+ // eth兑换eth价格当然是1:1了
|
|
|
|
|
+ if (isEthToken) {
|
|
|
|
|
+ baseTokenConvertEthValueMap[baseTokenAddress] = 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 在ETH token中查找适合兑换的
|
|
|
|
|
+ for (const ethTokenAddress of ethTokenAddressList) {
|
|
|
|
|
+ const maxValueLp = maxValueLpMap[this.getKey(baseTokenAddress, ethTokenAddress)]
|
|
|
|
|
+ if (!maxValueLp) continue
|
|
|
|
|
+
|
|
|
|
|
+ const token0 = maxValueLp.token0
|
|
|
|
|
+ const token1 = maxValueLp.token1
|
|
|
|
|
+
|
|
|
|
|
+ if (baseTokenAddress === token0) {
|
|
|
|
|
+ baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.in1Token0OutToken1
|
|
|
|
|
+ } else if (baseTokenAddress === token1) {
|
|
|
|
|
+ baseTokenConvertEthValueMap[baseTokenAddress] = maxValueLp.in1Token1OutToken0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return baseTokenConvertEthValueMap
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getKey(hash0, hash1) {
|
|
|
|
|
+ if (hash0 < hash1) {
|
|
|
|
|
+ return hash0 + hash1
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return hash1 + hash0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ putLpValue(lpList) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|