Skip to content

Commit 515287a

Browse files
committed
some fixes
1 parent a0e67d9 commit 515287a

34 files changed

+470
-816
lines changed

src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ export const CollateralSwapActionsViaCowAdapters = ({
184184
}
185185
);
186186

187-
console.log('POST LIMIT ORDER', limitOrder, orderPostParams);
188-
189187
const result = await tradingSdk.postLimitOrder(limitOrder, orderPostParams.swapSettings);
190188

191189
trackingHandlers.trackSwap();

src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaParaswapAdapters.tsx

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { normalizeBN } from '@aave/math-utils';
1+
import { normalize } from '@aave/math-utils';
22
import { Trans } from '@lingui/macro';
33
import { BigNumber, PopulatedTransaction } from 'ethers';
4-
import { Dispatch, useEffect } from 'react';
4+
import { Dispatch, useEffect, useMemo } from 'react';
55
import { TxActionsWrapper } from 'src/components/transactions/TxActionsWrapper';
6-
import { ExactInSwapper, ExactOutSwapper } from 'src/hooks/paraswap/common';
6+
import { calculateSignedAmount, ExactInSwapper, ExactOutSwapper } from 'src/hooks/paraswap/common';
77
import { useModalContext } from 'src/hooks/useModal';
88
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
99
import { useRootStore } from 'src/store/root';
@@ -35,12 +35,17 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
3535
);
3636

