|
|
@@ -32,9 +32,7 @@ async function handlePosition(router: String, factory: String) {
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
-async function handleAFactory(routerObj: any, position: number, pairsLength: number, v2_410_tool: any) {
|
|
|
- const lpList: any = []
|
|
|
-
|
|
|
+async function handleAFactory(routerObj: any, position: number, pairsLength: number, v2_410_tool: any, lpList: any) {
|
|
|
while (position < pairsLength) {
|
|
|
try {
|
|
|
const info = await v2_410_tool.methods.getPairIdInfo(routerObj.factory, position).call()
|
|
|
@@ -72,13 +70,10 @@ async function handleAFactory(routerObj: any, position: number, pairsLength: num
|
|
|
|
|
|
position++
|
|
|
}
|
|
|
-
|
|
|
- return lpList
|
|
|
}
|
|
|
|
|
|
-async function getAllLp(v2Router: any, fromZero: boolean, v2_410_tool: any, v2_factory_abi: any) {
|
|
|
+async function getAllLp(v2Router: any, fromZero: boolean, v2_410_tool: any, v2_factory_abi: any, lpList: any) {
|
|
|
try {
|
|
|
-
|
|
|
const v2_factory_address = v2Router.factory
|
|
|
// 获取工厂实例
|
|
|
const v2_factory = new web3.eth.Contract(v2_factory_abi, v2_factory_address)
|
|
|
@@ -91,14 +86,12 @@ async function getAllLp(v2Router: any, fromZero: boolean, v2_410_tool: any, v2_f
|
|
|
logger.debug(`Router address: ${v2Router.router}`)
|
|
|
logger.debug(`factory: ${v2_factory_address}, ${position + 1} / ${pairsLength}.`)
|
|
|
|
|
|
- return await handleAFactory(v2Router, position, pairsLength, v2_410_tool)
|
|
|
+ await handleAFactory(v2Router, position, pairsLength, v2_410_tool, lpList)
|
|
|
}
|
|
|
} catch (e) {
|
|
|
logger.error(`New contract error, router: ${v2Router.router}`)
|
|
|
logger.error(e)
|
|
|
}
|
|
|
-
|
|
|
- return []
|
|
|
}
|
|
|
|
|
|
async function saveLpToSwapPath(lpList: any) {
|
|
|
@@ -156,9 +149,7 @@ async function saveToken(lpList: any) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function filterLp(lpList: any) {
|
|
|
- const filteredLpList: any = []
|
|
|
-
|
|
|
+async function filterLp(lpList: any, filteredLpList: any) {
|
|
|
for (let lpIndex in lpList) {
|
|
|
const lp = lpList[lpIndex]
|
|
|
|
|
|
@@ -170,8 +161,6 @@ async function filterLp(lpList: any) {
|
|
|
filteredLpList.push(lp)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return filteredLpList
|
|
|
}
|
|
|
|
|
|
async function main() {
|
|
|
@@ -185,12 +174,17 @@ async function main() {
|
|
|
const v2RouterInfo = require('../../config/v2RouterInfo.json')
|
|
|
|
|
|
let fromZero: boolean = false
|
|
|
+ const lpList: any = []
|
|
|
+ const filteredLpList: any = []
|
|
|
while (true) {
|
|
|
+ lpList.length = 0
|
|
|
+ filteredLpList.length = 0
|
|
|
+
|
|
|
for (let router_index = 0; router_index < v2RouterInfo.length; router_index++) {
|
|
|
// 1. 获取Lp
|
|
|
- let lpList = await getAllLp(v2RouterInfo[router_index], fromZero, v2_410_tool, v2_factory_abi)
|
|
|
+ await getAllLp(v2RouterInfo[router_index], fromZero, v2_410_tool, v2_factory_abi, lpList)
|
|
|
// 2. 过滤Lp
|
|
|
- lpList = await filterLp(lpList)
|
|
|
+ await filterLp(lpList, filteredLpList)
|
|
|
// 3. 将Lp保存到二阶表
|
|
|
await saveLpToSwapPath(lpList)
|
|
|
// 4. 保存Lp的Token到Token表
|