Skip to content

Commit

Permalink
Merge pull request #4348 from CrocSwap/fix-token-price-inference-for-…
Browse files Browse the repository at this point in the history
…pool-stats

fix token price inference for pool stats
  • Loading branch information
benwolski authored Nov 18, 2024
2 parents bfbb636 + 6a2193b commit f81c2c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/App/hooks/useFetchPoolStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ const useFetchPoolStats = (
crocEnv,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedQuerySpotPrice,
tokens.allDefaultTokens,
enableTotalSupply,
);
Expand All @@ -358,9 +357,9 @@ const useFetchPoolStats = (
quoteTvl: currentPoolStats?.quoteTvl || 0,
quoteVolume: currentPoolStats?.quoteVolume24hAgo || 0,
feeRate: currentPoolStats?.feeRate || 0,
lastPriceIndic: currentPoolStats?.priceIndic24hAgo || 0,
lastPriceLiq: currentPoolStats?.priceLiq24hAgo || 0,
lastPriceSwap: currentPoolStats?.priceSwap24hAgo || 0,
lastPriceIndic: currentPoolStats?.lastPriceIndic || 0,
lastPriceLiq: currentPoolStats?.lastPriceLiq || 0,
lastPriceSwap: currentPoolStats?.lastPriceSwap || 0,
latestTime: currentPoolStats?.latestTime || 0,
isHistorical: true,
};
Expand All @@ -373,7 +372,6 @@ const useFetchPoolStats = (
crocEnv,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedQuerySpotPrice,
tokens.allDefaultTokens,
);

Expand All @@ -382,7 +380,7 @@ const useFetchPoolStats = (
const volumeChange24h = volumeTotalNow - volumeTotal24hAgo;

const nowPrice = localPoolPriceNonDisplay[1];
const ydayPrice = expandedPoolStats24hAgo?.lastPriceSwap;
const ydayPrice = currentPoolStats?.priceSwap24hAgo;

const priceChangeResult =
ydayPrice && nowPrice && ydayPrice > 0 && nowPrice > 0
Expand Down Expand Up @@ -429,6 +427,7 @@ const useFetchPoolStats = (
const volumeChange24hString = getFormattedNumber({
value: volumeChange24h,
});

setPoolVolume24h(volumeChange24hString);
}
if (feesChange24h) {
Expand Down
3 changes: 1 addition & 2 deletions src/ambient-utils/dataLayer/functions/getPoolStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { FetchContractDetailsFn, TokenPriceFn } from '../../api';
import { memoizeCacheQueryFn } from './memoizePromiseFn';
import { SinglePoolDataIF, TokenIF } from '../../types';
import { PoolQueryFn } from './querySpotPrice';
import { isETHorStakedEthToken } from '..';

const getLiquidityFee = async (
Expand Down Expand Up @@ -153,7 +152,6 @@ export async function expandPoolStats(
crocEnv: CrocEnv,
cachedFetchTokenPrice: TokenPriceFn,
cachedTokenDetails: FetchContractDetailsFn,
cachedQuerySpotPrice: PoolQueryFn,
tokenList: TokenIF[],
enableTotalSupply?: boolean,
): Promise<PoolStatsIF> {
Expand Down Expand Up @@ -233,6 +231,7 @@ export async function expandPoolStats(
: quoteUsdPrice
? quoteUsdPrice / displayPoolPrice
: 0.0;

const quotePrice = quoteUsdPrice
? quoteUsdPrice
: isETHorStakedEthToken(quote)
Expand Down
12 changes: 5 additions & 7 deletions src/contexts/ExploreContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ExploreContext = createContext<ExploreContextIF>(

export const ExploreContextProvider = (props: { children: ReactNode }) => {
const { activeNetwork } = useContext(AppStateContext);
const { cachedQuerySpotPrice, cachedFetchTokenPrice, cachedTokenDetails } =
const { cachedFetchTokenPrice, cachedTokenDetails } =
useContext(CachedDataContext);
const { crocEnv, provider } = useContext(CrocEnvContext);
const { tokens } = useContext(TokenContext);
Expand Down Expand Up @@ -163,7 +163,6 @@ export const ExploreContextProvider = (props: { children: ReactNode }) => {
crocEnv,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedQuerySpotPrice,
tokens.tokenUniv,
);

Expand All @@ -175,9 +174,9 @@ export const ExploreContextProvider = (props: { children: ReactNode }) => {
quoteTvl: poolStats?.quoteTvl || 0,
quoteVolume: poolStats?.quoteVolume24hAgo || 0,
feeRate: poolStats?.feeRate || 0,
lastPriceIndic: poolStats?.priceIndic24hAgo || 0,
lastPriceLiq: poolStats?.priceLiq24hAgo || 0,
lastPriceSwap: poolStats?.priceSwap24hAgo || 0,
lastPriceIndic: poolStats?.lastPriceIndic || 0,
lastPriceLiq: poolStats?.lastPriceLiq || 0,
lastPriceSwap: poolStats?.lastPriceSwap || 0,
latestTime: poolStats?.latestTime || 0,
isHistorical: false,
};
Expand All @@ -190,7 +189,6 @@ export const ExploreContextProvider = (props: { children: ReactNode }) => {
crocEnv,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedQuerySpotPrice,
tokens.tokenUniv,
);

Expand All @@ -200,7 +198,7 @@ export const ExploreContextProvider = (props: { children: ReactNode }) => {
const volumeChange24h = volumeTotalNow - volumeTotal24hAgo;

const nowPrice = expandedPoolStatsNow?.lastPriceSwap;
const ydayPrice = expandedPoolStats24hAgo?.lastPriceSwap;
const ydayPrice = poolStats?.priceSwap24hAgo;

const feesTotalNow = expandedPoolStatsNow?.feesTotalUsd;
const feesTotal24hAgo = expandedPoolStats24hAgo?.feesTotalUsd;
Expand Down

0 comments on commit f81c2c0

Please sign in to comment.