Skip to content

Commit

Permalink
fix(swap): correct swap arguments calculation for trade-in and trade-…
Browse files Browse the repository at this point in the history
…out scenarios

- Updated swap arguments callback to handle trade-in and trade-out scenarios more accurately
- Replaced `amountOutMax` with `amountInMax` for better clarity
- Implemented conditional return logic to support different swap types
  • Loading branch information
ArturHoncharuk committed Jan 27, 2025
1 parent 40e4574 commit 93e458e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/features/swap/utils/swap-args.callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ export async function swapPayableArgsCallback(
const bnAmountOut = ethers.utils.parseEther(amountOut);

const amountOutMin = minimumAmountOut(`${slippageTolerance}%`, bnAmountOut);
const amountOutMax = maximumAmountIn(`${slippageTolerance}%`, bnAmountIn);
const amountInMax = maximumAmountIn(`${slippageTolerance}%`, bnAmountIn);

return [
tradeIn ? amountOutMin : amountOutMax,
path,
address,
timestamp,
{ value: tradeIn ? bnAmountIn : bnAmountOut }
];
if (tradeIn) {
return [amountOutMin, path, address, timestamp, { value: bnAmountIn }];
} else {
return [bnAmountOut, path, address, timestamp, { value: amountInMax }];
}
}

0 comments on commit 93e458e

Please sign in to comment.