Skip to content

Commit

Permalink
feat: gho incentives (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem authored Jun 3, 2024
1 parent e10a0ec commit 643335d
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 91 deletions.
18 changes: 9 additions & 9 deletions src/components/WalletConnection/WalletSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ export const WalletSelector = () => {
// Get UNS Tlds. Grabbing this fron an endpoint since Unstoppable adds new TLDs frequently, so this wills tay updated
useEffect(() => {
const unsTlds = async () => {
const url = 'https://resolve.unstoppabledomains.com/supported_tlds';
const response = await fetch(url);
const data = await response.json();
setUnsTlds(data['tlds']);
try {
const url = 'https://resolve.unstoppabledomains.com/supported_tlds';
const response = await fetch(url);
const data = await response.json();
setUnsTlds(data['tlds']);
} catch (e) {
console.log('Error fetching UNS TLDs: ', e);
}
};

try {
unsTlds();
} catch (e) {
console.log('Error fetching UNS TLDs: ', e);
}
unsTlds();
}, []);

const handleBlocking = () => {
Expand Down
16 changes: 5 additions & 11 deletions src/components/incentives/IncentivesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,32 @@ export const UserMeritIncentivesButton = ({ symbol }: { symbol: 'gho' | 'stkgho'
setOpen={setOpen}
open={open}
>
<Content incentives={[incentives]} incentivesNetAPR={+incentives.incentiveAPR} plus />
<Content incentives={[incentives]} incentivesNetAPR={+incentives.incentiveAPR} />
</ContentWithTooltip>
);
};

export const MeritIncentivesButton = ({ symbol }: { symbol: 'gho' | 'stkgho' }) => {
const [open, setOpen] = useState(false);
const { data: meritIncentives } = useMeritIncentives();
const { data: meritIncentives } = useMeritIncentives(symbol);

if (!meritIncentives) {
return null;
}

const incentives = {
incentiveAPR: (meritIncentives.actionsAPR[symbol] / 100).toString(),
rewardTokenSymbol: 'GHO', // rewards alwasy in gho, for now
rewardTokenAddress: '0x', // not used for merit program
};

return (
<ContentWithTooltip
tooltipContent={
<MeritIncentivesTooltipContent
incentiveAPR={incentives.incentiveAPR}
rewardTokenSymbol={incentives.rewardTokenSymbol}
incentiveAPR={meritIncentives.incentiveAPR}
rewardTokenSymbol={meritIncentives.rewardTokenSymbol}
/>
}
withoutHover
setOpen={setOpen}
open={open}
>
<Content incentives={[incentives]} incentivesNetAPR={+incentives.incentiveAPR} plus />
<Content incentives={[meritIncentives]} incentivesNetAPR={+meritIncentives.incentiveAPR} />
</ContentWithTooltip>
);
};
Expand Down
12 changes: 11 additions & 1 deletion src/components/transactions/Borrow/GhoBorrowModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { useGhoPoolReserve } from 'src/hooks/pool/useGhoPoolReserve';
import { useUserGhoPoolReserve } from 'src/hooks/pool/useUserGhoPoolReserve';
import { useAssetCaps } from 'src/hooks/useAssetCaps';
import { useMeritIncentives } from 'src/hooks/useMeritIncentives';
import { useModalContext } from 'src/hooks/useModal';
import { useRootStore } from 'src/store/root';
import { CustomMarket } from 'src/ui-config/marketsConfig';
Expand All @@ -38,7 +39,11 @@ import { CapType } from '../../caps/helper';
import { AssetInput } from '../AssetInput';
import { GasEstimationError } from '../FlowCommons/GasEstimationError';
import { ModalWrapperProps } from '../FlowCommons/ModalWrapper';
import { DetailsHFLine, TxModalDetails } from '../FlowCommons/TxModalDetails';
import {
DetailsHFLine,
DetailsIncentivesLine,
TxModalDetails,
} from '../FlowCommons/TxModalDetails';
import { BorrowActions } from './BorrowActions';
import { BorrowAmountWarning } from './BorrowAmountWarning';
import { GhoBorrowSuccessView } from './GhoBorrowSuccessView';
Expand Down Expand Up @@ -129,6 +134,7 @@ export const GhoBorrowModalContent = ({
const [interestRateMode, setInterestRateMode] = useState<InterestRate>(InterestRate.Variable);
const [amount, setAmount] = useState('');
const [riskCheckboxAccepted, setRiskCheckboxAccepted] = useState(false);
const { data: incentives } = useMeritIncentives('gho');

// Check if user has any open borrow positions on GHO
// Check if user can borrow at a discount
Expand Down Expand Up @@ -284,6 +290,10 @@ export const GhoBorrowModalContent = ({
healthFactor={user.healthFactor}
futureHealthFactor={newHealthFactor.toString(10)}
/>
<DetailsIncentivesLine
incentives={incentives ? [incentives] : []}
symbol={poolReserve.symbol}
/>
<Row
caption={
<Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TokenIcon } from 'src/components/primitives/TokenIcon';
import { Warning } from 'src/components/primitives/Warning';
import { useGeneralStakeUiData } from 'src/hooks/stake/useGeneralStakeUiData';
import { useUserStakeUiData } from 'src/hooks/stake/useUserStakeUiData';
import { useUserMeritIncentives } from 'src/hooks/useMeritIncentives';
import { useModalContext } from 'src/hooks/useModal';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { useRootStore } from 'src/store/root';
Expand Down Expand Up @@ -57,6 +58,9 @@ export const StakeCooldownModalContent = ({ stakeAssetName, icon }: StakeCooldow
const { data: stakeUserResult } = useUserStakeUiData(currentMarketData, stakeAssetName);
const { data: stakeGeneralResult } = useGeneralStakeUiData(currentMarketData, stakeAssetName);

const { data: meritIncentives } = useUserMeritIncentives();
const usersStkGhoIncentives = meritIncentives?.actionsAPR.stkgho || 0;

// states
const [cooldownCheck, setCooldownCheck] = useState(false);

Expand Down Expand Up @@ -334,6 +338,17 @@ export const StakeCooldownModalContent = ({ stakeAssetName, icon }: StakeCooldow
)}

<Warning severity="error">
{stakeAssetName === 'gho' && usersStkGhoIncentives !== 0 && (
<>
<Typography variant="caption">
<Trans>
During the cooldown period, you will not earn any merit rewards. However, rewards
earned up to this point will remain unaffected.
</Trans>
</Typography>
<br />
</>
)}
<Typography variant="caption">
<Trans>
If you DO NOT unstake within {timeMessage(stakeUnstakeWindow)} of unstake window, you
Expand Down
12 changes: 11 additions & 1 deletion src/hooks/useMeritIncentives.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives';
import { AaveV3Ethereum } from '@bgd-labs/aave-address-book';
import { useQuery } from '@tanstack/react-query';
import { useRootStore } from 'src/store/root';

Expand All @@ -11,7 +13,7 @@ type MeritIncentives = {

const url = 'https://apps.aavechan.com/api/merit/aprs';

export const useMeritIncentives = () => {
export const useMeritIncentives = (asset: 'gho' | 'stkgho') => {
return useQuery({
queryFn: async () => {
const response = await fetch(url);
Expand All @@ -20,6 +22,14 @@ export const useMeritIncentives = () => {
},
queryKey: ['meritIncentives'],
staleTime: 1000 * 60 * 5,
select: (data) => {
// rewards are always in GHO, for now
return {
incentiveAPR: (data.actionsAPR[asset] / 100).toString(),
rewardTokenAddress: AaveV3Ethereum.ASSETS.GHO.UNDERLYING,
rewardTokenSymbol: 'GHO',
} as ReserveIncentiveResponse;
},
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/messages.js

Large diffs are not rendered by default.

35 changes: 28 additions & 7 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ msgstr "Add to wallet"
msgid "Add {0} to wallet to track your balance."
msgstr "Add {0} to wallet to track your balance."

#: src/modules/markets/Gho/GhoBanner.tsx
msgid "Additionally, GHO borrowers recieve periodic rewards through the Merit program. This is a program initiated and implemented by the decentralised Aave community. Aave Labs does not guarantee the program and accepts no liability."
msgstr "Additionally, GHO borrowers recieve periodic rewards through the Merit program. This is a program initiated and implemented by the decentralised Aave community. Aave Labs does not guarantee the program and accepts no liability."

#: src/ui-config/errorMapping.tsx
msgid "Address is not a contract"
msgstr "Address is not a contract"
Expand Down Expand Up @@ -511,10 +515,6 @@ msgstr "Borrow info"
msgid "Borrow power used"
msgstr "Borrow power used"

#: src/modules/markets/Gho/GhoBanner.tsx
msgid "Borrow rate APY"
msgstr "Borrow rate APY"

#: src/modules/history/actions/ActionDetails.tsx
msgid "Borrow rate change"
msgstr "Borrow rate change"
Expand Down Expand Up @@ -796,6 +796,10 @@ msgstr "Current LTV"
msgid "Current differential"
msgstr "Current differential"

#: src/modules/reserve-overview/Gho/GhoDiscountCalculator.tsx
msgid "Current rewards"
msgstr "Current rewards"

#: src/modules/migration/MigrationListMobileItem.tsx
msgid "Current v2 Balance"
msgstr "Current v2 Balance"
Expand Down Expand Up @@ -945,6 +949,10 @@ msgstr "Due to internal stETH mechanics required for rebasing support, it is not
msgid "Due to the Horizon bridge exploit, certain assets on the Harmony network are not at parity with Ethereum, which affects the Aave V3 Harmony market."
msgstr "Due to the Horizon bridge exploit, certain assets on the Harmony network are not at parity with Ethereum, which affects the Aave V3 Harmony market."

#: src/components/transactions/StakeCooldown/StakeCooldownModalContent.tsx
msgid "During the cooldown period, you will not earn any merit rewards. However, rewards earned up to this point will remain unaffected."
msgstr "During the cooldown period, you will not earn any merit rewards. However, rewards earned up to this point will remain unaffected."

#: src/modules/dashboard/DashboardEModeButton.tsx
msgid "E-Mode"
msgstr "E-Mode"
Expand Down Expand Up @@ -1036,6 +1044,10 @@ msgstr "Enter an amount"
msgid "Error connecting. Try refreshing the page."
msgstr "Error connecting. Try refreshing the page."

#: src/modules/markets/Gho/GhoBanner.tsx
msgid "Estimated borrow rate"
msgstr "Estimated borrow rate"

#: src/components/incentives/GhoIncentivesCard.tsx
msgid "Estimated compounding interest, including discount for Staking {0}AAVE in Safety Module."
msgstr "Estimated compounding interest, including discount for Staking {0}AAVE in Safety Module."
Expand Down Expand Up @@ -1134,6 +1146,10 @@ msgstr "French"
msgid "Funds in the Safety Module"
msgstr "Funds in the Safety Module"

#: src/modules/reserve-overview/Gho/GhoDiscountCalculator.tsx
msgid "GHO borrowers recieve periodic rewards through the Merit program. This is a program initiated and implemented by the decentralised Aave community. Aave Labs does not guarantee the program and accepts no liability."
msgstr "GHO borrowers recieve periodic rewards through the Merit program. This is a program initiated and implemented by the decentralised Aave community. Aave Labs does not guarantee the program and accepts no liability."

#: src/modules/reserve-overview/Gho/GhoReserveConfiguration.tsx
msgid "GHO is a native decentralized, collateral-backed digital asset pegged to USD. It is created by users via borrowing against multiple collateral. When user repays their GHO borrow position, the protocol burns that user's GHO. All the interest payments accrued by minters of GHO would be directly transferred to the AaveDAO treasury."
msgstr "GHO is a native decentralized, collateral-backed digital asset pegged to USD. It is created by users via borrowing against multiple collateral. When user repays their GHO borrow position, the protocol burns that user's GHO. All the interest payments accrued by minters of GHO would be directly transferred to the AaveDAO treasury."
Expand Down Expand Up @@ -1495,9 +1511,9 @@ msgstr "Meet GHO"
msgid "Menu"
msgstr "Menu"

#: src/modules/markets/Gho/GhoBanner.tsx
msgid "Merit rewards"
msgstr "Merit rewards"
#: src/modules/reserve-overview/Gho/GhoDiscountCalculator.tsx
msgid "Merit Program"
msgstr "Merit Program"

#: src/components/transactions/MigrateV3/MigrateV3Actions.tsx
#: src/components/transactions/StakingMigrate/StakingMigrateActions.tsx
Expand Down Expand Up @@ -2821,6 +2837,10 @@ msgstr "User is in isolation mode or LTV is zero"
msgid "User is trying to borrow multiple assets including a siloed one"
msgstr "User is trying to borrow multiple assets including a siloed one"

#: src/modules/markets/Gho/GhoBanner.tsx
msgid "Users who stake AAVE in Safety Module (i.e. stkAAVE holders) receive a discount on GHO borrow interest rate."
msgstr "Users who stake AAVE in Safety Module (i.e. stkAAVE holders) receive a discount on GHO borrow interest rate."

#: src/modules/reserve-overview/Gho/GhoDiscountCalculator.tsx
msgid "Users who stake AAVE in Safety Module (i.e. stkAAVE holders) receive a discount on GHO borrow interest rate. The discount applies to 100 GHO for every 1 stkAAVE held. Use the calculator below to see GHO borrow rate with the discount applied."
msgstr "Users who stake AAVE in Safety Module (i.e. stkAAVE holders) receive a discount on GHO borrow interest rate. The discount applies to 100 GHO for every 1 stkAAVE held. Use the calculator below to see GHO borrow rate with the discount applied."
Expand Down Expand Up @@ -3255,6 +3275,7 @@ msgid "for"
msgstr "for"

#: src/components/caps/DebtCeilingStatus.tsx
#: src/modules/markets/Gho/GhoBanner.tsx
#: src/modules/reserve-overview/BorrowInfo.tsx
#: src/modules/reserve-overview/BorrowInfo.tsx
#: src/modules/reserve-overview/Gho/GhoBorrowInfo.tsx
Expand Down
Loading

2 comments on commit 643335d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.