Skip to content

Commit

Permalink
check for nil response data in numia tokens endpoint (#3847)
Browse files Browse the repository at this point in the history
* check for nil response data

* check volume & price

* remove old token query

* fix index

* update type
  • Loading branch information
jonator authored Sep 18, 2024
1 parent 8956a00 commit c0894d0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 104 deletions.
4 changes: 2 additions & 2 deletions packages/server/src/queries/complex/assets/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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 =
Expand All @@ -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`
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/queries/data-services/token-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/stores/src/queries-external/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 0 additions & 7 deletions packages/stores/src/queries-external/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -35,7 +34,6 @@ export class QueriesExternalStore {
public readonly queryChainStatus: DeepReadonly<ObservableQueryIbcChainsStatus>;
public readonly queryMarketCaps: DeepReadonly<ObservableQueryMarketCaps>;
public readonly queryTokenHistoricalChart: DeepReadonly<ObservableQueryTokensHistoricalChart>;
public readonly queryTokenData: DeepReadonly<ObservableQueryTokensData>;
public readonly queryActiveGauges: DeepReadonly<ObservableQueryActiveGauges>;
public readonly queryICNSNames: DeepReadonly<ObservableQueryICNSNames>;
public readonly queryPositionsPerformaceMetrics: DeepReadonly<ObservableQueryPositionsPerformanceMetrics>;
Expand Down Expand Up @@ -90,11 +88,6 @@ export class QueriesExternalStore {
kvStore,
indexerDataBaseUrl
);
this.queryTokenData = new ObservableQueryTokensData(
kvStore,
priceStore,
timeseriesDataBaseUrl
);
this.queryActiveGauges = new ObservableQueryActiveGauges(
kvStore,
webApiBaseUrl,
Expand Down
74 changes: 0 additions & 74 deletions packages/stores/src/queries-external/token-data/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/stores/src/queries-external/token-data/types.ts

This file was deleted.

0 comments on commit c0894d0

Please sign in to comment.