-
Notifications
You must be signed in to change notification settings - Fork 446
feat: show boosted incentives in debt and collateral swap #2663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import { ProtocolAction } from '@aave/contract-helpers'; | ||
| import { valueToBigNumber } from '@aave/math-utils'; | ||
| import { ArrowNarrowRightIcon } from '@heroicons/react/solid'; | ||
| import { Trans } from '@lingui/macro'; | ||
| import { Box, Skeleton, SvgIcon } from '@mui/material'; | ||
| import { Box, Skeleton } from '@mui/material'; | ||
| import React from 'react'; | ||
| import { FormattedNumber } from 'src/components/primitives/FormattedNumber'; | ||
| import { Row } from 'src/components/primitives/Row'; | ||
| import { TokenIcon } from 'src/components/primitives/TokenIcon'; | ||
| import { DetailsIncentivesLine } from 'src/components/transactions/FlowCommons/TxModalDetails'; | ||
| import { DetailsAPYTransitionLine } from 'src/components/transactions/FlowCommons/TxModalDetails'; | ||
|
|
||
| import { ComputedUserReserveData } from '../../../hooks/app-data-provider/useAppDataProvider'; | ||
|
|
||
|
|
@@ -19,12 +19,8 @@ export type DebtSwitchModalDetailsProps = { | |
| sourceBalance: string; | ||
| sourceBorrowAPY: string; | ||
| targetBorrowAPY: string; | ||
| market?: string; | ||
| }; | ||
| const ArrowRightIcon = ( | ||
| <SvgIcon color="primary" sx={{ fontSize: '14px', mx: 1 }}> | ||
| <ArrowNarrowRightIcon /> | ||
| </SvgIcon> | ||
| ); | ||
|
|
||
| export const DebtSwitchModalDetails = ({ | ||
| switchSource, | ||
|
|
@@ -35,6 +31,7 @@ export const DebtSwitchModalDetails = ({ | |
| sourceBalance, | ||
| sourceBorrowAPY, | ||
| targetBorrowAPY, | ||
| market, | ||
| }: DebtSwitchModalDetailsProps) => { | ||
| const sourceAmountAfterSwap = valueToBigNumber(sourceBalance).minus(valueToBigNumber(fromAmount)); | ||
|
|
||
|
|
@@ -56,27 +53,22 @@ export const DebtSwitchModalDetails = ({ | |
|
|
||
| return ( | ||
| <> | ||
| <Row caption={<Trans>Borrow apy</Trans>} captionVariant="description" mb={4}> | ||
| <Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
| {loading ? ( | ||
| <Skeleton variant="rectangular" height={20} width={100} sx={{ borderRadius: '4px' }} /> | ||
| ) : ( | ||
| <> | ||
| <FormattedNumber value={sourceBorrowAPY} variant="secondary14" percent /> | ||
| {ArrowRightIcon} | ||
| <FormattedNumber value={targetBorrowAPY} variant="secondary14" percent /> | ||
| </> | ||
| )} | ||
| </Box> | ||
| </Row> | ||
|
|
||
| <DetailsIncentivesLine | ||
| incentives={switchSource.reserve.aIncentivesData} | ||
| symbol={switchSource.reserve.symbol} | ||
| futureIncentives={switchSource.reserve.aIncentivesData} | ||
| futureSymbol={switchSource.reserve.symbol} | ||
| loading={loading} | ||
| /> | ||
| {market && ( | ||
| <DetailsAPYTransitionLine | ||
| symbol={switchSource.reserve.symbol} | ||
| market={market} | ||
| protocolAction={ProtocolAction.borrow} | ||
| protocolAPY={+sourceBorrowAPY} | ||
| incentives={switchSource.reserve.vIncentivesData} | ||
| address={switchSource.reserve.underlyingAsset} | ||
| futureSymbol={switchTarget.reserve.symbol} | ||
| futureMarket={market} | ||
| futureProtocolAPY={+targetBorrowAPY} | ||
| futureIncentives={switchTarget.reserve.vIncentivesData} | ||
| futureAddress={switchTarget.reserve.aTokenAddress} | ||
|
||
| loading={loading} | ||
| /> | ||
| )} | ||
|
|
||
| <Row | ||
| caption={<Trans>Borrow balance after switch</Trans>} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { ProtocolAction } from '@aave/contract-helpers'; | ||
| import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives'; | ||
| import { Trans } from '@lingui/macro'; | ||
| import { Box, Skeleton, Typography } from '@mui/material'; | ||
| import React from 'react'; | ||
| import { useBoostedAPY } from 'src/hooks/useBoostedAPY'; | ||
|
|
||
| import { | ||
| EthenaIncentivesButton, | ||
| EtherfiIncentivesButton, | ||
| IncentivesButton, | ||
| MeritIncentivesButton, | ||
| MerklIncentivesButton, | ||
| SonicIncentivesButton, | ||
| } from '../../incentives/IncentivesButton'; | ||
| import { FormattedNumber } from '../../primitives/FormattedNumber'; | ||
| import { Row } from '../../primitives/Row'; | ||
|
|
||
| interface DetailsAPYLineProps { | ||
| symbol: string; | ||
| market: string; | ||
| protocolAction?: ProtocolAction; | ||
| protocolAPY: number; | ||
| incentives?: ReserveIncentiveResponse[]; | ||
| address?: string; | ||
| loading?: boolean; | ||
| } | ||
|
|
||
| export const DetailsAPYLine = ({ | ||
| symbol, | ||
| market, | ||
| protocolAction, | ||
| protocolAPY, | ||
| incentives = [], | ||
| address, | ||
| loading = false, | ||
| }: DetailsAPYLineProps) => { | ||
| const boostedData = useBoostedAPY({ | ||
| symbol, | ||
| market, | ||
| protocolAction, | ||
| protocolAPY, | ||
| incentives, | ||
| address, | ||
| }); | ||
|
|
||
| const { displayAPY, hasIncentives } = boostedData; | ||
|
|
||
| // Create incentive buttons | ||
| const incentivesContent = ( | ||
| <> | ||
| <IncentivesButton | ||
| incentives={incentives} | ||
| symbol={symbol} | ||
| market={market} | ||
| protocolAction={protocolAction} | ||
| protocolAPY={protocolAPY} | ||
| address={address} | ||
| /> | ||
| <MeritIncentivesButton | ||
| symbol={symbol} | ||
| market={market} | ||
| protocolAction={protocolAction} | ||
| protocolAPY={protocolAPY} | ||
| protocolIncentives={incentives} | ||
| /> | ||
| <MerklIncentivesButton | ||
| market={market} | ||
| rewardedAsset={address} | ||
| protocolAction={protocolAction} | ||
| protocolAPY={protocolAPY} | ||
| protocolIncentives={incentives} | ||
| /> | ||
| <EthenaIncentivesButton rewardedAsset={address} /> | ||
| <EtherfiIncentivesButton symbol={symbol} market={market} protocolAction={protocolAction} /> | ||
| <SonicIncentivesButton rewardedAsset={address} /> | ||
| </> | ||
| ); | ||
|
|
||
| return ( | ||
| <Row caption={<Trans>APY</Trans>} captionVariant="description" mb={4}> | ||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, flexWrap: 'wrap' }}> | ||
| {loading ? ( | ||
| <Skeleton variant="rectangular" height={20} width={100} sx={{ borderRadius: '4px' }} /> | ||
| ) : ( | ||
| <> | ||
| {displayAPY === 'Infinity' ? ( | ||
| <Typography variant="secondary14">∞ %</Typography> | ||
| ) : ( | ||
| <FormattedNumber value={displayAPY} percent variant="secondary14" /> | ||
| )} | ||
| {hasIncentives && incentivesContent} | ||
| </> | ||
| )} | ||
| </Box> | ||
| </Row> | ||
| ); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For debt swaps, the future address should use
switchTarget.reserve.underlyingAssetinstead ofaTokenAddressto match the pattern used for the current asset address on line 63.Copilot uses AI. Check for mistakes.