Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IRouter

Git Source

Title: Router Interface

Author: Async Labs

This interface defines the functions for the Router contract, which allows users to swap tokens and fill orders using async orders.

Functions

swap

Swaps tokens using an async order.

function swap(AsyncOrder calldata order, bytes calldata userData) external payable;

Parameters

NameTypeDescription
orderAsyncOrderThe async order to be placed.
userDatabytesAdditional 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

NameTypeDescription
orderAsyncOrderThe async order to be filled.
userDatabytesAdditional 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

NameTypeDescription
ordersAsyncOrder[]Array of orders to execute.
ordersDatabytes[]Array of filler data corresponding to each order.

Returns

NameTypeDescription
resultsbool[]Array of booleans indicating success/failure for each order.

Structs

SwapCallback

Callback structure for the swap function.

struct SwapCallback {
  ActionType action;
  AsyncOrder order;
  uint256 amountOut;
}

Properties

NameTypeDescription
actionActionTypeThe action type, either Swap or FillOrder.
orderAsyncOrderThe async order that is in context for the swap or fill operation.
amountOutuint256The amount the filler is offering (only used for FillOrder action).

WithdrawCallback

struct WithdrawCallback {
  ActionType action;
  PoolKey key;
  bool zeroForOne;
  uint256 amount;
  address user;
}

MulticallCallback

struct MulticallCallback {
  ActionType action;
  AsyncOrder[] orders;
  bytes[] ordersData;
}

Enums

ActionType

Enum representing the action type for the swap callback.

  1. Swap - If the action is a swap, this will specify the async swap order intent.
  2. FillOrder - If the action is a fill order, this will specify fill order intent.
  3. Withdrawal - If the action is a withdrawal, this will specify withdrawal intent.
  4. Multicall - If the action is a multicall, this will specify multicall intent.
enum ActionType {
  Swap,
  FillOrder,
  Withdrawal,
  Multicall
}