Skip to main content

IBookManager

IBookManager

The interface for the BookManager contract

InvalidUnitSize

error InvalidUnitSize()

InvalidFeePolicy

error InvalidFeePolicy()

InvalidProvider

error InvalidProvider(address provider)

LockedBy

error LockedBy(address locker, address hook)

CurrencyNotSettled

error CurrencyNotSettled()

Open

event Open(BookId id, Currency base, Currency quote, uint64 unitSize, FeePolicy makerPolicy, FeePolicy takerPolicy, contract IHooks hooks)

Event emitted when a new book is opened

Parameters

NameTypeDescription
idBookIdThe book id
baseCurrencyThe base currency
quoteCurrencyThe quote currency
unitSizeuint64The unit size of the book
makerPolicyFeePolicyThe maker fee policy
takerPolicyFeePolicyThe taker fee policy
hookscontract IHooksThe hooks contract

Make

event Make(BookId bookId, address user, Tick tick, uint256 orderIndex, uint64 unit, address provider)

Event emitted when a new order is made

Parameters

NameTypeDescription
bookIdBookIdThe book id
useraddressThe user address
tickTickThe order tick
orderIndexuint256The order index
unituint64The order unit
provideraddressThe provider address

Take

event Take(BookId bookId, address user, Tick tick, uint64 unit)

Event emitted when an order is taken

Parameters

NameTypeDescription
bookIdBookIdThe book id
useraddressThe user address
tickTickThe order tick
unituint64The order unit

Cancel

event Cancel(OrderId orderId, uint64 unit)

Event emitted when an order is canceled

Parameters

NameTypeDescription
orderIdOrderIdThe order id
unituint64The canceled unit

Claim

event Claim(OrderId orderId, uint64 unit)

Event emitted when an order is claimed

Parameters

NameTypeDescription
orderIdOrderIdThe order id
unituint64The claimed unit

Whitelist

event Whitelist(address provider)

Event emitted when a provider is whitelisted

Parameters

NameTypeDescription
provideraddressThe provider address

Delist

event Delist(address provider)

Event emitted when a provider is delisted

Parameters

NameTypeDescription
provideraddressThe provider address

Collect

event Collect(address provider, address recipient, Currency currency, uint256 amount)

Event emitted when a provider collects fees

Parameters

NameTypeDescription
provideraddressThe provider address
recipientaddressThe recipient address
currencyCurrencyThe currency
amountuint256The collected amount

SetDefaultProvider

event SetDefaultProvider(address newDefaultProvider)

Event emitted when new default provider is set

Parameters

NameTypeDescription
newDefaultProvideraddressThe new default provider address

BookKey

This structure represents a unique identifier for a book in the BookManager.

Parameters

NameTypeDescription
struct BookKey {
Currency base;
uint64 unitSize;
Currency quote;
FeePolicy makerPolicy;
contract IHooks hooks;
FeePolicy takerPolicy;
}

baseURI

function baseURI() external view returns (string)

Returns the base URI

Return Values

NameTypeDescription
[0]stringThe base URI

contractURI

function contractURI() external view returns (string)

Returns the contract URI

Return Values

NameTypeDescription
[0]stringThe contract URI

defaultProvider

function defaultProvider() external view returns (address)

Returns the default provider

Return Values

NameTypeDescription
[0]addressThe default provider

reservesOf

function reservesOf(Currency currency) external view returns (uint256)

Returns the total reserves of a given currency

Parameters

NameTypeDescription
currencyCurrencyThe currency in question

Return Values

NameTypeDescription
[0]uint256The total reserves amount

isWhitelisted

function isWhitelisted(address provider) external view returns (bool)

Checks if a provider is whitelisted

Parameters

NameTypeDescription
provideraddressThe address of the provider

Return Values

NameTypeDescription
[0]boolTrue if the provider is whitelisted, false otherwise

checkAuthorized

function checkAuthorized(address owner, address spender, uint256 tokenId) external view

