Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement underlying token APYs #2092

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3e68e0a
feat: start implementing token native yield
MartinGbz Jun 19, 2024
d0390b0
feat: implement native steth yield in "Net APY" & "APY" box + compute…
MartinGbz Jun 20, 2024
a64d87d
feat: add native apy in asset apy
MartinGbz Jun 20, 2024
f4905ac
refactor: use "underlying" instead of "token native" term + add new c…
MartinGbz Jun 20, 2024
c7969b5
refactor: code cleaning
MartinGbz Jun 20, 2024
94c5fb2
feat: add underlying apr to borrow section
MartinGbz Jun 21, 2024
d23dd15
refactor: use symbol instead of token address for mapping underlying …
MartinGbz Jun 21, 2024
cefcd39
feat: refactor get underlying yields + implement assets lists
MartinGbz Jun 21, 2024
2ebae4f
refactor: remove logs and comments
MartinGbz Jun 21, 2024
d29d70d
feat: add underlying apy to markets page
MartinGbz Jun 24, 2024
24fc051
fix: apy details 0 value issue
MartinGbz Jun 24, 2024
ffaccc3
feat: implement sdai apy
MartinGbz Jun 24, 2024
4911482
feat: implement reth apy
MartinGbz Jun 24, 2024
bdf945b
fix: code cleaning
MartinGbz Jun 24, 2024
3c53b2d
feat: implement ethx apy
MartinGbz Jun 25, 2024
e06e800
refactor: _getApyFromPreviousRates
MartinGbz Jun 25, 2024
dfe6631
feat: implement cbETH
MartinGbz Jun 25, 2024
083da58
refactor: code
MartinGbz Jun 25, 2024
7fb9cc2
feat: implement weeth apy
MartinGbz Jun 26, 2024
85ecd2c
refactor: code
MartinGbz Jun 26, 2024
16ad928
refactor: use global variable for events period
MartinGbz Jun 26, 2024
e8350df
refactor: code cleaning
MartinGbz Jun 26, 2024
b578675
fix: typing error
MartinGbz Jun 28, 2024
8f8e132
fix: use aave-address-book addresses + add config file for other addr…
MartinGbz Jul 12, 2024
cac4374
fix: set block range to 1k max for event fetching
MartinGbz Jul 16, 2024
9e52af3
fix: change block range + clean code
MartinGbz Jul 16, 2024
aed099d
Merge branch 'aave:main' into feat/implement-lst-native-yield
MartinGbz Aug 1, 2024
9d26f95
Merge branch 'main' into feat/implement-lst-native-yield
MartinGbz Aug 1, 2024
a0830ba
fix: adapt underlying apy tooltip with superfest one
MartinGbz Aug 1, 2024
c931137
Merge branch 'feat/implement-lst-native-yield' of https://github.com/…
MartinGbz Aug 1, 2024
5495d97
fix: use rocketStorage contract to get rocketNetworkBalances address
MartinGbz Sep 20, 2024
2b8b14d
fix: apy display issue on borrow disabled
MartinGbz Sep 24, 2024
011c582
feat: add log to apy API functions
MartinGbz Sep 24, 2024
e7515b3
fix: borrow/supply apy label
MartinGbz Sep 24, 2024
bba6dfa
refactor: use side enum type
MartinGbz Sep 24, 2024
f6b77ff
fix: use side prop in ListAPYDetails
MartinGbz Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hooks/app-data-provider/useAppDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ export const AppDataProvider: React.FC = ({ children }) => {

const currentMarketData = useRootStore((state) => state.currentMarketData);
const currentMarket = useRootStore((state) => state.currentMarket);
// pool hooks

// pool hooks
const { data: reservesData, isLoading: reservesDataLoading } =
usePoolReservesHumanized(currentMarketData);

const { data: formattedPoolReserves, isLoading: formattedPoolReservesLoading } =
usePoolFormattedReserves(currentMarketData);
const baseCurrencyData = reservesData?.baseCurrencyData;
// user hooks

// user hooks
const eModes = reservesData?.reservesData ? formatEmodes(reservesData.reservesData) : {};

const { data: userReservesData, isLoading: userReservesDataLoading } =
Expand Down
21 changes: 16 additions & 5 deletions src/hooks/pool/usePoolFormattedReserves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { formatReservesAndIncentives } from '@aave/math-utils';
import dayjs from 'dayjs';
import memoize from 'micro-memoize';
import { UnderlyingAPYs } from 'src/services/UnderlyingYieldService';
import { reserveSortFn } from 'src/store/poolSelectors';
import { MarketDataType } from 'src/ui-config/marketsConfig';
import { fetchIconSymbolAndName, IconMapInterface } from 'src/ui-config/reservePatches';
Expand All @@ -14,6 +15,7 @@ import { getNetworkConfig, NetworkConfig } from 'src/utils/marketsAndNetworksCon
import { selectBaseCurrencyData, selectReserves } from './selectors';
import { usePoolsReservesHumanized } from './usePoolReserves';
import { usePoolsReservesIncentivesHumanized } from './usePoolReservesIncentives';
import { useUnderlyingYields } from './useUnderlyingYield';
import { combineQueries, SimplifiedUseQueryResult } from './utils';

export type FormattedReservesAndIncentives = ReturnType<
Expand All @@ -22,13 +24,16 @@ export type FormattedReservesAndIncentives = ReturnType<
IconMapInterface & {
isEmodeEnabled: boolean;
isWrappedBaseAsset: boolean;
} & ReserveDataHumanized;
} & ReserveDataHumanized & {
underlyingAPY: number | null;
};

