diff --git a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts index 1f03da2a56..c34b66eb95 100644 --- a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts +++ b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts @@ -4,7 +4,7 @@ import { useSelector, useDispatch } from 'react-redux'; import { TokenMap } from '../../constants/index'; import { bigNumberResult } from '../../util/Ledger'; import useGetChainToken from '~/hooks/chain/useGetChainToken'; -import { DAI, ETH, USDC, USDT } from '../../constants/tokens'; +import { CRV3, DAI, ETH, USDC, USDT, WETH } from '../../constants/tokens'; import { DAI_CHAINLINK_ADDRESSES, USDT_CHAINLINK_ADDRESSES, @@ -14,6 +14,7 @@ import { import { useAggregatorV3Contract } from '~/hooks/ledger/useContract'; import { AppState } from '../../state/index'; import { updateTokenPrices } from '~/state/beanstalk/tokenPrices/actions'; +import useSdk from '../sdk'; const getBNResult = (result: any, decimals: number) => { const bnResult = bigNumberResult(result); @@ -35,16 +36,19 @@ export default function useDataFeedTokenPrices() { AppState['_beanstalk']['tokenPrices'] >((state) => state._beanstalk.tokenPrices); + const sdk = useSdk(); + const daiPriceFeed = useAggregatorV3Contract(DAI_CHAINLINK_ADDRESSES); const usdtPriceFeed = useAggregatorV3Contract(USDT_CHAINLINK_ADDRESSES); const usdcPriceFeed = useAggregatorV3Contract(USDC_CHAINLINK_ADDRESSES); const ethPriceFeed = useAggregatorV3Contract(ETH_CHAINLINK_ADDRESS); + const crv3Pool = sdk.contracts.curve.pools.pool3; const getChainToken = useGetChainToken(); const dispatch = useDispatch(); const fetch = useCallback(async () => { if (Object.values(tokenPriceMap).length) return; - if (!daiPriceFeed || !usdtPriceFeed || !usdcPriceFeed || !ethPriceFeed) + if (!daiPriceFeed || !usdtPriceFeed || !usdcPriceFeed || !ethPriceFeed || !crv3Pool) return; console.debug('[beanstalk/tokenPrices/useCrvUnderlylingPrices] FETCH'); @@ -58,6 +62,7 @@ export default function useDataFeedTokenPrices() { usdcPriceDecimals, ethPriceData, ethPriceDecimals, + crv3Price, ] = await Promise.all([ daiPriceFeed.latestRoundData(), daiPriceFeed.decimals(), @@ -67,12 +72,15 @@ export default function useDataFeedTokenPrices() { usdcPriceFeed.decimals(), ethPriceFeed.latestRoundData(), ethPriceFeed.decimals(), + crv3Pool.get_virtual_price(), ]); const dai = getChainToken(DAI); const usdc = getChainToken(USDC); const usdt = getChainToken(USDT); const eth = getChainToken(ETH); + const weth = getChainToken(WETH); + const crv3 = getChainToken(CRV3); const priceDataCache: TokenMap = {}; @@ -99,6 +107,16 @@ export default function useDataFeedTokenPrices() { ethPriceData.answer, ethPriceDecimals ); + priceDataCache[weth.address] = getBNResult( + ethPriceData.answer, + ethPriceDecimals + ); + } + if (crv3Price) { + priceDataCache[crv3.address] = getBNResult( + crv3Price, + crv3.decimals + ); } console.debug( @@ -112,6 +130,7 @@ export default function useDataFeedTokenPrices() { usdtPriceFeed, usdcPriceFeed, ethPriceFeed, + crv3Pool, getChainToken, ]); diff --git a/projects/ui/src/hooks/farmer/useFarmerBalancesWithFiatValue.ts b/projects/ui/src/hooks/farmer/useFarmerBalancesWithFiatValue.ts index 0818191f88..e338171301 100644 --- a/projects/ui/src/hooks/farmer/useFarmerBalancesWithFiatValue.ts +++ b/projects/ui/src/hooks/farmer/useFarmerBalancesWithFiatValue.ts @@ -15,9 +15,11 @@ const sortMap = { urBEAN: 2, urBEAN3CRV: 3, ETH: 4, - DAI: 5, - USDC: 6, - USDT: 7, + WETH: 5, + "3CRV": 6, + DAI: 7, + USDC: 8, + USDT: 9, } as const; export type TokenBalanceWithFiatValue = {