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

AsyncSwap

Git Source

Inherits: BaseHook, IAsyncSwapAMM

Author: Asyncswap Labs

State Variables

asyncOrders

Mapping to store async orders.

mapping(PoolId poolId => AsyncFiller.State) public asyncOrders

ALGORITHM

Ordering algortim

IAlgorithm public immutable ALGORITHM

kvolatility

mapping(uint256 block => uint256 volatility) public kvolatility

Functions

constructor

Initializes the Async Swap Hook contract with the PoolManager address and sets an transaction ordering algorithm.

constructor(IPoolManager poolManager, IAlgorithm orderingAlgorithm) BaseHook(poolManager);

Parameters

NameTypeDescription
poolManagerIPoolManagerThe address of the PoolManager contract.
orderingAlgorithmIAlgorithmThe address of the ordering algorithm

_beforeInitialize

function _beforeInitialize(address, PoolKey calldata key, uint160) internal virtual override returns (bytes4);

getHookPermissions

Returns a struct of permissions to signal which hook functions are to be implemented

Used at deployment to validate the address correctly represents the expected permissions

function getHookPermissions() public pure override returns (Hooks.Permissions memory);

_beforeAddLiquidity

function _beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
  internal
  pure
  override
  returns (bytes4);

asyncOrderAmount

function asyncOrderAmount(PoolId poolId, address user, bool zeroForOne) external view returns (uint256 claimable);

isExecutor

function isExecutor(PoolId poolId, address user, address executor) external view returns (bool);

calculateHookFee

function calculateHookFee(uint256) public pure returns (uint256);

calculatePoolFee

function calculatePoolFee(uint24, uint256) public pure returns (uint256);

executeOrders

Fills async orders in batching mode, allowing multiple orders to be executed in a single transaction.

function executeOrders(AsyncOrder[] calldata orders, bytes calldata userParams) external;

Parameters

NameTypeDescription
ordersAsyncOrder[]An array of async orders to be executed.
userParamsbytesAdditional data for the user, allowing user to specify an executor.

executeOrder

Fill an async order in an Async Swap AMM.

function executeOrder(AsyncOrder calldata order, bytes calldata) external;

Parameters

NameTypeDescription
orderAsyncOrderThe async order to be filled.
<none>bytes

_beforeSwap

function _beforeSwap(
  address sender,
  PoolKey calldata key,
  IPoolManager.SwapParams calldata params,
  bytes calldata hookParams
) internal override returns (bytes4, BeforeSwapDelta, uint24);

Events

HookSwap

Event emitted when a swap is executed.

event HookSwap(
  bytes32 indexed id,
  address indexed sender,
  int128 amount0,
  int128 amount1,
  uint128 hookLPfeeAmount0,
  uint128 hookLPfeeAmount1
);

Parameters

NameTypeDescription
idbytes32The poolId of the pool where the swap occurred.
senderaddressThe address that initiated the swap.
amount0int128The amount of currency0 taken in the swap (negative for exact input).
amount1int128The amount of currency1 taken in the swap (negative for exact input).
hookLPfeeAmount0uint128Fee amount taken for LP in currency0.
hookLPfeeAmount1uint128Fee amount taken for LP in currency1.

Errors

UnsupportedLiquidity

Error thrown when liquidity is not supported in this hook.

error UnsupportedLiquidity();