Skip to content
Merged
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
30 changes: 22 additions & 8 deletions src/hooks/useMerklPointsIncentives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ type ReserveIncentiveAdditionalData = {
};

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

const checkOpportunityAction = (
opportunityAction: OpportunityAction,
Expand Down Expand Up @@ -74,15 +75,20 @@ export const useMerklPointsIncentives = ({
enabled: enabled && !!rewardedAsset && !!protocolAction,
select: (merklOpportunities) => {
const opportunities = merklOpportunities.filter((opportunity) => {
if (!rewardedAsset || !opportunity.explorerAddress || !protocolAction) {
if (!rewardedAsset || !protocolAction) {
return false;
}
const matchingToken = opportunity.tokens.find(

// Prefer explorerAddress (aToken/vToken) but fall back to token list to handle
// API inconsistencies where explorerAddress isn't aligned with token[0].
const matchesExplorer =
opportunity.explorerAddress?.toLowerCase() === rewardedAsset.toLowerCase();
const matchesToken = opportunity.tokens.some(
(token) => token.address.toLowerCase() === rewardedAsset.toLowerCase()
);

return (
matchingToken &&
(matchesExplorer || matchesToken) &&
checkOpportunityAction(opportunity.action, protocolAction) &&
opportunity.chainId === currentChainId
);
Expand All @@ -92,13 +98,21 @@ export const useMerklPointsIncentives = ({
return null;
}

const opportunity = opportunities.find((opp) => opp.status === OpportunityStatus.LIVE);
const pointsOpportunities = opportunities.filter((opp) =>
opp.rewardsRecord.breakdowns.some((breakdown) =>
INK_POINT_TOKEN_ADDRESSES.includes(breakdown.token.address.toLowerCase())
)
);

const opportunity = pointsOpportunities.find((opp) => opp.status === OpportunityStatus.LIVE);

if (!opportunity) {
return null;
}

const rewardsBreakdown = opportunity.rewardsRecord.breakdowns[0];
const rewardsBreakdown = opportunity.rewardsRecord.breakdowns.find((breakdown) =>
INK_POINT_TOKEN_ADDRESSES.includes(breakdown.token.address.toLowerCase())
);

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

const rewardToken = rewardsBreakdown.token;

if (!INK_POINT_TOKEN_ADDRESSES.includes(rewardToken.address)) {
if (!INK_POINT_TOKEN_ADDRESSES.includes(rewardToken.address.toLowerCase())) {
return null;
}

Expand Down
Loading