Units System
Understanding the Units and Conversions Used in the GTE CLOB Protocol
Introduction
In the GTE CLOB protocol, understanding the units system is essential for correctly interpreting token quantities and order book interactions. The system is designed to ensure precision when interacting with different markets, each involving a base token (e.g., ETH) and a quote token (e.g., USDC). These tokens are represented using the smallest indivisible units, referred to as atoms.
Atom is a term adopted from Solana terminology. For Ethereum, an atom of Ether is traditionally called Wei.
This page explains how these atoms relate to their more human-readable values, known as units, and how the protocol handles quantities, prices, and lot sizes for both base and quote tokens.
Atoms and Units
Every token in the protocol can be expressed in two forms:
- Atoms: The smallest measurable quantity of a token, usually defined by the token’s decimals.
- Units: The human-readable form, equivalent to how the token is displayed in typical applications (e.g., 1.0 USDC).
The conversion between atoms and units follows this formula:
For example, if a token like USDC has 6 decimals, then:
Lot Sizes
Every market in the GTE protocol defines lot sizes, which represent the smallest quantity of a token that can be traded on the platform. This ensures consistency when orders are placed on the order book.
- Base Lot Size: The smallest amount of the base token that can be traded, measured in base atoms per base lot.
- Quote Lot Size: The smallest amount of the quote token that can be traded, measured in quote atoms per quote lot.
For example, if the base token is ETH and the base lot size is 0.001 ETH, this means:
Likewise, if the quote token is USDC and the quote lot size is 0.01 USDC, this means:
Prices and Ticks
In the GTE protocol, prices are expressed in ticks, which represent the smallest possible price increment between two orders on the order book. A tick is defined as a number of quote lots per base unit, ensuring that price changes on the order book are always discrete and represented by integer values.
Understanding Ticks
Each market has a defined tick size, which specifies how many quote lots per base unit make up a single tick. The size of a tick is determined by the following factors:
- Tick Size (T): The number of quote lots per base unit for each tick.
- Quote Lots/Quote Unit (Q): The number of quote lots that make up one human-readable quote unit.
Converting Ticks to Human-Readable Prices
To calculate the human-readable price in quote units per base unit from the price in ticks, use the following formula:
Where:
- ( P ) is the price in ticks.
- ( T ) is the tick size (in quote lots per base unit per tick).
- ( Q ) is the number of quote lots per quote unit.
This formula converts the integer tick-based price into a human-readable form that is expressed in quote units per base unit (e.g., USDC per ETH).
Example
Let’s go through an example to clarify how the conversion works, using a more realistic price for ETH/USDC.
Assume:
- The current price is 3000 USDC per ETH (quote units per base unit).
- We need to convert this into ticks using the tick size and quote lots per quote unit.
Let’s use the following values:
- Price (P) = 600,000 ticks
- Tick Size (T) = 50 quote lots per base unit per tick
- Quote Lots/Quote Unit (Q) = 10,000 quote lots per quote unit (USDC)
Now, using the formula:
Substitute the values:
Thus, a price of 600,000 ticks corresponds to a human-readable price of 3000 USDC per ETH.
Order Sizes
Each order on the GTE order book is specified by its size, which is measured in base lots. To calculate the total number of base atoms in an order, multiply the size (in base lots) by the base lot size.
For example, if an order size is 100 base lots, and the base lot size is atoms (wei), then the total amount of base atoms is:
Similarly, the quote token amount required to fill an order is calculated using the price in ticks and the tick size.