Universal Router
The Universal Router is a single smart contract that can execute swaps across both V2 and V3 pools. It serves as the unified entry point for all trading operations on Kroko DEX.Why a Universal Router?
Without it, swapping through V2 and V3 would require separate contracts and separate transactions. The Universal Router:- Unifies execution — One contract handles V2, V3, and mixed-protocol swaps
- Enables complex routes — Multi-hop swaps that cross between V2 and V3 pools
- Reduces gas — Batches operations in a single transaction
- Integrates Permit2 — Pulls tokens via Permit2 for streamlined approvals
How It Works
The Universal Router receives encoded commands and inputs via itsexecute() function:
- commands: A byte string where each byte is a command code (e.g., V2_SWAP_EXACT_IN, V3_SWAP_EXACT_IN, WRAP_ETH, UNWRAP_WETH, etc.)
- inputs: ABI-encoded parameters for each command
- deadline: Unix timestamp after which the transaction reverts
Typical Swap Flow
Slippage Protection
The encoded calldata includes on-chain slippage checks:| Trade Type | Protection | Description |
|---|---|---|
| Exact Input | minAmountOut | Reverts if output is below minimum |
| Exact Output | maxAmountIn | Reverts if input exceeds maximum |
Native KAS Handling
When a swap involves native KAS (not WKAS), the Universal Router automatically:- Selling KAS: Wraps the KAS sent as
msg.valueinto WKAS before the swap - Buying KAS: Unwraps WKAS to KAS and sends it to the recipient after the swap
value field in the Swap API response is non-zero when native KAS is the input token.