Merge remote-tracking branch 'origin/main' into ekubo
This commit is contained in:
@@ -111,8 +111,7 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
/**
|
||||
* @notice Executes a swap operation based on a predefined swap graph, supporting internal token amount splits.
|
||||
* This function enables multi-step swaps, optional ETH wrapping/unwrapping, and validates the output amount
|
||||
* against a user-specified minimum. This function expects the input tokens to already be in the router at
|
||||
* the time of calling.
|
||||
* against a user-specified minimum. This function performs a transferFrom to retrieve tokens from the caller.
|
||||
*
|
||||
* @dev
|
||||
* - If `wrapEth` is true, the contract wraps the provided native ETH into WETH and uses it as the sell token.
|
||||
@@ -259,14 +258,13 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
: IERC20(tokenIn).balanceOf(address(this));
|
||||
|
||||
amountOut = _swap(amountIn, nTokens, swaps);
|
||||
|
||||
uint256 currentBalance = tokenIn == address(0)
|
||||
? address(this).balance
|
||||
: IERC20(tokenIn).balanceOf(address(this));
|
||||
|
||||
uint256 amountConsumed = initialBalance - currentBalance;
|
||||
|
||||
if (amountConsumed != amountIn) {
|
||||
if (tokenIn != tokenOut && amountConsumed != amountIn) {
|
||||
revert TychoRouter__AmountInDiffersFromConsumed(
|
||||
amountIn, amountConsumed
|
||||
);
|
||||
@@ -299,12 +297,15 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
* - The indices of the input and output tokens (via `tokenInIndex()` and `tokenOutIndex()`).
|
||||
* - The portion of the available amount to be used for the swap, indicated by the `split` value.
|
||||
*
|
||||
* Two important notes:
|
||||
* Three important notes:
|
||||
* - The contract assumes that token indexes follow a specific order: the sell token is at index 0, followed by any
|
||||
* intermediary tokens, and finally the buy token.
|
||||
* - A `split` value of 0 is interpreted as 100% of the available amount (i.e., the entire remaining balance).
|
||||
* This means that in scenarios without explicit splits the value should be 0, and when splits are present,
|
||||
* the last swap should also have a split value of 0.
|
||||
* - In case of cyclic swaps, the output token is the same as the input token.
|
||||
* `cyclicSwapAmountOut` is used to track the amount of the output token, and is updated when
|
||||
* the `tokenOutIndex` is 0.
|
||||
*
|
||||
* @param amountIn The initial amount of the sell token to be swapped.
|
||||
* @param nTokens The total number of tokens involved in the swap path, used to initialize arrays for internal tracking.
|
||||
@@ -329,6 +330,7 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
|
||||
uint256[] memory remainingAmounts = new uint256[](nTokens);
|
||||
uint256[] memory amounts = new uint256[](nTokens);
|
||||
uint256 cyclicSwapAmountOut = 0;
|
||||
amounts[0] = amountIn;
|
||||
remainingAmounts[0] = amountIn;
|
||||
|
||||
@@ -345,11 +347,16 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
currentAmountOut = _callExecutor(
|
||||
swapData.executor(), currentAmountIn, swapData.protocolData()
|
||||
);
|
||||
amounts[tokenOutIndex] += currentAmountOut;
|
||||
// Checks if the output token is the same as the input token
|
||||
if (tokenOutIndex == 0) {
|
||||
cyclicSwapAmountOut += currentAmountOut;
|
||||
} else {
|
||||
amounts[tokenOutIndex] += currentAmountOut;
|
||||
}
|
||||
remainingAmounts[tokenOutIndex] += currentAmountOut;
|
||||
remainingAmounts[tokenInIndex] -= currentAmountIn;
|
||||
}
|
||||
return amounts[tokenOutIndex];
|
||||
return tokenOutIndex == 0 ? cyclicSwapAmountOut : amounts[tokenOutIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user