Core Concepts
Factory Contract
The Factory contract serves as the main entry point for creating new trading pairs. Its main responsibilities include:
- Creating new Exchange contract instances for token pairs
- Maintaining a registry of all created trading pairs
- Managing service fees and fee receivers
- Ensuring unique trading pairs (preventing duplicate pairs)
Exchange/Market Contract
The Exchange contract is the heart of the trading system. Each trading pair has its own Exchange contract instance. Key features include:
1. Order Management
- Handles both buy and sell orders
- Maintains order books for both sides of the market
- Processes order matching and execution
- Manages partial fills and order cancellations
2. Asset Management
- Handles token deposits and withdrawals
- Tracks user balances
- Manages fee collection and distribution
3. Price Discovery
- Maintains price levels and volumes
- Provides order book depth information
- Supports price queries and best execution
Supporting Libraries
LinkedListLib
This library implements a linked list data structure used for managing orders at each price level. Features:
- Efficient order insertion and deletion
- Order tracking by unique IDs
- Sequential order processing for matching
PVNodeLib
Manages price-volume nodes that track the total volume at each price level. Used for:
- Market depth calculations
- Volume tracking at each price point
- Quick access to price level information

