Documentation
¶
Overview ¶
Package dexvm implements a high-performance decentralized exchange VM for the Lux blockchain network.
The DEX VM provides:
- Central Limit Order Book (CLOB) trading with nanosecond price updates
- Automated Market Maker (AMM) liquidity pools
- Cross-chain atomic swaps via Warp messaging
- 200ms block times for high-frequency trading
- LX-First arbitrage strategy support
Architecture:
- Uses the Lux consensus engine for finality
- Integrates with Warp 1.5 for cross-chain messaging
- Supports both spot and perpetual trading
- Designed for institutional-grade performance
Index ¶
- Variables
- type BlockResult
- type Codec
- type CodecRequest
- type Factory
- type VM
- func (vm *VM) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error
- func (vm *VM) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, ...) error
- func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, ...) error
- func (vm *VM) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
- func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, v *version.Application) error
- func (vm *VM) CreateHandlers(ctx context.Context) (map[string]http.Handler, error)
- func (vm *VM) CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, ...) error
- func (vm *VM) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, ...) error
- func (vm *VM) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error
- func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error
- func (vm *VM) GetBlockHeight() uint64
- func (vm *VM) GetLastBlockTime() time.Time
- func (vm *VM) GetLiquidityManager() *liquidity.Manager
- func (vm *VM) GetOrCreateOrderbook(symbol string) *orderbook.Orderbook
- func (vm *VM) GetOrderbook(symbol string) (*orderbook.Orderbook, error)
- func (vm *VM) GetPerpetualsEngine() *perpetuals.Engine
- func (vm *VM) HealthCheck(ctx context.Context) (interface{}, error)
- func (vm *VM) Initialize(ctx context.Context, consensusCtx interface{}, dbManager interface{}, ...) error
- func (vm *VM) IsBootstrapped() bool
- func (vm *VM) ProcessBlock(ctx context.Context, blockHeight uint64, blockTime time.Time, txs [][]byte) (*BlockResult, error)
- func (vm *VM) SetState(ctx context.Context, stateNum uint32) error
- func (vm *VM) Shutdown(ctx context.Context) error
- func (vm *VM) Version(ctx context.Context) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // VMID is the unique identifier for the DEX VM VMID = [32]byte{'d', 'e', 'x', 'v', 'm'} )
Functions ¶
This section is empty.
Types ¶
type BlockResult ¶
type BlockResult struct {
// BlockHeight is the height of the processed block
BlockHeight uint64
// Timestamp is when this block was processed
Timestamp time.Time
// MatchedTrades from order matching in this block
MatchedTrades []orderbook.Trade
// FundingPayments processed in this block (if any)
FundingPayments []*perpetuals.FundingPayment
// Liquidations executed in this block (if any)
Liquidations []*perpetuals.LiquidationEvent
// StateRoot is the merkle root of state after this block
StateRoot ids.ID
}
BlockResult represents the deterministic result of processing a block. All state changes are captured here for verifiability.
type Codec ¶
type Codec struct{}
Codec implements gorilla/rpc codec interface.
func (*Codec) NewRequest ¶
func (c *Codec) NewRequest(*http.Request) rpc.CodecRequest
type CodecRequest ¶
type CodecRequest struct{}
CodecRequest implements rpc.CodecRequest
func (*CodecRequest) Method ¶
func (r *CodecRequest) Method() (string, error)
func (*CodecRequest) ReadRequest ¶
func (r *CodecRequest) ReadRequest(interface{}) error
func (*CodecRequest) WriteError ¶
func (r *CodecRequest) WriteError(http.ResponseWriter, int, error)
func (*CodecRequest) WriteResponse ¶
func (r *CodecRequest) WriteResponse(http.ResponseWriter, interface{})
type VM ¶
VM implements the DEX Virtual Machine using a pure functional architecture. All state transitions happen deterministically within block processing:
- Central Limit Order Book (CLOB) trading
- Automated Market Maker (AMM) liquidity pools
- Cross-chain atomic swaps via Warp messaging
- 1ms block times for ultra-low latency HFT support
DESIGN: No background goroutines. All operations are block-driven and deterministic. This ensures:
- Every node produces identical state from identical inputs
- No race conditions or non-deterministic behavior
- Easy to test and verify
- Replay-safe for auditing
func NewVMForTest ¶
NewVMForTest creates a new VM instance for testing purposes. This allows external test packages to create VM instances without needing to access internal fields directly.
func (*VM) AppGossip ¶
AppGossip implements consensuscore.VM interface. It handles gossiped messages from peers.
func (*VM) AppRequest ¶
func (vm *VM) AppRequest( ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte, ) error
AppRequest implements consensuscore.VM interface. It handles direct requests from peers.
func (*VM) AppRequestFailed ¶
func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *consensuscore.AppError) error
AppRequestFailed implements consensuscore.VM interface.
func (*VM) AppResponse ¶
func (vm *VM) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
AppResponse implements consensuscore.VM interface.
func (*VM) CreateHandlers ¶
CreateHandlers implements consensuscore.VM interface. It creates HTTP handlers for the DEX API.
func (*VM) CrossChainAppRequest ¶
func (vm *VM) CrossChainAppRequest( ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, request []byte, ) error
CrossChainAppRequest implements consensuscore.VM interface.
func (*VM) CrossChainAppRequestFailed ¶
func (vm *VM) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, appErr *consensuscore.AppError) error
CrossChainAppRequestFailed implements consensuscore.VM interface.
func (*VM) CrossChainAppResponse ¶
func (vm *VM) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error
CrossChainAppResponse implements consensuscore.VM interface.
func (*VM) Disconnected ¶
Disconnected implements consensuscore.VM interface.
func (*VM) GetBlockHeight ¶
GetBlockHeight returns the current block height.
func (*VM) GetLastBlockTime ¶
GetLastBlockTime returns the timestamp of the last processed block.
func (*VM) GetLiquidityManager ¶
GetLiquidityManager returns the liquidity pool manager.
func (*VM) GetOrCreateOrderbook ¶
GetOrCreateOrderbook returns or creates an orderbook for a symbol.
func (*VM) GetOrderbook ¶
GetOrderbook returns the orderbook for a symbol.
func (*VM) GetPerpetualsEngine ¶
func (vm *VM) GetPerpetualsEngine() *perpetuals.Engine
GetPerpetualsEngine returns the perpetual futures engine.
func (*VM) HealthCheck ¶
HealthCheck implements consensuscore.VM interface.
func (*VM) Initialize ¶
func (vm *VM) Initialize( ctx context.Context, consensusCtx interface{}, dbManager interface{}, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, msgChan interface{}, fxs []interface{}, appSender interface{}, ) error
Initialize implements consensuscore.VM interface. It sets up the VM with the provided context, database, and genesis data.
func (*VM) IsBootstrapped ¶
IsBootstrapped returns true if the VM is fully bootstrapped.
func (*VM) ProcessBlock ¶
func (vm *VM) ProcessBlock(ctx context.Context, blockHeight uint64, blockTime time.Time, txs [][]byte) (*BlockResult, error)
ProcessBlock is the core function that processes all DEX operations deterministically. This is called by the consensus engine for each new block. All state changes happen here in a deterministic, reproducible manner.
Operations performed per block:
- Order matching for all orderbooks
- Funding rate processing (every 8 hours)
- Liquidation checks
- State commitment
func (*VM) SetState ¶
SetState implements consensuscore.VM interface. It transitions the VM between bootstrapping and normal operation states. NOTE: No background goroutines are started - all operations are block-driven.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api provides RPC and REST API handlers for the DEX VM.
|
Package api provides RPC and REST API handlers for the DEX VM. |
|
Package block implements block structure for the DEX VM.
|
Package block implements block structure for the DEX VM. |
|
Package config defines configuration types for the DEX VM.
|
Package config defines configuration types for the DEX VM. |
|
Package lending provides a DeFi lending protocol for the DEX VM.
|
Package lending provides a DeFi lending protocol for the DEX VM. |
|
Package liquidity implements AMM liquidity pools for the DEX VM.
|
Package liquidity implements AMM liquidity pools for the DEX VM. |
|
Package network provides peer-to-peer networking and Warp messaging for the DEX VM.
|
Package network provides peer-to-peer networking and Warp messaging for the DEX VM. |
|
Package orderbook implements a high-performance order book for the DEX VM.
|
Package orderbook implements a high-performance order book for the DEX VM. |
|
Package state manages persistent state for the DEX VM.
|
Package state manages persistent state for the DEX VM. |
|
Package txs defines transaction types for the DEX VM.
|
Package txs defines transaction types for the DEX VM. |