Universal Router Contract
The Universal Router executes swaps across V2 and V3 pools via an encoded command interface. In practice, you do not need to encode commands yourself — the Swap API generates the calldata for you. For the concept overview, see Universal Router Concepts.Key Functions
execute
Executes a sequence of commands in order.| Parameter | Type | Description |
|---|---|---|
commands | bytes | Sequence of command codes (1 byte each) |
inputs | bytes[] | ABI-encoded parameters for each command |
deadline | uint256 | Unix timestamp after which the transaction reverts |
Command Types
| Command | Code | Description |
|---|---|---|
V2_SWAP_EXACT_IN | 0x00 | V2 swap with exact input amount |
V2_SWAP_EXACT_OUT | 0x01 | V2 swap with exact output amount |
V3_SWAP_EXACT_IN | 0x02 | V3 swap with exact input amount |
V3_SWAP_EXACT_OUT | 0x03 | V3 swap with exact output amount |
WRAP_ETH | 0x0b | Wrap native KAS to WKAS |
UNWRAP_WETH | 0x0c | Unwrap WKAS to native KAS |
PERMIT2_PERMIT | 0x0a | Execute a Permit2 signature-based permit |
TRANSFER | 0x04 | Transfer tokens |
Usage Pattern
The recommended pattern is to use the Swap API to generate calldata:Error Handling
Common revert reasons:| Error | Cause | Solution |
|---|---|---|
EXPIRED | Transaction deadline exceeded | Use a longer deadline or submit faster |
V3_INVALID_AMOUNT_OUT | Output below minAmountOut | Increase slippage tolerance |
TRANSFER_FROM_FAILED | Insufficient approval or balance | Check Permit2 approval and token balance |
INSUFFICIENT_ETH | Not enough native KAS sent | Ensure value matches the required amount |