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 all 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 @@ -34,7 +34,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 @@ -46,6 +46,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 @@ -3471,6 +3471,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 @@ -166,6 +166,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 @@ -11,6 +11,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 @@ -27,6 +28,7 @@ export const BorrowAssetsListItem = ({
vIncentivesData,
underlyingAsset,
isFreezed,
underlyingAPY,
}: DashboardReserve) => {
const { openBorrow } = useModalContext();
const { currentMarket } = useProtocolDataContext();
Expand Down Expand Up @@ -61,15 +63,21 @@ export const BorrowAssetsListItem = ({
}
/>
<ListAPRColumn
value={Number(variableBorrowRate)}
value={
underlyingAPY ? Number(variableBorrowRate) + underlyingAPY : Number(variableBorrowRate)
}
tooltip={
underlyingAPY ? (
<ListAPYDetails
apy={Number(variableBorrowRate)}
side={Side.BORROW}
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 @@ -11,6 +11,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 @@ -26,6 +27,7 @@ export const BorrowAssetsListMobileItem = ({
vIncentivesData,
underlyingAsset,
isFreezed,
underlyingAPY,
}: DashboardReserve) => {
const { openBorrow } = useModalContext();
const { currentMarket } = useProtocolDataContext();
Expand Down Expand Up @@ -68,7 +70,18 @@ export const BorrowAssetsListMobileItem = ({
mb={2}
>
<IncentivesCard
value={Number(variableBorrowRate)}
value={
underlyingAPY ? Number(variableBorrowRate) + underlyingAPY : Number(variableBorrowRate)
}
tooltip={
underlyingAPY ? (
<ListAPYDetails
apy={Number(variableBorrowRate)}
side={Side.BORROW}
underlyingAPY={underlyingAPY}
/>
) : null
}
incentives={vIncentivesData}
symbol={symbol}
variant="secondary14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { showSuperFestTooltip, Side } from 'src/utils/utils';

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 @@ -139,7 +140,20 @@ 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
apy={borrowAPY}
side={Side.BORROW}
underlyingAPY={reserve.underlyingAPY}
/>
) : null
}
incentives={incentives}
symbol={reserve.symbol}
/>

<ListColumn>
<ListItemAPYButton
Expand Down Expand Up @@ -229,7 +243,16 @@ 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
apy={borrowAPY}
side={Side.BORROW}
underlyingAPY={reserve.underlyingAPY}
/>
) : null
}
incentives={incentives}
symbol={symbol}
variant="secondary14"
Expand Down
47 changes: 47 additions & 0 deletions src/modules/dashboard/lists/ListAPYDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Trans } from '@lingui/macro';
import { Box } from '@mui/material';
import { IncentivesCard } from 'src/components/incentives/IncentivesCard';
import { TextWithTooltip } from 'src/components/TextWithTooltip';
import { Side } from 'src/utils/utils';

interface ListAPYDetailsProps {
underlyingAPY: number;
apy: number;
side: Side;
}

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, apy, side }: ListAPYDetailsProps) => {
return (
<TextWithTooltip>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: '4px',
}}
>
<APYBox
symbol={side == Side.SUPPLY ? 'Supply APY' : side == Side.BORROW ? 'Borrow APY' : ''}
value={apy}
/>
<APYBox symbol="Underlying APY" value={underlyingAPY} />
</Box>
</TextWithTooltip>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -69,7 +70,20 @@ export const SuppliedPositionsListItem = ({
/>

<ListAPRColumn
value={Number(reserve.supplyAPY)}
value={
reserve.underlyingAPY
? Number(reserve.supplyAPY) + reserve.underlyingAPY
: Number(reserve.supplyAPY)
}
tooltip={
reserve.underlyingAPY ? (
<ListAPYDetails
apy={Number(reserve.supplyAPY)}
side={Side.SUPPLY}
underlyingAPY={reserve.underlyingAPY}
/>
) : null
}
incentives={aIncentivesData}
symbol={reserve.symbol}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -36,6 +37,7 @@ export const SuppliedPositionsListMobileItem = ({
isFrozen,
isActive,
isPaused,
underlyingAPY,
} = reserve;

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