Skip to main content

Callbacks

Git Source

Library for handling callbacks

This library is based on the design of UniswapV4's Hooks library (https://github.com/Uniswap/v4-core/blob/main/src/libraries/Hooks.sol) and is published under the same MIT license.

We use the term callbacks because it is more appropriate for the type of extensibility we are providing to the Axis auction system. The system decides whether to invoke specific hooks by inspecting the leading bits (first byte) of the address that the callbacks contract is deployed to. For example, a callbacks contract deployed to address: 0x9000000000000000000000000000000000000000 has leading bits '1001' which would cause the 'onCreate' and 'onPurchase' callbacks to be used.

There are 8 flags

State Variables

ON_CREATE_FLAG

uint256 internal constant ON_CREATE_FLAG = 1 << 159;

ON_CANCEL_FLAG

uint256 internal constant ON_CANCEL_FLAG = 1 << 158;

ON_CURATE_FLAG

uint256 internal constant ON_CURATE_FLAG = 1 << 157;

ON_PURCHASE_FLAG

uint256 internal constant ON_PURCHASE_FLAG = 1 << 156;

ON_BID_FLAG

uint256 internal constant ON_BID_FLAG = 1 << 155;

ON_SETTLE_FLAG

uint256 internal constant ON_SETTLE_FLAG = 1 << 154;

RECEIVE_QUOTE_TOKENS_FLAG

uint256 internal constant RECEIVE_QUOTE_TOKENS_FLAG = 1 << 153;

SEND_BASE_TOKENS_FLAG

uint256 internal constant SEND_BASE_TOKENS_FLAG = 1 << 152;

Functions

validateCallbacksPermissions

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 validateCallbacksPermissions(
ICallback self,
Permissions memory permissions
) internal pure;

Parameters

NameTypeDescription
selfICallback
permissionsPermissionsThe hooks that are intended to be called

isValidCallbacksAddress

Ensures that the callbacks contract includes at least one of the required flags and more if sending/receiving tokens

function isValidCallbacksAddress(ICallback callbacks) internal pure returns (bool);

Parameters

NameTypeDescription
callbacksICallbackThe callbacks contract to verify

callback

performs a call using the given calldata on the given callback

function callback(ICallback self, bytes memory data) internal;

onCreate

calls onCreate callback if permissioned and validates return value

function onCreate(
ICallback self,
uint96 lotId,
address seller,
address baseToken,
address quoteToken,
uint256 capacity,
bool preFund,
bytes calldata callbackData
) internal;

onCancel

calls onCancel callback if permissioned and validates return value

function onCancel(
ICallback self,
uint96 lotId,
uint256 refund,
bool preFunded,
bytes calldata callbackData
) internal;

onCurate

calls onCurate callback if permissioned and validates return value

function onCurate(
ICallback self,
uint96 lotId,
uint256 curatorFee,
bool preFund,
bytes calldata callbackData
) internal;

onPurchase

calls onPurchase callback if permissioned and validates return value

function onPurchase(
ICallback self,
uint96 lotId,
address buyer,
uint256 amount,
uint256 payout,
bool preFunded,
bytes calldata callbackData
) internal;

onBid

calls onBid callback if permissioned and validates return value

function onBid(
ICallback self,
uint96 lotId,
uint64 bidId,
address buyer,
uint256 amount,
bytes calldata callbackData
) internal;

onSettle

calls onSettle callback if permissioned and validates return value

function onSettle(
ICallback self,
uint96 lotId,
uint256 proceeds,
uint256 refund,
bytes calldata callbackData
) internal;

hasPermission

function hasPermission(ICallback self, uint256 flag) internal pure returns (bool);

_revert

bubble up revert if present. Else throw FailedCallback error

function _revert(bytes memory result) private pure;

Errors

CallbacksAddressNotValid

Thrown if the address will not lead to the specified callbacks being called

error CallbacksAddressNotValid(address callbacks);

Parameters

NameTypeDescription
callbacksaddressThe address of the callbacks contract

InvalidCallbackResponse

Callback did not return its selector

error InvalidCallbackResponse();

FailedCallback

thrown when a callback fails

error FailedCallback();

Structs

Permissions

struct Permissions {
bool onCreate;
bool onCancel;
bool onCurate;
bool onPurchase;
bool onBid;
bool onSettle;
bool receiveQuoteTokens;
bool sendBaseTokens;
}