Units
A deep dive into the Phoenix units system
Last updated
A deep dive into the Phoenix units system
Last updated
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.
On Solana, all token quantities can be interpreted as a decimal value.
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:
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).
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.
SOL
Base
0.001
1,000,000
USDC
Quote
0.00001
10
We can perform a similar conversion for the quote token.
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.
Observe some examples in the table below:
2000
1000
10000
20.00
2000
100
1000
20.00
400
5000
10000
20.00
We know that the number of base atoms per base unit (for SOL) is . 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:
Suppose the market has quote lots per quote unit and a tick size of quote lots per base unit per tick. The following formula converts a price of ticks to the human-readable quote units per base unit:
Every order on the book is represented with a size in base lots at some price in ticks.
To compute the number of quote lots 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 quote lots per base unit per tick and base lots per base unit.
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 quote lots where is a nonnegative integer. We can rearrange the formula from the previous section to get the following equivalence: