Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/components/transactions/Swap/hooks/useFlowSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ export const healthFactorSensibleSwapFlowSelector = ({
? valueToBigNumber(hfAfterSwap).lt(LIQUIDATION_DANGER_THRESHOLD)
: false;

// Paraswap can't price or trade aTokens, so a collateral swap can't use the simple aToken path; it must go through the flashloan adapter, which unwraps to the underlying. CoW repay/debt swaps likewise have no non-flashloan path.
const forceFlashloanFlow =
state.provider === SwapProvider.COW_PROTOCOL &&
(state.swapType === SwapType.RepayWithCollateral || state.swapType === SwapType.DebtSwap);
(state.provider === SwapProvider.COW_PROTOCOL &&
(state.swapType === SwapType.RepayWithCollateral || state.swapType === SwapType.DebtSwap)) ||
(state.provider === SwapProvider.PARASWAP && state.swapType === SwapType.CollateralSwap);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Force flashloan before requiring a ParaSwap quote

This new ParaSwap collateral-swap override only runs after the early guard has already required state.swapRate (line 97), but the first quote is still requested with useFlashloan === false, so useSwapQuote uses the aToken addressToSwap pair for ParaSwap. For any collateral pair where ParaSwap rejects the unlisted aToken quote instead of returning a bogus route, state.swapRate remains undefined and this line is never reached, leaving the flow stuck on the broken non-flashloan/aToken path with a quote error. The forced flow needs to be selected before the initial quote can fail, or this fix only works for aTokens that happen to get a response.

Useful? React with 👍 / 👎.

const useFlashloan =
forceFlashloanFlow ||
(extendedUser?.healthFactor !== '-1' &&
Expand Down
Loading