Phoenix DEX
  • Getting Started
    • Phoenix Overview
    • Technical Overview
      • Key Structures
      • Events
      • Instructions
      • Technical Glossary
      • Seats
        • Phoenix Seat Manager Program
      • Units
      • Market Addresses
    • Market Maker Overview
    • Developer Overview
      • Rust SDK
Powered by GitBook
On this page
  • Atoms and Units
  • Base and Quote
  • Lots
  • Ticks
  • Order Sizes
  • Invariants
  1. Getting Started
  2. Technical Overview

Units

A deep dive into the Phoenix units system

Nomenclature and precision are important for understanding the internals of Phoenix. These quantities and conversions enable a robust way to understand how numerical data flows through the matching engine.

Atoms and Units

On Solana, all token quantities can be interpreted as a decimal value.

Token
Decimals
Amount (atoms)
Decimal interpretation (units)

SOL

9

1,000,000,000

1.0 SOL

USDC

6

1,000,000

1.0 USDC

In the context of Phoenix, the smallest possible quantity of a token is referred to as an atom. The associated decimal value for a number of atoms is measured in units.

To convert from an amount of atoms to units, we apply the following formula:

1 unit=10decimals atomsA atoms=K10decimals units\begin{align*} 1 \text{ unit} &= 10^{\text{decimals}} \text{ atoms} \\ A \text{ atoms} &= \frac{K}{10^{\text{decimals}}} \text{ units} \end{align*}1 unitA atoms​=10decimals atoms=10decimalsK​ units​

Base and Quote

Every Phoenix market represents a venue for exchange between 2 assets (e.g. SOL/USDC). The asset being traded (in our example, SOL) is referred to as the base token and the asset that prices the base token is referred to as the quote token (in our example, USDC).

Lots

A lot is the smallest discrete unit of a token that the Phoenix matching engine can process. Every quantity that is passed into Phoenix must first be converted into the an integer number of lots. Note that lot sizes are set on a per-market level.

The smallest amount of base token (in atoms) the matching engine can work with is referred to as the base lot size, which is a quantity measured in base atoms per base lot.

The smallest amount of quote token (in atoms) the matching engine can work with is referred to as the quote lot size, which is a quantity measured in quote atoms per quote lot.

Converting Between Atoms and Lots

Token
Type
Lot size (units)
Lot size (atoms per lot)

SOL

Base

0.001

1,000,000

USDC

Quote

0.00001

10

We know that the number of base atoms per base unit (for SOL) is 10910^9109. So if the base lot size in base units per base lot is 0.001 SOL, we can apply the following conversion to get the base lot size in base atoms per base lot:

0.001base unitsbase lot×109base atomsbase units=106base atomsbase lot\begin{equation*} 0.001 \frac{\text{base units}}{\text{base lot}} \times 10^9 \frac{\text{base atoms}}{\text{base units}} = 10^6 \frac{\text{base atoms}}{\text{base lot}} \end{equation*}0.001base lotbase units​×109base unitsbase atoms​=106base lotbase atoms​​

We can perform a similar conversion for the quote token.

0.00001quote unitsquote lot×106quote atomsquote unit=10quote atomsquote lot0.00001 \frac{\text{quote units}}{\text{quote lot}} \times 10^6 \frac{\text{quote atoms}}{\text{quote unit}} = 10 \frac{\text{quote atoms}}{\text{quote lot}}0.00001quote lotquote units​×106quote unitquote atoms​=10quote lotquote atoms​

Ticks

A tick is the smallest discrete unit of price by which 2 orders on the book can differ; all valid prices on a market are an integer number of ticks. The size of a tick is measured in an integer number of quote lots per base unit.

Prices on the book are measured in an integer number of ticks.

Suppose the market has QQQ quote lots per quote unit and a tick size of TTT quote lots per base unit per tick. The following formula converts a price of PPP ticks to the human-readable quote units per base unit:

P ticks×Tquote lotsbase unit×tick×1Qquote unitsquote lot=PTQquote unitsbase unitP \text{ ticks} \times T \frac{\text{quote lots}}{\text{base unit} \times \text{tick}} \times \frac{1}{Q} \frac{\text{quote units}}{\text{quote lot}} = \frac{PT}{Q} \frac{\text{quote units}}{\text{base unit}}P ticks×Tbase unit×tickquote lots​×Q1​quote lotquote units​=QPT​base unitquote units​

Observe some examples in the table below:

Price (P)
Tick size (T)
Quote Lots/Quote Unit
Price (quote units/base unit)

2000

1000

10000

20.00

2000

100

1000

20.00

400

5000

10000

20.00

Order Sizes

Every order on the book is represented with a size SSS in base lots at some price PPP in ticks.

To compute the number of quote lots QQQ this order represents (amount posted for bids and amount required to fill the order for offers), use the following formula. Assume a tick size of TTT quote lots per base unit per tick and BBB base lots per base unit.

P ticks×Tquote lotsbase unit×tick×S base lots×1Bbase unitsbase lot=PTSB quote lotsP \text{ ticks} \times T \frac{\text{quote lots}}{\text{base unit} \times \text{tick}} \times S \text{ base lots} \times \frac{1}{B} \frac{\text{base units}}{\text{base lot}} = \frac{PTS}{B} \text{ quote lots}P ticks×Tbase unit×tickquote lots​×S base lots×B1​base lotbase units​=BPTS​ quote lots

Invariants

One important guarantee is that the book will enable trades of an integer number of quote lots for a single base lot at any price. What this means is that at a price of 1 tick, selling a 1 base lot, will return KKKquote lots where KKKis a nonnegative integer. We can rearrange the formula from the previous section to get the following equivalence:

K∗b quote lotsbase unit ∗ tick=T quote lotsbase unit ∗ tickK* b \ \frac{quote\ lots}{base\ unit\ *\ tick} = T\ \frac{quote\ lots}{base\ unit\ *\ tick}K∗b base unit ∗ tickquote lots​=T base unit ∗ tickquote lots​

This indicates that the tick size must be an integer multiple of the number of base lots found in a base unit

PreviousPhoenix Seat Manager ProgramNextMarket Addresses

Last updated 1 year ago