Overview
TomoX is Viction’s decentralized exchange protocol that enables permissionless and trustless token trading directly on the blockchain. It provides a secure, efficient orderbook-based trading system integrated at the protocol level.Key Features
On-Chain Order Matching
TomoX processes all orders on-chain through the trading state database, ensuring transparency and security:- Order Processing: Orders are matched and executed in blocks
- State Management: Trading state is maintained in a dedicated state trie
- Transaction Finality: All trades benefit from Viction’s 2-second block time
Relayer Network
Relayers operate decentralized exchanges by:- Maintaining order books for trading pairs
- Collecting trade fees (0-10% configurable)
- Providing user interfaces and APIs
- Depositing collateral to ensure honest operation
Architecture
Trading State Database
The TomoX protocol maintains a separate state database for trading operations:tomox/tomox.go:52
Order Structure
Orders contain all necessary information for matching:tomox/order_processor.go
Order Processing Flow
1. Order Submission
Users submit signed order transactions to the network:- Orders are signed with the user’s private key
- Each order has a unique nonce to prevent replay attacks
- Orders enter the pending transaction pool
2. Order Matching
The protocol matches orders during block processing:tomox/tomox.go:157
3. Trade Execution
When orders match:- Tokens are transferred between buyer and seller
- Trade fees are collected by the relayer
- Order status is updated (Filled, PartialFilled, or Rejected)
- Trade records are stored on-chain
Order Types
Limit Orders
Execute at a specific price or better:- Remain in the order book until filled or cancelled
- Can be partially filled
- Status: Open → PartialFilled → Filled
Market Orders
Execute immediately at the best available price:- Filled against existing limit orders
- May result in multiple trades at different prices
- Status: Filled or Rejected if no liquidity
Price Discovery
TomoX maintains price information for trading pairs:tomox/tomox.go:267
Prices are tracked per epoch and used for:
- Collateral valuation in TomoX Lending
- Fee calculations
- Token conversions
Relayer Registration
To operate a relayer, you must register through the smart contract:Registration Contract
contracts/tomox/contract/Registration.sol:9
Requirements
- Minimum Deposit: Collateral in VIC tokens
- Trade Fee: 0-10% (0-1000 basis points)
- Token Pairs: Must include TOMO pairs for price discovery
- Maximum Pairs: Configurable limit per relayer
Managing a Relayer
Relayer owners can:- Update: Change trading pairs and fees
- Deposit More: Increase collateral
- Transfer: Change ownership
- Resign: Request to close (4-week waiting period)
- Refund: Withdraw collateral after resignation period
SDK Node Integration
SDK nodes provide enhanced functionality for relayers:tomox/tomox.go:317
SDK nodes use MongoDB to provide:
- Real-time order book data
- Trade history
- Order status tracking
- API endpoints for frontend applications
API Access
The TomoX RPC API provides protocol information:tomox/api.go:23
Order Book Structure
Order books are identified by trading pair hashes:- Base Token: The token being traded (e.g., BTC)
- Quote Token: The token used for pricing (e.g., VIC)
- Order Book Hash:
Keccak256(baseToken + quoteToken)
- Buy orders (bids) sorted by price descending
- Sell orders (asks) sorted by price ascending
- Price-time priority matching
Token Listing
Before trading, tokens must be listed:contracts/tomox/contract/TOMOXListing.sol:27
Listing Fee: 1000 VIC (transferred to foundation)
Performance
- Block Time: 2 seconds
- Maximum Orders per Block: 1000
- Order Matching: O(n log n) for price-time priority
- State Updates: Optimized with caching (1024 entry LRU cache)
How does TomoX differ from traditional DEXs?
How does TomoX differ from traditional DEXs?
TomoX is integrated at the protocol level, not as a smart contract. This provides:
- Lower gas costs (orders don’t execute EVM bytecode)
- Faster execution (native code in the consensus layer)
- Better security (no smart contract vulnerabilities)
- Direct state access without contract overhead
What happens if a relayer goes offline?
What happens if a relayer goes offline?
Orders and trades are stored in the blockchain state, not on the relayer. If a relayer goes offline:
- Your orders remain in the protocol state
- You can cancel orders directly through another interface
- Your funds are never held by the relayer
- You can access your trading history through any SDK node
How are trade disputes resolved?
How are trade disputes resolved?
All trades are executed on-chain with cryptographic signatures:
- Every order is signed by the user’s private key
- All matching logic is deterministic and verifiable
- Trade execution is part of consensus
- No disputes are possible as everything is cryptographically provable
Can I run my own relayer?
Can I run my own relayer?
Yes, anyone can run a relayer by:
- Meeting the minimum deposit requirement
- Registering through the RelayerRegistration contract
- Running relayer software (frontend + SDK node)
- Configuring trading pairs and fees
See Also
- TomoX Lending - Lending protocol built on TomoX
- TRC21 Tokens - Gasless token standard
- Smart Contracts - EVM compatibility