AsyncSwap
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
| Name | Type | Description |
|---|---|---|
poolManager | IPoolManager | The address of the PoolManager contract. |
orderingAlgorithm | IAlgorithm | The 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
| Name | Type | Description |
|---|---|---|
orders | AsyncOrder[] | An array of async orders to be executed. |
userParams | bytes | Additional 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
| Name | Type | Description |
|---|---|---|
order | AsyncOrder | The 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
| Name | Type | Description |
|---|---|---|
id | bytes32 | The poolId of the pool where the swap occurred. |
sender | address | The address that initiated the swap. |
amount0 | int128 | The amount of currency0 taken in the swap (negative for exact input). |
amount1 | int128 | The amount of currency1 taken in the swap (negative for exact input). |
hookLPfeeAmount0 | uint128 | Fee amount taken for LP in currency0. |
hookLPfeeAmount1 | uint128 | Fee amount taken for LP in currency1. |
Errors
UnsupportedLiquidity
Error thrown when liquidity is not supported in this hook.
error UnsupportedLiquidity();