Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@amplitude/analytics-browser": "^2.13.0",
"@cowprotocol/sdk-app-data": "4.1.6",
"@cowprotocol/cow-sdk": "7.1.1",
"@cowprotocol/sdk-flash-loans": "1.5.2",
"@cowprotocol/sdk-flash-loans": "1.5.3",
"@cowprotocol/sdk-viem-adapter": "0.2.0",
"@bgd-labs/aave-address-book": "^4.36.0",
"@emotion/cache": "11.10.3",
Expand Down
6 changes: 1 addition & 5 deletions src/components/transactions/Swap/constants/cow.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ export const COW_UNSUPPORTED_ASSETS: Partial<
[SupportedChainId.BASE]: 'ALL', // Base is not supported
},
[SwapType.CollateralSwap]: {
[SupportedChainId.ARBITRUM_ONE]: 'ALL',
[SupportedChainId.AVALANCHE]: 'ALL',
[SupportedChainId.BNB]: 'ALL',
[SupportedChainId.GNOSIS_CHAIN]: 'ALL',
[SupportedChainId.MAINNET]: 'ALL',
[SupportedChainId.BNB]: 'ALL',
[SupportedChainId.POLYGON]: 'ALL',
[SupportedChainId.SEPOLIA]: 'ALL',
// Base is supported
},
[SwapType.RepayWithCollateral]: {
[SupportedChainId.ARBITRUM_ONE]: 'ALL',
Expand Down
4 changes: 3 additions & 1 deletion src/components/transactions/Swap/errors/SwapErrors.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Dispatch, useEffect } from 'react';
import { useZeroLTVBlockingWithdraw } from 'src/hooks/useZeroLTVBlockingWithdraw';

