File tree Expand file tree Collapse file tree
src/components/transactions/Swap Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,8 +81,11 @@ export const DebtSwapActionsViaCoW = ({
8181 [ state . expiry ]
8282 ) ;
8383
84- // Pre-compute instance address
84+ // Pre-compute instance address.
85+ // Skip recalculation while approval is in progress or succeeded to prevent in-flight quote
86+ // responses from changing the adapter address and invalidating the user's signature.
8587 useEffect ( ( ) => {
88+ if ( approvalTxState . loading || approvalTxState . success ) return ;
8689 calculateInstanceAddress ( {
8790 user,
8891 validTo,
@@ -113,6 +116,8 @@ export const DebtSwapActionsViaCoW = ({
113116 state . orderType ,
114117 state . chainId ,
115118 APP_CODE_PER_SWAP_TYPE [ state . swapType ] ,
119+ approvalTxState . loading ,
120+ approvalTxState . success ,
116121 ] ) ;
117122
118123 const amountToApprove = useMemo ( ( ) => {
Original file line number Diff line number Diff line change @@ -81,8 +81,11 @@ export const RepayWithCollateralActionsViaCoW = ({
8181 [ state . expiry ]
8282 ) ;
8383
84- // Pre-compute instance address
84+ // Pre-compute instance address.
85+ // Skip recalculation while approval is in progress or succeeded to prevent in-flight quote
86+ // responses from changing the adapter address and invalidating the user's signature.
8587 useEffect ( ( ) => {
88+ if ( approvalTxState . loading || approvalTxState . success ) return ;
8689 calculateInstanceAddress ( {
8790 user,
8891 validTo,
@@ -113,6 +116,8 @@ export const RepayWithCollateralActionsViaCoW = ({
113116 state . orderType ,
114117 state . chainId ,
115118 APP_CODE_PER_SWAP_TYPE [ state . swapType ] ,
119+ approvalTxState . loading ,
120+ approvalTxState . success ,
116121 ] ) ;
117122
118123 // Approval is aToken ERC20 Approval
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ export const calculateInstanceAddress = async ({
5858 const {
5959 sellAmountWithMarginForDustProtection,
6060 buyAmountWithMarginForDustProtection,
61- buyAmount,
6261 sellToken,
6362 buyToken,
6463 quoteId,
@@ -77,7 +76,6 @@ export const calculateInstanceAddress = async ({
7776 state . orderType
7877 ) ,
7978 sellToken : state . sellAmountToken ,
80- buyAmount : state . buyAmountBigInt ,
8179 buyToken : state . buyAmountToken ,
8280 quoteId : isCowProtocolRates ( state . swapRate ) ? state . swapRate ?. quoteId : undefined ,
8381 side : state . processedSide ,
@@ -100,7 +98,7 @@ export const calculateInstanceAddress = async ({
10098 buyToken : buyToken . underlyingAddress ,
10199 buyTokenDecimals : buyToken . decimals ,
102100 sellAmount : sellAmountToSign . toString ( ) ,
103- buyAmount : buyAmount . toString ( ) ,
101+ buyAmount : buyAmountWithMarginForDustProtection . toString ( ) ,
104102 kind : side === 'buy' ? OrderKind . BUY : OrderKind . SELL ,
105103 quoteId,
106104 validTo,
Original file line number Diff line number Diff line change @@ -227,8 +227,13 @@ export const useSwapQuote = ({
227227 }
228228 } , [ ratesError ] ) ;
229229
230+ // Apply incoming quote to state. Discard in-flight responses that arrive after
231+ // the user has started the approval flow (quoteRefreshPaused) to prevent
232+ // amount changes that would invalidate the adapter instance address / signature.
230233 useEffect ( ( ) => {
231234 if ( swapQuote ) {
235+ if ( state . quoteRefreshPaused ) return ;
236+
232237 const isAutoRefreshed = Boolean ( state . quoteLastUpdatedAt ) ;
233238 trackingHandlers ?. trackSwapQuote ( isAutoRefreshed , swapQuote ) ;
234239
You can’t perform that action at this time.
0 commit comments