ZooBC wiki
Tokens and markets

Markets and orders

A ZooBC market is an order book for one pair of assets, kept and matched by the chain itself. Every node applies the same matching rules when an order transaction is applied, so every node reaches the same fills, no operator holds the traders' funds, and nobody can reorder the book. Anyone can open a market, and a busy market pays its own rent.

Opening a market

A market is a pair (base, quote): for example a token, the base, priced in ZBC, the quote. The pair is ordered, so (A, B) and (B, A) are two different markets. Both assets need 8 decimals (see decimals and the step).

CreateMarket (type 21) costs market_creation_cost, 50 ZBC on mainnet. That cost becomes the market's rent deposit (see below).

Placing an order

A PlaceOrder (type 22) states the market, a side (buy or sell), a limit price, an amount, flags and an optional expiry. The flags can make it a market order (immediate-or-cancel) or post-only.

Prices are in quote atomic units per base atomic unit, multiplied by 10⁸. A price of 1.015 ZBC per token is therefore written 101,500,000.

When a block applies the order:

  1. The order holds what it may spend: a sell order holds its base amount; a buy order holds amount × price ÷ 10⁸ of the quote.
  2. It matches at once against the resting orders on the other side, best price first and, among equal prices, the lower transaction id first. Each fill trades at the resting order's price, not at the taker's limit.
  3. What is not filled rests on the book, except for a market order, whose remainder is refunded.

Every product is rounded down in 128-bit arithmetic, so every node computes exactly the same fills.

An ask ladder at 1.004, 1.013 and 1.026; a buy order limited at 1.015 fills the first two levels, each at its own price; 0.1 % of the base received goes to the block producer, and the unused hold returns to the taker
An ask ladder at 1.004, 1.013 and 1.026; a buy order limited at 1.015 fills the first two levels, each at its own price; 0.1 % of the base received goes to the block producer, and the unused hold returns to the taker

Two rules keep order books clean: an order's quote value must be at least 2,500,000 atomic units (0.025 of the quote asset), and a taker never fills against its own resting order.

The taker fee

Only the taker pays a trading fee: exchange_taker_fee_bps, 10 basis points (0.1 %) on mainnet, taken from the asset the taker receives (the base for a buy, the quote for a sell) and paid to the producer of the block. In the example above, 0.3 of the 300 tokens received go to the producer. The rate is a chain parameter that can range from 1 to 100 basis points. Makers pay no trading fee, and the market's creator gets no share.

The taker fee is separate from the transaction fee. The fees of PlaceOrder and CancelOrder are ordinary fees, which go to the coinbase lottery. When the block's producer is not yet mature (see maturity and earnings), its taker fee goes to the coinbase lottery as well.

Cancelling and expiry

CancelOrder (type 23) lets the maker, and only the maker, withdraw a resting order; whatever remains of its hold returns. A resting order with an expiry expires at the start of a block, judged by the previous block's timestamp.

Market rent

A market occupies the chain's state, so it pays rent like everything else that does:

  • the 50 ZBC creation cost is a deposit that prepays 12 periods of rent; each period of 172,800 blocks (30 days) takes a twelfth, about 4.17 ZBC, into the longevity pool;
  • every PlaceOrder and CancelOrder adds 20 % of its own fee to the deposit, on top of the fee, up to a deposit of 24 periods, so the orders themselves keep a busy market funded;
  • a market that cannot pay a period, or one of whose assets has expired, is pruned: its resting orders are refunded to their makers, the rest of the deposit goes to the longevity pool, and the pair can be opened again later.
A market stall with a rent deposit of 12 slots at creation; each order adds 20 % of its fee; every 30 days one slot goes to the longevity pool; when the deposit runs out the market closes and the resting orders are refunded
A market stall with a rent deposit of 12 slots at creation; each order adds 20 % of its fee; every 30 days one slot goes to the longevity pool; when the deposit runs out the market closes and the resting orders are refunded

ZooBC has no automated market-maker pools: every trade is between orders that people place. For a one-off trade of any two assets, including tokens with fewer than 8 decimals, see swap offers.

See also