feat: Decode single and sequential swaps in LibSwap

- The old way was useful when we just had split swaps. Unfortunately, we now have split, sequential, and single swaps, which don't always require token indices or split percentages, so we need to decode differently for each case.
This commit is contained in:
TAMARA LIPOWSKI
2025-03-18 01:37:14 -04:00
committed by Diana Carvalho
parent 3ae9d3ad67
commit 1dad4afb6b
5 changed files with 148 additions and 111 deletions

View File

@@ -30,10 +30,10 @@ contract TychoRouterExposed is TychoRouter {
return _splitSwap(amountIn, nTokens, swaps);
}
function exposedSequentialSwap(
uint256 amountIn,
bytes calldata swaps
) external returns (uint256) {
function exposedSequentialSwap(uint256 amountIn, bytes calldata swaps)
external
returns (uint256)
{
return _sequentialSwap(amountIn, swaps);
}
}
@@ -188,19 +188,23 @@ contract TychoRouterTestSetup is Constants {
}
}
function encodeSplitSwap(
uint8 tokenInIndex,
uint8 tokenOutIndex,
uint24 split,
address executor,
bytes memory protocolData
) internal pure returns (bytes memory) {
return abi.encodePacked(
tokenInIndex, tokenOutIndex, split, executor, protocolData
);
function encodeSingleSwap(address executor, bytes memory protocolData)
internal
pure
returns (bytes memory)
{
return abi.encodePacked(executor, protocolData);
}
function encodeSequentialSwap(
function encodeSequentialSwap(address executor, bytes memory protocolData)
internal
pure
returns (bytes memory)
{
return abi.encodePacked(executor, protocolData);
}
function encodeSplitSwap(
uint8 tokenInIndex,
uint8 tokenOutIndex,
uint24 split,