What are decoders?
This contract is used to decode and verify the swap data that is passed to the Uniswap Universal Router. It supports decoding swap data for Uniswap V2, V3, and V4.
Decoding the swap data:
The main function used to decode the swap data is decodeExchangeInput:
function decodeExchangeInput(
uint256,
bytes calldata inputData
)
external
view
override
returns (address fromToken, address toToken, uint256 fromAmount, uint256 toAmount, address recipient)
{}
inputData this is the data used to call the universal router.Returns:
fromToken: the input tokentoToken: the output tokenfromAmount: input amounttoAmount: output amountrecipient: recipient of output tokensThe first step in the decoding process is to check that the first 4 bytes of the data correspond to a valid function signature:
if (selector == 0x24856bc3) {
(commands, inputs) = abi.decode(inputData[4:], (bytes, bytes[]));
} else if (selector == 0x3593564c) {
(commands, inputs, ) = abi.decode(inputData[4:], (bytes, bytes[], uint256));
} else {
revert CantDecode(inputData);
}
These signatures correspond to the functions execute(bytes, bytes[], uint256) and execute(bytes, bytes[]) in the UniversalRouter.
After extracting the function parameters, we iterate over the commands and decode the input for each one. Some of key verification checks: