diff --git a/src/components/Sidebar/NavContent.tsx b/src/components/Sidebar/NavContent.tsx index 7e5ca1e7c..4206564a0 100644 --- a/src/components/Sidebar/NavContent.tsx +++ b/src/components/Sidebar/NavContent.tsx @@ -1,4 +1,4 @@ -import { Box, Link, Paper, SvgIcon, Typography, useTheme } from "@mui/material"; +import { Box, Link, Paper, SvgIcon, Typography } from "@mui/material"; import { styled } from "@mui/material/styles"; import { Icon } from "@olympusdao/component-library"; import React from "react"; @@ -7,8 +7,9 @@ import OlympusIcon from "src/assets/icons/olympus-nav-header.svg?react"; import NavItem from "src/components/library/NavItem"; import { formatCurrency } from "src/helpers"; import { Environment } from "src/helpers/environment/Environment/Environment"; -import { useGohmPriceDefiLlama, useOhmPriceDefillama } from "src/hooks/usePrices"; +import { useGohmPriceContract } from "src/hooks/usePrices"; import { useTestableNetworks } from "src/hooks/useTestableNetworks"; +import { usePriceContractPrice } from "src/views/Range/hooks"; import { useNetwork } from "wagmi"; const PREFIX = "NavContent"; @@ -24,11 +25,10 @@ const StyledBox = styled(Box)(({ theme }) => ({ })); const NavContent: React.VFC = () => { - const theme = useTheme(); const { chain = { id: 1 } } = useNetwork(); const networks = useTestableNetworks(); - const { data: ohmPrice } = useOhmPriceDefillama(); - const { data: gohmPrice } = useGohmPriceDefiLlama(); + const { data: ohmPrice } = usePriceContractPrice(); + const { data: gohmPrice } = useGohmPriceContract(); const protocolMetricsEnabled = Boolean(Environment.getWundergraphNodeUrl()); const emissionsManagerEnabled = Environment.getEmissionsManagerEnabled(); diff --git a/src/helpers/pricing/useGetDefillamaPrice.ts b/src/helpers/pricing/useGetDefillamaPrice.ts index 68529eb53..b907ee782 100644 --- a/src/helpers/pricing/useGetDefillamaPrice.ts +++ b/src/helpers/pricing/useGetDefillamaPrice.ts @@ -19,6 +19,8 @@ export const useGetDefillamaPrice = ({ addresses }: { addresses: string[] }) => const response = await axios.get( `https://coins.llama.fi/prices/current/${joinedAddresses}`, ); + + console.log("coins", response.data.coins); return response.data.coins; } catch (error) { return {}; diff --git a/src/hooks/usePrices.ts b/src/hooks/usePrices.ts index f50c2798e..cc4dd8a47 100644 --- a/src/hooks/usePrices.ts +++ b/src/hooks/usePrices.ts @@ -1,12 +1,11 @@ import { useQuery } from "@tanstack/react-query"; import { NetworkId } from "src/constants"; -import { OHM_ADDRESSES } from "src/constants/addresses"; import { OHM_TOKEN } from "src/constants/tokens"; import { DecimalBigNumber } from "src/helpers/DecimalBigNumber/DecimalBigNumber"; -import { useGetDefillamaPrice } from "src/helpers/pricing/useGetDefillamaPrice"; import { queryAssertion } from "src/helpers/react-query/queryAssertion"; import { nonNullable } from "src/helpers/types/nonNullable"; import { useCurrentIndex } from "src/hooks/useCurrentIndex"; +import { usePriceContractPrice } from "src/views/Range/hooks"; export const ohmPriceQueryKey = () => ["useOhmPrice"]; @@ -21,22 +20,6 @@ export const useOhmPrice = () => { }); }; -export const useOhmPriceDefillama = () => { - const { data: currentMarketPrices } = useGetDefillamaPrice({ - addresses: [OHM_ADDRESSES[1]], - }); - - return useQuery( - ["useOhmPriceDefillama"], - async () => { - const ohmPriceUSD = currentMarketPrices?.[`ethereum:${OHM_ADDRESSES[1]}`].price; - - return ohmPriceUSD; - }, - { enabled: !!currentMarketPrices }, - ); -}; - export const gohmPriceQueryKey = (marketPrice?: number, currentIndex?: DecimalBigNumber) => ["useGOHMPrice", marketPrice, currentIndex].filter(nonNullable); @@ -62,8 +45,8 @@ export const useGohmPrice = () => { /** * Returns the calculated price of gOHM. */ -export const useGohmPriceDefiLlama = () => { - const { data: ohmPrice } = useOhmPriceDefillama(); +export const useGohmPriceContract = () => { + const { data: ohmPrice } = usePriceContractPrice(); const { data: currentIndex } = useCurrentIndex(); const key = gohmPriceQueryKey(ohmPrice, currentIndex); diff --git a/src/views/MyBalances/MyCoolerLoans.tsx b/src/views/MyBalances/MyCoolerLoans.tsx index e682d12ef..e25f985ea 100644 --- a/src/views/MyBalances/MyCoolerLoans.tsx +++ b/src/views/MyBalances/MyCoolerLoans.tsx @@ -4,7 +4,7 @@ import { ethers } from "ethers"; import { Link as RouterLink } from "react-router-dom"; import lendAndBorrowIcon from "src/assets/icons/lendAndBorrow.svg?react"; import { formatCurrency } from "src/helpers"; -import { useGohmPriceDefiLlama } from "src/hooks/usePrices"; +import { useGohmPriceContract } from "src/hooks/usePrices"; import { useGetClearingHouse } from "src/views/Lending/Cooler/hooks/useGetClearingHouse"; import { useGetCoolerLoans } from "src/views/Lending/Cooler/hooks/useGetCoolerLoans"; import { useAccount } from "wagmi"; @@ -12,7 +12,7 @@ import { useAccount } from "wagmi"; export const MyCoolerLoans = ({ balance, balanceUSD }: { balance: string; balanceUSD: string }) => { const theme = useTheme(); const { address } = useAccount(); - const { data: gOhmPrice = 0 } = useGohmPriceDefiLlama(); + const { data: gOhmPrice = 0 } = useGohmPriceContract(); const { data: clearingHouseV1 } = useGetClearingHouse({ clearingHouse: "clearingHouseV1" }); const { data: clearingHouseV2 } = useGetClearingHouse({ clearingHouse: "clearingHouseV2" }); diff --git a/src/views/MyBalances/MyGohmBalances.tsx b/src/views/MyBalances/MyGohmBalances.tsx index 792ffdd28..caca2f9ca 100644 --- a/src/views/MyBalances/MyGohmBalances.tsx +++ b/src/views/MyBalances/MyGohmBalances.tsx @@ -5,13 +5,13 @@ import WalletIcon from "src/assets/icons/wallet.svg?react"; import { formatCurrency } from "src/helpers"; import { DecimalBigNumber } from "src/helpers/DecimalBigNumber/DecimalBigNumber"; import { useGohmBalance } from "src/hooks/useBalance"; -import { useGohmPriceDefiLlama } from "src/hooks/usePrices"; +import { useGohmPriceContract } from "src/hooks/usePrices"; import { useTestableNetworks } from "src/hooks/useTestableNetworks"; import { NetworkId } from "src/networkDetails"; export const MyGohmBalances = ({ walletBalance }: { walletBalance?: DecimalBigNumber }) => { const gohmBalances = useGohmBalance(); - const { data: gOhmPrice = 0 } = useGohmPriceDefiLlama(); + const { data: gOhmPrice = 0 } = useGohmPriceContract(); const networks = useTestableNetworks(); diff --git a/src/views/MyBalances/index.tsx b/src/views/MyBalances/index.tsx index a5d1274b2..958e71f0a 100644 --- a/src/views/MyBalances/index.tsx +++ b/src/views/MyBalances/index.tsx @@ -18,7 +18,6 @@ import { useWsohmBalance, } from "src/hooks/useBalance"; import { useCurrentIndex } from "src/hooks/useCurrentIndex"; -import { useOhmPriceDefillama } from "src/hooks/usePrices"; import { useTestableNetworks } from "src/hooks/useTestableNetworks"; import { NetworkId } from "src/networkDetails"; import { useGetClearingHouse } from "src/views/Lending/Cooler/hooks/useGetClearingHouse"; @@ -29,6 +28,7 @@ import { LearnAboutOhm } from "src/views/MyBalances/LearnAboutOhm"; import { MyCoolerLoans } from "src/views/MyBalances/MyCoolerLoans"; import { MyGohmBalances } from "src/views/MyBalances/MyGohmBalances"; import { MyOhmBalances } from "src/views/MyBalances/MyOhmBalances"; +import { usePriceContractPrice } from "src/views/Range/hooks"; import { useAccount, useNetwork } from "wagmi"; /** @@ -42,7 +42,7 @@ export const MyBalances: FC = () => { const { address } = useAccount(); const networks = useTestableNetworks(); const { chain = { id: 1 } } = useNetwork(); - const { data: ohmPrice = 0 } = useOhmPriceDefillama(); + const { data: ohmPrice = 0 } = usePriceContractPrice(); const { data: currentIndex = new DecimalBigNumber("0", 9) } = useCurrentIndex(); const { data: v1OhmBalance = new DecimalBigNumber("0", 9) } = useV1OhmBalance()[networks.MAINNET]; const { data: v1SohmBalance = new DecimalBigNumber("0", 9) } = useV1SohmBalance()[networks.MAINNET]; diff --git a/src/views/Range/hooks.tsx b/src/views/Range/hooks.tsx index e8d41c14f..45356c4d5 100644 --- a/src/views/Range/hooks.tsx +++ b/src/views/Range/hooks.tsx @@ -76,11 +76,11 @@ export const PriceHistory = () => { /** * Returns the current price of the Operator at the given address */ -export const OperatorPrice = () => { +export const usePriceContractPrice = () => { const networks = useTestableNetworks(); const contract = RANGE_PRICE_CONTRACT.getEthersContract(networks.MAINNET); - const { data, isFetched, isLoading } = useQuery(["getOperatorPrice", networks.MAINNET], async () => { + const { data, isFetched, isLoading } = useQuery(["getPriceContractPrice", networks.MAINNET], async () => { return parseBigNumber(await contract.getCurrentPrice(), 18); }); return { data, isFetched, isLoading }; diff --git a/src/views/Range/index.tsx b/src/views/Range/index.tsx index 430a79939..36cd68fbb 100644 --- a/src/views/Range/index.tsx +++ b/src/views/Range/index.tsx @@ -24,11 +24,11 @@ import { useTestableNetworks } from "src/hooks/useTestableNetworks"; import { DetermineRangePrice, LastSnapshotPrice, - OperatorPrice, OperatorReserveSymbol, RangeBondMaxPayout, RangeData, RangeNextBeat, + usePriceContractPrice, useRangeCheckActive, } from "src/views/Range/hooks"; import RangeChart from "src/views/Range/RangeChart"; @@ -63,7 +63,7 @@ export const Range = () => { const { data: reserveBalance = new DecimalBigNumber("0", 18) } = useBalance(USDS_ADDRESSES)[networks.MAINNET]; const { data: ohmBalance = new DecimalBigNumber("0", 9) } = useBalance(OHM_ADDRESSES)[networks.MAINNET]; - const { data: currentPrice } = OperatorPrice(); + const { data: currentPrice } = usePriceContractPrice(); const { data: lastPrice } = LastSnapshotPrice(); const { data: currentMarketPrices } = useGetDefillamaPrice({ addresses: [USDS_ADDRESSES[1], OHM_ADDRESSES[1]],