Skip to content
Closed
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 @@ -3,7 +3,6 @@ import { Dispatch } from 'react';
import { TrackAnalyticsHandlers } from '../../analytics/useTrackAnalytics';
import { ProtocolSwapParams, ProtocolSwapState, SwapProvider, SwapState } from '../../types';
import { SwapActionsViaCoW } from '../SwapActions/SwapActionsViaCoW';
import { SwapActionsViaParaswap } from '../SwapActions/SwapActionsViaParaswap';
import { CollateralSwapActionsViaCowAdapters } from './CollateralSwapActionsViaCoWAdapters';
import { CollateralSwapActionsViaParaswapAdapters } from './CollateralSwapActionsViaParaswapAdapters';

Expand Down Expand Up @@ -41,25 +40,16 @@ export const CollateralSwapActions = ({
);
}
case SwapProvider.PARASWAP:
if (state.useFlashloan) {
return (
<CollateralSwapActionsViaParaswapAdapters
params={params}
state={state}
setState={setState}
trackingHandlers={trackingHandlers}
/>
);
} else {
// Essentially traditional aTokens swap
return (
<SwapActionsViaParaswap
params={params}
state={state}
setState={setState}
trackingHandlers={trackingHandlers}
/>
);
}
// Paraswap can't swap aTokens directly, so always use the adapter. It runs swapAndDeposit
// (no flashloan) or a flashloan based on state.useFlashloan, which useFlowSelector sets from
// the health-factor impact.
return (
<CollateralSwapActionsViaParaswapAdapters
params={params}
state={state}
setState={setState}
trackingHandlers={trackingHandlers}
/>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
symbol: state.sourceToken.symbol,
blocked: areActionsBlocked(state),
isMaxSelected: isMaxSelected,
useFlashLoan: true,
useFlashLoan: state.useFlashloan ?? false,
swapCallData: swapCallData,
augustus: augustus,
signature: signatureParams?.splitedSignature,
Expand Down
4 changes: 3 additions & 1 deletion src/components/transactions/Swap/hooks/useSwapQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ const getTokenSelectionForQuote = (
const destTokenObj = invertedQuoteRoute ? state.sourceToken : state.destinationToken;

// Quote tokens must match what the order will post on, otherwise CoW's per-pair volume-fee policy and gas estimate apply to a different pair than the order and the cushion computed in useSwapOrderAmounts comes out short. Read provider from the active query arg, not state.provider, which lags during provider transitions.
// Paraswap collateral swaps go through the adapter (swapAndDeposit or flashloan), which operates on the underlying tokens, so quote the underlying. Quoting the aToken depends on Paraswap pricing it correctly, which it doesn't for every chain (e.g. Sonic aUSDC comes back as 18 decimals / $0).
const usesAddressToSwap =
state.useFlashloan === false &&
(provider === SwapProvider.COW_PROTOCOL ||
(provider === SwapProvider.PARASWAP &&
state.swapType !== SwapType.WithdrawAndSwap &&
state.swapType !== SwapType.RepayWithCollateral));
state.swapType !== SwapType.RepayWithCollateral &&
state.swapType !== SwapType.CollateralSwap));

const srcToken = usesAddressToSwap ? srcTokenObj.addressToSwap : srcTokenObj.underlyingAddress;
const destToken = usesAddressToSwap ? destTokenObj.addressToSwap : destTokenObj.underlyingAddress;
Expand Down
Loading