Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 0 deletions src/components/incentives/IncentivesTooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ const IncentivesSymbolMap: {
symbol: 'aUSDT',
aToken: true,
},
aUSDT: {
tokenIconSymbol: 'usdt',
symbol: 'aUSDT',
aToken: true,
},
aManUSDe: {
tokenIconSymbol: 'USDe',
symbol: 'aUSDe',
Expand Down
84 changes: 41 additions & 43 deletions src/components/incentives/MerklIncentivesTooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,52 +187,50 @@ export const MerklIncentivesTooltipContent = ({
</Row>
) : merklIncentives.rewardsTokensMappedApys &&
merklIncentives.rewardsTokensMappedApys.length > 1 ? (
<>
{merklIncentives.rewardsTokensMappedApys.map((reward, index) => {
const { tokenIconSymbol, symbol, aToken } = getSymbolMap({
rewardTokenSymbol: reward.token.symbol,
rewardTokenAddress: reward.token.address,
incentiveAPR: reward.apy.toString(),
});
return (
<Row
key={index}
height={32}
caption={
<Box
sx={{
display: 'flex',
alignItems: 'center',
mb: 0,
}}
>
<TokenIcon
symbol={tokenIconSymbol}
aToken={aToken}
sx={{ fontSize: '20px', mr: 1 }}
/>
<Typography variant={typographyVariant}>{symbol}</Typography>
<Typography variant={typographyVariant} sx={{ ml: 0.5 }}>
{merklIncentives.breakdown.isBorrow ? '(-)' : '(+)'}
</Typography>
</Box>
}
width="100%"
>
<Box sx={{ display: 'inline-flex', alignItems: 'center' }}>
<FormattedNumber
value={merklIncentives.breakdown.isBorrow ? -reward.apy : reward.apy}
percent
variant={typographyVariant}
merklIncentives.rewardsTokensMappedApys.map((reward, index) => {
const { tokenIconSymbol, symbol, aToken } = getSymbolMap({
rewardTokenSymbol: reward.token.symbol,
rewardTokenAddress: reward.token.address,
incentiveAPR: reward.apy.toString(),
});
return (
<Row
key={index}
height={32}
caption={
<Box
sx={{
display: 'flex',
alignItems: 'center',
mb: 0,
}}
>
<TokenIcon
symbol={tokenIconSymbol}
aToken={aToken}
sx={{ fontSize: '20px', mr: 1 }}
/>
<Typography variant={typographyVariant} sx={{ ml: 1 }}>
<Trans>APY</Trans>
<Typography variant={typographyVariant}>{symbol}</Typography>
<Typography variant={typographyVariant} sx={{ ml: 0.5 }}>
{merklIncentives.breakdown.isBorrow ? '(-)' : '(+)'}
</Typography>
</Box>
</Row>
);
})}
</>
}
width="100%"
>
<Box sx={{ display: 'inline-flex', alignItems: 'center' }}>
<FormattedNumber
value={merklIncentives.breakdown.isBorrow ? -reward.apy : reward.apy}
percent
variant={typographyVariant}
/>
<Typography variant={typographyVariant} sx={{ ml: 1 }}>
<Trans>APY</Trans>
</Typography>
</Box>
</Row>
);
})
) : (
<Row
height={32}
Expand Down
27 changes: 4 additions & 23 deletions src/hooks/useMerklIncentives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,9 @@ export type MerklIncentivesBreakdown = {
pointsPerThousandUsd: number;
};
};
type WhitelistApiResponse = {
whitelistedRewardTokens: string[];
additionalIncentiveInfo: Record<string, ReserveIncentiveAdditionalData>;
};

const MERKL_ENDPOINT =
'https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave&items=100&status=LIVE'; // Merkl API
const WHITELIST_ENDPOINT = 'https://apps.aavechan.com/api/aave/merkl/whitelist-token-list'; // Endpoint to fetch whitelisted tokens
const AAVE_NET_APR_DISTRIBUTION_TYPE = 'AAVE_NET_APR';
const convertApyToApr = (apy: number) => 12 * ((1 + apy) ** (1 / 12) - 1);

Expand Down Expand Up @@ -194,19 +189,6 @@ const checkOpportunityAction = (
return false;
}
};
const useWhitelistedTokens = () => {
return useQuery({
queryFn: async (): Promise<WhitelistApiResponse> => {
const response = await fetch(WHITELIST_ENDPOINT);
if (!response.ok) {
throw new Error('Failed to fetch whitelisted tokens');
}
return await response.json();
},
queryKey: ['whitelistedTokens'],
staleTime: 1000 * 60 * 5, // 5 minutes
});
};

export const useMerklIncentives = ({
market,
Expand All @@ -222,7 +204,6 @@ export const useMerklIncentives = ({
protocolIncentives?: ReserveIncentiveResponse[];
}) => {
const currentChainId = useRootStore((state) => state.currentChainId);
const { data: whitelistData } = useWhitelistedTokens();

return useQuery({
queryFn: async () => {
Expand Down Expand Up @@ -252,14 +233,13 @@ export const useMerklIncentives = ({
(opp) => opp.status === OpportunityStatus.LIVE && opp.apr > 0
);

if (!whitelistData?.whitelistedRewardTokens) {
if (!EXTRA_WHITELIST_TOKENS?.whitelistedRewardTokens) {
return null;
}

const whitelistedTokensSet = new Set(
[
...whitelistData.whitelistedRewardTokens.map((token) => token.toLowerCase()),
...EXTRA_WHITELIST_TOKENS,
...EXTRA_WHITELIST_TOKENS.whitelistedRewardTokens.map((token) => token.toLowerCase()),
].filter(Boolean)
);

Expand Down Expand Up @@ -334,7 +314,8 @@ export const useMerklIncentives = ({
: protocolAPY + protocolIncentivesAPY + merklIncentivesAPY;

const incentiveKey = `${currentChainId}-${checksumAddress(rewardedAsset as Address)}`;
const incentiveAdditionalData = whitelistData?.additionalIncentiveInfo?.[incentiveKey];
const incentiveAdditionalData =
EXTRA_WHITELIST_TOKENS?.additionalIncentiveInfo?.[incentiveKey];

return {
incentiveAPR: merklIncentivesAPY.toString(),
Expand Down
Loading
Loading