From 38de6b997708e6f0b48534a362ad834113270328 Mon Sep 17 00:00:00 2001 From: yosuke Date: Thu, 2 Jan 2025 18:00:33 +0900 Subject: [PATCH 1/7] replace 0x00... to 0x11ff569892Ca55846dACAa2B43C1877424ceB0CB --- constants/pools.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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, From c5a49f3b1b642ea23e3f6674d304a331556f151a Mon Sep 17 00:00:00 2001 From: yosuke Date: Thu, 2 Jan 2025 18:21:46 +0900 Subject: [PATCH 2/7] add constant AddressZero and modify fetchPriceFeed --- constants/chains.ts | 2 ++ hooks/util/priceFeedUtils.ts | 2 ++ 2 files changed, 4 insertions(+) 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/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(); From 68775e9a73977a4ee0ae9d29bb4ee81d17a99edb Mon Sep 17 00:00:00 2001 From: yosuke Date: Fri, 3 Jan 2025 11:07:38 +0900 Subject: [PATCH 3/7] use usePoolData and modify GraphModel --- components/pool/graph/GraphModel.tsx | 5 +++-- components/pool/graph/RewardGraph.tsx | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/pool/graph/GraphModel.tsx b/components/pool/graph/GraphModel.tsx index 2ae3624..a4901be 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,11 @@ 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..5f40ce8 100644 --- a/components/pool/graph/RewardGraph.tsx +++ b/components/pool/graph/RewardGraph.tsx @@ -3,9 +3,16 @@ 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 { priceFeedData, baseAssetData, tokenRewardData, positionSummary } = + usePoolData(); + // if(tokenRewardData){ + // console.log(tokenRewardData.supplyRewardAPR); + // console.log(tokenRewardData.borrowRewardAPR); + // } const rateSlopeHigh = parseFloat( (OneHundred / (OneHundred - poolData.rewardKink)).toFixed(2), @@ -29,8 +36,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, }} /> ); From f62ffa0a9675dd58f44ebde3d8d69b94dda260a5 Mon Sep 17 00:00:00 2001 From: yosuke Date: Fri, 3 Jan 2025 11:16:18 +0900 Subject: [PATCH 4/7] remove calculateTotalBalance and calculateRewardData from hooks/util/graph --- hooks/graph/useRewardData.ts | 26 +------------------------- hooks/util/graph.ts | 25 +------------------------ 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/hooks/graph/useRewardData.ts b/hooks/graph/useRewardData.ts index d91571b..b7d0eee 100644 --- a/hooks/graph/useRewardData.ts +++ b/hooks/graph/useRewardData.ts @@ -2,7 +2,6 @@ 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({ @@ -22,30 +21,7 @@ const useRewardData = ({ poolData }: { poolData: PoolConfig }) => { 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; diff --git a/hooks/util/graph.ts b/hooks/util/graph.ts index 4b8ec67..c5cba8b 100644 --- a/hooks/util/graph.ts +++ b/hooks/util/graph.ts @@ -102,27 +102,4 @@ export const getTransform = ( ? "translateX(-100%)" : "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; +}; \ No newline at end of file From b52a0670427d3fdd7ac2b25a4e242f936d512d01 Mon Sep 17 00:00:00 2001 From: yosuke Date: Fri, 3 Jan 2025 11:17:57 +0900 Subject: [PATCH 5/7] remove RewardDataProps from interfaces/graph --- hooks/graph/useRewardData.ts | 3 +-- interfaces/graph.ts | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/hooks/graph/useRewardData.ts b/hooks/graph/useRewardData.ts index b7d0eee..2f33272 100644 --- a/hooks/graph/useRewardData.ts +++ b/hooks/graph/useRewardData.ts @@ -1,10 +1,9 @@ import { useEffect, useState } from "react"; import usePoolData from "hooks/pool/usePoolData"; import { PoolConfig } from "interfaces/pool"; -import { RewardDataProps } from "interfaces/graph"; const useRewardData = ({ poolData }: { poolData: PoolConfig }) => { - const [tempRewardData, setTempRewardData] = useState({ + const [tempRewardData, setTempRewardData] = useState({ borrow: undefined, earn: undefined, }); diff --git a/interfaces/graph.ts b/interfaces/graph.ts index 1306b99..06a0881 100644 --- a/interfaces/graph.ts +++ b/interfaces/graph.ts @@ -30,7 +30,3 @@ export interface RenderGraphSectionProps { poolData: PoolConfig; } -export interface RewardDataProps { - borrow: number | undefined; - earn: number | undefined; -} From 4d8a12fd54def1d5de2b64c9eac49b0e19f81b3e Mon Sep 17 00:00:00 2001 From: yosuke Date: Fri, 3 Jan 2025 11:19:21 +0900 Subject: [PATCH 6/7] remove useRewardData --- components/pool/graph/RewardGraph.tsx | 8 +------- hooks/graph/useRewardData.ts | 29 --------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 hooks/graph/useRewardData.ts diff --git a/components/pool/graph/RewardGraph.tsx b/components/pool/graph/RewardGraph.tsx index 5f40ce8..71a0ff3 100644 --- a/components/pool/graph/RewardGraph.tsx +++ b/components/pool/graph/RewardGraph.tsx @@ -2,17 +2,11 @@ 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 { priceFeedData, baseAssetData, tokenRewardData, positionSummary } = + const { tokenRewardData } = usePoolData(); - // if(tokenRewardData){ - // console.log(tokenRewardData.supplyRewardAPR); - // console.log(tokenRewardData.borrowRewardAPR); - // } const rateSlopeHigh = parseFloat( (OneHundred / (OneHundred - poolData.rewardKink)).toFixed(2), diff --git a/hooks/graph/useRewardData.ts b/hooks/graph/useRewardData.ts deleted file mode 100644 index 2f33272..0000000 --- a/hooks/graph/useRewardData.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useEffect, useState } from "react"; -import usePoolData from "hooks/pool/usePoolData"; -import { PoolConfig } from "interfaces/pool"; - -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; - - }, [priceFeedData, totalPoolData]); - - return tempRewardData; -}; - -export default useRewardData; From c2669ccac2687b439e6f17f9187b838120adb5d5 Mon Sep 17 00:00:00 2001 From: yosuke Date: Sat, 4 Jan 2025 17:53:50 +0900 Subject: [PATCH 7/7] excute format --- components/pool/graph/GraphModel.tsx | 9 +++++++-- components/pool/graph/RewardGraph.tsx | 3 +-- hooks/util/graph.ts | 2 +- interfaces/graph.ts | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/pool/graph/GraphModel.tsx b/components/pool/graph/GraphModel.tsx index a4901be..46871b5 100644 --- a/components/pool/graph/GraphModel.tsx +++ b/components/pool/graph/GraphModel.tsx @@ -62,11 +62,16 @@ const GraphModel: React.FC = ({ useEffect(() => { if (rewardAPRValue?.borrow || rewardAPRValue?.borrow === 0) { setRewardBorrow( - (truncateTo3DecimalPlaces(rewardAPRValue.borrow) * hoverData.borrowValue) / OneHundred, + (truncateTo3DecimalPlaces(rewardAPRValue.borrow) * + hoverData.borrowValue) / + OneHundred, ); } if (rewardAPRValue?.earn || rewardAPRValue?.earn === 0) { - setRewardEarn((truncateTo3DecimalPlaces(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 71a0ff3..a7e568a 100644 --- a/components/pool/graph/RewardGraph.tsx +++ b/components/pool/graph/RewardGraph.tsx @@ -5,8 +5,7 @@ import { OneHundred, rateSlopeLow } from "constants/graph"; import usePoolData from "hooks/pool/usePoolData"; const RewardGraph = ({ poolData }: { poolData: PoolConfig }) => { - const { tokenRewardData } = - usePoolData(); + const { tokenRewardData } = usePoolData(); const rateSlopeHigh = parseFloat( (OneHundred / (OneHundred - poolData.rewardKink)).toFixed(2), diff --git a/hooks/util/graph.ts b/hooks/util/graph.ts index c5cba8b..25583cb 100644 --- a/hooks/util/graph.ts +++ b/hooks/util/graph.ts @@ -102,4 +102,4 @@ export const getTransform = ( ? "translateX(-100%)" : "translateX(-50%)"; } -}; \ No newline at end of file +}; diff --git a/interfaces/graph.ts b/interfaces/graph.ts index 06a0881..0b76d54 100644 --- a/interfaces/graph.ts +++ b/interfaces/graph.ts @@ -29,4 +29,3 @@ export interface RenderGraphSectionProps { GraphComponent: React.FC<{ poolData: PoolConfig }>; poolData: PoolConfig; } -