From 910eb39a2512c5dc51a27228380d2458e8f4250f Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 30 Nov 2023 15:38:14 +0700 Subject: [PATCH] fix: use migrate flag --- packages/oraidex-server/package.staging.json | 2 +- packages/oraidex-sync/src/index.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/oraidex-server/package.staging.json b/packages/oraidex-server/package.staging.json index 99debf18..0864de03 100644 --- a/packages/oraidex-server/package.staging.json +++ b/packages/oraidex-server/package.staging.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-server-staging", - "version": "1.0.35", + "version": "1.0.36", "main": "dist/index.js", "bin": "dist/index.js", "license": "MIT", diff --git a/packages/oraidex-sync/src/index.ts b/packages/oraidex-sync/src/index.ts index f3b561a2..d890c5fb 100644 --- a/packages/oraidex-sync/src/index.ts +++ b/packages/oraidex-sync/src/index.ts @@ -67,7 +67,7 @@ class OraiDexSync { console.time("timer-updateLatestPairInfos"); const pairInfos = await getAllPairInfos(); const allPools = await this.duckDb.getPools(); - if (allPools.length > 0 && pairInfos.length === allPools.length) return; + if (allPools.length > 0 && pairInfos.length === allPools.length) return false; await this.duckDb.insertPairInfos( pairInfos.map((pair) => { const symbols = getSymbolFromAsset(pair.asset_infos); @@ -86,18 +86,18 @@ class OraiDexSync { }) ); console.timeEnd("timer-updateLatestPairInfos"); + return true; } catch (error) { console.log("error in updateLatestPairInfos: ", error); } } - private async updateLatestLpAmountHistory(currentHeight: number) { + private async updateLatestLpAmountHistory(currentHeight: number, isNewPool: boolean) { try { console.time("timer-updateLatestLpAmountHistory"); const countLpAmounts = await this.duckDb.getLpAmountHistory(); - if (countLpAmounts > 0) return; - const pairInfos = await this.duckDb.getPools(); - + if (countLpAmounts > 0 && !isNewPool && !process.env.IS_MIGRATE_POOL) return; + const pairInfos = await this.duckDb.getPools(); // 13 pools const poolInfos = await getPoolInfos( pairInfos.map((pair) => pair.pairAddr), currentHeight @@ -181,10 +181,10 @@ class OraiDexSync { } console.log("current ind: ", currentInd); - await this.updateLatestPairInfos(); + const isNewPool = await this.updateLatestPairInfos(); // update offer & ask, total share of pool history in the first time - await this.updateLatestLpAmountHistory(currentInd); + await this.updateLatestLpAmountHistory(currentInd, isNewPool); // NOTE: need to updateLatestLpAmountHistory before update apr in the first time // to get the offerAmount, askAmount from lp amount history table.