Technical Reference
Functions
All transactions to the UniversalRouter are processed through the UniversalRouter.execute functions:
execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline)execute(bytes calldata commands, bytes[] calldata inputs)
The first function allows setting a transaction deadline. If the block.timestamp surpasses the provided deadline, the transaction will revert. Otherwise, both functions execute identically.
These functions operate like a simplified virtual machine (VM). They accept a list of commands and corresponding inputs, executing them in the specified order.
Command Structure
The first parameter (bytes calldata commands) is a list of commands for the contract to execute, ordered as intended. Each command is encoded in a single byte, divided as follows:
| 0 | 1 2 | 3 4 5 6 7 |
|---|---|---|
| f | r | command |
f
A single bit flag indicating whether the command can revert independently without causing the entire transaction to fail:
- If
fis0(false) and the command reverts, the entire transaction fails, and subsequent commands are not executed. - If
fis1(true) and the command reverts, the transaction proceeds, enabling partial fills. If using this flag, ensure to include further commands to utilize any leftover funds in theUniversalRoutercontract.
r
Two unused bits reserved for future use. These bits can be set to 0 to save gas, with any provided values ignored. Future versions of the UniversalRouter might utilize these bits for additional functionalities.
command
A 5-bit unique identifier for the command to execute.
Commands not defined at present will cause the transaction to revert with InvalidCommandType.
The table below lists the complete set of commands:
| Command | Value |
|---|---|
0x02 | PERMIT2_TRANSFER_FROM |
0x03 | PERMIT2_PERMIT_BATCH |
0x04 | SWEEP |
0x05 | TRANSFER |
0x06 | PAY_PORTION |
0x08 | V2_SWAP_EXACT_IN |
0x09 | V2_SWAP_EXACT_OUT |
0x0a | PERMIT2_PERMIT |
0x0b | WRAP_ETH |
0x0c | UNWRAP_WETH |
0x0d | PERMIT2_TRANSFER_FROM_BATCH |
Command Details
Each command is followed by specific parameters:
PERMIT2_TRANSFER_FROM
address: Token to fetch from Permit2address: Recipient of the fetched tokensuint256: Amount of tokens to fetch
The tokens are fetched from the msg.sender of the transaction.
PERMIT2_PERMIT_BATCH
IAllowanceTransfer.PermitBatch: PermitBatch struct detailing Permit2 permits to executebytes: Signature for Permit2
The signer of the permits must be the msg.sender of the transaction.
SWEEP
address: ERC20 token to sweep (or Constants.STEAMX for STEAMX)address: Recipient of the sweepuint256: Minimum tokens to receive from the sweep
TRANSFER
address: ERC20 token to transfer (or Constants.STEAMX for STEAMX)address: Recipient of the transferuint256: Amount to transfer
PAY_PORTION
address: ERC20 token to transfer (or Constants.STEAMX for STEAMX)address: Recipient of the transferuint256: Percentage of the contract's balance to transfer (in basis points)
V2_SWAP_EXACT_IN
address: Recipient of the trade outputuint256: Amount of input tokens for the tradeuint256: Minimum desired output tokensaddress[]: Rails Network SwapV2 token path for the tradebool: Flag indicating whether input tokens should come frommsg.sender(via Permit2) or are already in theUniversalRouter
V2_SWAP_EXACT_OUT
address: Recipient of the trade outputuint256: Amount of output tokens to receiveuint256: Maximum input tokens to spendaddress[]: Rails Network SwapV2 token path for the tradebool: Flag indicating whether input tokens should come frommsg.sender(via Permit2) or are already in theUniversalRouter
PERMIT2_PERMIT
IAllowanceTransfer.PermitSingle: PermitSingle struct outlining the Permit2 permit to executebytes: Signature for Permit2
The signer of the permit must be the msg.sender of the transaction.
WRAP_ETH
address: Recipient of the WSTEAMXuint256: Amount of STEAMX to wrap
UNWRAP_WETH
address: Recipient of the STEAMXuint256: Minimum required STEAMX to receive from the unwrapping
PERMIT2_TRANSFER_FROM_BATCH
IAllowanceTransfer.AllowanceTransferDetails[]: Array of AllowanceTransferDetails structs, each describing a Permit2 transfer to perform
SWEEP_ERC721
address: ERC721 token address to transferaddress: Recipient of the transferuint256: Token ID to transfer
NFT20
uint256: STEAMX value to forward to the NFT20 contractbytes: Calldata to call the NFT20 contract
FOUNDATION
uint256: STEAMX value to forward to the Foundation contractbytes: Calldata to call the Foundation contractaddress: Recipient of the ERC721address: ERC721 token addressuint256: ID of the ERC721
SWEEP_ERC1155
address: ERC1155 token address to sweepaddress: Recipient of the sweepuint256: Token ID to sweepuint256: Minimum tokens to receive from the sweep