Skip to content

Commit dd4c1b4

Browse files
authored
Fix: Fixed bug not showing Merit Incentives rewards breakdown across all Blockchains & update tooltip to show combined merit rewards (#2620)
1 parent 91bfce1 commit dd4c1b4

4 files changed

Lines changed: 103 additions & 50 deletions

File tree

src/components/incentives/IncentivesCard.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const IncentivesCard = ({
4747
inlineIncentives = false,
4848
}: IncentivesCardProps) => {
4949
const router = useRouter();
50-
5150
const protocolAPY = typeof value === 'string' ? parseFloat(value) : value;
5251

5352
const protocolIncentivesAPR =
@@ -75,6 +74,7 @@ export const IncentivesCard = ({
7574
});
7675

7776
const meritIncentivesAPR = meritIncentives?.breakdown?.meritIncentivesAPR || 0;
77+
7878
// TODO: This is a one-off for the Self campaign.
7979
// Remove once the Self incentives are finished.
8080
const selfAPY = ENABLE_SELF_CAMPAIGN ? meritIncentives?.variants?.selfAPY ?? 0 : 0;
@@ -106,7 +106,6 @@ export const IncentivesCard = ({
106106
protocolAPY={protocolAPY}
107107
address={address}
108108
/>
109-
110109
<MeritIncentivesButton
111110
symbol={symbol}
112111
market={market}
@@ -115,7 +114,6 @@ export const IncentivesCard = ({
115114
protocolIncentives={incentives || []}
116115
hideValue={hideMeritValue}
117116
/>
118-
119117
<MerklIncentivesButton
120118
market={market}
121119
rewardedAsset={address}

src/components/incentives/MeritIncentivesTooltipContent.tsx

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const isSelfVerificationCampaign = (action: MeritAction): boolean => {
5858
return selfCampaignConfig.has(action) && ENABLE_SELF_CAMPAIGN;
5959
};
6060

61+
const isCeloSupplyMultipleBorrowUsdt = (actions: MeritAction[]): boolean => {
62+
return actions.includes(MeritAction.CELO_SUPPLY_MULTIPLE_BORROW_USDT);
63+
};
64+
const isMultipleCampaigns = (actions: MeritAction[]): boolean => {
65+
return actions.length > 1;
66+
};
67+
6168
const getCampaignConfig = (action: MeritAction): CampaignConfig => {
6269
if (isSelfVerificationCampaign(action)) {
6370
return {
@@ -85,7 +92,10 @@ export const MeritIncentivesTooltipContent = ({
8592
}: {
8693
meritIncentives: ExtendedReserveIncentiveResponse & {
8794
breakdown?: MeritIncentivesBreakdown;
88-
variants?: { selfAPY: number | null; totalAPYWithSelf: number | null };
95+
96+
variants?: { selfAPY: number | null };
97+
activeActions: MeritAction[];
98+
actionMessages: Record<string, { customMessage?: string; customForumLink?: string }>;
8999
};
90100
}) => {
91101
const theme = useTheme();
@@ -94,6 +104,9 @@ export const MeritIncentivesTooltipContent = ({
94104

95105
const campaignConfig = getCampaignConfig(meritIncentives.action);
96106
const selfConfig = selfCampaignConfig.get(meritIncentives.action);
107+
const celoSupplyMultipleBorrowUsdtCampaign = isCeloSupplyMultipleBorrowUsdt(
108+
meritIncentives.activeActions
109+
);
97110

98111
return (
99112
<Box
@@ -175,13 +188,16 @@ export const MeritIncentivesTooltipContent = ({
175188
</Typography>
176189
</>
177190
)}
178-
{/* Show if SpecialContent is needed */}
179-
{/* {campaignConfig.type === CampaignType.SELF_VERIFICATION &&
180-
campaignConfig.hasSpecialContent &&
181-
''} */}
182-
{/* Show if SpecialContent is needed */}
183-
{/* {campaignConfig.type === CampaignType.CELO_STANDARD && campaignConfig.hasSpecialContent && ''} */}
184-
191+
{celoSupplyMultipleBorrowUsdtCampaign && (
192+
<Typography variant="caption" color="text.secondary">
193+
<Trans>
194+
{
195+
meritIncentives.actionMessages?.[MeritAction.CELO_SUPPLY_MULTIPLE_BORROW_USDT]
196+
?.customMessage
197+
}
198+
</Trans>
199+
</Typography>
200+
)}
185201
{meritIncentives.customMessage ? (
186202
<Typography variant="caption" color="text.secondary">
187203
<Trans>{meritIncentives.customMessage}</Trans>
@@ -304,12 +320,44 @@ export const MeritIncentivesTooltipContent = ({
304320
/>
305321
</Row>
306322
)}
323+
324+
{campaignConfig.type === CampaignType.STANDARD && (
325+
<Row
326+
height={24}
327+
caption={
328+
<Box sx={{ display: 'flex', alignItems: 'center' }}>
329+
{isMultipleCampaigns(meritIncentives.activeActions) ? (
330+
<Typography variant={typographyVariant}>Merit Incentives Combined</Typography>
331+
) : (
332+
<Typography variant={typographyVariant}>Merit Incentives</Typography>
333+
)}
334+
335+
<Typography variant={typographyVariant} sx={{ ml: 0.5 }}>
336+
{meritIncentives.breakdown.isBorrow ? '(-)' : '(+)'}
337+
</Typography>
338+
</Box>
339+
}
340+
width="100%"
341+
>
342+
<FormattedNumber
343+
value={meritIncentives.breakdown.meritIncentivesAPR}
344+
percent
345+
variant={typographyVariant}
346+
/>
347+
</Row>
348+
)}
349+
307350
{campaignConfig.type === CampaignType.CELO_STANDARD && (
308351
<Row
309352
height={24}
310353
caption={
311354
<Box sx={{ display: 'flex', alignItems: 'center' }}>
312-
<Typography variant={typographyVariant}>Merit Incentives</Typography>
355+
{celoSupplyMultipleBorrowUsdtCampaign ? (
356+
<Typography variant={typographyVariant}>Merit Incentives Combined</Typography>
357+
) : (
358+
<Typography variant={typographyVariant}>Merit Incentives</Typography>
359+
)}
360+
313361
<Typography variant={typographyVariant} sx={{ ml: 0.5 }}>
314362
{meritIncentives.breakdown.isBorrow ? '(-)' : '(+)'}
315363
</Typography>
@@ -331,7 +379,12 @@ export const MeritIncentivesTooltipContent = ({
331379
height={24}
332380
caption={
333381
<Box sx={{ display: 'flex', alignItems: 'center' }}>
334-
<Typography variant={typographyVariant}>Merit Incentives</Typography>
382+
{celoSupplyMultipleBorrowUsdtCampaign ? (
383+
<Typography variant={typographyVariant}>Merit Incentives Combined</Typography>
384+
) : (
385+
<Typography variant={typographyVariant}>Merit Incentives</Typography>
386+
)}
387+
335388
<Typography variant={typographyVariant} sx={{ ml: 0.5 }}>
336389
{meritIncentives.breakdown.isBorrow ? '(-)' : '(+)'}
337390
</Typography>
@@ -387,11 +440,7 @@ export const MeritIncentivesTooltipContent = ({
387440
width="100%"
388441
>
389442
<FormattedNumber
390-
value={
391-
campaignConfig.type === CampaignType.SELF_VERIFICATION
392-
? meritIncentives.variants?.totalAPYWithSelf ?? 0
393-
: meritIncentives.breakdown?.totalAPY ?? 0
394-
}
443+
value={meritIncentives.breakdown?.totalAPY ?? 0}
395444
percent
396445
variant={typographyVariant}
397446
fontWeight="600"

src/hooks/useMeritIncentives.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const joinedEthCorrelatedIncentiveForumLink =
153153
const AusdRenewalForumLink =
154154
'https://governance.aave.com/t/arfc-set-aci-as-emission-manager-for-liquidity-mining-programs/17898/88';
155155
const AvalancheRenewalForumLink =
156-
'https://governance.aave.com/t/arfc-set-aci-as-emission-manager-for-liquidity-mining-programs/17898/146';
156+
'https://governance.aave.com/t/arfc-set-aci-as-emission-manager-for-liquidity-mining-programs/17898/89';
157157

158158
// const lbtcCbbtcForumLink =
159159
// 'https://governance.aave.com/t/arfc-set-aci-as-emission-manager-for-liquidity-mining-programs/17898/91';
@@ -737,6 +737,7 @@ export const useMeritIncentives = ({
737737
staleTime: 1000 * 60 * 5,
738738
select: (data) => {
739739
const meritReserveIncentiveData = getMeritData(market, symbol);
740+
740741
if (!meritReserveIncentiveData) {
741742
return null;
742743
}
@@ -749,58 +750,59 @@ export const useMeritIncentives = ({
749750
return null;
750751
}
751752

752-
let maxTotalAPR = null;
753-
let selectedIncentive = null;
753+
let totalMeritAPR: number | null = null;
754+
let totalSelfAPR: number | null = null;
754755

755756
for (const incentive of incentives) {
756757
const standardAPR = data.actionsAPR[incentive.action];
757-
if (!standardAPR) continue;
758+
if (standardAPR == null) continue;
759+
760+
if (totalMeritAPR === null) totalMeritAPR = 0;
761+
totalMeritAPR += standardAPR;
758762

759763
const variants = getAprVariants(incentive.action, data.actionsAPR);
760-
const selfAPR = ENABLE_SELF_CAMPAIGN ? variants.selfAPR ?? 0 : 0;
761-
const totalAPR = standardAPR + selfAPR; // Merit + Self APR
764+
const selfAPR = ENABLE_SELF_CAMPAIGN ? variants.selfAPR : null;
762765

763-
if (maxTotalAPR === null || totalAPR > maxTotalAPR) {
764-
maxTotalAPR = totalAPR;
765-
selectedIncentive = incentive;
766+
if (selfAPR != null) {
767+
if (totalSelfAPR === null) totalSelfAPR = 0;
768+
totalSelfAPR += selfAPR;
766769
}
767770
}
768771

769-
if (!selectedIncentive || maxTotalAPR === null) {
772+
if (totalMeritAPR === null) {
770773
return null;
771774
}
772775

773-
const variants = getAprVariants(selectedIncentive.action, data.actionsAPR);
774-
const variantsAPY = {
775-
selfAPY: variants.selfAPR ? convertAprToApy(variants.selfAPR / 100) : null,
776-
};
777-
const selectedStandardAPR = data.actionsAPR[selectedIncentive.action]!;
778-
const meritIncentivesAPR = selectedStandardAPR / 100;
779-
const meritIncentivesAPY = convertAprToApy(meritIncentivesAPR);
776+
const meritIncentivesAPY = convertAprToApy(totalMeritAPR / 100);
777+
778+
const selfIncentivesAPY = totalSelfAPR != null ? convertAprToApy(totalSelfAPR / 100) : null;
780779

781780
const protocolIncentivesAPR = protocolIncentives.reduce((sum, inc) => {
782781
return sum + (inc.incentiveAPR === 'Infinity' ? 0 : +inc.incentiveAPR);
783782
}, 0);
784783

785784
const isBorrow = protocolAction === ProtocolAction.borrow;
786785
const totalAPY = isBorrow
787-
? protocolAPY - protocolIncentivesAPR - meritIncentivesAPY
788-
: protocolAPY + protocolIncentivesAPR + meritIncentivesAPY;
789-
const totalAPYWithSelf =
790-
variantsAPY.selfAPY !== null
791-
? isBorrow
792-
? protocolAPY - protocolIncentivesAPR - meritIncentivesAPY - variantsAPY.selfAPY
793-
: protocolAPY + protocolIncentivesAPR + meritIncentivesAPY + variantsAPY.selfAPY
794-
: null;
786+
? protocolAPY - protocolIncentivesAPR - meritIncentivesAPY - (selfIncentivesAPY ?? 0)
787+
: protocolAPY + protocolIncentivesAPR + meritIncentivesAPY + (selfIncentivesAPY ?? 0);
795788

796789
return {
797790
incentiveAPR: meritIncentivesAPY.toString(),
798-
rewardTokenAddress: selectedIncentive.rewardTokenAddress,
799-
rewardTokenSymbol: selectedIncentive.rewardTokenSymbol,
800-
action: selectedIncentive.action,
801-
customMessage: selectedIncentive.customMessage,
802-
customForumLink: selectedIncentive.customForumLink,
803-
variants: { selfAPY: variantsAPY.selfAPY, totalAPYWithSelf },
791+
rewardTokenAddress: incentives[0].rewardTokenAddress,
792+
rewardTokenSymbol: incentives[0].rewardTokenSymbol,
793+
activeActions: incentives.map((incentive) => incentive.action),
794+
actionMessages: incentives.reduce((acc, incentive) => {
795+
acc[incentive.action] = {
796+
customMessage: incentive.customMessage,
797+
customForumLink: incentive.customForumLink,
798+
};
799+
return acc;
800+
}, {} as Record<string, { customMessage?: string; customForumLink?: string }>),
801+
action: incentives[0].action,
802+
customMessage: incentives[0].customMessage,
803+
customForumLink: incentives[0].customForumLink,
804+
variants: { selfAPY: selfIncentivesAPY },
805+
804806
breakdown: {
805807
protocolAPY,
806808
protocolIncentivesAPR,
@@ -815,7 +817,10 @@ export const useMeritIncentives = ({
815817
} as MeritIncentivesBreakdown,
816818
} as ExtendedReserveIncentiveResponse & {
817819
breakdown: MeritIncentivesBreakdown;
818-
variants: { selfAPY: number | null; totalAPYWithSelf: number | null };
820+
821+
activeActions: MeritAction[];
822+
actionMessages: Record<string, { customMessage?: string; customForumLink?: string }>;
823+
variants: { selfAPY: number | null };
819824
};
820825
},
821826
});

src/locales/en/messages.po

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ msgstr "I confirm the swap with a potential {0}% value loss"
11871187
msgid "deposited"
11881188
msgstr "deposited"
11891189

1190+
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
11901191
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
11911192
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
11921193
#: src/components/incentives/MerklIncentivesTooltipContent.tsx

0 commit comments

Comments
 (0)