fix: remove amountIn addition to amountOut in _swap for cyclic swaps, add testCyclicSwapWithTwoPools test to verify

This commit is contained in:
royvardhan
2025-03-06 19:10:45 +05:30
parent 5532c64d87
commit 57acbd58c5
3 changed files with 44 additions and 1 deletions

View File

@@ -345,7 +345,9 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
currentAmountOut = _callExecutor(
swapData.executor(), currentAmountIn, swapData.protocolData()
);
amounts[tokenOutIndex] += currentAmountOut;
amounts[tokenOutIndex] = tokenOutIndex == 0
? currentAmountOut
: amounts[tokenOutIndex] + currentAmountOut;
remainingAmounts[tokenOutIndex] += currentAmountOut;
remainingAmounts[tokenInIndex] -= currentAmountIn;
}