Skip to main content

Hooks

Hooks

V4 decides whether to invoke specific hooks by inspecting the leading bits of the address that the hooks contract is deployed to. For example, a hooks contract deployed to address: 0x9000000000000000000000000000000000000000 has leading bits '1001' which would cause the 'before open' and 'after make' hooks to be used.

BEFORE_OPEN_FLAG

uint256 BEFORE_OPEN_FLAG

AFTER_OPEN_FLAG

uint256 AFTER_OPEN_FLAG

BEFORE_MAKE_FLAG

uint256 BEFORE_MAKE_FLAG

AFTER_MAKE_FLAG

uint256 AFTER_MAKE_FLAG

BEFORE_TAKE_FLAG

uint256 BEFORE_TAKE_FLAG

AFTER_TAKE_FLAG

uint256 AFTER_TAKE_FLAG

BEFORE_CANCEL_FLAG

uint256 BEFORE_CANCEL_FLAG

AFTER_CANCEL_FLAG

uint256 AFTER_CANCEL_FLAG

BEFORE_CLAIM_FLAG

uint256 BEFORE_CLAIM_FLAG

AFTER_CLAIM_FLAG

uint256 AFTER_CLAIM_FLAG

Permissions

struct Permissions {
bool beforeOpen;
bool afterOpen;
bool beforeMake;
bool afterMake;
bool beforeTake;
bool afterTake;
bool beforeCancel;
bool afterCancel;
bool beforeClaim;
bool afterClaim;
}

HookAddressNotValid

error HookAddressNotValid(address hooks)

Thrown if the address will not lead to the specified hook calls being called

Parameters

NameTypeDescription
hooksaddressThe address of the hooks contract

InvalidHookResponse

error InvalidHookResponse()

Hook did not return its selector

FailedHookCall

error FailedHookCall()

thrown when a hook call fails

validateHookPermissions

function validateHookPermissions(contract IHooks self, struct Hooks.Permissions permissions) internal pure

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

Parameters

NameTypeDescription
selfcontract IHooks
permissionsstruct Hooks.PermissionsThe hooks that are intended to be called

isValidHookAddress

function isValidHookAddress(contract IHooks hook) internal pure returns (bool)

Ensures that the hook address includes at least one hook flag or is the 0 address

Parameters

NameTypeDescription
hookcontract IHooksThe hook to verify

callHook

function callHook(contract IHooks self, bytes data) internal

performs a hook call using the given calldata on the given hook

beforeOpen

function beforeOpen(contract IHooks self, struct IBookManager.BookKey key, bytes hookData) internal

calls beforeOpen hook if permissioned and validates return value

afterOpen

function afterOpen(contract IHooks self, struct IBookManager.BookKey key, bytes hookData) internal

calls afterOpen hook if permissioned and validates return value

beforeMake

function beforeMake(contract IHooks self, struct IBookManager.MakeParams params, bytes hookData) internal

calls beforeMake hook if permissioned and validates return value

afterMake

function afterMake(contract IHooks self, struct IBookManager.MakeParams params, OrderId orderId, bytes hookData) internal

calls afterMake hook if permissioned and validates return value

beforeTake

function beforeTake(contract IHooks self, struct IBookManager.TakeParams params, bytes hookData) internal

calls beforeTake hook if permissioned and validates return value

afterTake

function afterTake(contract IHooks self, struct IBookManager.TakeParams params, uint64 takenAmount, bytes hookData) internal

calls afterTake hook if permissioned and validates return value

beforeCancel

function beforeCancel(contract IHooks self, struct IBookManager.CancelParams params, bytes hookData) internal

calls beforeCancel hook if permissioned and validates return value

afterCancel

function afterCancel(contract IHooks self, struct IBookManager.CancelParams params, uint64 canceledAmount, bytes hookData) internal

calls afterCancel hook if permissioned and validates return value

beforeClaim

function beforeClaim(contract IHooks self, OrderId orderId, bytes hookData) internal

calls beforeClaim hook if permissioned and validates return value

afterClaim

function afterClaim(contract IHooks self, OrderId orderId, uint64 claimedAmount, bytes hookData) internal

calls afterClaim hook if permissioned and validates return value

hasPermission

function hasPermission(contract IHooks self, uint256 flag) internal pure returns (bool)