Router
Inherits: IRouter
Title: Router Contract
Author: Async Labs
This contract implements the Router interface, allowing users to swap tokens and fill async orders through the PoolManager and Async Swap hook.
State Variables
POOLMANAGER
PoolManager contract to interact with the pools.
IPoolManager immutable POOLMANAGER
HOOK
Async Swap Hook contract to execute async orders.
IAsyncSwapAMM immutable HOOK
ACTION_LOCATION
keccak256("Router.ActionType") - 1
bytes32 constant ACTION_LOCATION = 0xf3b150ebf41dad0872df6788629edb438733cb4a5c9ea779b1b1f3614faffc69
USER_LOCATION
keccak256("Router.User") - 1
bytes32 constant USER_LOCATION = 0x3dde20d9bf5cc25a9f487c6d6b54d3c19e3fa4738b91a7a509d4fc4180a72356
ASYNC_FILLER_LOCATION
keccak256("Router.AsyncFiller") - 1
bytes32 constant ASYNC_FILLER_LOCATION = 0xd972a937b59dc5cb8c692dd9f211e85afa8def4caee6e05b31db0f53e16d02e0
Functions
constructor
Initializes the Router contract with the PoolManager and Async CSMM hook.
constructor(IPoolManager _poolManager, IAsyncSwapAMM _hook) ;
Parameters
| Name | Type | Description |
|---|---|---|
_poolManager | IPoolManager | The PoolManager contract that manages the pools. |
_hook | IAsyncSwapAMM | The Async CSMM hook contract that executes async orders. |
onlyPoolManager
Only allow the PoolManager to call certain functions.
modifier onlyPoolManager() ;
_checkCallerIsPoolManager
function _checkCallerIsPoolManager() internal view;
swap
Swaps tokens using an async order.
function swap(AsyncOrder calldata order, bytes memory userData) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
order | AsyncOrder | The async order to be placed. |
userData | bytes | Additional data for the user, allowing user to specify an executor. |
fillOrder
Fills an async order.
function fillOrder(AsyncOrder calldata order, bytes calldata userData) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
order | AsyncOrder | The async order to be filled. |
userData | bytes | Additional data for the user, allowing user to specify an executor. |
withdraw
function withdraw(PoolKey memory key, bool zeroForOne, uint256 amount) external;
multicall
Execute multiple orders with graceful failure handling.
Individual order failures don't revert the entire transaction.
function multicall(AsyncOrder[] calldata orders, bytes[] calldata ordersData)
external
payable
returns (bool[] memory results);
Parameters
| Name | Type | Description |
|---|---|---|
orders | AsyncOrder[] | Array of orders to execute. |
ordersData | bytes[] | Array of filler data corresponding to each order. |
Returns
| Name | Type | Description |
|---|---|---|
results | bool[] | Array of booleans indicating success/failure for each order. |
unlockCallback
Callback handler to unlock the PoolManager after a swap or fill order.
function unlockCallback(bytes calldata data) external onlyPoolManager returns (bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The callback data containing the action type and order information. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes | Data to return back to the PoolManager after unlock. |
_tryMulticall
Internal function to try decoding and executing as multicall
This is external to enable try-catch, but should only be called by this contract
function _tryMulticall(bytes calldata data) external returns (bool[] memory results);