feat: Assume that funds will never go straight from a pool to the receiver

- The funds will always go through the router
- Rename splitSwap for Swap
- Improve tests

--- don't change below this line ---
ENG-4041 Took 24 minutes


Took 23 seconds

Took 42 seconds
This commit is contained in:
Diana Carvalho
2025-01-28 16:13:24 +00:00
parent dfa7033d2e
commit 655cf91984
6 changed files with 69 additions and 63 deletions

View File

@@ -143,15 +143,12 @@ contract TychoRouter is
);
}
amountOut = _splitSwap(amountIn, nTokens, swaps);
amountOut = _swap(amountIn, nTokens, swaps);
if (fee > 0) {
uint256 feeAmount = (amountOut * fee) / 10000;
amountOut -= feeAmount;
IERC20(tokenOut).safeTransfer(feeReceiver, feeAmount);
if (!unwrapEth) {
IERC20(tokenOut).safeTransfer(receiver, amountOut);
}
}
if (minAmountOut > 0 && amountOut < minAmountOut) {
@@ -162,14 +159,15 @@ contract TychoRouter is
_unwrapETH(amountOut);
// slither-disable-next-line arbitrary-send-eth
payable(receiver).transfer(amountOut);
} else {
IERC20(tokenOut).safeTransfer(receiver, amountOut);
}
}
function _splitSwap(
uint256 amountIn,
uint256 nTokens,
bytes calldata swaps_
) internal returns (uint256) {
function _swap(uint256 amountIn, uint256 nTokens, bytes calldata swaps_)
internal
returns (uint256)
{
uint256 currentAmountIn;
uint256 currentAmountOut;
uint8 tokenInIndex;