Hooks
Git Source - Generated with forge doc
V4 decides whether to invoke specific hooks by inspecting the least significant bits of the address that the hooks contract is deployed to. For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400 has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
State Variables
ALL_HOOK_MASK
uint160 internal constant ALL_HOOK_MASK = uint160((1 << 14) - 1);
BEFORE_INITIALIZE_FLAG
uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 13;
AFTER_INITIALIZE_FLAG
uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 12;
BEFORE_ADD_LIQUIDITY_FLAG
uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11;
AFTER_ADD_LIQUIDITY_FLAG
uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10;
BEFORE_REMOVE_LIQUIDITY_FLAG
uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9;
AFTER_REMOVE_LIQUIDITY_FLAG
uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8;
BEFORE_SWAP_FLAG
uint160 internal constant BEFORE_SWAP_FLAG = 1 << 7;
AFTER_SWAP_FLAG
uint160 internal constant AFTER_SWAP_FLAG = 1 << 6;
BEFORE_DONATE_FLAG
uint160 internal constant BEFORE_DONATE_FLAG = 1 << 5;
AFTER_DONATE_FLAG
uint160 internal constant AFTER_DONATE_FLAG = 1 << 4;
BEFORE_SWAP_RETURNS_DELTA_FLAG
uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3;
AFTER_SWAP_RETURNS_DELTA_FLAG
uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2;
AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG
uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 1;
AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG
uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 0;
Functions
validateHookPermissions
Utility function intended to be used in hook constructors to ensure the deployed hooks address causes the intended hooks to be called
permissions param is memory as the function will be called from constructors
function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure;
Parameters
| Name | Type | Description |
|---|---|---|
self | IHooks | |
permissions | Permissions | The hooks that are intended to be called |
isValidHookAddress
Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address
function isValidHookAddress(IHooks self, uint24 fee) internal pure returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
self | IHooks | The hook to verify |
fee | uint24 | The fee of the pool the hook is used with |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | bool True if the hook address is valid |
callHook
performs a hook call using the given calldata on the given hook that doesn't return a delta
function callHook(IHooks self, bytes memory data) internal returns (bytes memory result);
Returns
| Name | Type | Description |
|---|---|---|
result | bytes | The complete data returned by the hook |
callHookWithReturnDelta
performs a hook call using the given calldata on the given hook
function callHookWithReturnDelta(IHooks self, bytes memory data, bool parseReturn) internal returns (int256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | int256 | int256 The delta returned by the hook |
noSelfCall
modifier to prevent calling a hook if they initiated the action
modifier noSelfCall(IHooks self);