Verifies if an owner has authorized a spender for a token

Parameters

NameTypeDescription
owneraddressThe address of the token owner
spenderaddressThe address of the spender
tokenIduint256The token ID

tokenOwed

function tokenOwed(address provider, Currency currency) external view returns (uint256)

Calculates the amount owed to a provider in a given currency

Parameters

NameTypeDescription
provideraddressThe provider's address
currencyCurrencyThe currency in question

Return Values

NameTypeDescription
[0]uint256The owed amount

getCurrencyDelta

function getCurrencyDelta(address locker, Currency currency) external view returns (int256)

Calculates the currency balance changes for a given locker

Parameters

NameTypeDescription
lockeraddressThe address of the locker
currencyCurrencyThe currency in question

Return Values

NameTypeDescription
[0]int256The net change in currency balance

getBookKey

function getBookKey(BookId id) external view returns (struct IBookManager.BookKey)

Retrieves the book key for a given book ID

Parameters

NameTypeDescription
idBookIdThe book ID

Return Values

NameTypeDescription
[0]struct IBookManager.BookKeyThe book key

OrderInfo

This structure represents a current status for an order in the BookManager.

Parameters

NameTypeDescription
struct OrderInfo {
address provider;
uint64 open;
uint64 claimable;
}

getOrder

function getOrder(OrderId id) external view returns (struct IBookManager.OrderInfo)

Provides information about an order

Parameters

NameTypeDescription
idOrderIdThe order ID

Return Values

NameTypeDescription
[0]struct IBookManager.OrderInfoOrder information including provider, open status, and claimable unit

getLock

function getLock(uint256 i) external view returns (address locker, address lockCaller)

Retrieves the locker and caller addresses for a given lock

Parameters

NameTypeDescription
iuint256The index of the lock

Return Values

NameTypeDescription
lockeraddressThe locker's address
lockCalleraddressThe caller's address

getLockData

function getLockData() external view returns (uint128, uint128)

Provides the lock data

Return Values

NameTypeDescription
[0]uint128The lock data including necessary numeric values
[1]uint128

getDepth

function getDepth(BookId id, Tick tick) external view returns (uint64)

Returns the depth of a given book ID and tick

Parameters

NameTypeDescription
idBookIdThe book ID
tickTickThe tick

Return Values

NameTypeDescription
[0]uint64The depth of the tick

getHighest

function getHighest(BookId id) external view returns (Tick tick)

Retrieves the highest tick for a given book ID

Parameters

NameTypeDescription
idBookIdThe book ID

Return Values

NameTypeDescription
tickTickThe highest tick

maxLessThan

function maxLessThan(BookId id, Tick tick) external view returns (Tick)

Finds the maximum tick less than a specified tick in a book

Returns Tick.wrap(type(int24).min) if the specified tick is the lowest

Parameters

NameTypeDescription
idBookIdThe book ID
tickTickThe specified tick

Return Values

NameTypeDescription
[0]TickThe next lower tick

isOpened

function isOpened(BookId id) external view returns (bool)

Checks if a book is opened

Parameters

NameTypeDescription
idBookIdThe book ID

Return Values

NameTypeDescription
[0]boolTrue if the book is opened, false otherwise

isEmpty

function isEmpty(BookId id) external view returns (bool)

Checks if a book is empty

Parameters

NameTypeDescription
idBookIdThe book ID

Return Values

NameTypeDescription
[0]boolTrue if the book is empty, false otherwise

encodeBookKey

function encodeBookKey(struct IBookManager.BookKey key) external pure returns (BookId)

Encodes a BookKey into a BookId

Parameters

NameTypeDescription
keystruct IBookManager.BookKeyThe BookKey to encode

Return Values

NameTypeDescription
[0]BookIdThe encoded BookId

load

function load(bytes32 slot) external view returns (bytes32)

Loads a value from a specific storage slot

Parameters

NameTypeDescription
slotbytes32The storage slot

Return Values

NameTypeDescription
[0]bytes32The value in the slot

load

function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes)

Loads a sequence of values starting from a specific slot

Parameters

NameTypeDescription
startSlotbytes32The starting slot
nSlotuint256The number of slots to load

Return Values

NameTypeDescription
[0]bytesThe sequence of values

open

function open(struct IBookManager.BookKey key, bytes hookData) external

Opens a new book

Parameters

NameTypeDescription
keystruct IBookManager.BookKeyThe book key
hookDatabytesThe hook data

lock

function lock(address locker, bytes data) external returns (bytes)

Locks a book manager function

Parameters

NameTypeDescription
lockeraddressThe locker address
databytesThe lock data

Return Values

NameTypeDescription
[0]bytesThe lock return data

MakeParams

This structure represents the parameters for making an order.

Parameters

NameTypeDescription
struct MakeParams {
struct IBookManager.BookKey key;
Tick tick;
uint64 unit;
address provider;
}

make

function make(struct IBookManager.MakeParams params, bytes hookData) external returns (OrderId id, uint256 quoteAmount)

Make a limit order

Parameters

NameTypeDescription
paramsstruct IBookManager.MakeParamsThe order parameters
hookDatabytesThe hook data

Return Values

NameTypeDescription
idOrderIdThe order id. Returns 0 if the order is not settled
quoteAmountuint256The amount of quote currency to be paid

TakeParams

This structure represents the parameters for taking orders in the specified tick.

Parameters

NameTypeDescription
struct TakeParams {
struct IBookManager.BookKey key;
Tick tick;
uint64 maxUnit;
}

take

function take(struct IBookManager.TakeParams params, bytes hookData) external returns (uint256 quoteAmount, uint256 baseAmount)

Take a limit order at specific tick

Parameters

NameTypeDescription
paramsstruct IBookManager.TakeParamsThe order parameters
hookDatabytesThe hook data

Return Values

NameTypeDescription
quoteAmountuint256The amount of quote currency to be received
baseAmountuint256The amount of base currency to be paid

CancelParams

This structure represents the parameters for canceling an order.

Parameters

NameTypeDescription
struct CancelParams {
OrderId id;
uint64 toUnit;
}

cancel

function cancel(struct IBookManager.CancelParams params, bytes hookData) external returns (uint256 canceledAmount)

Cancel a limit order

Parameters

NameTypeDescription
paramsstruct IBookManager.CancelParamsThe order parameters
hookDatabytesThe hook data

Return Values

NameTypeDescription
canceledAmountuint256The amount of quote currency canceled

claim

function claim(OrderId id, bytes hookData) external returns (uint256 claimedAmount)

Claims an order

Parameters

NameTypeDescription
idOrderIdThe order ID
hookDatabytesThe hook data

Return Values

NameTypeDescription
claimedAmountuint256The amount claimed

collect

function collect(address recipient, Currency currency) external returns (uint256)

Collects fees from a provider

Parameters

NameTypeDescription
recipientaddressThe recipient address
currencyCurrencyThe currency

Return Values

NameTypeDescription
[0]uint256The collected amount

withdraw

function withdraw(Currency currency, address to, uint256 amount) external

Withdraws a currency

Parameters

NameTypeDescription
currencyCurrencyThe currency
toaddressThe recipient address
amountuint256The amount

settle

function settle(Currency currency) external payable returns (uint256)

Settles a currency

Parameters

NameTypeDescription
currencyCurrencyThe currency

Return Values

NameTypeDescription
[0]uint256The settled amount

whitelist

function whitelist(address provider) external

Whitelists a provider

Parameters

NameTypeDescription
provideraddressThe provider address

delist

function delist(address provider) external

Delists a provider

Parameters

NameTypeDescription
provideraddressThe provider address

setDefaultProvider

function setDefaultProvider(address newDefaultProvider) external

Sets the default provider

Parameters

NameTypeDescription
newDefaultProvideraddressThe new default provider address