From c0894d05415d7996a6c322ab1810fa5bb72b0f0d Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Wed, 18 Sep 2024 16:37:21 -0400 Subject: [PATCH] check for nil response data in numia tokens endpoint (#3847) * check for nil response data * check volume & price * remove old token query * fix index * update type --- .../src/queries/complex/assets/market.ts | 4 +- .../complex/assets/price/providers/sidecar.ts | 14 +++- .../src/queries/data-services/token-data.ts | 4 +- packages/stores/src/queries-external/index.ts | 1 - packages/stores/src/queries-external/store.ts | 7 -- .../src/queries-external/token-data/index.ts | 74 ------------------- .../src/queries-external/token-data/types.ts | 14 ---- 7 files changed, 14 insertions(+), 104 deletions(-) delete mode 100644 packages/stores/src/queries-external/token-data/index.ts delete mode 100644 packages/stores/src/queries-external/token-data/types.ts diff --git a/packages/server/src/queries/complex/assets/market.ts b/packages/server/src/queries/complex/assets/market.ts index 57d162e80c..27c7a6cf5a 100644 --- a/packages/server/src/queries/complex/assets/market.ts +++ b/packages/server/src/queries/complex/assets/market.ts @@ -231,14 +231,14 @@ function makeMarketActivityFromTokenData(tokenData: TokenData) { : undefined, denom: tokenData.denom, symbol: tokenData.symbol, - liquidity: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.liquidity), + liquidity: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.liquidity ?? 0), liquidity24hChange: tokenData.liquidity_24h_change !== null ? new RatePretty( new Dec(tokenData.liquidity_24h_change).quo(new Dec(100)) ) : undefined, - volume24h: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.volume_24h), + volume24h: new PricePretty(DEFAULT_VS_CURRENCY, tokenData.volume_24h ?? 0), volume24hChange: tokenData.volume_24h_change !== null ? new RatePretty(new Dec(tokenData.volume_24h_change).quo(new Dec(100))) diff --git a/packages/server/src/queries/complex/assets/price/providers/sidecar.ts b/packages/server/src/queries/complex/assets/price/providers/sidecar.ts index 90c72c30b8..3d192ff395 100644 --- a/packages/server/src/queries/complex/assets/price/providers/sidecar.ts +++ b/packages/server/src/queries/complex/assets/price/providers/sidecar.ts @@ -1,5 +1,6 @@ import { Dec } from "@keplr-wallet/unit"; import { Asset } from "@osmosis-labs/types"; +import { isNil } from "@osmosis-labs/utils"; import cachified, { CacheEntry } from "cachified"; import { LRUCache } from "lru-cache"; @@ -30,8 +31,8 @@ function getBatchLoader() { ttl: 1000 * 60 * 10, // 10 minutes getFreshValue: () => new EdgeDataLoader( - (coinMinimalDenoms: readonly string[]) => { - return queryPrices(coinMinimalDenoms as string[]).then((priceMap) => + (coinMinimalDenoms: readonly string[]) => + queryPrices(coinMinimalDenoms as string[]).then((priceMap) => coinMinimalDenoms.map((baseCoinMinimalDenom) => { try { const price = @@ -40,6 +41,12 @@ function getBatchLoader() { // trim to 18 decimals to silence Dec warnings const p = price.replace(/(\.\d{18})\d*/, "$1"); + if (isNil(p)) { + return new Error( + `No SQS price result for ${baseCoinMinimalDenom} and USDC` + ); + } + if (new Dec(p).isZero()) return new Error( `No SQS price result for ${baseCoinMinimalDenom} and USDC` @@ -51,8 +58,7 @@ function getBatchLoader() { ); } }) - ); - }, + ), { // SQS imposes a limit on URI length from its Nginx configuration, so we impose a limit to avoid hitting that limit. maxBatchSize: 100, diff --git a/packages/server/src/queries/data-services/token-data.ts b/packages/server/src/queries/data-services/token-data.ts index b392ca36b5..3d24f816a0 100644 --- a/packages/server/src/queries/data-services/token-data.ts +++ b/packages/server/src/queries/data-services/token-data.ts @@ -7,9 +7,9 @@ export interface TokenData { denom: string; symbol: string; main: boolean; - liquidity: number; + liquidity: number | null; liquidity_24h_change: number | null; - volume_24h: number; + volume_24h: number | null; volume_24h_change: number | null; name: string; price_1h_change: number | null; diff --git a/packages/stores/src/queries-external/index.ts b/packages/stores/src/queries-external/index.ts index 9bd0f6ed26..8171d7551a 100644 --- a/packages/stores/src/queries-external/index.ts +++ b/packages/stores/src/queries-external/index.ts @@ -7,7 +7,6 @@ export * from "./pool-fees"; export * from "./pool-rewards"; export * from "./pools"; export * from "./store"; -export * from "./token-data"; export * from "./token-historical-chart"; export const IMPERATOR_TIMESERIES_DEFAULT_BASEURL = diff --git a/packages/stores/src/queries-external/store.ts b/packages/stores/src/queries-external/store.ts index 0b98c1b2d9..d6e022e0e6 100644 --- a/packages/stores/src/queries-external/store.ts +++ b/packages/stores/src/queries-external/store.ts @@ -24,7 +24,6 @@ import { ObservableQueryPoolAprs } from "./numia"; import { ObservableQueryPoolFeesMetrics } from "./pool-fees"; import { ObservableQueryAccountsPoolRewards } from "./pool-rewards"; import { ObservableQueryPositionsPerformanceMetrics } from "./position-performance"; -import { ObservableQueryTokensData } from "./token-data"; import { ObservableQueryTokensHistoricalChart } from "./token-historical-chart"; import { ObservableQueryMarketCap } from "./token-market-cap"; @@ -35,7 +34,6 @@ export class QueriesExternalStore { public readonly queryChainStatus: DeepReadonly; public readonly queryMarketCaps: DeepReadonly; public readonly queryTokenHistoricalChart: DeepReadonly; - public readonly queryTokenData: DeepReadonly; public readonly queryActiveGauges: DeepReadonly; public readonly queryICNSNames: DeepReadonly; public readonly queryPositionsPerformaceMetrics: DeepReadonly; @@ -90,11 +88,6 @@ export class QueriesExternalStore { kvStore, indexerDataBaseUrl ); - this.queryTokenData = new ObservableQueryTokensData( - kvStore, - priceStore, - timeseriesDataBaseUrl - ); this.queryActiveGauges = new ObservableQueryActiveGauges( kvStore, webApiBaseUrl, diff --git a/packages/stores/src/queries-external/token-data/index.ts b/packages/stores/src/queries-external/token-data/index.ts deleted file mode 100644 index 2babb0b4f7..0000000000 --- a/packages/stores/src/queries-external/token-data/index.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { KVStore } from "@keplr-wallet/common"; -import { Dec, PricePretty, RatePretty } from "@keplr-wallet/unit"; -import { HasMapStore } from "@osmosis-labs/keplr-stores"; -import { computed, makeObservable } from "mobx"; - -import { IPriceStore } from "../../price"; -import { IMPERATOR_TIMESERIES_DEFAULT_BASEURL } from ".."; -import { ObservableQueryExternalBase } from "../base"; -import { TokenData } from "./types"; - -/** Queries Imperator token history data chart. */ -export class ObservableQueryTokenData extends ObservableQueryExternalBase< - TokenData[] -> { - constructor( - kvStore: KVStore, - protected readonly priceStore: IPriceStore, - baseURL: string, - protected readonly denom: string - ) { - super(kvStore, baseURL, `/tokens/v2/${denom}`); - - makeObservable(this); - } - - protected canFetch(): boolean { - return Boolean(this.denom); - } - - @computed - get get24hrChange(): RatePretty | undefined { - if (!this.response) return undefined; - - try { - return new RatePretty( - new Dec(this.response.data[0].price_24h_change / 100) - ); - } catch { - return undefined; - } - } - - @computed - get price() { - const fiat = this.priceStore.getFiatCurrency( - this.priceStore.defaultVsCurrency - ); - - if (!this?.response?.data[0]?.price || !fiat) return undefined; - - return new PricePretty(fiat, new Dec(this.response.data[0].price)); - } -} - -export class ObservableQueryTokensData extends HasMapStore { - constructor( - kvStore: KVStore, - priceStore: IPriceStore, - timeseriesDataBaseUrl = IMPERATOR_TIMESERIES_DEFAULT_BASEURL - ) { - super((symbol: string) => { - return new ObservableQueryTokenData( - kvStore, - priceStore, - timeseriesDataBaseUrl, - symbol - ); - }); - } - - get(symbol: string) { - return super.get(symbol) as ObservableQueryTokenData; - } -} diff --git a/packages/stores/src/queries-external/token-data/types.ts b/packages/stores/src/queries-external/token-data/types.ts deleted file mode 100644 index 8127925057..0000000000 --- a/packages/stores/src/queries-external/token-data/types.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface TokenData { - price: number; - denom: string; - symbol: string; - main: boolean; - liquidity: number; - liquidity_24h_change: number; - volume_24h: number; - volume_24h_change: number; - name: string; - price_24h_change: number; - exponent: number; - display: string; -}