diff --git a/apps/cowswap-frontend/src/common/containers/CoWAmmBanner/types.ts b/apps/cowswap-frontend/src/common/containers/CoWAmmBanner/types.ts deleted file mode 100644 index 9e9b7a0fae..0000000000 --- a/apps/cowswap-frontend/src/common/containers/CoWAmmBanner/types.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { LpToken } from '@cowprotocol/common-const' -import { LpTokenProvider } from '@cowprotocol/types' -import { BigNumber } from '@ethersproject/bignumber' - -import { PoolInfo } from 'modules/yield/state/poolsInfoAtom' - -export interface TokenWithAlternative { - token: LpToken - alternative: LpToken - tokenBalance: BigNumber -} - -export interface TokenWithSuperiorAlternative extends TokenWithAlternative { - tokenPoolInfo: PoolInfo - alternativePoolInfo: PoolInfo -} - -export interface VampireAttackContext { - alternatives: TokenWithAlternative[] | null - superiorAlternatives: TokenWithSuperiorAlternative[] | null - cowAmmLpTokensCount: number - poolsAverageData: Partial | undefined> - averageApyDiff: number | undefined -} diff --git a/apps/cowswap-frontend/src/common/pure/CoWAmmBannerContent/index.tsx b/apps/cowswap-frontend/src/common/pure/CoWAmmBannerContent/index.tsx index bb0d9d3e08..e5dece358c 100644 --- a/apps/cowswap-frontend/src/common/pure/CoWAmmBannerContent/index.tsx +++ b/apps/cowswap-frontend/src/common/pure/CoWAmmBannerContent/index.tsx @@ -42,7 +42,7 @@ export function CoWAmmBannerContent({ }: CoWAmmBannerContentProps) { const isMobile = useMediaQuery(upToSmall) const arrowBackgroundRef = useRef(null) - const { superiorAlternatives, cowAmmLpTokensCount, averageApyDiff, poolsAverageData } = vampireAttackContext + const { superiorAlternatives, cowAmmLpTokensCount, averageAprDiff, poolsAverageData } = vampireAttackContext const handleCTAMouseEnter = useCallback(() => { if (arrowBackgroundRef.current) { @@ -59,9 +59,9 @@ export function CoWAmmBannerContent({ }, []) const firstItemWithBetterCowAmm = superiorAlternatives?.[0] - const isCowAmmAverageBetter = !!averageApyDiff && averageApyDiff > 0 - const betterAlternativeApyDiff = firstItemWithBetterCowAmm - ? firstItemWithBetterCowAmm.alternativePoolInfo.apy - firstItemWithBetterCowAmm.tokenPoolInfo.apy + const isCowAmmAverageBetter = !!averageAprDiff && averageAprDiff > 0 + const betterAlternativeAprDiff = firstItemWithBetterCowAmm + ? firstItemWithBetterCowAmm.alternativePoolInfo.apr - firstItemWithBetterCowAmm.tokenPoolInfo.apr : undefined const worseThanCoWAmmProviders = useMemo(() => { @@ -82,7 +82,7 @@ export function CoWAmmBannerContent({ if (!aVal || !bVal) return 0 - return bVal.apy - aVal.apy + return bVal - aVal }) as LpTokenProvider[] }, [poolsAverageData]) @@ -108,10 +108,10 @@ export function CoWAmmBannerContent({ minFontSize={isTokenSelectorView ? 35 : isMobile ? 40 : isCowAmmAverageBetter ? 60 : 80} maxFontSize={isTokenSelectorView ? 65 : isMobile ? 50 : isCowAmmAverageBetter ? 60 : 80} > - {firstItemWithBetterCowAmm && betterAlternativeApyDiff && betterAlternativeApyDiff > 0 - ? `+${betterAlternativeApyDiff.toFixed(1)}%` + {firstItemWithBetterCowAmm && betterAlternativeAprDiff && betterAlternativeAprDiff > 0 + ? `+${betterAlternativeAprDiff.toFixed(1)}%` : isCowAmmAverageBetter - ? `+${averageApyDiff}%` + ? `+${averageAprDiff}%` : `${cowAmmLpTokensCount}+`} diff --git a/apps/cowswap-frontend/src/modules/tokensList/containers/LpTokenPage/index.tsx b/apps/cowswap-frontend/src/modules/tokensList/containers/LpTokenPage/index.tsx index bd6e91f505..de0d16a6cc 100644 --- a/apps/cowswap-frontend/src/modules/tokensList/containers/LpTokenPage/index.tsx +++ b/apps/cowswap-frontend/src/modules/tokensList/containers/LpTokenPage/index.tsx @@ -86,7 +86,7 @@ export function LpTokenPage({ poolAddress, onBack, onDismiss, onSelectToken }: L
APR
- {renderValue(info?.apy, (t) => `${t}%`, '-')} + {renderValue(info?.apr, (t) => `${t}%`, '-')}
diff --git a/apps/cowswap-frontend/src/modules/tokensList/pure/LpTokenLists/index.tsx b/apps/cowswap-frontend/src/modules/tokensList/pure/LpTokenLists/index.tsx index c5faf698ba..2541f57aea 100644 --- a/apps/cowswap-frontend/src/modules/tokensList/pure/LpTokenLists/index.tsx +++ b/apps/cowswap-frontend/src/modules/tokensList/pure/LpTokenLists/index.tsx @@ -102,7 +102,7 @@ export function LpTokenLists({ onSelectToken(token)}> {commonContent} - + onSelectToken(token)}> {commonContent} {BalanceDisplay} - {info?.apy ? `${info.apy}%` : ''} + {info?.apr ? `${info.apr}%` : ''} diff --git a/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/elements.tsx b/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/elements.tsx index 7b4411d9a0..33b53433e1 100644 --- a/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/elements.tsx +++ b/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/elements.tsx @@ -16,7 +16,7 @@ export const CoWAmmGreenLogo = ( ) -export const CoWAmmInlineBanner = ({ token, apyDiff }: { token: LpToken | undefined; apyDiff: number | undefined }) => { +export const CoWAmmInlineBanner = ({ token, aprDiff }: { token: LpToken | undefined; aprDiff: number | undefined }) => { return ( Boost Your Yield with One-Click Conversion - {token && apyDiff && apyDiff > 0 ? ( + {token && aprDiff && aprDiff > 0 ? ( <> Convert your LP tokens into CoW AMM pools and earn up to{' '} - +{apyDiff.toFixed(1)}% more yield compared to . Or, swap + +{aprDiff.toFixed(1)}% more yield compared to . Or, swap ) : ( 'Swap' diff --git a/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/index.tsx b/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/index.tsx index 9ee5f5e376..500d1e44f8 100644 --- a/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/index.tsx +++ b/apps/cowswap-frontend/src/modules/yield/containers/YieldWidget/index.tsx @@ -98,8 +98,8 @@ export function YieldWidget() { }, [outputCurrency, poolsInfo]) const isOutputLpToken = Boolean(outputCurrency && outputCurrency instanceof LpToken) - const inputApy = inputPoolState?.info.apy - const outputApy = outputPoolState?.info.apy + const inputApy = inputPoolState?.info.apr + const outputApy = outputPoolState?.info.apr const isTradeContainAlternativePool = inputCurrency instanceof LpToken && @@ -167,9 +167,9 @@ export function YieldWidget() { const slots: TradeWidgetSlots = { topContent: vampireAttackContext ? ( - + ) : !account ? ( - + ) : null, selectTokenWidget: , settingsWidget: , diff --git a/apps/cowswap-frontend/src/modules/yield/hooks/useVampireAttack.ts b/apps/cowswap-frontend/src/modules/yield/hooks/useVampireAttack.ts index 5dbebadc9b..94fd9aed8a 100644 --- a/apps/cowswap-frontend/src/modules/yield/hooks/useVampireAttack.ts +++ b/apps/cowswap-frontend/src/modules/yield/hooks/useVampireAttack.ts @@ -17,14 +17,14 @@ export function useVampireAttackFirstTarget() { if (superiorAlternative) { return { target: superiorAlternative, - apyDiff: superiorAlternative.alternativePoolInfo.apy - superiorAlternative.tokenPoolInfo.apy, + aprDiff: superiorAlternative.alternativePoolInfo.apr - superiorAlternative.tokenPoolInfo.apr, } } if (alternative) { return { target: alternative, - apyDiff: undefined, + aprDiff: undefined, } } diff --git a/apps/cowswap-frontend/src/modules/yield/state/poolsInfoAtom.ts b/apps/cowswap-frontend/src/modules/yield/state/poolsInfoAtom.ts index 2c73bcc9f4..b26db81b85 100644 --- a/apps/cowswap-frontend/src/modules/yield/state/poolsInfoAtom.ts +++ b/apps/cowswap-frontend/src/modules/yield/state/poolsInfoAtom.ts @@ -6,7 +6,7 @@ import { SupportedChainId, mapSupportedNetworks } from '@cowprotocol/cow-sdk' import { walletInfoAtom } from '@cowprotocol/wallet' export interface PoolInfo { - apy: number + apr: number tvl: number feeTier: number volume24h: number diff --git a/apps/cowswap-frontend/src/modules/yield/types.ts b/apps/cowswap-frontend/src/modules/yield/types.ts index 0c0d2f61fe..ff80a9e4dc 100644 --- a/apps/cowswap-frontend/src/modules/yield/types.ts +++ b/apps/cowswap-frontend/src/modules/yield/types.ts @@ -19,6 +19,6 @@ export interface VampireAttackContext { alternatives: TokenWithAlternative[] | null superiorAlternatives: TokenWithSuperiorAlternative[] | null cowAmmLpTokensCount: number - poolsAverageData: Partial | undefined> - averageApyDiff: number | undefined + poolsAverageData: Partial | undefined> + averageAprDiff: number | undefined } diff --git a/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/index.tsx b/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/index.tsx index 78a0bf9ca1..023fc5ac56 100644 --- a/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/index.tsx +++ b/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/index.tsx @@ -1,28 +1,32 @@ import { useSetAtom } from 'jotai' import { useEffect, useMemo } from 'react' +import { BFF_BASE_URL, SWR_NO_REFRESH_OPTIONS } from '@cowprotocol/common-const' +import { useWalletInfo } from '@cowprotocol/wallet' + import ms from 'ms.macro' +import useSWR from 'swr' import { TradeType, useTradeTypeInfo } from 'modules/trade' -import { MOCK_POOL_INFO } from './mockPoolInfo' - import { useLpTokensWithBalances } from '../../hooks/useLpTokensWithBalances' import { usePoolsInfo } from '../../hooks/usePoolsInfo' -import { upsertPoolsInfoAtom } from '../../state/poolsInfoAtom' +import { PoolInfo, upsertPoolsInfoAtom } from '../../state/poolsInfoAtom' const POOL_INFO_CACHE_TIME = ms`1h` -/** - * The API should return info about requested pools + alternative COW AMM pools - * When tokenAddresses is null, it should return info about all pools - */ -function fetchPoolsInfo(tokenAddresses: string[] | null) { - console.log('TODO', tokenAddresses) - return Promise.resolve(MOCK_POOL_INFO) +interface PoolInfoDto { + apr: number + chain_id: number + contract_address: string + fee: number + project: string + tvl: number + volume: number } export function PoolsInfoUpdater() { + const { chainId } = useWalletInfo() const poolsInfo = usePoolsInfo() const upsertPoolsInfo = useSetAtom(upsertPoolsInfoAtom) const tradeTypeInfo = useTradeTypeInfo() @@ -42,13 +46,37 @@ export function PoolsInfoUpdater() { const tokensKey = useMemo(() => tokensToUpdate.join(','), [tokensToUpdate]) + const { data: poolsAverageData } = useSWR( + tokensKey || isYield ? [chainId, tokensToUpdate, 'getPoolsInfo'] : null, + async ([chainId, tokensToUpdate]) => { + const results: PoolInfoDto[] = await fetch(`${BFF_BASE_URL}/${chainId}/yield/pools`, { + method: 'post', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify(tokensToUpdate), + }).then((res) => res.json()) + + return results.reduce( + (acc, val) => { + acc[val.contract_address.toLowerCase()] = { + apr: +val.apr.toFixed(2), + tvl: +val.tvl.toFixed(2), + feeTier: val.fee, + volume24h: +val.volume.toFixed(2), + } + + return acc + }, + {} as Record, + ) + }, + SWR_NO_REFRESH_OPTIONS, + ) + useEffect(() => { - if (tokensToUpdate.length > 0 || isYield) { - fetchPoolsInfo(isYield ? null : tokensToUpdate).then(upsertPoolsInfo) - } - // To avoid excessive recalculations we use tokensKey instead of tokensToUpdate in deps - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isYield, tokensKey, upsertPoolsInfo]) + if (!poolsAverageData) return + + upsertPoolsInfo(poolsAverageData) + }, [poolsAverageData, upsertPoolsInfo]) return null } diff --git a/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/mockPoolInfo.ts b/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/mockPoolInfo.ts deleted file mode 100644 index e06ff6099e..0000000000 --- a/apps/cowswap-frontend/src/modules/yield/updaters/PoolsInfoUpdater/mockPoolInfo.ts +++ /dev/null @@ -1,216 +0,0 @@ -import { LpTokenProvider } from '@cowprotocol/types' - -import { PoolInfo } from '../../state/poolsInfoAtom' - -const MOCK_POOL_INFO_OVERRIDE = localStorage.getItem('MOCK_POOL_INFO') -const POOLS_AVERAGE_DATA_MOCK_OVERRIDE = localStorage.getItem('POOLS_AVERAGE_DATA_MOCK') - -export const MOCK_POOL_INFO: Record = MOCK_POOL_INFO_OVERRIDE - ? JSON.parse(MOCK_POOL_INFO_OVERRIDE) - : { - // COW AMM - '0xf706c50513446d709f08d3e5126cd74fb6bfda19': { - apy: 6.07, - tvl: 52972, - feeTier: 0.3, - volume24h: 10, - }, - '0xf8f5b88328dff3d19e5f4f11a9700293ac8f638f': { apy: 2.41, tvl: 4462967, feeTier: 0.3, volume24h: 226375 }, - '0x9bd702e05b9c97e4a4a3e47df1e0fe7a0c26d2f1': { apy: 2.37, tvl: 2767573, feeTier: 0.3, volume24h: 202029 }, - '0xdfee48c9df6d26c734296c0e6bd02401100a7217': { apy: 2.87, tvl: 4690794, feeTier: 0.3, volume24h: 120412 }, - '0x8ec257dc0b17b0c862d428c801fdcc8c382bf918': { apy: 2.94, tvl: 5483238, feeTier: 0.3, volume24h: 224116 }, - '0x3b124c8b4846836ba52df6cb6576ef66ca167dc1': { apy: 1.79, tvl: 210934, feeTier: 0.3, volume24h: 146902 }, - '0x41ff63c864097a7fbdf206fe676223e29f729fcb': { apy: 1.76, tvl: 4532413, feeTier: 0.3, volume24h: 209869 }, - '0x0c8ee93df5a4bad1c6f05e2676f87e6440b0b956': { apy: 2.77, tvl: 1043567, feeTier: 0.3, volume24h: 67002 }, - '0xfec04c31b6099ce76c4c5d6d754a34141884fd91': { apy: 1.62, tvl: 5533351, feeTier: 0.3, volume24h: 33251 }, - '0x96f8dfa1e922f88c313052d5357cc6a910e19c1e': { apy: 1.05, tvl: 1980623, feeTier: 0.3, volume24h: 193107 }, - '0x9fb7106c879fa48347796171982125a268ff0630': { apy: 2.9, tvl: 3377248, feeTier: 0.3, volume24h: 168811 }, - '0xb3d37552eebbbdbea36258ba0948f4bbcaa3584e': { apy: 1.92, tvl: 2229323, feeTier: 0.3, volume24h: 47080 }, - '0x9b8b93fc2a454f4f0f240aaf6644dbd77a528246': { apy: 1.45, tvl: 4685880, feeTier: 0.3, volume24h: 166951 }, - '0x42d9e44eed903a0ee477c9c04d1d1730c5e87272': { apy: 2.77, tvl: 3465509, feeTier: 0.3, volume24h: 132239 }, - '0x477a8982515e3a3d3aa6447b019b7c647e4162f8': { apy: 2.11, tvl: 2365870, feeTier: 0.3, volume24h: 122669 }, - '0xa7401066570960894a12b403f461cb61e8804b7b': { apy: 1.21, tvl: 5948103, feeTier: 0.3, volume24h: 184775 }, - '0xbf8868b754a77e90ea68ffc0b5b10a7c729457e1': { apy: 2.08, tvl: 5546198, feeTier: 0.3, volume24h: 62557 }, - '0x11f2a400de0a2fc93a32f88d8779d8199152c6a4': { apy: 1.47, tvl: 765773, feeTier: 0.3, volume24h: 140156 }, - '0xf08d4dea369c456d26a3168ff0024b904f2d8b91': { apy: 2.85, tvl: 2861876, feeTier: 0.3, volume24h: 104464 }, - '0xd7855be714943928236bda82d9cd7caf189f2806': { apy: 2.02, tvl: 650441, feeTier: 0.3, volume24h: 213673 }, - '0x4359a8ea4c353d93245c0b6b8608a28bb48a05e2': { apy: 2.09, tvl: 4596484, feeTier: 0.3, volume24h: 61945 }, - '0x6ff0531ee19272675b3c7d30401a5b2b2c7b0c67': { apy: 1.44, tvl: 4694812, feeTier: 0.3, volume24h: 140088 }, - '0xa62e2c047b65aee3c3ba7fc7c2bd95c82a514de2': { apy: 2.56, tvl: 2406025, feeTier: 0.3, volume24h: 191543 }, - '0x7c838b3ed3c15a5d5032e809b8714f0ae5e9a821': { apy: 1.64, tvl: 4647147, feeTier: 0.3, volume24h: 107370 }, - '0x9d0e8cdf137976e03ef92ede4c30648d05e25285': { apy: 1.41, tvl: 1911255, feeTier: 0.3, volume24h: 168747 }, - // UNIV2 - '0xc3689fbb396340be64c45b43a2aec84196bb207f': { apy: 2.74, tvl: 1932085, feeTier: 0.3, volume24h: 75383 }, - '0xc2adda861f89bbb333c90c492cb837741916a225': { apy: 1.34, tvl: 5047912, feeTier: 0.3, volume24h: 195365 }, - '0xcd6bcca48069f8588780dfa274960f15685aee0e': { apy: 2.94, tvl: 1197489, feeTier: 0.3, volume24h: 240967 }, - '0x5201523c0ad5ba792c40ce5aff7df2d1a721bbf8': { apy: 1.37, tvl: 3516485, feeTier: 0.3, volume24h: 222732 }, - '0x7054b0f980a7eb5b3a6b3446f3c947d80162775c': { apy: 2.99, tvl: 5539047, feeTier: 0.3, volume24h: 223551 }, - '0x2a6c340bcbb0a79d3deecd3bc5cbc2605ea9259f': { apy: 2.41, tvl: 3973854, feeTier: 0.3, volume24h: 14617 }, - '0x2947dc50cc24cc55afbf22807a49cc302d65568c': { apy: 1.57, tvl: 4143693, feeTier: 0.3, volume24h: 196902 }, - '0x9ec9367b8c4dd45ec8e7b800b1f719251053ad60': { apy: 1.53, tvl: 2005446, feeTier: 0.3, volume24h: 3128 }, - '0x0ae8d75e6168420a7d52a791c2465b43307408b4': { apy: 2.44, tvl: 3661164, feeTier: 0.3, volume24h: 100091 }, - '0x539b4dfcd1e4dc3153e59204004c2141f796f432': { apy: 1.18, tvl: 2310777, feeTier: 0.3, volume24h: 180998 }, - '0x95f4408736988549212db071b1c8d20f7c4e6304': { apy: 1.93, tvl: 4697846, feeTier: 0.3, volume24h: 24634 }, - '0xd3772a963790fede65646cfdae08734a17cd0f47': { apy: 1.91, tvl: 4839359, feeTier: 0.3, volume24h: 219066 }, - '0xe45b4a84e0ad24b8617a489d743c52b84b7acebe': { apy: 1.08, tvl: 390105, feeTier: 0.3, volume24h: 186472 }, - '0x4e34da137f0b317c633838458e0c923a5e088752': { apy: 2.72, tvl: 3558018, feeTier: 0.3, volume24h: 226275 }, - '0x77010f531b1603d0a6dfd5e0ae96d04090ab6fda': { apy: 1.5, tvl: 6026291, feeTier: 0.3, volume24h: 243344 }, - '0xcb37089fc6a6faff231b96e000300a6994d7a625': { apy: 2.47, tvl: 1319306, feeTier: 0.3, volume24h: 120610 }, - '0xda3a20aad0c34fa742bd9813d45bbf67c787ae0b': { apy: 2.9, tvl: 2689994, feeTier: 0.3, volume24h: 70167 }, - '0x12490e03f079fa7e3c20e9bf797bdb7a7f495fd4': { apy: 1.96, tvl: 1919878, feeTier: 0.3, volume24h: 117471 }, - '0xa1bf0e900fb272089c9fd299ea14bfccb1d1c2c0': { apy: 1.68, tvl: 496286, feeTier: 0.3, volume24h: 242005 }, - '0x4dd26482738be6c06c31467a19dcda9ad781e8c4': { apy: 1.57, tvl: 2934009, feeTier: 0.3, volume24h: 61483 }, - '0xa8f590c8eadf61769d32cb084d30a4b309146458': { apy: 1.7, tvl: 2099333, feeTier: 0.3, volume24h: 210062 }, - '0x5ced44f03ff443bbe14d8ea23bc24425fb89e3ed': { apy: 1.14, tvl: 2520024, feeTier: 0.3, volume24h: 109274 }, - '0xd9fe79a0b8d00b0eeeca68dd802d7c9574f7ed25': { apy: 1.34, tvl: 3331481, feeTier: 0.3, volume24h: 33975 }, - '0xc77efc40c20f1578a9bd714f9a871dfc1a81b234': { apy: 2.34, tvl: 774745, feeTier: 0.3, volume24h: 62087 }, - '0x11181bd3baf5ce2a478e98361985d42625de35d1': { apy: 1.21, tvl: 4778872, feeTier: 0.3, volume24h: 169155 }, - '0x4df1c47ecfbac8482a4811d373128e2acc007d02': { apy: 1.6, tvl: 4536199, feeTier: 0.3, volume24h: 82920 }, - '0xc730ef0f4973da9cc0ab8ab291890d3e77f58f79': { apy: 1.54, tvl: 1301355, feeTier: 0.3, volume24h: 166390 }, - '0x629d22e6eeac46a11dbc96be93b90aee9309be4c': { apy: 1.18, tvl: 1338149, feeTier: 0.3, volume24h: 16354 }, - '0xfa5562729fdc3ed3a52c3aab2e12bd504fd24991': { apy: 1.38, tvl: 5426365, feeTier: 0.3, volume24h: 239402 }, - '0x2c8f9bbae004854b9548f6c84720c70a8fceea23': { apy: 1.26, tvl: 1386582, feeTier: 0.3, volume24h: 2448 }, - '0x29c830864930c897efa2b9e9851342187b82010e': { apy: 2.3, tvl: 578601, feeTier: 0.3, volume24h: 32995 }, - '0x440bb7a5fc57764d9e7f89e55ad57a342f92b9a2': { apy: 2.91, tvl: 4997306, feeTier: 0.3, volume24h: 118960 }, - '0x43de4318b6eb91a7cf37975dbb574396a7b5b5c6': { apy: 2.1, tvl: 5792305, feeTier: 0.3, volume24h: 59058 }, - '0xce5debe9dd76f96bb5fa00eb3cc084d43ec0dbf3': { apy: 1.34, tvl: 2013060, feeTier: 0.3, volume24h: 44202 }, - '0x8d58e202016122aae65be55694dbce1b810b4072': { apy: 1.52, tvl: 4208606, feeTier: 0.3, volume24h: 106742 }, - '0x0afd65ec6b286d353c42268738d66bbf56ba9de5': { apy: 1.02, tvl: 1423178, feeTier: 0.3, volume24h: 198749 }, - '0x3beeab9d5624e487045e01d12332975204a04a8a': { apy: 2.22, tvl: 1073944, feeTier: 0.3, volume24h: 166776 }, - '0x180efc1349a69390ade25667487a826164c9c6e4': { apy: 2.59, tvl: 3872670, feeTier: 0.3, volume24h: 241030 }, - '0x9ec96dcb54331626b79d8450a3daa9bcfa02e0b0': { apy: 2.34, tvl: 4281558, feeTier: 0.3, volume24h: 228909 }, - '0xe99191b4a562ccb416ea8e00085e13105cf80639': { apy: 2.78, tvl: 3818273, feeTier: 0.3, volume24h: 15755 }, - '0x8296d84e911e0c1f827e1e7d4b50c2568e807b36': { apy: 1.67, tvl: 3010265, feeTier: 0.3, volume24h: 142523 }, - '0x7c1c4a2cf81d2fc83b89bfd34f4d2c7e90044b32': { apy: 2.82, tvl: 3817577, feeTier: 0.3, volume24h: 168959 }, - '0x2cc846fff0b08fb3bffad71f53a60b4b6e6d6482': { apy: 2.1, tvl: 4819460, feeTier: 0.3, volume24h: 232346 }, - '0x56d8bbe2d518205b521aeb86a58e1b53b047a44f': { apy: 2.94, tvl: 1418687, feeTier: 0.3, volume24h: 3277 }, - '0x450a136224734a05a494323be8623ef668f74c0e': { apy: 2.55, tvl: 5585853, feeTier: 0.3, volume24h: 167677 }, - '0x5fa9569b0ed6aa01e234468e6a15b77988b950df': { apy: 1.41, tvl: 3092154, feeTier: 0.3, volume24h: 113477 }, - '0xcf4236db746dbc1855a4d095aaf58da9b030491e': { apy: 1.25, tvl: 5212187, feeTier: 0.3, volume24h: 206611 }, - '0xbe8bc29765e11894f803906ee1055a344fdf2511': { apy: 1.39, tvl: 88814, feeTier: 0.3, volume24h: 118087 }, - '0xe945683b3462d2603a18bdfbb19261c6a4f03ad1': { apy: 2.09, tvl: 5630317, feeTier: 0.3, volume24h: 118131 }, - '0xdeba8fd61c1c87b6321a501ebb19e61e610421bf': { apy: 2.04, tvl: 2082290, feeTier: 0.3, volume24h: 137404 }, - // CURVE - '0xb7ecb2aa52aa64a717180e030241bc75cd946726': { apy: 1.8, tvl: 4160844, feeTier: 0.3, volume24h: 170746 }, - '0xb9446c4ef5ebe66268da6700d26f96273de3d571': { apy: 2.49, tvl: 3641587, feeTier: 0.3, volume24h: 159109 }, - '0x42e03280c99579b048bc001531bf7015bc252653': { apy: 1.37, tvl: 2893007, feeTier: 0.3, volume24h: 126615 }, - '0x4e0915c88bc70750d68c481540f081fefaf22273': { apy: 2.4, tvl: 5590624, feeTier: 0.3, volume24h: 135895 }, - '0xb37d6c07482bc11cd28a1f11f1a6ad7b66dec933': { apy: 1.89, tvl: 5914771, feeTier: 0.3, volume24h: 186517 }, - '0xf05cfb8b4382c69f3b451c5fb55210b232e0edfa': { apy: 1.56, tvl: 2682101, feeTier: 0.3, volume24h: 26871 }, - '0x413928a25d6ea1a26f2625d633207755f67bf97c': { apy: 2.89, tvl: 5526764, feeTier: 0.3, volume24h: 44419 }, - '0xba3436fd341f2c8a928452db3c5a3670d1d5cc73': { apy: 2.81, tvl: 1053154, feeTier: 0.3, volume24h: 225832 }, - '0xf985005a3793dba4cce241b3c19ddcd3fe069ff4': { apy: 1.32, tvl: 2942848, feeTier: 0.3, volume24h: 233176 }, - '0x6663b6d50992ef4fc0380199397c87c2f5256075': { apy: 1.76, tvl: 4237073, feeTier: 0.3, volume24h: 226044 }, - '0x30bf3e17cad0baf1d6b64079ec219808d2708feb': { apy: 1.15, tvl: 4127474, feeTier: 0.3, volume24h: 73275 }, - '0x8efd02a0a40545f32dba5d664cbbc1570d3fedf6': { apy: 2.6, tvl: 5705857, feeTier: 0.3, volume24h: 22284 }, - '0xb657b895b265c38c53fff00166cf7f6a3c70587d': { apy: 2.7, tvl: 5513844, feeTier: 0.3, volume24h: 82295 }, - '0x43b4fdfd4ff969587185cdb6f0bd875c5fc83f8c': { apy: 1.85, tvl: 643616, feeTier: 0.3, volume24h: 223809 }, - '0xb30da2376f63de30b42dc055c93fa474f31330a5': { apy: 2.35, tvl: 4871716, feeTier: 0.3, volume24h: 48753 }, - '0xa8e14f03124ea156a4fc416537c82ff91a647d50': { apy: 2.6, tvl: 3323615, feeTier: 0.3, volume24h: 242323 }, - '0xf5d7c5484c02c03cf131b76c67c3eb969828bd3d': { apy: 1.32, tvl: 5180937, feeTier: 0.3, volume24h: 26865 }, - '0x8f476f43baa2d4b6c215d2408340919bf7de0520': { apy: 1.26, tvl: 3112951, feeTier: 0.3, volume24h: 24362 }, - '0xa4eddfe4ba5143ac17fd6bc1e53de0384df8c660': { apy: 2.56, tvl: 5921481, feeTier: 0.3, volume24h: 154626 }, - '0x09b2e090531228d1b8e3d948c73b990cb6e60720': { apy: 1.1, tvl: 2572855, feeTier: 0.3, volume24h: 191549 }, - '0x137469b55d1f15651ba46a89d0588e97dd0b6562': { apy: 1.69, tvl: 231789, feeTier: 0.3, volume24h: 193844 }, - '0x8ea96fc70c577d59528c98c31bc4bf39027c1c3e': { apy: 2.37, tvl: 3527695, feeTier: 0.3, volume24h: 138392 }, - '0x410e3e86ef427e30b9235497143881f717d93c2a': { apy: 2.93, tvl: 4041073, feeTier: 0.3, volume24h: 69969 }, - '0x5ca0313d44551e32e0d7a298ec024321c4bc59b4': { apy: 1.83, tvl: 852006, feeTier: 0.3, volume24h: 172126 }, - '0xd0fb39e59037fc6ae8af5cb495cea690ed501fdd': { apy: 2.35, tvl: 4470364, feeTier: 0.3, volume24h: 175572 }, - '0x4807862aa8b2bf68830e4c8dc86d0e9a998e085a': { apy: 1.49, tvl: 663743, feeTier: 0.3, volume24h: 217067 }, - '0x8fdb0bb9365a46b145db80d0b1c5c5e979c84190': { apy: 1.9, tvl: 4523632, feeTier: 0.3, volume24h: 141090 }, - '0x397c5908b1d8af00b2c2cce499cdd0cf42165d19': { apy: 1.55, tvl: 2296113, feeTier: 0.3, volume24h: 115446 }, - '0x839d6bdedff886404a6d7a788ef241e4e28f4802': { apy: 1.25, tvl: 965939, feeTier: 0.3, volume24h: 21183 }, - '0x5b6c539b224014a09b3388e51caaa8e354c959c8': { apy: 1.75, tvl: 976979, feeTier: 0.3, volume24h: 215284 }, - '0x845838df265dcd2c412a1dc9e959c7d08537f8a2': { apy: 1.71, tvl: 3935336, feeTier: 0.3, volume24h: 62730 }, - '0x9fc689ccada600b6df723d9e47d84d76664a1f23': { apy: 2.2, tvl: 333049, feeTier: 0.3, volume24h: 203086 }, - '0x6c280db098db673d30d5b34ec04b6387185d3620': { apy: 2.79, tvl: 3139046, feeTier: 0.3, volume24h: 208923 }, - '0x84c333e94aea4a51a21f6cf0c7f528c50dc7592c': { apy: 1.75, tvl: 184423, feeTier: 0.3, volume24h: 155274 }, - '0xf9835375f6b268743ea0a54d742aa156947f8c06': { apy: 2.66, tvl: 5962153, feeTier: 0.3, volume24h: 66558 }, - '0xb85010193fd15af8390dbd62790da70f46c1126b': { apy: 2.49, tvl: 1141984, feeTier: 0.3, volume24h: 83499 }, - '0xa3f152837492340daaf201f4dfec6cd73a8a9760': { apy: 2.14, tvl: 4385410, feeTier: 0.3, volume24h: 237960 }, - '0xb73527615c25ac2d226db2581525f69968926caf': { apy: 2.49, tvl: 5806095, feeTier: 0.3, volume24h: 136940 }, - '0xc4ad29ba4b3c580e6d59105fff484999997675ff': { apy: 1.9, tvl: 4518961, feeTier: 0.3, volume24h: 25625 }, - '0x2889302a794da87fbf1d6db415c1492194663d13': { apy: 2.36, tvl: 1405952, feeTier: 0.3, volume24h: 224999 }, - '0x3a283d9c08e8b55966afb64c515f5143cf907611': { apy: 2.95, tvl: 4451819, feeTier: 0.3, volume24h: 162487 }, - '0xc7de47b9ca2fc753d6a2f167d8b3e19c6d18b19a': { apy: 2.22, tvl: 2632062, feeTier: 0.3, volume24h: 206129 }, - '0xef484de8c07b6e2d732a92b5f78e81b38f99f95e': { apy: 2.79, tvl: 2942020, feeTier: 0.3, volume24h: 52701 }, - '0x3d229e1b4faab62f621ef2f6a610961f7bd7b23b': { apy: 2.68, tvl: 4642289, feeTier: 0.3, volume24h: 204976 }, - '0x4d1941a887ec788f059b3bfcc8ee1e97b968825b': { apy: 2.29, tvl: 2069435, feeTier: 0.3, volume24h: 29468 }, - '0xfc2838a17d8e8b1d5456e0a351b0708a09211147': { apy: 1.35, tvl: 5561116, feeTier: 0.3, volume24h: 101229 }, - '0xc34993c9adf6a5ab3b4ca27dc71b9c7894a53974': { apy: 1.3, tvl: 4216532, feeTier: 0.3, volume24h: 207313 }, - '0x5be6c45e2d074faa20700c49ada3e88a1cc0025d': { apy: 1.56, tvl: 5679638, feeTier: 0.3, volume24h: 162899 }, - '0x733a2a4f6d111e04040e88d6595083828965e01b': { apy: 2.16, tvl: 595954, feeTier: 0.3, volume24h: 141853 }, - '0x68e26daf88da63bebd3da05fc9c880fa37080d3e': { apy: 1.68, tvl: 2155124, feeTier: 0.3, volume24h: 11082 }, - // SUSHI - '0xba13afecda9beb75de5c56bbaf696b880a5a50dd': { apy: 1.99, tvl: 3485637, feeTier: 0.3, volume24h: 118895 }, - '0xd9a1df87e01b31f1154f788041625030af1927be': { apy: 1.19, tvl: 1017915, feeTier: 0.3, volume24h: 16103 }, - '0x86f518368e0d49d5916e2bd9eb162e9952b7b04d': { apy: 2.18, tvl: 4257965, feeTier: 0.3, volume24h: 110901 }, - '0xd75ea151a61d06868e31f8988d28dfe5e9df57b4': { apy: 1.92, tvl: 4670302, feeTier: 0.3, volume24h: 171243 }, - '0x9cbc2a6ab3f10edf7d71c9cf3b6bdb7ee5629550': { apy: 1.22, tvl: 4362129, feeTier: 0.3, volume24h: 131948 }, - '0x9e48fadf799e0513d2ef4631478ea186741fa617': { apy: 1.42, tvl: 3746364, feeTier: 0.3, volume24h: 41457 }, - '0x1f4c763bde1d4832b3ea0640e66da00b98831355': { apy: 1.68, tvl: 5519215, feeTier: 0.3, volume24h: 200575 }, - '0x0d15e893cf50724382368cafed222cf131b55307': { apy: 2.69, tvl: 1655574, feeTier: 0.3, volume24h: 203334 }, - '0x364248b2f1f57c5402d244b2d469a35b4c0e9dab': { apy: 1.27, tvl: 2921484, feeTier: 0.3, volume24h: 209688 }, - '0x7b98e476de2c50b6fa284dbd410dd516f9a72b30': { apy: 2.03, tvl: 388343, feeTier: 0.3, volume24h: 163216 }, - '0xf55c33d94150d93c2cfb833bcca30be388b14964': { apy: 2.96, tvl: 2011214, feeTier: 0.3, volume24h: 100661 }, - '0x0589e281d35ee1acf6d4fd32f1fba60effb5281b': { apy: 1.79, tvl: 3891323, feeTier: 0.3, volume24h: 6855 }, - '0x1241f4a348162d99379a23e73926cf0bfcbf131e': { apy: 2.53, tvl: 1705196, feeTier: 0.3, volume24h: 236308 }, - '0x201e6a9e75df132a8598720433af35fe8d73e94d': { apy: 2.94, tvl: 3784139, feeTier: 0.3, volume24h: 123848 }, - '0xb27c7b131cf4915bec6c4bc1ce2f33f9ee434b9f': { apy: 1.11, tvl: 594587, feeTier: 0.3, volume24h: 108357 }, - '0x130f4322e5838463ee460d5854f5d472cfc8f253': { apy: 1.37, tvl: 1175014, feeTier: 0.3, volume24h: 24410 }, - '0xa8aec03d5cf2824fd984ee249493d6d4d6740e61': { apy: 1.31, tvl: 3123438, feeTier: 0.3, volume24h: 186588 }, - '0x53162d78dca413d9e28cf62799d17a9e278b60e8': { apy: 1.57, tvl: 3128531, feeTier: 0.3, volume24h: 48653 }, - '0x17a2194d55f52fd0c711e0e42b41975494bb109b': { apy: 2.21, tvl: 4509973, feeTier: 0.3, volume24h: 172535 }, - '0x5654d65578cda52791879751141f2f3d7dc27fe4': { apy: 2.52, tvl: 4040513, feeTier: 0.3, volume24h: 101102 }, - '0x0c365789dbbb94a29f8720dc465554c587e897db': { apy: 2.21, tvl: 2713413, feeTier: 0.3, volume24h: 244300 }, - '0x57fbc21ca3c157a26b6ea57334d6b082be1060a7': { apy: 2.8, tvl: 1014029, feeTier: 0.3, volume24h: 97009 }, - '0xa75f7c2f025f470355515482bde9efa8153536a8': { apy: 2.57, tvl: 1027123, feeTier: 0.3, volume24h: 113090 }, - '0x938625591adb4e865b882377e2c965f9f9b85e34': { apy: 2.99, tvl: 661710, feeTier: 0.3, volume24h: 142896 }, - '0x2c51eaa1bcc7b013c3f1d5985cdcb3c56dc3fbc1': { apy: 1.73, tvl: 732769, feeTier: 0.3, volume24h: 111936 }, - '0x072b999fc3d82f9ea08b8adbb9d63a980ff2b14d': { apy: 2.48, tvl: 415034, feeTier: 0.3, volume24h: 83299 }, - '0x0eee7f7319013df1f24f5eaf83004fcf9cf49245': { apy: 2.84, tvl: 2238403, feeTier: 0.3, volume24h: 197261 }, - '0xf8937dc1ca081161527c0bc1eb6379420195c894': { apy: 2.28, tvl: 1301031, feeTier: 0.3, volume24h: 74966 }, - '0x5fa4370164a2fabeef159b893299d59ff5dc1e6d': { apy: 2.72, tvl: 5248047, feeTier: 0.3, volume24h: 47424 }, - '0x0bec54c89a7d9f15c4e7faa8d47adedf374462ed': { apy: 2.27, tvl: 3823505, feeTier: 0.3, volume24h: 87971 }, - '0xe12af1218b4e9272e9628d7c7dc6354d137d024e': { apy: 1.46, tvl: 1117439, feeTier: 0.3, volume24h: 94695 }, - '0xdd51121d1efc398b4c09fd0cb84d79ae2c923fc9': { apy: 2.23, tvl: 458749, feeTier: 0.3, volume24h: 102395 }, - '0x53813285cc60b13fcd2105c6472a47af01f8ac84': { apy: 1.88, tvl: 983255, feeTier: 0.3, volume24h: 227946 }, - '0x613c836df6695c10f0f4900528b6931441ac5d5a': { apy: 1.46, tvl: 5039905, feeTier: 0.3, volume24h: 29981 }, - '0x65f550d18cac8e19a97e73108618b443bf301d20': { apy: 2.66, tvl: 1010681, feeTier: 0.3, volume24h: 88790 }, - '0x44d34985826578e5ba24ec78c93be968549bb918': { apy: 1.93, tvl: 3294863, feeTier: 0.3, volume24h: 146703 }, - '0x57024267e8272618f9c5037d373043a8646507e5': { apy: 2.05, tvl: 4236986, feeTier: 0.3, volume24h: 238855 }, - '0x164fe0239d703379bddde3c80e4d4800a1cd452b': { apy: 2.94, tvl: 4002574, feeTier: 0.3, volume24h: 1344 }, - '0xd46004eed3885e0a74d452811c80eb41270a5728': { apy: 2.28, tvl: 296097, feeTier: 0.3, volume24h: 73247 }, - '0x557b08a0cab46bfe22471b65522757ea92a9e7a5': { apy: 1.12, tvl: 2723359, feeTier: 0.3, volume24h: 115824 }, - '0x4632ac4a94b57573f6b0297229fc8d54046f9be4': { apy: 1.02, tvl: 4226822, feeTier: 0.3, volume24h: 104692 }, - '0xf7ac1f571856d7dbfbb56728c48823a2a19e4326': { apy: 2.81, tvl: 1574589, feeTier: 0.3, volume24h: 143480 }, - '0x31503dcb60119a812fee820bb7042752019f2355': { apy: 2.85, tvl: 3327566, feeTier: 0.3, volume24h: 193759 }, - '0x7c03cf21483fa45006e81669b991af3a16733a44': { apy: 1.41, tvl: 2353206, feeTier: 0.3, volume24h: 19494 }, - '0xf169cea51eb51774cf107c88309717dda20be167': { apy: 2.5, tvl: 4924920, feeTier: 0.3, volume24h: 240489 }, - '0x840fdb210cf93318e8a16a51f24938c866a32d3c': { apy: 1.39, tvl: 858541, feeTier: 0.3, volume24h: 13334 }, - '0x2a93167ed63a31f35ca4788e2eb9fbd9fa6089d0': { apy: 2.23, tvl: 5268283, feeTier: 0.3, volume24h: 90308 }, - '0x1c580cc549d03171b13b55074dc1658f60641c73': { apy: 1.12, tvl: 875610, feeTier: 0.3, volume24h: 193969 }, - '0x05767d9ef41dc40689678ffca0608878fb3de906': { apy: 1.67, tvl: 4540867, feeTier: 0.3, volume24h: 214645 }, - '0x33f6ddaea2a8a54062e021873bcaee006cdf4007': { apy: 1.16, tvl: 4610326, feeTier: 0.3, volume24h: 56219 }, - } - -export const POOLS_AVERAGE_DATA_MOCK: Partial> = - POOLS_AVERAGE_DATA_MOCK_OVERRIDE - ? JSON.parse(POOLS_AVERAGE_DATA_MOCK_OVERRIDE) - : { - [LpTokenProvider.COW_AMM]: { - apy: 5.3, - }, - [LpTokenProvider.UNIV2]: { - apy: 3.1, - }, - [LpTokenProvider.CURVE]: { - apy: 0.4, - }, - [LpTokenProvider.PANCAKE]: { - apy: 0.2, - }, - [LpTokenProvider.SUSHI]: { - apy: 0.41, - }, - } diff --git a/apps/cowswap-frontend/src/modules/yield/updaters/VampireAttackUpdater.tsx b/apps/cowswap-frontend/src/modules/yield/updaters/VampireAttackUpdater.tsx index 06fcad7cff..6090f75118 100644 --- a/apps/cowswap-frontend/src/modules/yield/updaters/VampireAttackUpdater.tsx +++ b/apps/cowswap-frontend/src/modules/yield/updaters/VampireAttackUpdater.tsx @@ -1,12 +1,14 @@ import { useAtomValue, useSetAtom } from 'jotai' import { useEffect, useMemo } from 'react' +import { BFF_BASE_URL, SWR_NO_REFRESH_OPTIONS } from '@cowprotocol/common-const' import { LP_TOKEN_LIST_COW_AMM_ONLY, useAllLpTokens } from '@cowprotocol/tokens' import { LpTokenProvider } from '@cowprotocol/types' import { useWalletInfo } from '@cowprotocol/wallet' +import useSWR from 'swr' + import { useLpTokensWithBalances, usePoolsInfo } from 'modules/yield/shared' -import { POOLS_AVERAGE_DATA_MOCK } from 'modules/yield/updaters/PoolsInfoUpdater/mockPoolInfo' import { useSafeMemoObject } from 'common/hooks/useSafeMemo' import { areLpBalancesLoadedAtom } from 'common/updaters/LpBalancesAndAllowancesUpdater' @@ -14,13 +16,44 @@ import { areLpBalancesLoadedAtom } from 'common/updaters/LpBalancesAndAllowances import { vampireAttackAtom } from '../state/vampireAttackAtom' import { TokenWithAlternative, TokenWithSuperiorAlternative } from '../types' +const lpProviderNameMap: Record = { + 'CoW AMM': LpTokenProvider.COW_AMM, + uniswap: LpTokenProvider.UNIV2, + pancakeswap: LpTokenProvider.PANCAKE, + curve: LpTokenProvider.CURVE, + sushiswap: LpTokenProvider.SUSHI, + balancer: LpTokenProvider.BALANCERV2, +} + export function VampireAttackUpdater(): null { - const { account } = useWalletInfo() + const { account, chainId } = useWalletInfo() const { tokens: lpTokensWithBalances, count: lpTokensWithBalancesCount } = useLpTokensWithBalances() const cowAmmLpTokens = useAllLpTokens(LP_TOKEN_LIST_COW_AMM_ONLY) const poolsInfo = usePoolsInfo() const areLpBalancesLoaded = useAtomValue(areLpBalancesLoadedAtom) const setVampireAttack = useSetAtom(vampireAttackAtom) + const { data: poolsAverageApr } = useSWR( + [chainId, 'getPoolsAverageApr'], + async ([chainId]) => { + const result: Record = await fetch(`${BFF_BASE_URL}/${chainId}/yield/pools-average-apr`).then( + (res) => res.json(), + ) + + return Object.keys(result).reduce( + (acc, key) => { + const provider = lpProviderNameMap[key] + + if (provider) { + acc[provider] = result[key] + } + + return acc + }, + {} as Record, + ) + }, + SWR_NO_REFRESH_OPTIONS, + ) const alternativesResult = useMemo(() => { if (lpTokensWithBalancesCount === 0) return null @@ -37,7 +70,7 @@ export function VampireAttackUpdater(): null { const alternativePoolInfo = poolsInfo?.[alternative.address.toLowerCase()]?.info // When CoW AMM pool has better APY - if (alternativePoolInfo?.apy && tokenPoolInfo?.apy && alternativePoolInfo.apy > tokenPoolInfo.apy) { + if (alternativePoolInfo?.apr && tokenPoolInfo?.apr && alternativePoolInfo.apr > tokenPoolInfo.apr) { acc.superiorAlternatives.push({ token: lpToken, alternative, @@ -63,7 +96,7 @@ export function VampireAttackUpdater(): null { superiorAlternatives: result.superiorAlternatives.sort((a, b) => { if (!b.tokenPoolInfo || !a.tokenPoolInfo) return 0 - return b.tokenPoolInfo.apy - a.tokenPoolInfo.apy + return b.tokenPoolInfo.apr - a.tokenPoolInfo.apr }), alternatives: result.alternatives.sort((a, b) => { const aBalance = lpTokensWithBalances[a.token.address.toLowerCase()].balance @@ -75,7 +108,9 @@ export function VampireAttackUpdater(): null { }, [lpTokensWithBalancesCount, lpTokensWithBalances, cowAmmLpTokens, poolsInfo]) const averageApy = useMemo(() => { - const keys = Object.keys(POOLS_AVERAGE_DATA_MOCK) + if (!poolsAverageApr) return 0 + + const keys = Object.keys(poolsAverageApr) let count = 0 return ( @@ -85,22 +120,22 @@ export function VampireAttackUpdater(): null { if (key === LpTokenProvider.COW_AMM) return result count++ - const pool = POOLS_AVERAGE_DATA_MOCK[key] + const poolApr = poolsAverageApr[key] - return result + (pool?.apy || 0) + return result + (poolApr || 0) }, 0) / count ) - }, []) + }, [poolsAverageApr]) - const { [LpTokenProvider.COW_AMM]: cowAmmData, ...poolsAverageData } = POOLS_AVERAGE_DATA_MOCK - const averageApyDiff = cowAmmData ? +(cowAmmData.apy - averageApy).toFixed(2) : 0 + const { [LpTokenProvider.COW_AMM]: cowAmmApr, ...otherPoolsAverageData } = poolsAverageApr || {} + const averageAprDiff = cowAmmApr ? +(cowAmmApr - averageApy).toFixed(2) : 0 const context = useSafeMemoObject({ superiorAlternatives: alternativesResult?.superiorAlternatives || null, alternatives: alternativesResult?.alternatives || null, cowAmmLpTokensCount: cowAmmLpTokens.length, - poolsAverageData, - averageApyDiff, + poolsAverageData: otherPoolsAverageData, + averageAprDiff, }) useEffect(() => {