Skip to content

Commit e8fb88d

Browse files
committed
some fixes
1 parent a0e67d9 commit e8fb88d

34 files changed

+532
-772
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: 70 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({
@@ -98,6 +98,18 @@ export const DebtSwapActionsViaParaswap = ({
9898

9999
const inferredKind = state.swapRate.optimalRateData.side === 'SELL' ? 'sell' : 'buy';
100100

101+
console.log('getTransactionParams', {
102+
inferredKind,
103+
chainId: state.chainId,
104+
sourceToken: state.destinationToken.addressToSwap,
105+
sourceTokenDecimals: state.destinationToken.decimals,
106+
destinationToken: state.sourceToken.addressToSwap,
107+
destinationTokenDecimals: state.sourceToken.decimals,
108+
user: state.user,
109+
swapRate: state.swapRate.optimalRateData,
110+
slippage: Number(state.slippage) * 100,
111+
});
112+
101113
// CallData for ParaswapRoute, which is inversed to the actual swap (dest -> src)
102114
const { swapCallData, augustus } = await getTransactionParams(
103115
inferredKind,
@@ -111,15 +123,39 @@ export const DebtSwapActionsViaParaswap = ({
111123
Number(state.slippage)
112124
);
113125

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();
126+
console.log({
127+
sellAmountFormatted: state.sellAmountBigInt?.toString(),
128+
sellAmountTokenSymbol: state.sellAmountToken?.symbol,
129+
sellAmountTokenAddress: state.sellAmountToken?.underlyingAddress,
130+
131+
buyAmountFormatted: state.buyAmountBigInt?.toString(),
132+
buyAmountTokenSymbol: state.buyAmountToken?.symbol,
133+
buyAmountTokenAddress: state.buyAmountToken?.underlyingAddress,
134+
135+
optimalRateDataSrcAmount: state.swapRate.optimalRateData.srcAmount,
136+
optimalRateDataDestAmount: state.swapRate.optimalRateData.destAmount,
137+
optimalRateDataSrcToken: state.swapRate.optimalRateData.srcToken,
138+
optimalRateDataDestToken: state.swapRate.optimalRateData.destToken,
139+
});
140+
141+
const amountToReceiveForDebtSwitch = state.buyAmountBigInt?.toString() ?? '0';
142+
const amountToSwapForDebtSwitch = state.sellAmountBigInt?.toString() ?? '0';
143+
144+
console.log('debtSwitch from actions', {
145+
poolReserve: state.sourceReserve.reserve,
146+
targetReserve: state.destinationReserve.reserve,
147+
amountToReceive: amountToSwapForDebtSwitch,
148+
amountToSwap: amountToReceiveForDebtSwitch,
149+
isMaxSelected: state.isMaxSelected,
150+
txCalldata: swapCallData,
151+
augustus: augustus,
152+
signatureParams: {
153+
signature: signatureParams.signature,
154+
deadline: signatureParams.deadline,
155+
amount: signatureParams.amount,
156+
},
157+
isWrongNetwork: state.isWrongNetwork,
158+
});
123159

124160
let debtSwitchTxData = debtSwitch({
125161
poolReserve: state.sourceReserve.reserve,
@@ -130,7 +166,7 @@ export const DebtSwapActionsViaParaswap = ({
130166
txCalldata: swapCallData,
131167
augustus: augustus,
132168
signatureParams: {
133-
signature: signatureParams.splitedSignature,
169+
signature: signatureParams.signature,
134170
deadline: signatureParams.deadline,
135171
amount: signatureParams.amount,
136172
},
@@ -170,10 +206,27 @@ export const DebtSwapActionsViaParaswap = ({
170206
} catch (error) {
171207
console.error('error', error);
172208
const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false);
173-
setTxError(parsedError);
174-
setState({
175-
actionsLoading: false,
176-
});
209+
210+
// For gas estimation errors in Paraswap actions, show as warning instead of blocking error
211+
if (parsedError.txAction === TxAction.GAS_ESTIMATION) {
212+
setState({
213+
actionsLoading: false,
214+
warnings: [
215+
{
216+
message:
217+
'Gas estimation error: The swap could not be estimated. Try increasing slippage or changing the amount.',
218+
},
219+
],
220+
error: undefined, // Clear any existing errors
221+
});
222+
} else {
223+
// For other errors, handle normally
224+
setTxError(parsedError);
225+
setState({
226+
actionsLoading: false,
227+
});
228+
}
229+
177230
setMainTxState({
178231
txHash: undefined,
179232
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
});

0 commit comments

Comments
 (0)