3737
// Approval is aToken ERC20 Approval
38+
const amountToApprove = useMemo(() => {
39+
if (!state.sellAmountFormatted || !state.sellAmountToken) return '0';
40+
return calculateSignedAmount(state.sellAmountFormatted, state.sellAmountToken.decimals);
41+
}, [state.sellAmountFormatted, state.sellAmountToken]);
42+
3843
const { requiresApproval, signatureParams, approval, tryPermit, approvedAmount } =
3944
useSwapTokenApproval({
4045
chainId: state.chainId,
4146
token: state.sourceToken.addressToSwap, // aToken
4247
symbol: state.sourceToken.symbol,
43-
amount: normalizeBN(state.inputAmount, -state.sourceToken.decimals).toString(),
48+
amount: normalize(amountToApprove.toString(), state.sourceToken?.decimals ?? 18),
4449
decimals: state.sourceToken.decimals,
4550
spender: currentMarketData.addresses.SWAP_COLLATERAL_ADAPTER,
4651
setState,
@@ -72,9 +77,6 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
7277
if (state.side === 'sell') {
7378
const swapper = ExactInSwapper(state.chainId);
7479

75-
console.log('SWAPPER getTransactionParams');
76-
console.log('maxSlippage', Number(state.slippage));
77-
7880
const result = await swapper.getTransactionParams(
7981
state.sourceToken.underlyingAddress,
8082
state.sourceToken.decimals,
@@ -84,20 +86,10 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
8486
optimalRateData,
8587
Number(state.slippage)
8688
);
87-
console.log('SWAPPER getTransactionParams result', result);
8889
swapCallData = result.swapCallData;
8990
augustus = result.augustus;
9091
} else {
9192
const swapper = ExactOutSwapper(state.chainId);
92-
console.log('optimalRateData', optimalRateData, {
93-
srcToken: state.destinationToken.underlyingAddress,
94-
srcDecimals: state.destinationToken.decimals,
95-
destToken: state.sourceToken.underlyingAddress,
96-
destDecimals: state.sourceToken.decimals,
97-
user: state.user,
98-
maxSlippage: Number(state.slippage),
99-
optimalRateData: optimalRateData,
100-
});
10193

10294
const result = await swapper.getTransactionParams(
10395
state.destinationToken.underlyingAddress,
@@ -119,30 +111,6 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
119111
const amountToSwap = state.inputAmount;
120112
const amountToReceive = state.buyAmountFormatted || '0';
121113

122-
console.log('!! CollateralSwapActionsViaParaswapAdapters', {
123-
amountToSwap: amountToSwap,
124-
amountToReceive: amountToReceive,
125-
signedAmount,
126-
});
127-
128-
console.log('Partner using app code', optimalRateData.partner);
129-
130-
console.log({
131-
amountToSwap: amountToSwap,
132-
amountToReceive: amountToReceive,
133-
poolReserve: state.sourceReserve.reserve,
134-
targetReserve: state.destinationReserve.reserve,
135-
isWrongNetwork: state.isWrongNetwork,
136-
symbol: state.sourceToken.symbol,
137-
blocked: state.actionsBlocked,
138-
isMaxSelected: isMaxSelected,
139-
useFlashLoan: true,
140-
swapCallData: swapCallData,
141-
signature: signatureParams?.splitedSignature,
142-
deadline: signatureParams?.deadline,
143-
signedAmount,
144-
});
145-
146114
let response;
147115
try {
148116
// 2. Prepare Tx
@@ -178,7 +146,6 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
178146
};
179147

180148
// 3. Estimate gas limit and send tx
181-
console.log('populatedTx', populatedTx);
182149
const txWithGasEstimation = await estimateGasLimit(populatedTx, state.chainId);
183150
response = await sendTx(txWithGasEstimation);
184151
await response.wait(1);
@@ -200,18 +167,43 @@ export const CollateralSwapActionsViaParaswapAdapters = ({
200167
});
201168
} catch (error) {
202169
const parsedError = getErrorTextFromError(error, TxAction.MAIN_ACTION, false);
203-
setTxError(parsedError);
170+
171+
// Check if this is a gas estimation error (from estimateGasLimit call)
172+
// Gas estimation errors typically occur when estimateGasLimit fails
173+
const errorMessage = parsedError.rawError?.message?.toLowerCase() || '';
174+
const isGasEstimationError =
175+
errorMessage.includes('gas') ||
176+
errorMessage.includes('estimation') ||
177+
(errorMessage.includes('execution reverted') && errorMessage.includes('estimation'));
178+
179+
// For gas estimation errors in Paraswap actions, show as warning instead of blocking error
180+
if (isGasEstimationError) {
181+
setState({
182+
actionsLoading: false,
183+
warnings: [
184+
{
185+
message:
186+
'Gas estimation error: The swap could not be estimated. Try increasing slippage or changing the amount.',
187+
},
188+
],
189+
error: undefined, // Clear any existing errors
190+
});
191+
} else {
192+
// For other errors, handle normally
193+
setTxError(parsedError);
194+
setState({
195+
actionsLoading: false,
196+
error: {
197+
rawError: parsedError.rawError,
198+
message: `Error: ${parsedError.error} on ${parsedError.txAction}`,
199+
actionBlocked: parsedError.actionBlocked,
200+
},
201+
});
202+
}
203+
204204
setMainTxState({
205205
loading: false,
206206
});
207-
setState({
208-
actionsLoading: false,
209-
error: {
210-
rawError: parsedError.rawError,
211-
message: `Error: ${parsedError.error} on ${parsedError.txAction}`,
212-
actionBlocked: parsedError.actionBlocked,
213-
},
214-
});
215207
}
216208
};
217209

src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ export const DebtSwapActionsViaCoW = ({
199199
}
200200
);
201201

202-
console.log('precalculatedInstanceAddress', precalculatedInstanceAddress);
203-
console.log('orderPostParams', orderPostParams);
204-
205-
console.log('limitOrder', limitOrder);
206202
const result = await tradingSdk.postLimitOrder(limitOrder, orderPostParams.swapSettings);
207203

208204
trackingHandlers.trackSwap();

src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaParaswap.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export const DebtSwapActionsViaParaswap = ({
5353
const amountToSwap = maxInputAmountWithSlippage(
5454
state.buyAmountFormatted ?? '0',
5555
(Number(state.slippage) * 100).toString(),
56-
state.destinationReserve.reserve.decimals || 18
56+
state.buyAmountToken?.decimals || 18
5757
);
5858

5959
const maxNewDebtAmountToReceiveWithSlippage = maxInputAmountWithSlippage(
60-
state.outputAmount,
60+
state.sellAmountFormatted ?? '0',
6161
(Number(state.slippage) * 100).toString(),
62-
state.destinationReserve.reserve.decimals || 18
62+
state.sellAmountToken?.decimals || 18
6363
);
6464

6565
const { requiresApproval, approval, tryPermit, signatureParams } = useSwapTokenApproval({
@@ -111,15 +111,8 @@ export const DebtSwapActionsViaParaswap = ({
111111
Number(state.slippage)
112112
);
113113

114-
// Transaction sent to Paraswap Adapter
115-
const amountToReceiveForDebtSwitch = parseUnits(
116-
maxNewDebtAmountToReceiveWithSlippage,
117-
state.sourceReserve.reserve.decimals
118-
).toString();
119-
const amountToSwapForDebtSwitch = parseUnits(
120-
amountToSwap,
121-
state.destinationReserve.reserve.decimals
122-
).toString();
114+
const amountToReceiveForDebtSwitch = state.buyAmountBigInt?.toString() ?? '0';
115+
const amountToSwapForDebtSwitch = state.sellAmountBigInt?.toString() ?? '0';
123116

124117
let debtSwitchTxData = debtSwitch({
125118
poolReserve: state.sourceReserve.reserve,
@@ -130,7 +123,7 @@ export const DebtSwapActionsViaParaswap = ({
130123
txCalldata: swapCallData,
131124
augustus: augustus,
132125
signatureParams: {
133-
signature: signatureParams.splitedSignature,
126+
signature: signatureParams.signature,
134127
deadline: signatureParams.deadline,
135128
amount: signatureParams.amount,
136129
},
@@ -170,10 +163,27 @@ export const DebtSwapActionsViaParaswap = ({
170163
} catch (error) {
171164
console.error('error', error);
172165
const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false);
173-
setTxError(parsedError);
174-
setState({
175-
actionsLoading: false,
176-
});
166+
167+
// For gas estimation errors in Paraswap actions, show as warning instead of blocking error
168+
if (parsedError.txAction === TxAction.GAS_ESTIMATION) {
169+
setState({
170+
actionsLoading: false,
171+
warnings: [
172+
{
173+
message:
174+
'Gas estimation error: The swap could not be estimated. Try increasing slippage or changing the amount.',
175+
},
176+
],
177+
error: undefined, // Clear any existing errors
178+
});
179+
} else {
180+
// For other errors, handle normally
181+
setTxError(parsedError);
182+
setState({
183+
actionsLoading: false,
184+
});
185+
}
186+
177187
setMainTxState({
178188
txHash: undefined,
179189
loading: false,

src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaParaswap.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ export const RepayWithCollateralActionsViaParaswap = ({
148148
Number(state.slippage)
149149
);
150150

151-
console.log('paraswapRepayWithCollateral', {
152-
repayAllDebt,
153-
repayAmount,
154-
rateMode: params.interestMode,
155-
repayWithAmount,
156-
157-
fromAssetData: state.destinationReserve.reserve,
158-
poolReserve: state.sourceReserve.reserve,
159-
160-
symbol: state.sourceReserve.reserve.symbol,
161-
isWrongNetwork: state.isWrongNetwork,
162-
useFlashLoan: state.useFlashloan || false,
163-
blocked: state.actionsBlocked,
164-
swapCallData,
165-
augustus,
166-
signature: signatureParams?.splitedSignature,
167-
deadline: signatureParams?.deadline,
168-
signedAmount: approvedAmount,
169-
});
170-
171151
const txs = await paraswapRepayWithCollateral({
172152
repayAllDebt,
173153
repayAmount,
@@ -215,7 +195,27 @@ export const RepayWithCollateralActionsViaParaswap = ({
215195
});
216196
} catch (error) {
217197
const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false);
218-
setTxError(parsedError);
198+
199+
// For gas estimation errors in Paraswap actions, show as warning instead of blocking error
200+
if (parsedError.txAction === TxAction.GAS_ESTIMATION) {
201+
setState({
202+
actionsLoading: false,
203+
warnings: [
204+
{
205+
message:
206+
'Gas estimation error: The swap could not be estimated. Try increasing slippage or changing the amount.',
207+
},
208+
],
209+
error: undefined, // Clear any existing errors
210+
});
211+
} else {
212+
// For other errors, handle normally
213+
setTxError(parsedError);
214+
setState({
215+
actionsLoading: false,
216+
});
217+
}
218+
219219
setMainTxState({
220220
loading: false,
221221
});

src/components/transactions/Swap/actions/SwapActions/SwapActionsViaParaswap.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getErrorTextFromError, TxAction } from 'src/ui-config/errorMapping';
99
import { useShallow } from 'zustand/shallow';
1010

1111
import { TrackAnalyticsHandlers } from '../../analytics/useTrackAnalytics';
12+
import { APP_CODE_PER_SWAP_TYPE } from '../../constants/shared.constants';
1213
import { useSwapGasEstimation } from '../../hooks/useSwapGasEstimation';
1314
import { isParaswapRates, SwapParams, SwapState } from '../../types';
1415
import { useSwapTokenApproval } from '../approval/useSwapTokenApproval';
@@ -66,6 +67,8 @@ export const SwapActionsViaParaswap = ({
6667
setMainTxState({ ...mainTxState, loading: true });
6768
if (isParaswapRates(state.swapRate)) {
6869
try {
70+
const appCode = APP_CODE_PER_SWAP_TYPE[params.swapType];
71+
6972
// Normal switch using paraswap
7073
const tx = await fetchParaswapTxParams({
7174
srcToken: state.sourceToken.addressToSwap,
@@ -77,7 +80,7 @@ export const SwapActionsViaParaswap = ({
7780
maxSlippage: Number(slippageInPercent) * 10000,
7881
permit: signatureParams && signatureParams.signature,
7982
deadline: signatureParams && signatureParams.deadline,
80-
partner: 'aave-widget', // TODO: Check with paraswap team if we can change it
83+
partner: appCode,
8184
});
8285
tx.chainId = state.chainId;
8386
const txWithGasEstimation = await estimateGasLimit(tx, state.chainId);
@@ -102,6 +105,7 @@ export const SwapActionsViaParaswap = ({
102105
params.invalidateAppState();
103106
trackingHandlers.trackSwap();
104107
} catch (error) {
108+
// This is for transaction waiting errors, not gas estimation, so handle normally
105109
const parsedError = getErrorTextFromError(error, TxAction.MAIN_ACTION, false);
106110
setTxError(parsedError);
107111
setMainTxState({
@@ -123,14 +127,39 @@ export const SwapActionsViaParaswap = ({
123127
}
124128
} catch (error) {
125129
const parsedError = getErrorTextFromError(error, TxAction.MAIN_ACTION, false);
126-
setTxError(parsedError);
130+
131+
// Check if this is a gas estimation error (from estimateGasLimit call)
132+
// Gas estimation errors typically occur when estimateGasLimit fails
133+
const errorMessage = parsedError.rawError?.message?.toLowerCase() || '';
134+
const isGasEstimationError =
135+
errorMessage.includes('gas') ||
136+
errorMessage.includes('estimation') ||
137+
(errorMessage.includes('execution reverted') && errorMessage.includes('estimation'));
138+
139+
// For gas estimation errors in Paraswap actions, show as warning instead of blocking error
140+
if (isGasEstimationError) {
141+
setState({
142+
actionsLoading: false,
143+
warnings: [
144+
{
145+
message:
146+
'Gas estimation error: The swap could not be estimated. Try increasing slippage or changing the amount.',
147+
},
148+
],
149+
error: undefined, // Clear any existing errors
150+
});
151+
} else {
152+
// For other errors, handle normally
153+
setTxError(parsedError);
154+
setState({
155+
actionsLoading: false,
156+
});
157+
}
158+
127159
setMainTxState({
128160
txHash: undefined,
129161
loading: false,
130162
});
131-
setState({
132-
actionsLoading: false,
133-
});
134163
}
135164
} else {
136165
setTxError(

0 commit comments

Comments
 (0)