import { useModalContext } from '../../../../hooks/useModal';
import { TrackAnalyticsHandlers } from '../analytics/useTrackAnalytics';
Expand Down Expand Up @@ -35,6 +36,7 @@ export const SwapErrors = ({
trackingHandlers: TrackAnalyticsHandlers;
}) => {
const { txError } = useModalContext();
const assetsBlockingWithdraw = useZeroLTVBlockingWithdraw();

useEffect(() => {
if (txError) {
Expand Down Expand Up @@ -78,7 +80,7 @@ export const SwapErrors = ({
);
}

if (hasZeroLTVBlocking(state, [])) {
if (hasZeroLTVBlocking(state, assetsBlockingWithdraw)) {
return (
<ZeroLTVBlockingGuard
state={state}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const ZeroLTVBlockingError = ({ sx }: { sx?: SxProps }) => {
<Warning severity="error" sx={{ mt: 4, ...sx }} icon={false}>
<Typography variant="caption">
<Trans>
You have assets with zero LTV that are blocking this operation. Please disable them as
collateral first.
You have assets with zero LTV that are blocking this operation. Please withdraw them or
disable them as collateral first.
</Trans>
</Typography>
</Warning>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { ActionsBlockedReason, SwapError, SwapState, SwapType } from '../../type
import { ZeroLTVBlockingError } from './ZeroLTVBlockingError';

export const hasZeroLTVBlocking = (state: SwapState, blockingAssets: string[]) => {
return (
blockingAssets.length > 0 &&
!blockingAssets.includes(state.sourceToken.symbol) &&
state.swapType !== SwapType.RepayWithCollateral
);
// Never block RepayWithCollateral
if (state.swapType === SwapType.RepayWithCollateral) {
return false;
}
// For CollateralSwap, block if the user has any zero-LTV collateral enabled
if (state.swapType === SwapType.CollateralSwap) {
return blockingAssets.length > 0;
}
Comment on lines +12 to +16

Choose a reason for hiding this comment

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

P1 Badge Clear zero-LTV blocking state when swap type changes

With the new swap-type-specific logic in hasZeroLTVBlocking, a user who triggers the zero-LTV guard while on a CollateralSwap and then switches to RepayWithCollateral (which this branch explicitly allows) will keep the previous ZeroLTVBlockingError and actionsBlocked state because the effect below only re-runs when assetsBlockingWithdraw or sourceToken change. In that scenario the UI continues to show a generic provider error and blocks the repay flow even though hasZeroLTVBlocking would now return false. Include state.swapType in the effect dependencies or otherwise clear the error on swap-type changes to avoid blocking permitted flows.

Useful? React with 👍 / 👎.

// For other swap types, block if there are zero-LTV assets enabled
// and the source token is not one of those (existing behavior)
return blockingAssets.length > 0 && !blockingAssets.includes(state.sourceToken.symbol);
};

export const ZeroLTVBlockingGuard = ({
Expand Down Expand Up @@ -38,7 +44,7 @@ export const ZeroLTVBlockingGuard = ({
const blockingError: SwapError = {
rawError: new Error('ZeroLTVBlockingError'),
message:
'You have assets with zero LTV that are blocking this operation. Please disable them as collateral first.',
'You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first.',
actionBlocked: true,
};
setState({
Expand Down
4 changes: 4 additions & 0 deletions src/components/transactions/Swap/helpers/cow/env.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const getCowFlashLoanSdk = async (chainId: number) => {
return new AaveCollateralSwapSdk({
hookAdapterPerType: HOOK_ADAPTER_PER_TYPE,
aaveAdapterFactory: ADAPTER_FACTORY,
hooksGasLimit: {
pre: BigInt(300000),
post: BigInt(700000),
},
});
};

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,10 @@ msgstr "Costs & Fees"
msgid "deposited"
msgstr "deposited"

#: src/components/transactions/Swap/errors/shared/ZeroLTVBlockingError.tsx
msgid "You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first."
msgstr "You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first."

#: src/components/incentives/MeritIncentivesTooltipContent.tsx
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
#: src/components/incentives/MerklIncentivesTooltipContent.tsx
Expand Down Expand Up @@ -3280,10 +3284,6 @@ msgstr "Cooldown to unstake"
msgid "User does not have outstanding variable rate debt on this reserve"
msgstr "User does not have outstanding variable rate debt on this reserve"

#: src/components/transactions/Swap/errors/shared/ZeroLTVBlockingError.tsx
msgid "You have assets with zero LTV that are blocking this operation. Please disable them as collateral first."
msgstr "You have assets with zero LTV that are blocking this operation. Please disable them as collateral first."

#: src/modules/faucet/FaucetAssetsList.tsx
msgid "Test Assets"
msgstr "Test Assets"
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es/messages.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/fr/messages.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1426,10 +1426,10 @@
"@cowprotocol/sdk-common" "0.3.0"
"@cowprotocol/sdk-config" "0.3.0"

"@cowprotocol/[email protected].2":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@cowprotocol/sdk-flash-loans/-/sdk-flash-loans-1.5.2.tgz#d5f8375441bf07a1a7a70ae786dcb969e91b2b73"
integrity sha512-RihEc1Gpow4p+b/tLCvptl+TLYNvXsqOC7KvA/5tdk40eOtWUqCiltb66J4FGnc5W8pqmLoRalql4myOMh8dLg==
"@cowprotocol/[email protected].3":
version "1.5.3"
resolved "https://registry.yarnpkg.com/@cowprotocol/sdk-flash-loans/-/sdk-flash-loans-1.5.3.tgz#da3b9c320bae16571f7bedb6f07f099c3db5c9b6"
integrity sha512-Bl9h9rGc7el/89VwNKYQi/oWD849xifH21ZmdvEqNp9iEw7X+vtszQU5kCzwwmwCU09i0E7ZY8pgfNb8rRkOBA==
dependencies:
"@cowprotocol/sdk-app-data" "4.1.6"
"@cowprotocol/sdk-common" "0.3.0"
Expand Down
Loading