LFG Perp Architecture
LFG Perp is built on a modern, scalable architecture that combines the security of blockchain with the performance needed for high-frequency trading.System Overview
The @oraichain/lfg-client-js SDK is a TypeScript client library that
developers use to interact with the Indexer API and Validator RPC. It’s not
part of the core architecture, but rather a convenient tool for building
applications.
Core Components
1. LFG DEX Side Chain
LFG DEX runs as an independent side chain connected to Oraichain mainnet via IBC (Inter-Blockchain Communication):Independent Chain
Dedicated Infrastructure
- Own validator set
- Optimized for trading
- High throughput for orders
- Custom trading modules
IBC Connected
Oraichain Integration
- Asset transfers via IBC
- Oracle price feeds from mainnet
- Shared security guarantees
- Cross-chain interoperability
Specialized Design
Trading Optimized
- Fast block times (~1s)
- Efficient order matching
- Low latency execution
- High transaction throughput
Cosmos SDK
Built on Cosmos
- Tendermint consensus
- Modular architecture
- Proven technology
- Easy upgrades
2. Oraichain Mainnet
The main Oraichain blockchain that LFG DEX connects to:IBC Hub
Cross-Chain Bridge
- IBC protocol support
- Asset transfers to LFG DEX
- Multi-chain connectivity
- Secure bridging
Oracle Services
Price Feeds
- Decentralized oracles
- Multiple data sources
- Price aggregation
- Real-time updates
Security
Shared Security
- Validator network
- Staking mechanism
- Slashing conditions
- Network protection
Governance
Chain Governance
- Proposal system
- Community voting
- Parameter updates
- Upgrade coordination
3. LFG Trading Modules
The core trading functionality implemented as Cosmos SDK modules on the LFG side chain:- Perpetuals Module
- Clob Module
- Bridge Module
- Oracle Module
Manages perpetual futures contracts and positions.Responsibilities:
- Order matching
- Position management
- Liquidation logic
- Funding rate calculations
- Collateral management
- Multiple markets
- Cross-margin support
- Risk parameters per market
- Emergency shutdown capability
4. Indexer Service
High-performance read-only API for market data (off-chain service):Architecture
Architecture
Components:
- PostgreSQL database for historical data
- Redis for caching hot data
- WebSocket server for real-time streams
- REST API for queries
- Listens to blockchain events
- Processes and indexes data
- Stores in optimized format
- Serves via API endpoints
Performance
Performance
Optimizations:
- Indexed database queries
- Aggressive caching strategy
- Denormalized data for reads
- Connection pooling
- Load balancing
- < 10ms query latency
- 1000+ req/s throughput
- 99.9% uptime
- Real-time updates
Data Provided
Data Provided
Market Data:
- Orderbook snapshots
- Trade history
- Price candles
- Market statistics
- Funding rates
- Balances
- Positions
- Order history
- Fill history
- PnL calculations
5. Client SDK (@oraichain/lfg-client-js)
A TypeScript library that simplifies interaction with LFG DEX:- Type-safe API wrappers
- Connection management
- Transaction signing helpers
- Error handling utilities
- Convenient abstractions
The SDK is not part of the core LFG DEX infrastructure. It’s a developer tool
that makes it easier to build applications that interact with the chain.
Data Flow
Order Placement Flow
“App” can be a web interface, trading bot, or any application using the SDK or
direct API calls.
Market Data Flow
Security Architecture
Multi-Layer Security
Wallet Security
User Responsibility:
- Private key management
- Transaction signing
- API key security
- Device security
Protocol Security
On-Chain Protection:
- Margin requirements
- Liquidation engine
- Position limits
- Circuit breakers
Oracle Security
Price Feed Protection:
- Multiple data sources
- Outlier detection
- Staleness checks
- Emergency pause
Infrastructure Security
Operational Security:
- DDoS protection
- Rate limiting
- API authentication
- Encrypted connections
Liquidation System
The liquidation system ensures exchange solvency:- Monitoring
- Execution
- Protection
Continuous Checks:
- Every block processes margin checks
- Calculates maintenance margin
- Identifies undercollateralized positions
- Flags accounts for liquidation
Scalability
Current Capacity
Throughput
1000+ TPSTransactions per second supported by Oraichain
Latency
< 1s FinalitySub-second block time for fast confirmations
Orders
100k+ OrdersConcurrent open orders supported
Future Scaling
Layer 2 Integration
Layer 2 Integration
Potential rollup integration for even higher throughput while maintaining security.
Optimistic Execution
Optimistic Execution
Parallel transaction processing for increased throughput.
Technology Stack
LFG DEX Side Chain
Oraichain Mainnet
Indexer
SDK
Network Topology
- Validators
- RPC Nodes
- Indexer Nodes
Validator Network:
- Geographic distribution
- Redundant infrastructure
- Load balancing
- Failover capability
- Block production
- Transaction validation
- State consensus
- Network security
Monitoring & Observability
Blockchain Metrics
- Block time
- Transaction throughput
- Validator health
- Network latency
Application Metrics
- API response times
- Order placement rate
- Liquidation events
- Funding rate history
System Health
- CPU and memory usage
- Database performance
- Cache hit rates
- Connection pools
User Activity
- Active traders
- Order volume
- Position sizes
- Unique addresses
Next Steps
Start Building
Begin developing on LFG Perp
SDK Reference
Explore the SDK documentation
Trading Guides
Learn how to trade
Security
Security best practices