From 2bb5298601370335decae30c8a906669dc000f2a Mon Sep 17 00:00:00 2001 From: vkulinich Date: Thu, 7 Mar 2024 15:12:26 +0100 Subject: [PATCH 1/3] Display zero farm apr --- src/api/farms.ts | 12 ++++++++---- .../components/detailsCard/FarmDetailsCard.tsx | 2 +- .../components/globalFarm/GlobalFarmRowMulti.tsx | 13 ++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/api/farms.ts b/src/api/farms.ts index 6802540d5..c4cf2ed10 100644 --- a/src/api/farms.ts +++ b/src/api/farms.ts @@ -280,10 +280,6 @@ function getFarmApr( apr = poolYieldPerPeriod.times(periodsPerYear) } - // multiply by 100 since APR should be a percentage - apr = apr.times(100) - - const minApr = loyaltyFactor ? apr.times(loyaltyFactor) : null // max distribution of rewards // https://www.notion.so/Screen-elements-mapping-Farms-baee6acc456542ca8d2cccd1cc1548ae?p=4a2f16a9f2454095945dbd9ce0eb1b6b&pm=s const distributedRewards = globalFarm.pendingRewards @@ -314,6 +310,13 @@ function getFarmApr( .times(100) .times(priceAdjustment.shiftedBy(-18)) + const isDistributed = distributedRewards.gte(maxRewards) + + // multiply by 100 since APR should be a percentage + apr = isDistributed ? BN_0 : apr.times(100) + + const minApr = loyaltyFactor ? apr.times(loyaltyFactor) : null + return { apr, minApr, @@ -327,6 +330,7 @@ function getFarmApr( rewardCurrency, incentivizedAsset, yieldFarmId: yieldFarm.id.toString(), + isDistributed, } } diff --git a/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx b/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx index f5ea30f91..c67873371 100644 --- a/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx +++ b/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx @@ -102,7 +102,7 @@ export const FarmDetailsCard = ({ - {apr.data.minApr + {apr.data.minApr && apr.data?.apr.gt(0) ? t("value.APR.range", { from: apr.data.minApr, to: apr.data?.apr }) : t("value.APR", { apr: apr.data?.apr })} diff --git a/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx b/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx index 4ab6be057..545f7e0e2 100644 --- a/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx +++ b/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx @@ -29,13 +29,16 @@ export const GlobalFarmRowMulti = ({ if (!farmAprs.data) return null + const { minApr, maxApr } = getMinAndMaxAPR(farmAprs) + return (
- {!!farmAprs.data && ( - - {t(`value.multiAPR`, getMinAndMaxAPR(farmAprs))} - - )} + + {maxApr.gt(0) + ? t(`value.multiAPR`, { minApr, maxApr }) + : t(`value.percentage`, { value: maxApr })} + + ({ From f75800603ed9ba805c1e7a55da02f24843c9b445 Mon Sep 17 00:00:00 2001 From: vkulinich Date: Thu, 7 Mar 2024 15:22:31 +0100 Subject: [PATCH 2/3] wip --- src/sections/pools/table/PoolsTable.utils.tsx | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/sections/pools/table/PoolsTable.utils.tsx b/src/sections/pools/table/PoolsTable.utils.tsx index fe9717a6f..800778c3b 100644 --- a/src/sections/pools/table/PoolsTable.utils.tsx +++ b/src/sections/pools/table/PoolsTable.utils.tsx @@ -17,7 +17,7 @@ import { useRpcProvider } from "providers/rpcProvider" import { MultipleIcons } from "components/MultipleIcons/MultipleIcons" import { AssetLogo } from "components/AssetIcon/AssetIcon" import { TPool, TXYKPool, isXYKPoolType } from "sections/pools/PoolsPage.utils" -import { Farm, useFarmAprs, useFarms } from "api/farms" +import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms" import { GlobalFarmRowMulti } from "sections/pools/farms/components/globalFarm/GlobalFarmRowMulti" import { Button, ButtonTransparent } from "components/Button/Button" import ChevronRightIcon from "assets/icons/ChevronRight.svg?react" @@ -212,27 +212,14 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => { const percentage = useMemo(() => { if (farmAprs.data?.length) { - const aprs = farmAprs.data - ? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0) - : BN_0 - const minAprs = farmAprs.data - ? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr)) - : [BN_0] - - const minApr = BN.minimum(...minAprs) - const maxApr = aprs - - return { - minApr, - maxApr, - } + return getMinAndMaxAPR(farmAprs) } return { minApr: BN_0, maxApr: BN_0, } - }, [farmAprs.data]) + }, [farmAprs]) const isLoading = farmAprs.isInitialLoading @@ -241,10 +228,12 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => { return ( - {t("value.percentage.range", { - from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy), - to: percentage.maxApr.plus(apy), - })} + {percentage.maxApr.gt(0) + ? t("value.percentage.range", { + from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy), + to: percentage.maxApr.plus(apy), + }) + : t("value.percentage", { value: BN(apy) })} ) From abd3617b1d624ba8a0bb37efbe6ad8daa1161f89 Mon Sep 17 00:00:00 2001 From: vkulinich Date: Thu, 7 Mar 2024 15:31:52 +0100 Subject: [PATCH 3/3] Adjust stats page --- .../omnipoolAsset/stats/AssetStats.tsx | 31 +++++++------------ .../OmnipoolAssetsTableWrapper.utils.tsx | 31 +++++++------------ 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx b/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx index 61ad234cb..6cc03cbc8 100644 --- a/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx +++ b/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx @@ -1,7 +1,7 @@ import { useTranslation } from "react-i18next" import { AssetStatsCard } from "./AssetStatsCard" import BN from "bignumber.js" -import { Farm, useFarmAprs, useFarms } from "api/farms" +import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms" import { useMemo } from "react" import { BN_0 } from "utils/constants" import { useRpcProvider } from "providers/rpcProvider" @@ -12,35 +12,26 @@ const APYFarmStatsCard = ({ farms, apy }: { farms: Farm[]; apy: number }) => { const percentage = useMemo(() => { if (farmAprs.data?.length) { - const aprs = farmAprs.data - ? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0) - : BN_0 - const minAprs = farmAprs.data - ? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr)) - : [BN_0] - - const minApr = BN.minimum(...minAprs) - const maxApr = aprs - - return { - minApr, - maxApr, - } + return getMinAndMaxAPR(farmAprs) } return { minApr: BN_0, maxApr: BN_0, } - }, [farmAprs.data]) + }, [farmAprs]) return ( diff --git a/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx b/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx index 87d51f2d5..22a97caff 100644 --- a/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx +++ b/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx @@ -12,7 +12,7 @@ import { OmnipoolAssetsTableColumn } from "sections/stats/components/OmnipoolAss import { useMedia } from "react-use" import { MultipleIcons } from "components/MultipleIcons/MultipleIcons" import { CellSkeleton } from "components/Skeleton/CellSkeleton" -import { Farm, useFarmAprs, useFarms } from "api/farms" +import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms" import { useMemo } from "react" import { BN_0 } from "utils/constants" import BigNumber from "bignumber.js" @@ -27,27 +27,14 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => { const percentage = useMemo(() => { if (farmAprs.data?.length) { - const aprs = farmAprs.data - ? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0) - : BN_0 - const minAprs = farmAprs.data - ? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr)) - : [BN_0] - - const minApr = BigNumber.minimum(...minAprs) - const maxApr = aprs - - return { - minApr, - maxApr, - } + return getMinAndMaxAPR(farmAprs) } return { minApr: BN_0, maxApr: BN_0, } - }, [farmAprs.data]) + }, [farmAprs]) const isLoading = farmAprs.isInitialLoading @@ -55,10 +42,14 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => { return ( - {t("value.percentage.range", { - from: percentage.minApr.lt(apy) ? percentage.minApr : BigNumber(apy), - to: percentage.maxApr.plus(apy), - })} + {percentage.maxApr.gt(0) + ? t("value.percentage.range", { + from: percentage.minApr.lt(apy) + ? percentage.minApr + : BigNumber(apy), + to: percentage.maxApr.plus(apy), + }) + : t("value.percentage", { value: BigNumber(apy) })} ) }