DeepBook 池
DeepBook 的核心是一个超高效的每个当前交易对共享对象池结构。该架构最大程度地利用了 Sui 的 Narwhal 和 Bullshark 引擎,以最小化争用并实现高吞吐量。
对于每个基础和报价资产交易对,创建一个全局共享的池,用于 1) 记账订单簿上的未结订单和 2) 处理订单的下单、取消和结算。在这种架构下,涉及不同交易对的交易可以轻松并行化,以最大程度地提高吞吐量。
struct Pool<phantom BaseAsset, phantom QuoteAsset> has key {
// The key to the following Critbit Tree are order prices.
id: UID,
// All open bid orders.
bids: CritbitTree<TickLevel>,
// All open ask orders.
asks: CritbitTree<TickLevel>,
// Order id of the next bid order, starting from 0.
next_bid_order_id: u64,
// Order id of the next ask order, starting from 1<<63.
next_ask_order_id: u64,
// Map from order id to price level for fast retrieval of orders upon canceling of orders.
usr_open_orders: Table<ID, Table<u64, Order>>,
// taker_fee_rate should be strictly greater than maker_rebate_rate.
// The difference between taker_fee_rate and maker_rabate_rate goes to the protocol.
// 10^9 scaling
taker_fee_rate: u64,
// 10^9 scaling
maker_rebate_rate: u64,
tick_size: u64,
lot_size: u64,
// other pool info
base_custodian: Custodian<BaseAsset>,
quote_custodian: Custodian<QuoteAsset>,
}