const formatReserves = memoize(
(
reservesData: ReservesDataHumanized,
incentivesData: ReservesIncentiveDataHumanized[],
networkConfig: NetworkConfig
networkConfig: NetworkConfig,
underlyingAPYs: UnderlyingAPYs
) => {
const reserves = selectReserves(reservesData);
const baseCurrencyData = selectBaseCurrencyData(reservesData);
Expand All @@ -45,6 +50,7 @@ const formatReserves = memoize(
isEmodeEnabled: r.eModeCategoryId !== 0,
isWrappedBaseAsset:
r.symbol.toLowerCase() === networkConfig.wrappedBaseAssetSymbol?.toLowerCase(),
underlyingAPY: underlyingAPYs ? underlyingAPYs[r.symbol] : null,
}))
.sort(reserveSortFn);
}
Expand All @@ -55,18 +61,23 @@ export const usePoolsFormattedReserves = (
): SimplifiedUseQueryResult<FormattedReservesAndIncentives[]>[] => {
const poolsReservesQueries = usePoolsReservesHumanized(marketsData);
const poolsReservesIncentivesQueries = usePoolsReservesIncentivesHumanized(marketsData);
const underlyingAPYs = useUnderlyingYields();

return poolsReservesQueries.map((poolReservesQuery, index) => {
const marketData = marketsData[index];
const poolReservesIncentivesQuery = poolsReservesIncentivesQueries[index];
const networkConfig = getNetworkConfig(marketData.chainId);
const selector = (
reservesData: ReservesDataHumanized,
incentivesData: ReservesIncentiveDataHumanized[]
incentivesData: ReservesIncentiveDataHumanized[],
underlyingAPYs: UnderlyingAPYs
) => {
return formatReserves(reservesData, incentivesData, networkConfig);
return formatReserves(reservesData, incentivesData, networkConfig, underlyingAPYs);
};
return combineQueries([poolReservesQuery, poolReservesIncentivesQuery] as const, selector);
return combineQueries(
[poolReservesQuery, poolReservesIncentivesQuery, underlyingAPYs] as const,
selector
);
});
};

Expand Down
15 changes: 15 additions & 0 deletions src/hooks/pool/useUnderlyingYield.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useQuery } from '@tanstack/react-query';
import { UnderlyingAPYs } from 'src/services/UnderlyingYieldService';
import { POLLING_INTERVAL, queryKeysFactory } from 'src/ui-config/queries';
import { useSharedDependencies } from 'src/ui-config/SharedDependenciesProvider';

import { SimplifiedUseQueryResult } from './utils';

export const useUnderlyingYields = (): SimplifiedUseQueryResult<UnderlyingAPYs> => {
const { underlyingYieldService } = useSharedDependencies();
return useQuery({
queryKey: queryKeysFactory.underlyingYields(),
queryFn: () => underlyingYieldService.getUnderlyingAPYs(),
refetchInterval: POLLING_INTERVAL,
});
};
8 changes: 7 additions & 1 deletion src/hooks/pool/useUserYield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const formatUserYield = memoize(
formattedGhoUserData: FormattedGhoUserData | undefined,
user: FormatUserSummaryAndIncentivesResponse,
currentMarket: string
) => {
): UserYield => {
const proportions = user.userReservesData.reduce(
(acc, value) => {
const reserve = formattedPoolReserves.find(
Expand All @@ -42,6 +42,12 @@ const formatUserYield = memoize(
acc.positiveProportion = acc.positiveProportion.plus(
new BigNumber(reserve.supplyAPY).multipliedBy(value.underlyingBalanceUSD)
);

if (reserve.underlyingAPY) {
acc.positiveProportion = acc.positiveProportion.plus(
new BigNumber(reserve.underlyingAPY).multipliedBy(value.underlyingBalanceUSD)
);
}
if (reserve.aIncentivesData) {
reserve.aIncentivesData.forEach((incentive) => {
acc.positiveProportion = acc.positiveProportion.plus(
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3350,6 +3350,7 @@ msgstr "withdrew"
#: src/layouts/TopBarNotify.tsx
#: src/layouts/TopBarNotify.tsx
#: src/modules/dashboard/DashboardEModeButton.tsx
#: src/modules/dashboard/lists/ListAPYDetails.tsx
#: src/modules/reserve-overview/ReserveTopDetailsWrapper.tsx
#: src/modules/staking/GhoDiscountProgram.tsx
msgid "{0}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const BorrowAssetsList = () => {
'asset',
filteredReserves as unknown as DashboardReserve[]
);

const borrowDisabled = !sortedReserves.length && !ghoReserve;

const RenderHeader: React.FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CapsHint } from '../../../../components/caps/CapsHint';
import { CapType } from '../../../../components/caps/helper';
import { Link, ROUTES } from '../../../../components/primitives/Link';
import { ListAPRColumn } from '../ListAPRColumn';
import { ListAPYDetails } from '../ListAPYDetails';
import { ListButtonsColumn } from '../ListButtonsColumn';
import { ListItemWrapper } from '../ListItemWrapper';
import { ListValueColumn } from '../ListValueColumn';
Expand All @@ -26,6 +27,7 @@ export const BorrowAssetsListItem = ({
vIncentivesData,
underlyingAsset,
isFreezed,
underlyingAPY,
}: DashboardReserve) => {
const { openBorrow } = useModalContext();
const { currentMarket } = useProtocolDataContext();
Expand Down Expand Up @@ -59,15 +61,17 @@ export const BorrowAssetsListItem = ({
}
/>
<ListAPRColumn
value={Number(variableBorrowRate)}
value={
underlyingAPY ? Number(variableBorrowRate) + underlyingAPY : Number(variableBorrowRate)
}
tooltip={
underlyingAPY ? (
<ListAPYDetails borrowAPY={Number(variableBorrowRate)} underlyingAPY={underlyingAPY} />
) : null
}
incentives={vIncentivesData}
symbol={symbol}
/>
{/* <ListAPRColumn
value={Number(stableBorrowRate)}
incentives={sIncentivesData}
symbol={symbol}
/> */}
<ListButtonsColumn>
<Button
disabled={disableBorrow}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IncentivesCard } from '../../../../components/incentives/IncentivesCard
import { Link, ROUTES } from '../../../../components/primitives/Link';
import { Row } from '../../../../components/primitives/Row';
import { useModalContext } from '../../../../hooks/useModal';
import { ListAPYDetails } from '../ListAPYDetails';
import { ListMobileItemWrapper } from '../ListMobileItemWrapper';
import { ListValueRow } from '../ListValueRow';

Expand All @@ -25,6 +26,7 @@ export const BorrowAssetsListMobileItem = ({
vIncentivesData,
underlyingAsset,
isFreezed,
underlyingAPY,
}: DashboardReserve) => {
const { openBorrow } = useModalContext();
const { currentMarket } = useProtocolDataContext();
Expand Down Expand Up @@ -66,7 +68,17 @@ export const BorrowAssetsListMobileItem = ({
mb={2}
>
<IncentivesCard
value={Number(variableBorrowRate)}
value={
underlyingAPY ? Number(variableBorrowRate) + underlyingAPY : Number(variableBorrowRate)
}
tooltip={
underlyingAPY ? (
<ListAPYDetails
borrowAPY={Number(variableBorrowRate)}
underlyingAPY={underlyingAPY}
/>
) : null
}
incentives={vIncentivesData}
symbol={symbol}
variant="secondary14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isFeatureEnabled } from 'src/utils/marketsAndNetworksConfig';

import { ListColumn } from '../../../../components/lists/ListColumn';
import { ListAPRColumn } from '../ListAPRColumn';
import { ListAPYDetails } from '../ListAPYDetails';
import { ListButtonsColumn } from '../ListButtonsColumn';
import { ListItemAPYButton } from '../ListItemAPYButton';
import { ListItemWrapper } from '../ListItemWrapper';
Expand Down Expand Up @@ -137,7 +138,16 @@ const BorrowedPositionsListItemDesktop = ({
>
<ListValueColumn symbol={reserve.symbol} value={totalBorrows} subValue={totalBorrowsUSD} />

<ListAPRColumn value={borrowAPY} incentives={incentives} symbol={reserve.symbol} />
<ListAPRColumn
value={reserve.underlyingAPY ? borrowAPY + reserve.underlyingAPY : borrowAPY}
tooltip={
reserve.underlyingAPY ? (
<ListAPYDetails borrowAPY={borrowAPY} underlyingAPY={reserve.underlyingAPY} />
) : null
}
incentives={incentives}
symbol={reserve.symbol}
/>

<ListColumn>
<ListItemAPYButton
Expand Down Expand Up @@ -226,7 +236,12 @@ const BorrowedPositionsListItemMobile = ({

<Row caption={<Trans>APY</Trans>} align="flex-start" captionVariant="description" mb={2}>
<IncentivesCard
value={borrowAPY}
value={reserve.underlyingAPY ? borrowAPY + reserve.underlyingAPY : borrowAPY}
tooltip={
reserve.underlyingAPY ? (
<ListAPYDetails borrowAPY={borrowAPY} underlyingAPY={reserve.underlyingAPY} />
) : null
}
incentives={incentives}
symbol={symbol}
variant="secondary14"
Expand Down
44 changes: 44 additions & 0 deletions src/modules/dashboard/lists/ListAPYDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Trans } from '@lingui/macro';
import { Box } from '@mui/material';
import { IncentivesCard } from 'src/components/incentives/IncentivesCard';
import { TextWithTooltip } from 'src/components/TextWithTooltip';

interface ListAPYDetailsProps {
underlyingAPY: number;
supplyAPY?: number;
borrowAPY?: number;
}

const APYBox = ({ symbol, value }: { symbol: string; value: number }) => {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'row',
gap: '4px',
alignItems: 'baseline',
}}
>
<Trans>{symbol + ':'}</Trans>
<IncentivesCard symbol={symbol} value={value} />
</Box>
);
};

export const ListAPYDetails = ({ underlyingAPY, supplyAPY, borrowAPY }: ListAPYDetailsProps) => {
return (
<TextWithTooltip>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: '4px',
}}
>
{supplyAPY !== undefined && <APYBox symbol="Supply APY" value={supplyAPY} />}
{borrowAPY !== undefined && <APYBox symbol="Borrow APY" value={borrowAPY} />}
<APYBox symbol="Underlying APY" value={underlyingAPY} />
</Box>
</TextWithTooltip>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ListColumn } from '../../../../components/lists/ListColumn';
import { useProtocolDataContext } from '../../../../hooks/useProtocolDataContext';
import { isFeatureEnabled } from '../../../../utils/marketsAndNetworksConfig';
import { ListAPRColumn } from '../ListAPRColumn';
import { ListAPYDetails } from '../ListAPYDetails';
import { ListButtonsColumn } from '../ListButtonsColumn';
import { ListItemUsedAsCollateral } from '../ListItemUsedAsCollateral';
import { ListItemWrapper } from '../ListItemWrapper';
Expand Down Expand Up @@ -66,7 +67,19 @@ export const SuppliedPositionsListItem = ({
/>

<ListAPRColumn
value={Number(reserve.supplyAPY)}
value={
reserve.underlyingAPY
? Number(reserve.supplyAPY) + reserve.underlyingAPY
: Number(reserve.supplyAPY)
}
tooltip={
reserve.underlyingAPY ? (
<ListAPYDetails
supplyAPY={Number(reserve.supplyAPY)}
underlyingAPY={reserve.underlyingAPY}
/>
) : null
}
incentives={aIncentivesData}
symbol={reserve.symbol}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Row } from '../../../../components/primitives/Row';
import { useModalContext } from '../../../../hooks/useModal';
import { useProtocolDataContext } from '../../../../hooks/useProtocolDataContext';
import { isFeatureEnabled } from '../../../../utils/marketsAndNetworksConfig';
import { ListAPYDetails } from '../ListAPYDetails';
import { ListItemUsedAsCollateral } from '../ListItemUsedAsCollateral';
import { ListMobileItemWrapper } from '../ListMobileItemWrapper';
import { ListValueRow } from '../ListValueRow';
Expand All @@ -35,6 +36,7 @@ export const SuppliedPositionsListMobileItem = ({
isFrozen,
isActive,
isPaused,
underlyingAPY,
} = reserve;

const canBeEnabledAsCollateral = user
Expand Down Expand Up @@ -74,7 +76,12 @@ export const SuppliedPositionsListMobileItem = ({
mb={2}
>
<IncentivesCard
value={Number(supplyAPY)}
value={underlyingAPY ? Number(supplyAPY) + underlyingAPY : Number(supplyAPY)}
tooltip={
underlyingAPY ? (
<ListAPYDetails supplyAPY={Number(supplyAPY)} underlyingAPY={underlyingAPY} />
) : null
}
incentives={aIncentivesData}
symbol={symbol}
variant="secondary14"
Expand Down
Loading