diff --git a/packages/server/src/queries/complex/assets/market.ts b/packages/server/src/queries/complex/assets/market.ts index dcf5708c5e..336b6a1b7b 100644 --- a/packages/server/src/queries/complex/assets/market.ts +++ b/packages/server/src/queries/complex/assets/market.ts @@ -184,7 +184,8 @@ async function batchFetchCoingeckoCoins(keys: readonly string[]) { } const coingeckoCoinBatchLoader = new EdgeDataLoader(batchFetchCoingeckoCoins); -async function getActiveCoingeckoCoins() { +/** Set of active CoinGecko IDs that CoinGecko has data for (is "active"). */ +export async function getActiveCoingeckoCoins() { return await cachified({ cache: assetMarketCache, ttl: 1000 * 60 * 60, // 1 hour diff --git a/packages/web/pages/assets/[denom].tsx b/packages/web/pages/assets/[denom].tsx index 939efc5bd4..58e494d8fb 100644 --- a/packages/web/pages/assets/[denom].tsx +++ b/packages/web/pages/assets/[denom].tsx @@ -1,10 +1,13 @@ import { Dec } from "@keplr-wallet/unit"; import { CoingeckoCoin, + getActiveCoingeckoCoins, getAsset, + getAssetMarketActivity, getTokenInfo, queryCoingeckoCoin, RichTweet, + sort, TokenCMSData, Twitter, } from "@osmosis-labs/server"; @@ -560,23 +563,49 @@ const TokenChart = observer(() => { export default AssetInfoPage; +/** Number of assets, sorted by volume, to generate static paths for. */ +const TOP_VOLUME_ASSETS_COUNT = 50; + /** - * Prerender all the denoms, we can also filter this value to reduce - * build time + * Prerender important denoms. See function body for what we consider "important". */ export const getStaticPaths = async (): Promise => { let paths: { params: { denom: string } }[] = []; - const currencies = ChainList.map((info) => info.keplrChain.currencies).reduce( - (a, b) => [...a, ...b] + const assets = AssetLists.flatMap((list) => list.assets); + const activeCoinGeckoIds = await getActiveCoingeckoCoins(); + + const importantAssets = assets.filter( + (asset) => + asset.verified && + !asset.unstable && + !asset.preview && + // Prevent repeated "coin not found" errors from CoinGecko coin query downsteram + asset.coingeckoId && + activeCoinGeckoIds.has(asset.coingeckoId) ); + const marketAssets = ( + await Promise.all( + importantAssets.map((asset) => + getAssetMarketActivity(asset).then((activity) => ({ + ...activity, + ...asset, + })) + ) + ) + ).filter((asset): asset is NonNullable => asset !== undefined); + + const topVolumeAssets = sort(marketAssets, "volume7d").slice( + 0, + TOP_VOLUME_ASSETS_COUNT + ); /** * Add cache for all available currencies */ - paths = currencies.map((currency) => ({ + paths = topVolumeAssets.map((asset) => ({ params: { - denom: currency.coinDenom, + denom: asset.symbol, }, }));