Skip to content
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

feat: add message about flash loan fee when required #2134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const testData = {
},
};

describe.skip('USDbC INTEGRATION SPEC, BASE V3 MARKET', () => {
const skipTestState = skipState(true);
describe('USDbC INTEGRATION SPEC, BASE V3 MARKET', () => {
const skipTestState = skipState(false);
configEnvWithTenderlyBnbFork({
v3: true,
tokens: tokenSet(tokensToRequest),
Expand Down
27 changes: 25 additions & 2 deletions src/components/transactions/FlowCommons/TxModalDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives';
import { ArrowNarrowRightIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import { Box, FormControlLabel, Skeleton, SvgIcon, Switch, Typography } from '@mui/material';
import { Box, FormControlLabel, Skeleton, Stack, SvgIcon, Switch, Typography } from '@mui/material';
import { parseUnits } from 'ethers/lib/utils';
import React, { ReactNode } from 'react';
import {
Expand All @@ -10,6 +10,7 @@ import {
UnavailableDueToIsolationBadge,
} from 'src/components/isolationMode/IsolatedBadge';
import { Row } from 'src/components/primitives/Row';
import { TextWithTooltip } from 'src/components/TextWithTooltip';
import { CollateralType } from 'src/helpers/types';

import { HealthFactorNumber } from '../../HealthFactorNumber';
Expand Down Expand Up @@ -280,23 +281,45 @@ export const DetailsIncentivesLine = ({
);
};

export const HealthFactorFlashloanFeeCaption = ({ fee }: { fee: string }) => {
return (
<Stack justifyContent="space-between">
<Trans>Health factor</Trans>
<Stack sx={{ mt: 0.5 }} direction="row" alignItems="center">
<Typography variant="helperText" color="text.secondary">
<Trans>Flash loan fee {fee}</Trans>
</Typography>
<TextWithTooltip>
<Trans>
Due to a low health factor (or if a reserve is frozen), a flash loan is required to
perform this action, which incurs a fee. A portion of the fee goes to liquidity
providers, while the rest goes to the protocol treasury.
</Trans>
</TextWithTooltip>
</Stack>
</Stack>
);
};

export interface DetailsHFLineProps {
healthFactor: string;
futureHealthFactor: string;
visibleHfChange: boolean;
loading?: boolean;
caption?: ReactNode;
}

export const DetailsHFLine = ({
healthFactor,
futureHealthFactor,
visibleHfChange,
loading = false,
caption,
}: DetailsHFLineProps) => {
if (healthFactor === '-1' && futureHealthFactor === '-1') return null;
return (
<Row
caption={<Trans>Health factor</Trans>}
caption={caption ? caption : <Trans>Health factor</Trans>}
captionVariant="description"
mb={4}
align="flex-start"
Expand Down
15 changes: 13 additions & 2 deletions src/components/transactions/Repay/CollateralRepayModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import {
} from 'src/hooks/paraswap/common';
import { useCollateralRepaySwap } from 'src/hooks/paraswap/useCollateralRepaySwap';
import { useModalContext } from 'src/hooks/useModal';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useZeroLTVBlockingWithdraw } from 'src/hooks/useZeroLTVBlockingWithdraw';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { ListSlippageButton } from 'src/modules/dashboard/lists/SlippageList';
import { useRootStore } from 'src/store/root';
import { calculateHFAfterRepay } from 'src/utils/hfUtils';

import { Asset, AssetInput } from '../AssetInput';
Expand All @@ -32,6 +32,7 @@ import { TxSuccessView } from '../FlowCommons/Success';
import {
DetailsHFLine,
DetailsNumberLineWithSub,
HealthFactorFlashloanFeeCaption,
TxModalDetails,
} from '../FlowCommons/TxModalDetails';
import { ErrorType, useFlashloan } from '../utils';
Expand All @@ -48,7 +49,12 @@ export function CollateralRepayModalContent({
}: ModalWrapperProps & { debtType: InterestRate; user: ExtendedFormattedUser }) {
const { reserves, userReserves } = useAppDataContext();
const { gasLimit, txError, mainTxState } = useModalContext();
const { currentChainId, currentNetworkConfig } = useProtocolDataContext();
const [currentChainId, currentNetworkConfig, currentMarketData] = useRootStore((store) => [
store.currentChainId,
store.currentNetworkConfig,
store.currentMarketData,
]);

const { currentAccount } = useWeb3Context();

// List of tokens eligble to repay with, ordered by USD value
Expand Down Expand Up @@ -353,6 +359,11 @@ export function CollateralRepayModalContent({
healthFactor={user?.healthFactor}
futureHealthFactor={hfAfterSwap.toString(10)}
loading={loadingSkeleton}
caption={
shouldUseFlashloan && (
<HealthFactorFlashloanFeeCaption fee={currentMarketData.v3 ? '0.05%' : '0.09%'} />
)
}
/>
<DetailsNumberLineWithSub
description={<Trans>Borrow balance after repay</Trans>}
Expand Down
12 changes: 10 additions & 2 deletions src/components/transactions/Swap/SwapModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { minimumReceivedAfterSlippage } from 'src/hooks/paraswap/common';
import { useCollateralSwap } from 'src/hooks/paraswap/useCollateralSwap';
import { getDebtCeilingData } from 'src/hooks/useAssetCaps';
import { useModalContext } from 'src/hooks/useModal';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useZeroLTVBlockingWithdraw } from 'src/hooks/useZeroLTVBlockingWithdraw';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { ListSlippageButton } from 'src/modules/dashboard/lists/SlippageList';
import { useRootStore } from 'src/store/root';
import { remainingCap } from 'src/utils/getMaxAmountAvailableToSupply';
import { displayGhoForMintableMarket } from 'src/utils/ghoUtilities';
import { calculateHFAfterSwap } from 'src/utils/hfUtils';
Expand Down Expand Up @@ -47,7 +47,14 @@ export const SwapModalContent = ({
user,
}: ModalWrapperProps & { user: ExtendedFormattedUser }) => {
const { reserves, marketReferencePriceInUsd } = useAppDataContext();
const { currentChainId, currentMarket, currentNetworkConfig } = useProtocolDataContext();
const [currentChainId, currentMarket, currentMarketData, currentNetworkConfig] = useRootStore(
(store) => [
store.currentChainId,
store.currentMarket,
store.currentMarketData,
store.currentNetworkConfig,
]
);
const { currentAccount } = useWeb3Context();
const { gasLimit, mainTxState: supplyTxState, txError } = useModalContext();

Expand Down Expand Up @@ -330,6 +337,7 @@ export const SwapModalContent = ({
toAmount={outputAmount}
fromAmount={amount === '' ? '0' : amount}
loading={loadingSkeleton}
flashloanFee={!shouldUseFlashloan ? undefined : currentMarketData.v3 ? '0.05%' : '0.09%'}
/>
</TxModalDetails>

Expand Down
4 changes: 4 additions & 0 deletions src/components/transactions/Swap/SwapModalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DetailsHFLine,
DetailsIncentivesLine,
DetailsNumberLine,
HealthFactorFlashloanFeeCaption,
} from 'src/components/transactions/FlowCommons/TxModalDetails';
import { CollateralType } from 'src/helpers/types';

Expand All @@ -25,6 +26,7 @@ export type SupplyModalDetailsProps = {
toAmount: string;
fromAmount: string;
loading: boolean;
flashloanFee?: string;
};

export const SwapModalDetails = ({
Expand All @@ -36,6 +38,7 @@ export const SwapModalDetails = ({
toAmount,
fromAmount,
loading,
flashloanFee,
}: SupplyModalDetailsProps) => {
const sourceAmountAfterSwap = valueToBigNumber(swapSource.underlyingBalance).minus(
valueToBigNumber(fromAmount)
Expand Down Expand Up @@ -65,6 +68,7 @@ export const SwapModalDetails = ({
futureHealthFactor={healthFactorAfterSwap}
visibleHfChange={showHealthFactor}
loading={loading}
caption={flashloanFee && <HealthFactorFlashloanFeeCaption fee={flashloanFee} />}
/>
)}
<DetailsNumberLine
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/messages.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,10 @@ msgstr "Docs"
msgid "Download"
msgstr "Download"

#: src/components/transactions/FlowCommons/TxModalDetails.tsx
msgid "Due to a low health factor (or if a reserve is frozen), a flash loan is required to perform this action, which incurs a fee. A portion of the fee goes to liquidity providers, while the rest goes to the protocol treasury."
msgstr "Due to a low health factor (or if a reserve is frozen), a flash loan is required to perform this action, which incurs a fee. A portion of the fee goes to liquidity providers, while the rest goes to the protocol treasury."

#: src/components/transactions/Repay/CollateralRepayModalContent.tsx
#: src/components/transactions/Swap/SwapModalContent.tsx
msgid "Due to health factor impact, a flashloan is required to perform this transaction, but Aave Governance has disabled flashloan availability for this asset. Try lowering the amount or supplying additional collateral."
Expand Down Expand Up @@ -1172,6 +1176,10 @@ msgstr "Filter"
msgid "Fixed rate"
msgstr "Fixed rate"

#: src/components/transactions/FlowCommons/TxModalDetails.tsx
msgid "Flash loan fee {fee}"
msgstr "Flash loan fee {fee}"

#: src/components/infoTooltips/MigrationDisabledTooltip.tsx
msgid "Flashloan is disabled for this asset, hence this position cannot be migrated."
msgstr "Flashloan is disabled for this asset, hence this position cannot be migrated."
Expand Down Expand Up @@ -1244,6 +1252,7 @@ msgstr "Governance"
msgid "Greek"
msgstr "Greek"

#: src/components/transactions/FlowCommons/TxModalDetails.tsx
#: src/components/transactions/FlowCommons/TxModalDetails.tsx
#: src/modules/dashboard/DashboardTopPanel.tsx
#: src/modules/dashboard/LiquidationRiskParametresModal/LiquidationRiskParametresModal.tsx
Expand Down
Loading