Skip to content

Commit f5db583

Browse files
AGMASOCopilot
andauthored
fix: handle API inconsistency and update URL (#2875)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent c6356d6 commit f5db583

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎src/hooks/useMerklPointsIncentives.ts‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ type ReserveIncentiveAdditionalData = {
2828
};
2929

3030
// Hardcoded Merkl endpoint for INK/tydro incentives
31-
const INK_POINT_TOKEN_ADDRESSES = ['0x40aBd730Cc9dA34a8EE9823fEaBDBa35E50c4ac7'];
31+
// Normalize to lowercase for case-insensitive comparison
32+
const INK_POINT_TOKEN_ADDRESSES = ['0x40aBd730Cc9dA34a8EE9823fEaBDBa35E50c4ac7'.toLowerCase()];
3233
const MERKL_TYDRO_ENDPOINT =
33-
'https://api.merkl.xyz/v4/opportunities?mainProtocolId=tydro&chainName=ink'; // Merkl API
34+
'https://api.merkl.xyz/v4/opportunities?mainProtocolId=tydro&chainName=ink&items=100&status=LIVE'; // Merkl API
3435

3536
const checkOpportunityAction = (
3637
opportunityAction: OpportunityAction,
@@ -74,15 +75,20 @@ export const useMerklPointsIncentives = ({
7475
enabled: enabled && !!rewardedAsset && !!protocolAction,
7576
select: (merklOpportunities) => {
7677
const opportunities = merklOpportunities.filter((opportunity) => {
77-
if (!rewardedAsset || !opportunity.explorerAddress || !protocolAction) {
78+
if (!rewardedAsset || !protocolAction) {
7879
return false;
7980
}
80-
const matchingToken = opportunity.tokens.find(
81+
82+
// Prefer explorerAddress (aToken/vToken) but fall back to token list to handle
83+
// API inconsistencies where explorerAddress isn't aligned with token[0].
84+
const matchesExplorer =
85+
opportunity.explorerAddress?.toLowerCase() === rewardedAsset.toLowerCase();
86+
const matchesToken = opportunity.tokens.some(
8187
(token) => token.address.toLowerCase() === rewardedAsset.toLowerCase()
8288
);
8389

8490
return (
85-
matchingToken &&
91+
(matchesExplorer || matchesToken) &&
8692
checkOpportunityAction(opportunity.action, protocolAction) &&
8793
opportunity.chainId === currentChainId
8894
);
@@ -92,13 +98,21 @@ export const useMerklPointsIncentives = ({
9298
return null;
9399
}
94100

95-
const opportunity = opportunities.find((opp) => opp.status === OpportunityStatus.LIVE);
101+
const pointsOpportunities = opportunities.filter((opp) =>
102+
opp.rewardsRecord.breakdowns.some((breakdown) =>
103+
INK_POINT_TOKEN_ADDRESSES.includes(breakdown.token.address.toLowerCase())
104+
)
105+
);
106+
107+
const opportunity = pointsOpportunities.find((opp) => opp.status === OpportunityStatus.LIVE);
96108

97109
if (!opportunity) {
98110
return null;
99111
}
100112

101-
const rewardsBreakdown = opportunity.rewardsRecord.breakdowns[0];
113+
const rewardsBreakdown = opportunity.rewardsRecord.breakdowns.find((breakdown) =>
114+
INK_POINT_TOKEN_ADDRESSES.includes(breakdown.token.address.toLowerCase())
115+
);
102116

103117
if (!rewardsBreakdown) {
104118
return null;
@@ -109,7 +123,7 @@ export const useMerklPointsIncentives = ({
109123

110124
const rewardToken = rewardsBreakdown.token;
111125

112-
if (!INK_POINT_TOKEN_ADDRESSES.includes(rewardToken.address)) {
126+
if (!INK_POINT_TOKEN_ADDRESSES.includes(rewardToken.address.toLowerCase())) {
113127
return null;
114128
}
115129

0 commit comments

Comments
 (0)