dex

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dex provides the DEX L2 subnet adapter for the indexer. Handles orderbook, trades, liquidity pools, and swap operations. The DEX is a standalone L2 subnet (see ~/work/lux/dex), not a native chain.

Index

Constants

View Source
const (
	// DefaultPort for DEX L2 indexer API
	DefaultPort = 4800
	// DefaultDatabase name
	DefaultDatabase = "explorer_dchain"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements the DAG adapter interface for DEX L2

func New

func New(rpcEndpoint string) *Adapter

New creates a new DEX L2 adapter

func (*Adapter) GetRecentVertices

func (a *Adapter) GetRecentVertices(ctx context.Context, limit int) ([]json.RawMessage, error)

GetRecentVertices fetches recent vertices from DEX L2 RPC

func (*Adapter) GetStats

func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string]interface{}, error)

GetStats returns DEX L2 specific statistics using unified storage

func (*Adapter) GetVertexByID

func (a *Adapter) GetVertexByID(ctx context.Context, id string) (json.RawMessage, error)

GetVertexByID fetches a specific vertex by ID

func (*Adapter) InitSchema

func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error

InitSchema creates DEX L2 specific database tables using unified storage

func (*Adapter) ParseVertex

func (a *Adapter) ParseVertex(data json.RawMessage) (*dag.Vertex, error)

ParseVertex parses DEX L2 vertex data

func (*Adapter) StoreLiquidityEvent

func (a *Adapter) StoreLiquidityEvent(ctx context.Context, db *sql.DB, e LiquidityEvent) error

StoreLiquidityEvent stores a liquidity event

func (*Adapter) StoreOrder

func (a *Adapter) StoreOrder(ctx context.Context, db *sql.DB, o Order) error

StoreOrder stores an order

func (*Adapter) StorePool

func (a *Adapter) StorePool(ctx context.Context, db *sql.DB, p LiquidityPool) error

StorePool stores a liquidity pool

func (*Adapter) StoreSwap

func (a *Adapter) StoreSwap(ctx context.Context, db *sql.DB, s Swap) error

StoreSwap stores a swap

func (*Adapter) StoreTrade

func (a *Adapter) StoreTrade(ctx context.Context, db *sql.DB, t Trade) error

StoreTrade stores a trade

func (*Adapter) StoreVertex

func (a *Adapter) StoreVertex(ctx context.Context, db *sql.DB, v *dag.Vertex) error

StoreVertex stores vertex data

func (*Adapter) UpdateExtendedStats

func (a *Adapter) UpdateExtendedStats(ctx context.Context, db *sql.DB) error

UpdateExtendedStats updates DEX L2 specific statistics

type LiquidityEvent

type LiquidityEvent struct {
	ID        string    `json:"id"`
	PoolID    string    `json:"poolId"`
	Provider  string    `json:"provider"`
	Type      string    `json:"type"` // "add" or "remove"
	Amount0   string    `json:"amount0"`
	Amount1   string    `json:"amount1"`
	LPTokens  string    `json:"lpTokens"`
	Timestamp time.Time `json:"timestamp"`
}

LiquidityEvent represents add/remove liquidity

type LiquidityPool

type LiquidityPool struct {
	ID        string    `json:"id"`
	Token0    string    `json:"token0"`
	Token1    string    `json:"token1"`
	Reserve0  string    `json:"reserve0"`
	Reserve1  string    `json:"reserve1"`
	LPSupply  string    `json:"lpSupply"`
	Fee       uint32    `json:"fee"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

LiquidityPool represents an AMM pool

type Order

type Order struct {
	ID          string      `json:"id"`
	Owner       string      `json:"owner"`
	Symbol      string      `json:"symbol"`
	Side        OrderSide   `json:"side"`
	Type        OrderType   `json:"type"`
	Price       uint64      `json:"price"`
	Quantity    uint64      `json:"quantity"`
	FilledQty   uint64      `json:"filledQty"`
	TimeInForce string      `json:"timeInForce"`
	PostOnly    bool        `json:"postOnly"`
	ReduceOnly  bool        `json:"reduceOnly"`
	Status      OrderStatus `json:"status"`
	CreatedAt   time.Time   `json:"createdAt"`
	UpdatedAt   time.Time   `json:"updatedAt"`
}

Order represents a DEX order

type OrderSide

type OrderSide string

OrderSide represents buy or sell

const (
	OrderSideBuy  OrderSide = "buy"
	OrderSideSell OrderSide = "sell"
)

type OrderStatus

type OrderStatus string

OrderStatus represents order lifecycle state

const (
	OrderStatusOpen      OrderStatus = "open"
	OrderStatusFilled    OrderStatus = "filled"
	OrderStatusCancelled OrderStatus = "cancelled"
	OrderStatusPartial   OrderStatus = "partial"
	OrderStatusExpired   OrderStatus = "expired"
)

type OrderType

type OrderType string

OrderType represents the order type

const (
	OrderTypeLimit      OrderType = "limit"
	OrderTypeMarket     OrderType = "market"
	OrderTypeStopLoss   OrderType = "stop_loss"
	OrderTypeTakeProfit OrderType = "take_profit"
	OrderTypeStopLimit  OrderType = "stop_limit"
)

type Swap

type Swap struct {
	ID        string    `json:"id"`
	PoolID    string    `json:"poolId"`
	Sender    string    `json:"sender"`
	TokenIn   string    `json:"tokenIn"`
	TokenOut  string    `json:"tokenOut"`
	AmountIn  string    `json:"amountIn"`
	AmountOut string    `json:"amountOut"`
	Fee       string    `json:"fee"`
	Timestamp time.Time `json:"timestamp"`
}

Swap represents a pool swap

type Trade

type Trade struct {
	ID        string    `json:"id"`
	Symbol    string    `json:"symbol"`
	MakerID   string    `json:"makerId"`
	TakerID   string    `json:"takerId"`
	Maker     string    `json:"maker"`
	Taker     string    `json:"taker"`
	Side      OrderSide `json:"side"`
	Price     uint64    `json:"price"`
	Quantity  uint64    `json:"quantity"`
	Volume    uint64    `json:"volume"`
	Fee       uint64    `json:"fee"`
	Timestamp time.Time `json:"timestamp"`
}

Trade represents a completed trade

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL