Skip to main content

Book

Book

ZeroUnit

error ZeroUnit()

BookAlreadyOpened

error BookAlreadyOpened()

BookNotOpened

error BookNotOpened()

QueueReplaceFailed

error QueueReplaceFailed()

CancelFailed

error CancelFailed(uint64 maxCancelableUnit)

MAX_ORDER

uint40 MAX_ORDER

MAX_ORDER_M

uint256 MAX_ORDER_M

Order

struct Order {
address provider;
uint64 pending;
}

Queue

struct Queue {
struct SegmentedSegmentTree.Core tree;
struct Book.Order[] orders;
}

State

struct State {
struct IBookManager.BookKey key;
mapping(Tick => struct Book.Queue) queues;
mapping(uint256 => uint256) tickBitmap;
mapping(uint24 => uint256) totalClaimableOf;
}

open

function open(struct Book.State self, struct IBookManager.BookKey key) external

isOpened

function isOpened(struct Book.State self) internal view returns (bool)

checkOpened

function checkOpened(struct Book.State self) internal view

depth

function depth(struct Book.State self, Tick tick) internal view returns (uint64)

highest

function highest(struct Book.State self) internal view returns (Tick)

maxLessThan

function maxLessThan(struct Book.State self, Tick tick) internal view returns (Tick)

isEmpty

function isEmpty(struct Book.State self) internal view returns (bool)

getOrder

function getOrder(struct Book.State self, Tick tick, uint40 index) internal view returns (struct Book.Order)

make

function make(struct Book.State self, Tick tick, uint64 unit, address provider) external returns (uint40 orderIndex)

take

function take(struct Book.State self, Tick tick, uint64 maxTakeUnit) external returns (uint64 takenUnit)

Take orders from the book

Parameters

NameTypeDescription
selfstruct Book.StateThe book state
tickTick
maxTakeUnituint64The maximum unit to take

Return Values

NameTypeDescription
takenUnituint64The actual unit to take

cancel

function cancel(struct Book.State self, OrderId orderId, uint64 to) external returns (uint64 canceled, uint64 afterPending)

claim

function claim(struct Book.State self, Tick tick, uint40 index) external returns (uint64 claimedUnit)

calculateClaimableUnit

function calculateClaimableUnit(struct Book.State self, Tick tick, uint40 index) public view returns (uint64)