# Units

Nomenclature and precision are important for understanding the internals of Phoenix Legacy. 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.

<table><thead><tr><th width="129">Token</th><th width="109">Decimals</th><th width="193">Amount (atoms)</th><th>Decimal interpretation (units)</th></tr></thead><tbody><tr><td>SOL</td><td>9</td><td>1,000,000,000</td><td>1.0 SOL</td></tr><tr><td>USDC</td><td>6</td><td>1,000,000</td><td>1.0 USDC</td></tr></tbody></table>

In the context of Phoenix Legacy, 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:

$$
\begin{align\*}\
1 \text{ unit} &= 10^{\text{decimals}} \text{ atoms}
\ A \text{ atoms} &= \frac{K}{10^{\text{decimals}}} \text{ units}
\end{align\*}
$$

### Base and Quote

Every Phoenix Legacy 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 Legacy matching engine can process. Every quantity that is passed into Phoenix Legacy 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

<table><thead><tr><th width="130.33333333333331">Token</th><th width="119">Type</th><th width="188">Lot size (units)</th><th>Lot size (atoms per lot)</th></tr></thead><tbody><tr><td>SOL</td><td>Base</td><td>0.001</td><td>1,000,000</td></tr><tr><td>USDC</td><td>Quote</td><td>0.00001</td><td>10</td></tr></tbody></table>

We know that the number of **base atoms per base** **unit** (for SOL) is $$10^9$$. 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:

$$
\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\*}
$$

We can perform a similar conversion for the quote token.

$$
0.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}}
$$

### 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**.

{% hint style="info" %}
Prices on the book are measured in an integer number of ticks.
{% endhint %}

Suppose the market has $$Q$$ **quote lots per quote unit** and a tick size of $$T$$ **quote lots per base unit per tick**. The following formula converts a price of $$P$$ **ticks** to the human-readable **quote units per base unit**:

$$
P \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}}
$$

Observe some examples in the table below:

<table><thead><tr><th width="138">Price (P)</th><th width="102.33333333333331">Tick size (T)</th><th width="225">Quote Lots/Quote Unit</th><th>Price (quote units/base unit)</th></tr></thead><tbody><tr><td>2000</td><td>1000</td><td>10000</td><td>20.00</td></tr><tr><td>2000</td><td>100</td><td>1000</td><td>20.00</td></tr><tr><td>400</td><td>5000</td><td>10000</td><td>20.00</td></tr></tbody></table>

### Order Sizes

Every order on the book is represented with a size $$S$$ in **base lots** at some price $$P$$ in ticks.

To compute the number of **quote lots** $$Q$$ 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 $$T$$ **quote lots per base unit per tick** and $$B$$ **base lots per base unit**.

$$
P \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}
$$

### 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 $$K$$**quote lots** where $$K$$is a nonnegative integer. We can rearrange the formula from the previous section to get the following equivalence:

$$K\* b \ \frac{quote\ lots}{base\ unit\ \*\ tick} = T\ \frac{quote\ lots}{base\ unit\ \*\ tick}$$

{% hint style="info" %}
This indicates that the **tick size** must be an integer multiple of the number of **base lots** found in a **base unit**
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ellipsis-labs.gitbook.io/phoenix-dex/tRIkEFlLUzWK9uKO3W2V/getting-started/technical-overview/units.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
