Skip to main content

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:
Manages perpetual futures contracts and positions.Responsibilities:
  • Order matching
  • Position management
  • Liquidation logic
  • Funding rate calculations
  • Collateral management
Features:
  • 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):
Components:
  • PostgreSQL database for historical data
  • Redis for caching hot data
  • WebSocket server for real-time streams
  • REST API for queries
Data Flow:
  1. Listens to blockchain events
  2. Processes and indexes data
  3. Stores in optimized format
  4. Serves via API endpoints
Optimizations:
  • Indexed database queries
  • Aggressive caching strategy
  • Denormalized data for reads
  • Connection pooling
  • Load balancing
Metrics:
  • < 10ms query latency
  • 1000+ req/s throughput
  • 99.9% uptime
  • Real-time updates
Market Data:
  • Orderbook snapshots
  • Trade history
  • Price candles
  • Market statistics
  • Funding rates
Account Data:
  • Balances
  • Positions
  • Order history
  • Fill history
  • PnL calculations

5. Client SDK (@oraichain/lfg-client-js)

A TypeScript library that simplifies interaction with LFG DEX:
// SDK wraps the API calls
const client = await CompositeClient.connect(network);

// Read from Indexer API
const markets = await client.indexerClient.markets.getPerpetualMarkets();

// Write to Validator RPC
const tx = await client.placeShortTermOrder(/* ... */);
What the SDK Provides:
  • 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:
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

Potential rollup integration for even higher throughput while maintaining security.
Market-specific sharding to distribute load across validator set.
Parallel transaction processing for increased throughput.

Technology Stack

LFG DEX Side Chain

ComponentTechnologyPurpose
ConsensusTendermint BFTByzantine fault tolerance
FrameworkCosmos SDKModular blockchain development
LanguageGoChain implementation
IBCIBC ProtocolCross-chain communication

Oraichain Mainnet

ComponentTechnologyPurpose
ConsensusTendermint BFTNetwork consensus
FrameworkCosmos SDKBlockchain framework
IBCIBC ProtocolInter-chain bridging
OraclesCustom ModulesPrice feed infrastructure

Indexer

ComponentTechnologyPurpose
DatabasePostgreSQLHistorical data storage
CacheRedisHot data caching
APINode.js/TypeScriptREST and WebSocket server
QueueBullBackground job processing

SDK

ComponentTechnologyPurpose
LanguageTypeScriptType-safe development
HTTPAxiosAPI requests
WebSocketwsReal-time streams
Crypto@cosmjsTransaction signing

Network Topology

Validator Network:
  • Geographic distribution
  • Redundant infrastructure
  • Load balancing
  • Failover capability
Responsibilities:
  • 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