diff --git a/packages/oraidex-server/package.json b/packages/oraidex-server/package.json index 7db31590..bf31a846 100644 --- a/packages/oraidex-server/package.json +++ b/packages/oraidex-server/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-server", - "version": "1.0.29", + "version": "1.0.30", "main": "dist/index.js", "bin": "dist/index.js", "license": "MIT", diff --git a/packages/oraidex-server/package.staging.json b/packages/oraidex-server/package.staging.json index 3d8867d4..aa5b8b4d 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.39", + "version": "1.0.41", "main": "dist/index.js", "bin": "dist/index.js", "license": "MIT", diff --git a/packages/oraidex-server/src/index.ts b/packages/oraidex-server/src/index.ts index 19a68ab6..c393b54f 100644 --- a/packages/oraidex-server/src/index.ts +++ b/packages/oraidex-server/src/index.ts @@ -32,9 +32,10 @@ import { simulateSwapPrice, toDisplay, usdtInfo, - getMigrateStakingV3Client, oraixCw20Address, - usdcCw20Address + usdcCw20Address, + getPoolLiquidities, + getPoolAmounts } from "@oraichain/oraidex-sync"; import cors from "cors"; import "dotenv/config"; @@ -133,42 +134,36 @@ app.get("/tickers", async (req, res) => { return pair; }); - const data: TickerInfo[] = ( - await Promise.allSettled( - arrangedPairs.map(async (pair) => { - const symbols = pair.symbols; - const pairAddr = findPairAddress(pairInfos, pair.asset_infos); - const tickerId = parseSymbolsToTickerId(symbols); - const baseIndex = 0; - const targetIndex = 1; - const baseInfo = parseAssetInfoOnlyDenom(pair.asset_infos[baseIndex]); - const targetInfo = parseAssetInfoOnlyDenom(pair.asset_infos[targetIndex]); - const volume = await duckDb.queryAllVolumeRange(baseInfo, targetInfo, then, latestTimestamp); - const tickerInfo: TickerInfo = { - ticker_id: tickerId, - base_currency: symbols[baseIndex], - target_currency: symbols[targetIndex], - last_price: "", - base_volume: toDisplay(BigInt(volume.volume[baseInfo])).toString(), - target_volume: toDisplay(BigInt(volume.volume[targetInfo])).toString(), - pool_id: pairAddr ?? "", - base: symbols[baseIndex], - target: symbols[targetIndex] - }; - try { - // reverse because in pairs, we put base info as first index - const price = await simulateSwapPrice(pair.asset_infos, routerContract); - tickerInfo.last_price = price.toString(); - } catch (error) { - tickerInfo.last_price = "0"; - } - return tickerInfo; - }) - ) - ).map((result) => { - if (result.status === "fulfilled") return result.value; - else console.log("result: ", result.reason); - }); + const data: TickerInfo[] = []; + for (const pair of arrangedPairs) { + const symbols = pair.symbols; + const pairAddr = findPairAddress(pairInfos, pair.asset_infos); + const tickerId = parseSymbolsToTickerId(symbols); + const baseIndex = 0; + const targetIndex = 1; + const baseInfo = parseAssetInfoOnlyDenom(pair.asset_infos[baseIndex]); + const targetInfo = parseAssetInfoOnlyDenom(pair.asset_infos[targetIndex]); + const volume = await duckDb.queryAllVolumeRange(baseInfo, targetInfo, then, latestTimestamp); + const tickerInfo: TickerInfo = { + ticker_id: tickerId, + base_currency: symbols[baseIndex], + target_currency: symbols[targetIndex], + last_price: "", + base_volume: toDisplay(BigInt(volume.volume[baseInfo])).toString(), + target_volume: toDisplay(BigInt(volume.volume[targetInfo])).toString(), + pool_id: pairAddr ?? "", + base: symbols[baseIndex], + target: symbols[targetIndex] + }; + try { + // reverse because in pairs, we put base info as first index + const price = await simulateSwapPrice(pair.asset_infos, routerContract); + tickerInfo.last_price = price.toString(); + } catch (error) { + tickerInfo.last_price = "0"; + } + data.push(tickerInfo); + } res.status(200).send(data); } catch (error) { console.log("error: ", error); @@ -184,12 +179,13 @@ app.get("/volume/v2/historical/chart", async (req, res) => { const then = startTime ? parseInt(startTime as string) : getSpecificDateBeforeNow(new Date(latestTimestamp * 1000), 259200).getTime() / 1000; - const volumeInfos = await Promise.all( - pairsOnlyDenom.map((pair) => { - return duckDb.getVolumeRange(timeFrame, then, latestTimestamp, pairToString(pair.asset_infos)); - }) - ); - // console.log("volume infos: ", volumeInfos); + + const volumeInfos = []; + for (const { asset_infos } of pairsOnlyDenom) { + const volume = await duckDb.getVolumeRange(timeFrame, then, latestTimestamp, pairToString(asset_infos)); + volumeInfos.push(volume); + } + const volumeRanges: { [time: string]: VolumeRange[] } = {}; for (const volumePair of volumeInfos) { for (const volume of volumePair) { @@ -236,19 +232,12 @@ app.get("/v1/candles/", async (req: Request<{}, {}, {}, GetCandlesQuery>, res) = app.get("/v1/pools/", async (_req, res) => { try { - const [volumes, allFee7Days, pools, allPoolApr] = await Promise.all([ - getAllVolume24h(), - getAllFees(), - duckDb.getPools(), - duckDb.getAllAprs() - ]); - const liquidityPromises = pools.map((pair) => getPairLiquidity(pair)); - const poolAmountPromises = pools.map((pair) => duckDb.getLatestLpPoolAmount(pair.pairAddr)); - - const [allLiquidities, allPoolAmounts] = await Promise.all([ - Promise.all(liquidityPromises), - Promise.all(poolAmountPromises) - ]); + const volumes = await getAllVolume24h(); + const allFee7Days = await getAllFees(); + const pools = await duckDb.getPools(); + const allPoolApr = await duckDb.getAllAprs(); + const allLiquidities = await getPoolLiquidities(pools); + const allPoolAmounts = await getPoolAmounts(pools); const allPoolInfoResponse: PairInfoDataResponse[] = pools.map((pool, index) => { const poolApr = allPoolApr.find((item) => item.pairAddr === pool.pairAddr); @@ -309,11 +298,9 @@ app.get("/v1/pool-detail", async (req: Request<{}, {}, {}, GetPoolDetailQuery>, const currentDate = new Date(); const oneDayBeforeNow = getSpecificDateBeforeNow(new Date(), tf); const twoDayBeforeNow = getSpecificDateBeforeNow(new Date(), tf * 2); - const [poolVolume, poolVolumeOnedayBefore, pool] = await Promise.all([ - getVolumePairByUsdt(pair.asset_infos, oneDayBeforeNow, currentDate), - getVolumePairByUsdt(pair.asset_infos, twoDayBeforeNow, oneDayBeforeNow), - duckDb.getPoolByAssetInfos(pair.asset_infos) - ]); + const poolVolume = await getVolumePairByUsdt(pair.asset_infos, oneDayBeforeNow, currentDate); + const poolVolumeOnedayBefore = await getVolumePairByUsdt(pair.asset_infos, twoDayBeforeNow, oneDayBeforeNow); + const pool = await duckDb.getPoolByAssetInfos(pair.asset_infos); let percentVolumeChange = 0; if (poolVolumeOnedayBefore !== 0n) { @@ -347,12 +334,9 @@ app.get("/orai-info", async (req, res) => { const dateBeforeNow = getSpecificDateBeforeNow(new Date(), tf); const oneDayBeforeNow = getSpecificDateBeforeNow(new Date(), SECONDS_PER_DAY); const timestamp = Math.round(dateBeforeNow.getTime() / 1000); - - const [volume24h, oraiPriceByTime, currenOraiPrice] = await Promise.all([ - getVolumePairByUsdt([oraiInfo, usdtInfo], oneDayBeforeNow, currentDate), - getOraiPrice(timestamp), - getOraiPrice() - ]); + const volume24h = await getVolumePairByUsdt([oraiInfo, usdtInfo], oneDayBeforeNow, currentDate); + const oraiPriceByTime = await getOraiPrice(timestamp); + const currenOraiPrice = await getOraiPrice(); let percentPriceChange = 0; if (oraiPriceByTime !== 0) { @@ -389,10 +373,8 @@ app.get("/price", async (req: Request<{}, {}, {}, GetPricePairQuery>, res) => { if (!pair) return res.status(400).send(`Not found pair with assets: ${req.query.base_denom}-${req.query.quote_denom}`); - const [baseAssetPriceByTime, currentBaseAssetPrice] = await Promise.all([ - getPriceByAsset(pair.asset_infos, "base_in_quote", timestamp), - getPriceByAsset(pair.asset_infos, "base_in_quote") - ]); + const baseAssetPriceByTime = await getPriceByAsset(pair.asset_infos, "base_in_quote", timestamp); + const currentBaseAssetPrice = await getPriceByAsset(pair.asset_infos, "base_in_quote"); let percentPriceChange = 0; if (baseAssetPriceByTime !== 0) { diff --git a/packages/oraidex-sync/src/db.ts b/packages/oraidex-sync/src/db.ts index baf71bbf..b2f9294a 100644 --- a/packages/oraidex-sync/src/db.ts +++ b/packages/oraidex-sync/src/db.ts @@ -168,36 +168,6 @@ export class DuckDb { return volumeData; } - async queryAllVolume(offerDenom: string, askDenom: string): Promise { - const modifiedOfferDenom = replaceAllNonAlphaBetChar(offerDenom); - const modifiedAskDenom = replaceAllNonAlphaBetChar(askDenom); - const volume = ( - await Promise.all([ - this.conn.all( - `SELECT sum(offerAmount) as ${modifiedOfferDenom}, sum(returnAmount) as ${modifiedAskDenom} - from swap_ops_data - where offerDenom = ? - and askDenom = ?`, - offerDenom, - askDenom - ), - this.conn.all( - `SELECT sum(offerAmount) as ${modifiedAskDenom}, sum(returnAmount) as ${modifiedOfferDenom} - from swap_ops_data - where offerDenom = ? - and askDenom = ?`, - askDenom, - offerDenom - ) - ]) - ).flat(); - return { - offerDenom, - askDenom, - volume: this.reduceVolume(volume, { offerDenom, modifiedOfferDenom, askDenom, modifiedAskDenom }) - }; - } - async queryAllVolumeRange( offerDenom: string, // eg: orai askDenom: string, // usdt @@ -207,34 +177,32 @@ export class DuckDb { // need to replace because the denom can contain numbers and other figures. We replace for temporary only, will be reverted once finish reducing const modifiedOfferDenom = replaceAllNonAlphaBetChar(offerDenom); const modifiedAskDenom = replaceAllNonAlphaBetChar(askDenom); - const volume = ( - await Promise.all([ - this.conn.all( - `SELECT sum(offerAmount) as ${modifiedOfferDenom}, sum(returnAmount) as ${modifiedAskDenom} - from swap_ops_data - where offerDenom = ? - and askDenom = ? - and timestamp >= ? - and timestamp <= ?`, - offerDenom, - askDenom, - startTime, - endTime - ), - this.conn.all( - `SELECT sum(offerAmount) as ${modifiedAskDenom}, sum(returnAmount) as ${modifiedOfferDenom} - from swap_ops_data - where offerDenom = ? - and askDenom = ? - and timestamp >= ? - and timestamp <= ?`, - askDenom, - offerDenom, - startTime, - endTime - ) - ]) - ).flat(); + const volumeByOfferDenom = await this.conn.all( + `SELECT sum(offerAmount) as ${modifiedOfferDenom}, sum(returnAmount) as ${modifiedAskDenom} + from swap_ops_data + where offerDenom = ? + and askDenom = ? + and timestamp >= ? + and timestamp <= ?`, + offerDenom, + askDenom, + startTime, + endTime + ); + const volumeByAskDenom = await this.conn.all( + `SELECT sum(offerAmount) as ${modifiedAskDenom}, sum(returnAmount) as ${modifiedOfferDenom} + from swap_ops_data + where offerDenom = ? + and askDenom = ? + and timestamp >= ? + and timestamp <= ?`, + askDenom, + offerDenom, + startTime, + endTime + ); + const volume = [volumeByOfferDenom, volumeByAskDenom].flat(); + return { offerDenom, askDenom, @@ -394,9 +362,8 @@ export class DuckDb { async getFeeSwap(payload: GetFeeSwap): Promise<[number, number]> { const { offerDenom, askDenom, startTime, endTime } = payload; - const [feeRightDirection, feeReverseDirection] = await Promise.all([ - this.conn.all( - ` + const feeRightDirection = await this.conn.all( + ` SELECT sum(commissionAmount + taxAmount) as totalFee, FROM swap_ops_data @@ -405,13 +372,14 @@ export class DuckDb { AND offerDenom = ? AND askDenom = ? `, - startTime, - endTime, - offerDenom, - askDenom - ), - this.conn.all( - ` + startTime, + endTime, + offerDenom, + askDenom + ); + + const feeReverseDirection = await this.conn.all( + ` SELECT sum(commissionAmount + taxAmount) as totalFee, FROM swap_ops_data @@ -420,12 +388,11 @@ export class DuckDb { AND offerDenom = ? AND askDenom = ? `, - startTime, - endTime, - askDenom, - offerDenom - ) - ]); + startTime, + endTime, + askDenom, + offerDenom + ); return [feeRightDirection[0]?.totalFee, feeReverseDirection[0]?.totalFee]; } diff --git a/packages/oraidex-sync/src/helper.ts b/packages/oraidex-sync/src/helper.ts index 3e1f6bd1..cfccb674 100644 --- a/packages/oraidex-sync/src/helper.ts +++ b/packages/oraidex-sync/src/helper.ts @@ -374,15 +374,17 @@ async function getAllVolume24h(): Promise { const tf = 24 * 60 * 60; // second of 24h const currentDate = new Date(); const oneDayBeforeNow = getSpecificDateBeforeNow(new Date(), tf); - const allVolumes = await Promise.all( - pairs.map((pair) => getVolumePairByUsdt(pair.asset_infos, oneDayBeforeNow, currentDate)) - ); - return pairs.map((pair, index) => { - return { - assetInfos: pair.asset_infos, - volume: allVolumes[index] - }; - }); + + const poolVolumes = []; + for (const { asset_infos } of pairs) { + const volume = await getVolumePairByUsdt(asset_infos, oneDayBeforeNow, currentDate); + poolVolumes.push({ + assetInfos: asset_infos, + volume + }); + } + + return poolVolumes; } // ===== end get volume pairs =====> @@ -401,10 +403,8 @@ export const getFeeSwapInUsdt = async ( endTime: convertDateToSecond(endTime) }); - const [baseAssetPrice, quoteAssetPrice] = await Promise.all([ - getPriceAssetByUsdt(baseAsset), - getPriceAssetByUsdt(quoteAsset) - ]); + const baseAssetPrice = await getPriceAssetByUsdt(baseAsset); + const quoteAssetPrice = await getPriceAssetByUsdt(quoteAsset); const totalFeeInUsdt = baseAssetPrice * feeInBaseAsset + quoteAssetPrice * feeInQuoteAsset; return BigInt(Math.trunc(totalFeeInUsdt)); @@ -416,15 +416,14 @@ export const getFeePair = async ( endTime: Date ): Promise => { const duckDb = DuckDb.instances; - const [swapFee, liquidityFee] = await Promise.all([ - getFeeSwapInUsdt(asset_infos, startTime, endTime), - duckDb.getFeeLiquidity({ - offerDenom: parseAssetInfoOnlyDenom(asset_infos[0]), - askDenom: parseAssetInfoOnlyDenom(asset_infos[1]), - startTime: convertDateToSecond(startTime), - endTime: convertDateToSecond(endTime) - }) - ]); + + const swapFee = await getFeeSwapInUsdt(asset_infos, startTime, endTime); + const liquidityFee = await duckDb.getFeeLiquidity({ + offerDenom: parseAssetInfoOnlyDenom(asset_infos[0]), + askDenom: parseAssetInfoOnlyDenom(asset_infos[1]), + startTime: convertDateToSecond(startTime), + endTime: convertDateToSecond(endTime) + }); return swapFee + liquidityFee; }; @@ -436,13 +435,17 @@ async function getAllFees(): Promise { const tf = 7 * 24 * 60 * 60; // second of 7 days const currentDate = new Date(); const oneWeekBeforeNow = getSpecificDateBeforeNow(new Date(), tf); - const allFees = await Promise.all(pairs.map((pair) => getFeePair(pair.asset_infos, oneWeekBeforeNow, currentDate))); - return pairs.map((pair, index) => { - return { - assetInfos: pair.asset_infos, - fee: allFees[index] - }; - }); + + const poolFees = []; + for (const { asset_infos } of pairs) { + const fee = await getFeePair(asset_infos, oneWeekBeforeNow, currentDate); + poolFees.push({ + assetInfos: asset_infos, + fee + }); + } + + return poolFees; } // ==== end get fee pair ====> diff --git a/packages/oraidex-sync/src/index.ts b/packages/oraidex-sync/src/index.ts index ea81ec4c..f2f0542d 100644 --- a/packages/oraidex-sync/src/index.ts +++ b/packages/oraidex-sync/src/index.ts @@ -1,14 +1,16 @@ import { SyncData, Txs, WriteData } from "@oraichain/cosmos-rpc-sync"; import "dotenv/config"; import { DuckDb } from "./db"; -import { - concatAprHistoryToUniqueKey, - concatLpHistoryToUniqueKey, - getPairLiquidity, - getSymbolFromAsset -} from "./helper"; +import { concatAprHistoryToUniqueKey, concatLpHistoryToUniqueKey, getSymbolFromAsset } from "./helper"; import { parseAssetInfo, parsePoolAmount } from "./parse"; -import { fetchAprResult, getAllPairInfos, getPairByAssetInfos, getPoolInfos, handleEventApr } from "./pool-helper"; +import { + fetchAprResult, + getAllPairInfos, + getPairByAssetInfos, + getPoolInfos, + getPoolLiquidities, + handleEventApr +} from "./pool-helper"; import { parseTxs } from "./tx-parsing"; import { Env, PairInfoData, PoolAmountHistory, PoolApr, TxAnlysisResult } from "./types"; @@ -18,11 +20,13 @@ class WriteOrders extends WriteData { } private async insertParsedTxs(txs: TxAnlysisResult) { - await this.duckDb.insertSwapOps(txs.swapOpsData); - await this.duckDb.insertLpOps([...txs.provideLiquidityOpsData, ...txs.withdrawLiquidityOpsData]); - await this.duckDb.insertOhlcv(txs.ohlcv); - await this.duckDb.insertEarningHistories(txs.claimOpsData); - await this.duckDb.insertPoolAmountHistory(txs.poolAmountHistories); + await Promise.all([ + this.duckDb.insertSwapOps(txs.swapOpsData), + this.duckDb.insertLpOps([...txs.provideLiquidityOpsData, ...txs.withdrawLiquidityOpsData]), + this.duckDb.insertOhlcv(txs.ohlcv), + this.duckDb.insertEarningHistories(txs.claimOpsData), + this.duckDb.insertPoolAmountHistory(txs.poolAmountHistories) + ]); } async process(chunk: any): Promise { @@ -128,10 +132,8 @@ class OraiDexSync { private async updateLatestPoolApr(height: number) { const pools = await this.duckDb.getPools(); - const allLiquidities = (await Promise.allSettled(pools.map((pair) => getPairLiquidity(pair)))).map((result) => { - if (result.status === "fulfilled") return result.value; - else console.error("error get allLiquidities: ", result.reason); - }); + const allLiquidities = await getPoolLiquidities(pools); + const { allAprs, allTotalSupplies, allBondAmounts, allRewardPerSec } = await fetchAprResult(pools, allLiquidities); const poolAprs = allAprs.map((apr, index) => { diff --git a/packages/oraidex-sync/src/pool-helper.ts b/packages/oraidex-sync/src/pool-helper.ts index 8fb257fd..f7d6dcd7 100644 --- a/packages/oraidex-sync/src/pool-helper.ts +++ b/packages/oraidex-sync/src/pool-helper.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, MulticallQueryClient } from "@oraichain/common-contracts-sdk"; +import { MulticallQueryClient } from "@oraichain/common-contracts-sdk"; import { Tx } from "@oraichain/cosmos-rpc-sync"; import { Asset, @@ -34,6 +34,7 @@ import { PairInfoData, PairMapping, PoolAmountHistory, + PoolApr, ProvideLiquidityOperationData, SwapOperationData, WithdrawLiquidityOperationData @@ -289,18 +290,60 @@ export const getAllPairInfos = async (): Promise => { return queryAllPairInfos(firstFactoryClient, secondFactoryClient); }; +export const getPoolLiquidities = async (pools: PairInfoData[]): Promise => { + const allLiquidities: number[] = []; + for (const pool of pools) { + const liquidity = await getPairLiquidity(pool); + allLiquidities.push(liquidity); + } + return allLiquidities; +}; + +export const getPoolAmounts = async (pools: PairInfoData[]): Promise => { + const duckDb = DuckDb.instances; + const allPoolAmounts: PoolAmountHistory[] = []; + + for (const pool of pools) { + const poolAmount = await duckDb.getLatestLpPoolAmount(pool.pairAddr); + allPoolAmounts.push(poolAmount); + } + return allPoolAmounts; +}; + +export const getAllPoolByAssetInfos = async (assetInfos: [AssetInfo, AssetInfo][]): Promise => { + const duckDb = DuckDb.instances; + const pools: PairInfoData[] = []; + + for (const assetInfo of assetInfos) { + const pool = await duckDb.getPoolByAssetInfos(assetInfo); + pools.push(pool); + } + return pools; +}; + +export const getLatestPoolAprs = async (pools: PairInfoData[]): Promise => { + const duckDb = DuckDb.instances; + const latestPoolAprs: PoolApr[] = []; + for (const pool of pools) { + const poolApr = await duckDb.getLatestPoolApr(pool.pairAddr); + latestPoolAprs.push(poolApr); + } + return latestPoolAprs; +}; + export const triggerCalculateApr = async (assetInfos: [AssetInfo, AssetInfo][], newOffset: number) => { // get all infos relate to apr in duckdb from apr table -> call to calculateAprResult if (assetInfos.length === 0) return; const duckDb = DuckDb.instances; - const pools = await Promise.all(assetInfos.map((infos) => duckDb.getPoolByAssetInfos(infos))); - const allLiquidities = (await Promise.allSettled(pools.map((pair) => getPairLiquidity(pair)))).map((result) => { - if (result.status === "fulfilled") return result.value; - else console.error("error get allLiquidities: ", result.reason); - }); + const pools = await getAllPoolByAssetInfos(assetInfos); + const allLiquidities = await getPoolLiquidities(pools); + const poolAprInfos = []; + for (const pool of pools) { + const aprInfo = await duckDb.getLatestPoolApr(pool.pairAddr); + poolAprInfos.push(aprInfo); + } - const poolAprInfos = await Promise.all(pools.map((pool) => duckDb.getLatestPoolApr(pool.pairAddr))); const allTotalSupplies = poolAprInfos.map((item) => item.totalSupply); const allBondAmounts = poolAprInfos.map((info) => info.totalBondAmount); const allRewardPerSecs = poolAprInfos.map((info) => (info.rewardPerSec ? JSON.parse(info.rewardPerSec) : null)); @@ -333,7 +376,7 @@ export const refetchInfoApr = async ( ) => { if (assetInfos.length === 0) return; const duckDb = DuckDb.instances; - const pools = await Promise.all(assetInfos.map((assetInfo) => duckDb.getPoolByAssetInfos(assetInfo))); + const pools = await getAllPoolByAssetInfos(assetInfos); const stakingAssetInfo = pools.map((pair) => pair.liquidityAddr); let newInfos; switch (type) { @@ -353,7 +396,7 @@ export const refetchInfoApr = async ( break; } - const latestPoolAprs = await Promise.all(pools.map((pool) => duckDb.getLatestPoolApr(pool.pairAddr))); + const latestPoolAprs = await getLatestPoolAprs(pools); const newPoolAprs = latestPoolAprs.map((poolApr, index) => { return { ...poolApr, @@ -431,11 +474,9 @@ export const handleEventApr = async ( assetInfosTriggerRewardPerSec } = await getListAssetInfoShouldRefetchApr(txs, result); - await Promise.allSettled([ - refetchInfoApr("totalSupply", assetInfosTriggerTotalSupplies, newOffset), - refetchInfoApr("rewardPerSec", assetInfosTriggerRewardPerSec, newOffset), - refetchInfoApr("totalBondAmount", assetInfosTriggerTotalBond, newOffset) - ]); + await refetchInfoApr("totalSupply", assetInfosTriggerTotalSupplies, newOffset); + await refetchInfoApr("rewardPerSec", assetInfosTriggerRewardPerSec, newOffset); + await refetchInfoApr("totalBondAmount", assetInfosTriggerTotalBond, newOffset); // after refetchInfoApr above, we updated infos can impact to APR: totalSupply, rewardPerSec, totalBondAmount // so we re-calculate APR and accumulate to pool_apr table. diff --git a/packages/oraidex-sync/tests/db.spec.ts b/packages/oraidex-sync/tests/db.spec.ts index 47b29422..5faf6a28 100644 --- a/packages/oraidex-sync/tests/db.spec.ts +++ b/packages/oraidex-sync/tests/db.spec.ts @@ -5,84 +5,6 @@ describe("test-duckdb", () => { let duckDb: DuckDb; afterEach(jest.restoreAllMocks); - it.each<[string[], number[]]>([ - [ - ["orai", "atom"], - [121, 10012] - ], - [ - ["atom", "orai"], - [10012, 121] - ] - ])( - "test-duckdb-queryAllVolume-should-return-correct-total-volume-given-%s-should-have-%d", - async (denoms, expectedVolumes) => { - duckDb = await DuckDb.create(":memory:"); - await Promise.all([duckDb.createHeightSnapshot(), duckDb.createLiquidityOpsTable(), duckDb.createSwapOpsTable()]); - await duckDb.insertSwapOps([ - { - askDenom: "orai", - commissionAmount: 0, - direction: "Buy", - offerAmount: 10000, - offerDenom: "atom", - uniqueKey: "1", - returnAmount: 100, - spreadAmount: 0, - taxAmount: 0, - timestamp: 168961006800 / 1000, - txhash: "foo", - txheight: 1 - }, - { - askDenom: "orai", - commissionAmount: 0, - direction: "Buy", - offerAmount: 10, - offerDenom: "atom", - uniqueKey: "2", - returnAmount: 1, - spreadAmount: 0, - taxAmount: 0, - timestamp: 1589610068000 / 1000, - txhash: "foo", - txheight: 1 - }, - { - askDenom: "atom", - commissionAmount: 0, - direction: "Sell", - offerAmount: 10, - offerDenom: "orai", - uniqueKey: "3", - returnAmount: 1, - spreadAmount: 0, - taxAmount: 0, - timestamp: 1589610068000 / 1000, - txhash: "foo", - txheight: 1 - }, - { - askDenom: "atom", - commissionAmount: 0, - direction: "Sell", - offerAmount: 10, - offerDenom: "orai", - uniqueKey: "4", - returnAmount: 1, - spreadAmount: 0, - taxAmount: 0, - timestamp: 1589610068000 / 1000, - txhash: "foo", - txheight: 1 - } - ]); - let queryResult = await duckDb.queryAllVolume(denoms[0], denoms[1]); - expect(queryResult.volume[denoms[0]]).toEqual(expectedVolumes[0]); - expect(queryResult.volume[denoms[1]]).toEqual(expectedVolumes[1]); - } - ); - it("test-query-volume-last-24h", async () => { duckDb = await DuckDb.create(":memory:"); await Promise.all([duckDb.createHeightSnapshot(), duckDb.createLiquidityOpsTable(), duckDb.createSwapOpsTable()]);