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

Title: Async Swap Contract

Author: Asyncswap Labs

State Variables

asyncOrders

Mapping to store async orders.

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

ALGORITHM

Ordering algorithm

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) BaseHook(poolManager);

Parameters

NameTypeDescription
poolManagerIPoolManagerThe address of the PoolManager contract.

_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);

batch

function batch(
  AsyncOrder[] calldata buys,
  AsyncOrder[] calldata sells,
  bytes[] calldata buysData,
  bytes[] calldata sellsData
) external;

executeOrder

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

_beforeSwap

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

withdraw

function withdraw(PoolKey memory key, bool zeroForOne, uint256 amount, address user) external;

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();

OrderExpired

error OrderExpired();

InvalidWithdrawal

error InvalidWithdrawal();

NotApprovedExecutor

error NotApprovedExecutor();