@@ -2,9 +2,7 @@ import { ProtocolAction } from '@aave/contract-helpers';
22import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives' ;
33import { useQuery } from '@tanstack/react-query' ;
44import { useRootStore } from 'src/store/root' ;
5- import { additionalIncentiveInfo } from 'src/utils/addtional-incentive-infos' ;
65import { convertAprToApy } from 'src/utils/utils' ;
7- import { whitelistedRewardTokens } from 'src/utils/whitelist' ;
86import { Address , checksumAddress } from 'viem' ;
97
108enum OpportunityAction {
@@ -96,11 +94,15 @@ export type MerklIncentivesBreakdown = {
9694 merklIncentives : number ; // Now represents APY (converted from APR)
9795 } ;
9896} ;
97+ type WhitelistApiResponse = {
98+ whitelistedRewardTokens : string [ ] ;
99+ additionalIncentiveInfo : Record < string , ReserveIncentiveAdditionalData > ;
100+ } ;
99101
100102const hardcodedIncentives : Record < string , ExtendedReserveIncentiveResponse > = { } ;
101103
102104const MERKL_ENDPOINT = 'https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave' ; // Merkl API
103-
105+ const WHITELIST_ENDPOINT = 'https://apps.aavechan.com/api/aave/merkl/whitelist-token-list' ; // Endpoint to fetch whitelisted tokens
104106const checkOpportunityAction = (
105107 opportunityAction : OpportunityAction ,
106108 protocolAction : ProtocolAction
@@ -114,6 +116,19 @@ const checkOpportunityAction = (
114116 return false ;
115117 }
116118} ;
119+ const useWhitelistedTokens = ( ) => {
120+ return useQuery ( {
121+ queryFn : async ( ) : Promise < WhitelistApiResponse > => {
122+ const response = await fetch ( WHITELIST_ENDPOINT ) ;
123+ if ( ! response . ok ) {
124+ throw new Error ( 'Failed to fetch whitelisted tokens' ) ;
125+ }
126+ return response . json ( ) ;
127+ } ,
128+ queryKey : [ 'whitelistedTokens' ] ,
129+ staleTime : 1000 * 60 * 5 , // 5 minutes
130+ } ) ;
131+ } ;
117132
118133export const useMerklIncentives = ( {
119134 market,
@@ -129,6 +144,7 @@ export const useMerklIncentives = ({
129144 protocolIncentives ?: ReserveIncentiveResponse [ ] ;
130145} ) => {
131146 const currentChainId = useRootStore ( ( state ) => state . currentChainId ) ;
147+ const { data : whitelistData } = useWhitelistedTokens ( ) ;
132148
133149 return useQuery ( {
134150 queryFn : async ( ) => {
@@ -174,7 +190,15 @@ export const useMerklIncentives = ({
174190
175191 const rewardToken = opportunity . rewardsRecord . breakdowns [ 0 ] . token ;
176192
177- if ( ! whitelistedRewardTokens . has ( checksumAddress ( rewardToken . address as Address ) ) ) {
193+ if ( ! whitelistData ?. whitelistedRewardTokens ) {
194+ return null ;
195+ }
196+
197+ const whitelistedTokensSet = new Set (
198+ whitelistData . whitelistedRewardTokens . map ( ( token ) => token . toLowerCase ( ) )
199+ ) ;
200+
201+ if ( ! whitelistedTokensSet . has ( rewardToken . address . toLowerCase ( ) ) ) {
178202 return null ;
179203 }
180204
@@ -187,9 +211,8 @@ export const useMerklIncentives = ({
187211 ? protocolAPY - protocolIncentivesAPR - merklIncentivesAPY
188212 : protocolAPY + protocolIncentivesAPR + merklIncentivesAPY ;
189213
190- const incentiveAdditionalData = rewardedAsset
191- ? additionalIncentiveInfo [ checksumAddress ( rewardedAsset as Address ) ]
192- : undefined ;
214+ const incentiveKey = `${ currentChainId } -${ checksumAddress ( rewardedAsset as Address ) } ` ;
215+ const incentiveAdditionalData = whitelistData ?. additionalIncentiveInfo ?. [ incentiveKey ] ;
193216
194217 return {
195218 incentiveAPR : merklIncentivesAPY . toString ( ) ,
0 commit comments