OrderSignatures
Title: OrderSignatures
Author: @msakiart
EIP-712 types for signed AsyncSwap actions. Every type spells out the maker, both tokens and the amounts so wallets render a readable message instead of opaque calldata.
AsyncOrderis the Permit2 witness forRouter.swapWithSig(Permit2 domain).SetExecutorandUpdatePriceare verified by the hook (AsyncSwap domain).CancelOrderis verified by the Router (AsyncSwap Router domain).
Constants
POOL_KEY_TYPE
bytes internal constant POOL_KEY_TYPE =
"PoolKey(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)";ASYNC_ORDER_TYPE
bytes internal constant ASYNC_ORDER_TYPE =
"AsyncOrder(address maker,address tokenIn,address tokenOut,uint256 amountIn,uint256 amountOutMin,uint256 priorityFee,PoolKey pool)";POOL_KEY_TYPEHASH
bytes32 internal constant POOL_KEY_TYPEHASH = keccak256(POOL_KEY_TYPE);ASYNC_ORDER_TYPEHASH
bytes32 internal constant ASYNC_ORDER_TYPEHASH = keccak256(abi.encodePacked(ASYNC_ORDER_TYPE, POOL_KEY_TYPE));PERMIT2_WITNESS_TYPE
Witness type string appended by Permit2 to PermitWitnessTransferFrom(...).
Referenced types are sorted alphabetically per EIP-712.
string internal constant PERMIT2_WITNESS_TYPE = string(
abi.encodePacked(
"AsyncOrder witness)", ASYNC_ORDER_TYPE, POOL_KEY_TYPE, "TokenPermissions(address token,uint256 amount)"
)
);SET_EXECUTOR_TYPEHASH
bytes32 internal constant SET_EXECUTOR_TYPEHASH = keccak256(
abi.encodePacked(
"SetExecutor(address maker,address executor,bool allow,PoolKey pool,uint256 nonce,uint256 deadline)",
POOL_KEY_TYPE
)
);UPDATE_PRICE_TYPEHASH
bytes32 internal constant UPDATE_PRICE_TYPEHASH = keccak256(
"UpdatePrice(address maker,address tokenIn,address tokenOut,uint256 amountIn,uint256 newAmountOutMin,bytes32 orderId,uint64 createdSequence,uint32 reprices,uint256 nonce,uint256 deadline)"
);CANCEL_ORDER_TYPEHASH
bytes32 internal constant CANCEL_ORDER_TYPEHASH = keccak256(
"CancelOrder(address maker,address tokenIn,address tokenOut,bytes32 orderId,uint64 createdSequence,uint256 nonce,uint256 deadline)"
);Functions
tokens
function tokens(AsyncOrder memory order) internal pure returns (address tokenIn, address tokenOut);Parameters
| Name | Type | Description |
|---|---|---|
| order | AsyncOrder |
Returns
| Name | Type | Description |
|---|---|---|
| tokenIn | address | |
| tokenOut | address |
hashPoolKey
function hashPoolKey(PoolKey memory key) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| key | PoolKey |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
hashOrder
Struct hash of the order a maker signs as the Permit2 witness. Covers everything that
defines the order; sqrtPrice is excluded (the hook consumes the whole swap, so v4
never reads the price limit) and salt is assigned by the hook at create time.
function hashOrder(AsyncOrder memory order) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| order | AsyncOrder |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
hashSetExecutor
function hashSetExecutor(
PoolKey memory key,
address maker,
address executor,
bool allow,
uint256 nonce,
uint256 deadline
) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| key | PoolKey | |
| maker | address | |
| executor | address | |
| allow | bool | |
| nonce | uint256 | |
| deadline | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
hashUpdatePrice
function hashUpdatePrice(
AsyncOrder memory order,
bytes32 orderId,
uint256 amountIn,
uint256 newAmountOutMin,
uint64 createdSequence,
uint32 reprices,
uint256 nonce,
uint256 deadline
) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| order | AsyncOrder | |
| orderId | bytes32 | |
| amountIn | uint256 | The order's input when the maker signs, so the maker sees the size of the order they reprice.amountIn and newAmountOutMin together are the new price: if partial matches shrink the orderbefore the reprice lands, the hook scales the minimum to the remainder. |
| newAmountOutMin | uint256 | |
| createdSequence | uint64 | The order's creation sequence, so the signature cannot apply to an identical replacement order with the same id. |
| reprices | uint32 | How many times the order has been repriced, so a signature cannot undo a later reprice. Matches do not move it. |
| nonce | uint256 | |
| deadline | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
hashCancel
Carries a nonce: order ids can recur (identical order re-placed in the same block after a cancel), so order deletion alone does not stop a signed cancel from being replayed. It does not commit to the order's size: a cancel covers whatever remains, so a partial match before it lands cannot void it.
function hashCancel(
AsyncOrder memory order,
bytes32 orderId,
uint64 createdSequence,
uint256 nonce,
uint256 deadline
) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| order | AsyncOrder | |
| orderId | bytes32 | |
| createdSequence | uint64 | |
| nonce | uint256 | |
| deadline | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |