Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter out 0 liquidity assets and order by market cap #8175

Merged
merged 9 commits into from
Nov 28, 2024
Merged

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

55 changes: 47 additions & 8 deletions scripts/generateAssetData/color-map.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChainId } from '@shapeshiftoss/caip'
import { ASSET_NAMESPACE, bscChainId, toAssetId } from '@shapeshiftoss/caip'
import { ASSET_NAMESPACE, bscChainId, isNft, toAssetId } from '@shapeshiftoss/caip'
import { isEvmChainId } from '@shapeshiftoss/chain-adapters'
import type { Asset } from '@shapeshiftoss/types'
import type { MinimalAsset } from '@shapeshiftoss/utils'
Expand All @@ -9,7 +9,7 @@ import { useMemo } from 'react'
import { ALCHEMY_SUPPORTED_CHAIN_IDS } from 'lib/alchemySdkInstance'
import { isSome } from 'lib/utils'
import {
selectAssetsSortedByName,
selectAssetsSortedByMarketCapUserCurrencyBalanceCryptoPrecisionAndName,
selectPortfolioUserCurrencyBalances,
selectWalletConnectedChainIds,
} from 'state/slices/common-selectors'
Expand Down Expand Up @@ -39,7 +39,9 @@ export const SearchTermAssetList = ({
onAssetClick: handleAssetClick,
onImportClick,
}: SearchTermAssetListProps) => {
const assets = useAppSelector(selectAssetsSortedByName)
const assets = useAppSelector(
selectAssetsSortedByMarketCapUserCurrencyBalanceCryptoPrecisionAndName,
)
const portfolioUserCurrencyBalances = useAppSelector(selectPortfolioUserCurrencyBalances)
const assetsById = useAppSelector(selectAssets)
const walletConnectedChainIds = useAppSelector(selectWalletConnectedChainIds)
Expand All @@ -62,13 +64,15 @@ export const SearchTermAssetList = ({
const _assets = assetFilterPredicate ? assets.filter(assetFilterPredicate) : assets
if (activeChainId === 'All') {
if (allowWalletUnsupportedAssets) return _assets
return _assets.filter(asset => walletConnectedChainIds.includes(asset.chainId))
return _assets.filter(
asset => walletConnectedChainIds.includes(asset.chainId) && !isNft(asset.assetId),
)
}

// Should never happen, but paranoia.
if (!allowWalletUnsupportedAssets && !walletConnectedChainIds.includes(activeChainId)) return []

return _assets.filter(asset => asset.chainId === activeChainId)
return _assets.filter(asset => asset.chainId === activeChainId && !isNft(asset.assetId))
}, [
activeChainId,
allowWalletUnsupportedAssets,
Expand Down
7,046 changes: 3,874 additions & 3,172 deletions src/lib/asset-service/service/generatedAssetData.json

Large diffs are not rendered by default.

41 changes: 22 additions & 19 deletions src/lib/asset-service/service/relatedAssetIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@
"eip155:1/erc20:0x0bf43350076f95e0d16120b4d6bdfa1c9d50bdbd": [],
"eip155:1/erc20:0x0c4a68cf6857cc76fe946d04fe85fac5fae9625e": [],
"eip155:1/erc20:0x0bbcefa5f3630cae34842cb9d9b36bc0d4257a0d": [
"eip155:8453/erc20:0x3c3860d89b81c91974fc1f8a41aeeef604c17058",
"eip155:1/erc20:0x0bbcefa5f3630cae34842cb9d9b36bc0d4257a0d"
"eip155:137/erc20:0x8ad3d3e6b1b7b65138bd508e48330b544539b2c3",
"eip155:8453/erc20:0x3c3860d89b81c91974fc1f8a41aeeef604c17058"
],
"eip155:1/erc20:0x0b6f3ea2814f3fff804ba5d5c237aebbc364fba9": [
"eip155:56/bep20:0x0b6f3ea2814f3fff804ba5d5c237aebbc364fba9",
Expand Down Expand Up @@ -1277,7 +1277,7 @@
],
"eip155:1/erc20:0x1e4746dc744503b53b4a082cb3607b169a289090": [
"eip155:42161/erc20:0x34229b3f16fbcdfa8d8d9d17c0852f9496f4c7bb",
"eip155:1/erc20:0x1e4746dc744503b53b4a082cb3607b169a289090"
"eip155:8453/erc20:0xbd4e5c2f8de5065993d29a9794e2b7cefc41437a"
],
"eip155:1/erc20:0x19efa7d0fc88ffe461d1091f8cbe56dc2708a84f": [],
"eip155:1/erc20:0x1c98b54d673c026c8286badca3e840aaf72931a3": [
Expand Down Expand Up @@ -1481,9 +1481,9 @@
"eip155:1/erc20:0x20d60c6eb195868d4643f2c9b0809e4de6cc003d"
],
"eip155:1/erc20:0x21bfbda47a0b4b5b1248c767ee49f7caa9b23697": [
"eip155:8453/erc20:0x27e3bc3a66e24cad043ac3d93a12a8070e3897ba",
"eip155:56/bep20:0x7e35d0e9180bf3a1fc47b0d110be7a21a10b41fe",
"eip155:137/erc20:0x1631244689ec1fecbdd22fb5916e920dfc9b8d30",
"eip155:1/erc20:0x21bfbda47a0b4b5b1248c767ee49f7caa9b23697"
"eip155:137/erc20:0x1631244689ec1fecbdd22fb5916e920dfc9b8d30"
],
"eip155:1/erc20:0x21413c119b0c11c5d96ae1bd328917bc5c8ed67e": [
"eip155:42161/erc20:0x59a729658e9245b0cf1f8cb9fb37945d2b06ea27",
Expand Down Expand Up @@ -4099,7 +4099,7 @@
"eip155:42161/erc20:0x93b346b6bc2548da6a1e7d98e9a421b42541425b",
"eip155:10/erc20:0xc40f949f8a4e094d1b49a23ea9241d289b7b2819",
"eip155:137/erc20:0x23001f892c0c82b79303edc9b9033cd190bb21c7",
"eip155:1/erc20:0x5f98805a4e8be255a32880fdec7f6728c6568ba0"
"eip155:8453/erc20:0x368181499736d0c0cc614dbb145e2ec1ac86b8c6"
],
"eip155:1/erc20:0x60e254e35dd712394b3aba7a1d19114732e143dd": [],
"eip155:1/erc20:0x5ebffc53c3b8a71120789a211f9b91c79c78d1e0": [],
Expand Down Expand Up @@ -10556,7 +10556,10 @@
"eip155:1/erc20:0xf9a467d10fc76b2f20b4f8e2d88b1ad7dc278d4f": [],
"eip155:1/erc20:0xfa816739edaac4ebf329219d4ef575085cc28037": [],
"eip155:1/erc20:0xfcc5c47be19d06bf83eb04298b026f81069ff65b": [],
"eip155:1/erc20:0xfa2629b9cf3998d52726994e0fcdb750224d8b9d": [],
"eip155:1/erc20:0xfa2629b9cf3998d52726994e0fcdb750224d8b9d": [
"eip155:56/bep20:0x5a32d48411387577c26a15775cf939494da8064a",
"eip155:1/erc20:0xfa2629b9cf3998d52726994e0fcdb750224d8b9d"
],
"eip155:1/erc20:0xfda70e9a74837d647805e5576026db88744457d1": [],
"eip155:1/erc20:0xfad44dc24d07ef9be576d562b994f19578d441b8": [],
"eip155:1/erc20:0xfbcb5cbedeebcc55dcd136d34db1daaf74cf67e8": [],
Expand Down Expand Up @@ -27591,9 +27594,9 @@
"eip155:56/bep20:0x640bb7b0716a3c58b29f83a10e0b4b51580693d3"
],
"eip155:1/erc20:0x004e9c3ef86bc1ca1f0bb5c7662861ee93350568": [
"eip155:56/bep20:0x6b2a01a5f79deb4c2f3c0eda7b01df456fbd726a",
"eip155:10/erc20:0x93919784c523f39cacaa98ee0a9d96c3f32b593e",
"eip155:42161/erc20:0x6b2a01a5f79deb4c2f3c0eda7b01df456fbd726a",
"eip155:56/bep20:0x6b2a01a5f79deb4c2f3c0eda7b01df456fbd726a"
"eip155:42161/erc20:0x6b2a01a5f79deb4c2f3c0eda7b01df456fbd726a"
],
"eip155:1/erc20:0x01aac2b594f7bdbec740f0f1aa22910ebb4b74ab": [
"eip155:8453/erc20:0x01aac2b594f7bdbec740f0f1aa22910ebb4b74ab",
Expand Down Expand Up @@ -27630,8 +27633,8 @@
"eip155:1/erc20:0x31ea904a7eca45122890deb8da3473a2081bc9d1"
],
"eip155:1/erc20:0x306fd3e7b169aa4ee19412323e1a5995b8c1a1f4": [
"eip155:56/bep20:0x306fd3e7b169aa4ee19412323e1a5995b8c1a1f4",
"eip155:1/erc20:0x306fd3e7b169aa4ee19412323e1a5995b8c1a1f4"
"eip155:42161/erc20:0x306fd3e7b169aa4ee19412323e1a5995b8c1a1f4",
"eip155:56/bep20:0x306fd3e7b169aa4ee19412323e1a5995b8c1a1f4"
],
"eip155:56/bep20:0x38f9bf9dce51833ec7f03c9dc218197999999999": [
"eip155:8453/erc20:0x38f9bf9dce51833ec7f03c9dc218197999999999",
Expand Down Expand Up @@ -28081,21 +28084,21 @@
"eip155:42170/slip44:60",
"eip155:8453/slip44:60"
],
"eip155:1/erc20:0x2b66aade1e9c062ff411bd47c44e0ad696d43bd9": [
"eip155:56/bep20:0x73a325103935b0b5e7aa3aca6dba74ad22f82b03",
"eip155:8453/erc20:0xd329f9a8589723357c36727a2d5e15974c835ccf",
"eip155:1/erc20:0x2b66aade1e9c062ff411bd47c44e0ad696d43bd9"
],
"eip155:1/erc20:0x2103e845c5e135493bb6c2a4f0b8651956ea8682": [
"eip155:56/bep20:0x23ae4fd8e7844cdbc97775496ebd0e8248656028",
"eip155:1/erc20:0x2103e845c5e135493bb6c2a4f0b8651956ea8682"
],
"eip155:1/erc20:0x607f451f850cb612a07b37b6315be23f55165610": [
"eip155:42161/erc20:0xa71e2738704e367798baa2755af5a10499634953",
"eip155:1/erc20:0x607f451f850cb612a07b37b6315be23f55165610"
"eip155:1/erc20:0x2b66aade1e9c062ff411bd47c44e0ad696d43bd9": [
"eip155:56/bep20:0x73a325103935b0b5e7aa3aca6dba74ad22f82b03",
"eip155:8453/erc20:0xd329f9a8589723357c36727a2d5e15974c835ccf",
"eip155:1/erc20:0x2b66aade1e9c062ff411bd47c44e0ad696d43bd9"
],
"eip155:1/erc20:0x74d1984a64f447371be4019920180b52a33adadd": [
"eip155:56/bep20:0xb2b446386633c6746b0a2735fb57edbb066c5878",
"eip155:1/erc20:0x74d1984a64f447371be4019920180b52a33adadd"
],
"eip155:8453/erc20:0x06a63c498ef95ad1fa4fff841955e512b4b2198a": [
"eip155:1/erc20:0x7a78c790250fef60ce7e8ef85557d67cc4216a52",
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:mMykZc4tun2kFNgxbd7WiApAoGEaX8bxFuHjxzjnkrV"
]
}
1 change: 1 addition & 0 deletions src/lib/portals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type TokenInfo = {
pricePerShare: string | undefined
platform: string
network: string
liquidity: number
metrics: {
apy?: string
volumeUsd1d?: string
Expand Down
6 changes: 5 additions & 1 deletion src/lib/portals/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ export const getPortalTokens = async (

const portalsTokens = await fetchPortalsTokens({ chainIds: [chainId], limit })
return portalsTokens
.map(token => portalTokenToAsset({ token, portalsPlatforms, chainId, nativeAsset }))
.map(token =>
token.liquidity > 0
? portalTokenToAsset({ token, portalsPlatforms, chainId, nativeAsset })
: undefined,
)
.filter(isSome)
}

Expand Down
1 change: 1 addition & 0 deletions src/pages/Markets/hooks/usePortalsAssetsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const usePortalsAssetsQuery = ({
})

if (!asset) return acc
if (!token.liquidity) return acc

// upsert fetched asset if doesn't exist in generatedAssetData.json
if (!assets[assetId]) {
Expand Down
1 change: 1 addition & 0 deletions src/state/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const clearAssetsMigrations = {
20: clearAssets,
21: clearAssets,
22: clearAssets,
23: clearAssets,
} as unknown as Omit<MigrationManifest, '_persist'>

export const clearMarketDataMigrations = {
Expand Down
32 changes: 32 additions & 0 deletions src/state/slices/common-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,38 @@ export const selectAssetsSortedByMarketCapUserCurrencyBalanceAndName =
},
)

export const selectAssetsSortedByMarketCapUserCurrencyBalanceCryptoPrecisionAndName =
createDeepEqualOutputSelector(
selectAssets,
selectPortfolioAssetBalancesBaseUnit,
selectPortfolioUserCurrencyBalances,
selectMarketDataUsd,
(assets, portfolioBalancesCryptoBaseUnit, portfolioBalancesUserCurrency, marketDataUsd) => {
const getAssetBalanceCryptoPrecision = (asset: Asset) =>
fromBaseUnit(bnOrZero(portfolioBalancesCryptoBaseUnit[asset.assetId]), asset.precision)

const getAssetUserCurrencyBalance = (asset: Asset) =>
bnOrZero(portfolioBalancesUserCurrency[asset.assetId]).toNumber()

// This looks weird but isn't - looks like we could use the sorted selectAssetsByMarketCap instead of selectAssets
// but we actually can't - this would rug the quadruple-sorting
const getAssetMarketCap = (asset: Asset) =>
bnOrZero(marketDataUsd[asset.assetId]?.marketCap).toNumber()
const getAssetName = (asset: Asset) => asset.name

return orderBy(
Object.values(assets).filter(isSome),
[
getAssetUserCurrencyBalance,
getAssetMarketCap,
getAssetBalanceCryptoPrecision,
getAssetName,
],
['desc', 'desc', 'desc', 'asc'],
)
},
)

export const selectAssetsSortedByName = createDeepEqualOutputSelector(selectAssets, assets => {
const getAssetName = (asset: Asset) => asset.name
return orderBy(Object.values(assets).filter(isSome), [getAssetName], ['asc'])
Expand Down
2 changes: 2 additions & 0 deletions src/state/slices/portfolioSlice/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ export const makeAssets = async ({

const maybePortalsAsset = maybePortalsAccounts[token.assetId]
if (maybePortalsAsset) {
if (!maybePortalsAsset.liquidity) return prev

const isPool = Boolean(maybePortalsAsset.platform && maybePortalsAsset.tokens?.length)
const platform = maybePortalsPlatforms[maybePortalsAsset.platform]

Expand Down