diff --git a/components/pool/graph/GraphModel.tsx b/components/pool/graph/GraphModel.tsx index 2ae3624..46871b5 100644 --- a/components/pool/graph/GraphModel.tsx +++ b/components/pool/graph/GraphModel.tsx @@ -33,6 +33,7 @@ import { Center } from "utils/chakraUtils"; import usePoolData from "hooks/pool/usePoolData"; import useInitialUtilization from "hooks/graph/useInitialUtilization"; import { OneHundred } from "constants/graph"; +import { truncateTo3DecimalPlaces } from "utils/bigUtils"; const GraphModel: React.FC = ({ dataKeys, @@ -61,11 +62,16 @@ const GraphModel: React.FC = ({ useEffect(() => { if (rewardAPRValue?.borrow || rewardAPRValue?.borrow === 0) { setRewardBorrow( - (rewardAPRValue.borrow * hoverData.borrowValue) / OneHundred, + (truncateTo3DecimalPlaces(rewardAPRValue.borrow) * + hoverData.borrowValue) / + OneHundred, ); } if (rewardAPRValue?.earn || rewardAPRValue?.earn === 0) { - setRewardEarn((rewardAPRValue?.earn * hoverData.earnValue) / OneHundred); + setRewardEarn( + (truncateTo3DecimalPlaces(rewardAPRValue?.earn) * hoverData.earnValue) / + OneHundred, + ); } }, [rewardAPRValue, hoverData]); diff --git a/components/pool/graph/RewardGraph.tsx b/components/pool/graph/RewardGraph.tsx index 2f069f2..a7e568a 100644 --- a/components/pool/graph/RewardGraph.tsx +++ b/components/pool/graph/RewardGraph.tsx @@ -2,10 +2,10 @@ import React from "react"; import { PoolConfig } from "interfaces/pool"; import GraphModel from "./GraphModel"; import { OneHundred, rateSlopeLow } from "constants/graph"; -import useRewardData from "hooks/graph/useRewardData"; +import usePoolData from "hooks/pool/usePoolData"; const RewardGraph = ({ poolData }: { poolData: PoolConfig }) => { - const tempRewardData = useRewardData({ poolData }); + const { tokenRewardData } = usePoolData(); const rateSlopeHigh = parseFloat( (OneHundred / (OneHundred - poolData.rewardKink)).toFixed(2), @@ -29,8 +29,8 @@ const RewardGraph = ({ poolData }: { poolData: PoolConfig }) => { dataKeys={dataKeys} labels={{ borrow: "Borrow Reward", earn: "Earn Reward" }} rewardAPRValue={{ - borrow: tempRewardData.borrow, - earn: tempRewardData.earn, + borrow: tokenRewardData?.borrowRewardAPR ?? 0, + earn: tokenRewardData?.supplyRewardAPR ?? 0, }} /> ); diff --git a/constants/chains.ts b/constants/chains.ts index b82b061..8ef3da2 100644 --- a/constants/chains.ts +++ b/constants/chains.ts @@ -19,3 +19,5 @@ export const CHAIN_INFO: ChainInfo = { nativeCurrency: { name: "Sepolia ETH", symbol: "sepoliaETH", decimals: 18 }, }, }; + +export const AddressZero = "0x0000000000000000000000000000000000000000"; diff --git a/constants/pools.ts b/constants/pools.ts index cd7c3a7..b7521dc 100644 --- a/constants/pools.ts +++ b/constants/pools.ts @@ -214,7 +214,7 @@ export const POOL_CONFIG_MAP: PoolConfigMap = { decimals: 8, color: "#bc1c4c", logoURL: "/tokens/PND.png", - priceFeed: "0x0000000000000000000000000000000000000000", + priceFeed: "0x11ff569892Ca55846dACAa2B43C1877424ceB0CB", priceFeedDecimals: 8, }, supplyKink: 95, @@ -319,7 +319,7 @@ export const POOL_CONFIG_MAP: PoolConfigMap = { decimals: 8, color: "#bc1c4c", logoURL: "/tokens/PND.png", - priceFeed: "0x0000000000000000000000000000000000000000", + priceFeed: "0x11ff569892Ca55846dACAa2B43C1877424ceB0CB", priceFeedDecimals: 8, }, supplyKink: 95, @@ -424,7 +424,7 @@ export const POOL_CONFIG_MAP: PoolConfigMap = { decimals: 8, color: "#bc1c4c", logoURL: "/tokens/PND.png", - priceFeed: "0x0000000000000000000000000000000000000000", + priceFeed: "0x11ff569892Ca55846dACAa2B43C1877424ceB0CB", priceFeedDecimals: 8, }, supplyKink: 60, diff --git a/hooks/graph/useRewardData.ts b/hooks/graph/useRewardData.ts deleted file mode 100644 index d91571b..0000000 --- a/hooks/graph/useRewardData.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { useEffect, useState } from "react"; -import usePoolData from "hooks/pool/usePoolData"; -import { PoolConfig } from "interfaces/pool"; -import { RewardDataProps } from "interfaces/graph"; -import { calculateTotalBalance, calculateRewardData } from "hooks/util/graph"; - -const useRewardData = ({ poolData }: { poolData: PoolConfig }) => { - const [tempRewardData, setTempRewardData] = useState({ - borrow: undefined, - earn: undefined, - }); - const { priceFeedData, totalPoolData } = usePoolData(); - - useEffect(() => { - const totalSupply = - (totalPoolData?.totalBaseSupplyBalance ?? 0) >= - poolData?.baseMinForRewards - ? totalPoolData?.totalBaseSupplyBalance ?? 0 - : 0; - const totalBorrow = - (totalPoolData?.totalBaseBorrowBalance ?? 0) >= - poolData?.baseMinForRewards - ? totalPoolData?.totalBaseBorrowBalance ?? 0 - : 0; - const totalBaseSupplyBalance = calculateTotalBalance( - totalSupply, - priceFeedData, - ); - const totalBaseBorrowBalance = calculateTotalBalance( - totalBorrow, - priceFeedData, - ); - - const tempSupplyRewardData = calculateRewardData( - poolData.baseTrackingRewardSpeed, - totalBaseSupplyBalance, - priceFeedData?.rewardAsset, - ); - const tempBorrowRewardData = calculateRewardData( - poolData.baseTrackingRewardSpeed, - totalBaseBorrowBalance, - priceFeedData?.rewardAsset, - ); - - setTempRewardData({ - borrow: tempBorrowRewardData, - earn: tempSupplyRewardData, - }); - }, [priceFeedData, totalPoolData]); - - return tempRewardData; -}; - -export default useRewardData; diff --git a/hooks/util/graph.ts b/hooks/util/graph.ts index 4b8ec67..25583cb 100644 --- a/hooks/util/graph.ts +++ b/hooks/util/graph.ts @@ -103,26 +103,3 @@ export const getTransform = ( : "translateX(-50%)"; } }; - -export const calculateTotalBalance = ( - balance: number | undefined, - priceFeedData: PriceFeedData | undefined, -) => - balance !== undefined && - balance > 0 && - priceFeedData?.baseAsset !== undefined && - priceFeedData.baseAsset > 0 - ? balance * priceFeedData.baseAsset - : 0; - -export const calculateRewardData = ( - trackingRewardSpeed: number, - totalBalance: number, - rewardAsset: number | undefined, -) => - totalBalance > 0 - ? ((trackingRewardSpeed * DAYS_IN_YEAR * (rewardAsset || 0)) / - totalBalance) * - OneHundred * - REWARD_BONUS_RATE_VALUE - : 0; diff --git a/hooks/util/priceFeedUtils.ts b/hooks/util/priceFeedUtils.ts index 4b984ef..2ec95e3 100644 --- a/hooks/util/priceFeedUtils.ts +++ b/hooks/util/priceFeedUtils.ts @@ -6,6 +6,7 @@ import { } from "@wagmi/core"; import priceAbi from "static/price.json"; import { Address } from "abitype"; +import { AddressZero } from "constants/chains"; export const getPriceFeedContract = async ( address: Address, @@ -24,6 +25,7 @@ export const fetchPriceFeed = async ( configChainId?: number, ): Promise => { if (!priceFeedAddress) return undefined; + if (priceFeedAddress === AddressZero) return undefined; const { address } = getAccount(); const network = getNetwork(); diff --git a/interfaces/graph.ts b/interfaces/graph.ts index 1306b99..0b76d54 100644 --- a/interfaces/graph.ts +++ b/interfaces/graph.ts @@ -29,8 +29,3 @@ export interface RenderGraphSectionProps { GraphComponent: React.FC<{ poolData: PoolConfig }>; poolData: PoolConfig; } - -export interface RewardDataProps { - borrow: number | undefined; - earn: number | undefined; -}