Technical Reference
Functions
Transactions to the OmegaRouter all go through the execute function:
execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline)execute(bytes calldata commands, bytes[] calldata inputs)
Both functions behave and process the commands exactly the same; the first one includes a deadline. The function without the deadline parameter will not revert based on block.timestamp.
The execute function behaves like a minimal virtual machine. It interprets a list of 1-byte commands and their corresponding ABI-encoded inputs and executes them sequentially.
Command Structure
Each command byte uses the following bit structure:
f
r
command
f
A single bit flag that signals whether or not the command should be allowed to revert without the whole transaction failing.
If
fis0(false) and the command reverts, then the entire transaction will revert and none of the commands will be executed.If
fis1(true) and the command reverts, then the transaction will continue, allowing partial fills. If using this flag, include further commands that will remove any funds that could be left unused in theOmegaRoutercontract.
r
2 unused bits, reserved for future use. Leaving these 2 bits as 0 will save gas, but any value passed into the contract will be ignored. Later versions of the OmegaRouter may expand the 5 bits used for command to use at least 1 of these bits.
command
A 5-bit unique identifier for the command that should be carried out. The values of these commands can be found within Commands.sol (link below), or can be viewed in the table in the Supported Commands section.
Commands not defined (placeholders) will revert with InvalidCommandType if provided.
Key Features
Algebra Integral swaps
✅ INTEGRAL_SWAP_EXACT_IN, INTEGRAL_SWAP_EXACT_OUT
Integral position management
✅ INTEGRAL_POSITION_MANAGER_CALL, INTEGRAL_MINT, INTEGRAL_INCREASE_LIQUIDITY
Uniswap V3 swaps
✅ UNISWAP_V3_SWAP_EXACT_IN, UNISWAP_V3_SWAP_EXACT_OUT
Uniswap V2 swaps
✅ V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT
Permit2-based transfers
✅ Extended with batch transfers
ERC4626 vault support
✅ ERC4626_WRAP, ERC4626_UNWRAP
Sub-plan execution
✅ EXECUTE_SUB_PLAN
Supported Commands
0x00
INTEGRAL_SWAP_EXACT_IN
0x01
INTEGRAL_SWAP_EXACT_OUT
0x02
PERMIT2_TRANSFER_FROM
0x03
PERMIT2_PERMIT_BATCH
0x04
SWEEP
0x05
TRANSFER
0x06
PAY_PORTION
0x07
ERC4626_WRAP
0x08
V2_SWAP_EXACT_IN
0x09
V2_SWAP_EXACT_OUT
0x0a
PERMIT2_PERMIT
0x0b
WRAP_ETH
0x0c
UNWRAP_WETH
0x0d
PERMIT2_TRANSFER_FROM_BATCH
0x0e
BALANCE_CHECK_ERC20
0x0f
ERC4626_UNWRAP
0x10
UNISWAP_V3_SWAP_EXACT_IN
0x11
UNISWAP_V3_SWAP_EXACT_OUT
0x12
INTEGRAL_POSITION_MANAGER_CALL
0x13
INTEGRAL_MINT
0x14
INTEGRAL_POSITION_MANAGER_PERMIT
0x15
INTEGRAL_INCREASE_LIQUIDITY
0x21
EXECUTE_SUB_PLAN
Commands not listed are placeholders and will revert if called.
Command Inputs
Each command requires its own input structure. Inputs are encoded using abi.encode(...) and placed in inputs[i] to match commands[i]. For example: (use abi.encode(...) for each command's parameters)
Swap Commands
Algebra Integral Swaps
0x00 – INTEGRAL_SWAP_EXACT_IN
Parameters:
address recipientuint256 amountInuint256 amountOutMinbytes pathbool payerIsUser
Calls: integralSwapExactInput(...) in IntegralSwapModule
Usage: Swaps exact input amount on Algebra Integral pools.
0x01 – INTEGRAL_SWAP_EXACT_OUT
Parameters:
address recipientuint256 amountOutuint256 amountInMaxbytes pathbool payerIsUser
Calls: integralSwapExactOutput(...)
Usage: Swaps to receive exact output amount on Algebra Integral pools.
Uniswap V3 Swaps
0x10 – UNISWAP_V3_SWAP_EXACT_IN
Parameters:
address recipientuint256 amountInuint256 amountOutMinbytes pathbool payerIsUser
Calls: uniswapV3SwapExactInput(...) in UniswapV3SwapModule
Usage: Swaps exact input amount on Uniswap V3 pools.
0x11 – UNISWAP_V3_SWAP_EXACT_OUT
Parameters:
address recipientuint256 amountOutuint256 amountInMaxbytes pathbool payerIsUser
Calls: uniswapV3SwapExactOutput(...)
Usage: Swaps to receive exact output amount on Uniswap V3 pools.
Uniswap V2 Swaps
0x08 – V2_SWAP_EXACT_IN
Parameters:
address recipientuint256 amountInuint256 amountOutMinaddress[] pathbool payerIsUser
Calls: v2SwapExactInput(...) in V2SwapModule
Usage: Simple Uniswap v2-style fixed input swap using token pairs.
0x09 – V2_SWAP_EXACT_OUT
Parameters:
address recipientuint256 amountOutuint256 amountInMaxaddress[] pathbool payerIsUser
Calls: v2SwapExactOutput(...)
Usage: Swaps to get an exact output amount with limited token budget.
ERC4626 Vault Commands
0x07 – ERC4626_WRAP
Parameters:
address vaultaddress recipientuint256 amount
Calls: ERC4626.deposit(...)
Usage: Deposits assets into an ERC4626 vault and mints shares.
0x0f – ERC4626_UNWRAP
Parameters:
address vaultaddress recipientuint256 amount
Calls: ERC4626.redeem(...)
Usage: Redeems shares from an ERC4626 vault for underlying assets.
Permit2 Commands
About Permit2: Permit2 is Uniswap's signature-based approval contract that enables gasless token approvals. The Permit2 contract must be deployed on the chain (Uniswap has already deployed it on major networks; if not available, OmegaRouter can deploy it).
Workflow:
One-time approval: User approves the Permit2 contract to spend their tokens. This approval can be reused across different protocols on the same network.
Generate signature: User generates an off-chain signature via MetaMask, specifying:
Token address and amount
Target contract (OmegaRouter)
Expiration time
Execute with signature: The signature is passed to Permit2 commands before swap or liquidity operations, allowing the router to transfer tokens without additional on-chain approvals.
0x02 – PERMIT2_TRANSFER_FROM
Parameters:
address tokenaddress recipientuint160 amount
Calls: permit2TransferFrom(...)
Usage: Transfers a single token using Permit2 allowances. Always pulls from msg.sender.
0x03 – PERMIT2_PERMIT_BATCH
Parameters:
PermitBatch permitBatchbytes signature
Calls: PERMIT2.permit(...)
Usage: Sets approval for multiple tokens in one signature.
0x0a – PERMIT2_PERMIT
Parameters:
PermitSingle permitSinglebytes signature
Calls: PERMIT2.permit(...)
Usage: Sets approval for one token, often before PERMIT2_TRANSFER_FROM.
0x0d – PERMIT2_TRANSFER_FROM_BATCH
Parameters:
AllowanceTransferDetails[] batch
Calls: permit2TransferFrom(...)
Usage: Transfers many tokens in one call from a user to one or more destinations.
Payment & Balance Commands
0x04 – SWEEP
Parameters:
address tokenaddress recipientuint256 amountMin
Calls: Payments.sweep(...)
Usage: Clears out all router-held ETH or ERC20 tokens to a destination address.
0x05 – TRANSFER
Parameters:
address tokenaddress recipientuint256 amount
Calls: Payments.pay(...)
Usage: Transfers a specific amount (not full balance) from the router.
0x06 – PAY_PORTION
Parameters:
address tokenaddress recipientuint256 bips
Calls: Payments.payPortion(...)
Usage: Sends a % of the token balance (e.g., 2500 = 25%).
0x0e – BALANCE_CHECK_ERC20
Parameters:
address owneraddress tokenuint256 minBalance
Calls: view-only balanceOf(...)
Usage: Ensures required token balance exists; useful for conditional workflows.
ETH & WETH
0x0b – WRAP_ETH
Parameters:
address recipientuint256 amount
Calls: Payments.wrapETH(...) → WETH.deposit()
Usage: Converts ETH held by router into WETH and optionally sends it.
0x0c – UNWRAP_WETH
Parameters:
address recipientuint256 amountMin
Calls: Payments.unwrapWETH9(...)
Usage: Converts router-held WETH into ETH and sends it.
Algebra Integral Position Management
These commands interact with Algebra Integral's NonfungiblePositionManager to create and manage concentrated liquidity positions.
Router Balance Feature: INTEGRAL_MINT and INTEGRAL_INCREASE_LIQUIDITY were specifically designed to work with the router's token balance. This is essential for ERC4626 vault tokens, where the exact amount received from wrapping cannot be predicted due to variable exchange rates. Instead of specifying exact amounts, these commands use whatever token balance the router holds.
0x12 – INTEGRAL_POSITION_MANAGER_CALL
Parameters:
bytes callData
Calls: Arbitrary call to Algebra Integral NonfungiblePositionManager
Usage: Executes position operations like burn, collect, decreaseLiquidity on Integral NFT positions.
0x13 – INTEGRAL_MINT
Parameters:
address token0address token1int24 tickLowerint24 tickUpperuint256 amount0Desireduint256 amount1Desireduint256 amount0Minuint256 amount1Minaddress recipient
Calls: NonfungiblePositionManager.mint(...)
Usage: Creates a new liquidity position on Algebra Integral.
0x14 – INTEGRAL_POSITION_MANAGER_PERMIT
Parameters:
address spenderuint256 tokenIduint256 deadlineuint8 v, bytes32 r, bytes32 s
Calls: NonfungiblePositionManager.permit(...)
Usage: Grants router permission to operate on a user's Integral position NFT via signature.
0x15 – INTEGRAL_INCREASE_LIQUIDITY
Parameters:
uint256 tokenIduint256 amount0Desireduint256 amount1Desireduint256 amount0Minuint256 amount1Min
Calls: NonfungiblePositionManager.increaseLiquidity(...)
Usage: Adds liquidity to an existing Integral position NFT.
Composability
0x21 – EXECUTE_SUB_PLAN
Parameters:
bytes subCommandsbytes[] subInputs
Calls: execute(...) (reentrantly)
Usage: Nested command execution for conditional or fallback logic. Used to group steps or allow selective reverts (via f flag).
How EXECUTE_SUB_PLAN Works: EXECUTE_SUB_PLAN performs a reentrant call to the router's execute function with a nested set of commands and inputs. This allows you to:
Group related operations into logical units
Create fallback execution paths
Implement conditional logic using the ALLOW_REVERT flag
Build complex multi-step operations with partial execution guarantees
Execution Flow:
Main command sequence encounters EXECUTE_SUB_PLAN
Router calls itself with
subCommandsandsubInputsNested commands execute sequentially
If any nested command fails and ALLOW_REVERT is not set, the entire transaction reverts
If ALLOW_REVERT is set (0x80 | 0x21), the sub-plan can fail without reverting the main transaction
Execution returns to the main command sequence
Example: Vault Token Liquidity Addition
// Main commands:
// 1. PERMIT2_TRANSFER_FROM - get underlying tokens from user
// 2. EXECUTE_SUB_PLAN:
// a. ERC4626_WRAP - wrap to vault tokens (amount uncertain)
// b. INTEGRAL_MINT - add liquidity using router balance
// 3. SWEEP - return any leftover tokens to userReverting Command Example
To allow a command to fail without reverting the entire transaction, set the high bit:
command = 0x80 | <command_id>
// Examples:
0x80 | 0x00 = 0x80 // INTEGRAL_SWAP_EXACT_IN with ALLOW_REVERT
0x80 | 0x21 = 0xa1 // EXECUTE_SUB_PLAN with ALLOW_REVERT
0x80 | 0x13 = 0x93 // INTEGRAL_MINT with ALLOW_REVERTIf
f = 0(ALLOW_REVERT not set): Command failure reverts the entire transactionIf
f = 1(ALLOW_REVERT set): Command failure is caught, execution continues with next command
Be sure to follow such commands with cleanup logic (e.g., SWEEP) to handle unused ETH or tokens.
Example: Multi-Route Swap with Best Execution
// Try multiple DEX routes, execute whichever succeeds first
commands = [
0x02, // PERMIT2_TRANSFER_FROM - get input tokens
0x80, // INTEGRAL_SWAP_EXACT_IN (Route A) with ALLOW_REVERT
0x90, // UNISWAP_V3_SWAP_EXACT_IN (Route B) with ALLOW_REVERT
0x04 // SWEEP - send output to user
]
// If Route A succeeds, Route B is skipped (no input balance left)
// If Route A fails, Route B attempts the swap
// If both fail, SWEEP still executes (no tokens to sweep)References
https://github.com/cryptoalgebra/omega-router
https://github.com/cryptoalgebra/omega-router/blob/main/contracts/libraries/Commands.sol
https://docs.algebra.finance/
Last updated