Files
zeekayandHanzo Dev 10a084c0b2 refactor(dex): fold pkg/lx into pkg/dex — one matcher, one package
The matching engine (pkg/lx, 45.5K LOC incl. tests) and the deterministic
core layered on it (pkg/dex) are one matcher spread across two packages
(dex imported lx in 12 files; lx imported neither). Fold lx into dex and
drop the "lx" name entirely — pkg/dex is now the single matcher package.

Pure rename/fold, ZERO logic change. Behavior proven identical: the merged
pkg/dex runs 457 top-level tests (431 former-lx + 26 former-dex) and 489
test funcs (468 + 21), all green — matching, batch (BatchMatchEqualsSequential,
run-to-run determinism, tile boundary), GPU/CPU parity, truncation, and CL
swap math all pass unchanged.

What moved:
- git mv all 101 pkg/lx/*.go + 1 .c into pkg/dex/ (package lx -> package dex).
- lx's swap_test.go -> swap_math_test.go (only filename collision with dex's
  existing swap_test.go).
- Rewrote imports repo-wide: 54 pkg/lx import lines removed; 42 external
  importers (api, client, consensus, dchain, dpdk, lxgpu, marketdata, test/,
  tests/) repointed to pkg/dex with lx.X -> dex.X; the 12 in-package dex files
  had lx.X -> bare X. 717 selector lines rewritten. Stale pkg/lx comment refs
  updated (pkg/lxgpu left intact).

Collisions resolved (2, both package-level vars):
- ErrNoLiquidity: lx's pool-level error (dexError, used only in swap.go, never
  referenced via qualifier) renamed ErrPoolNoLiquidity to match the existing
  ErrPool* convention; dex's router-level ErrNoLiquidity (public, has errors.Is
  tests) kept.
- priceMultiplierBig: identical after fold (both big.NewInt(PriceMultiplier));
  deduped by deleting dex's copy.

Not folded — pkg/orderbook: it is NOT the GPU seam (that is orderbook_gpu.go,
which lives in the engine and folded in here). pkg/orderbook is a zero-importer,
placeholder-cgo island whose 13 core domain identifiers (Order, OrderBook, Trade,
OrderType, OrderStatus, PriceLevel, Buy, Sell, Market, Limit, Filled,
PartiallyFilled, NewOrderBook) collide incompatibly with the engine's. Folding
it verbatim breaks the build; folding via rename reintroduces the exact parallel
duplication this fold removes. Left for owner decision (recommend deletion as
dead code) — see refactor notes.

Follow-on (separate repos, not touched): 19 files under luxfi/dex import
pkg/lx externally — lux/precompile/dex, lux/precompile-dex/dex,
lux/consensus/examples/01-simple-bridge, lux/_consensus-v12537/examples,
lux/cex/pkg/engine — repoint to pkg/dex after this lands.

Verified: CGO_ENABLED=0 GOWORK=off go build ./... clean; go vet ./... clean;
go test ./... -count=1 all green (22 ok / 0 fail).

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-02 00:57:08 -07:00

114 lines
3.0 KiB
Makefile

# dexd Makefile — the ONE D-Chain DEX binary.
#
# dexd runs the DEX two ways (one binary, two modes):
# dexd run as a luxd rpcchainvm plugin (luxd execs it, no args)
# dexd run run the standalone D-Chain venue (ZAP + consensus sealer)
#
# Default build is CPU (CGO_ENABLED=0) — no GPU/MLX required. The GPU matcher
# (CGO_ENABLED=1, pkg/lx via the unified lux-gpu pkg-config bundle — one
# runtime-select backend: CUDA > HIP > Metal > CPU) is built only by
# Dockerfile.dvenue.
SHELL := /bin/bash
.PHONY: all build run test test-race bench vet fmt lint deps clean coverage \
docker proto sdk-typescript sdk-python sdk-go sdk-all ci help
# Version / build info
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Go
GO := go
CGO_ENABLED ?= 0
BINARY := dexd
BINARY_DIR := bin
IMAGE := ghcr.io/luxfi/dex
TEST_TIMEOUT := 60s
export CGO_ENABLED
all: fmt vet test build
help:
@echo "dexd Makefile:"
@echo " make build - Build dexd (CPU, CGO_ENABLED=0) -> $(BINARY_DIR)/$(BINARY)"
@echo " make run - Build and run the standalone venue (dexd run)"
@echo " make test - Run package tests"
@echo " make vet - go vet ./..."
@echo " make fmt - gofmt -s -w ."
@echo " make lint - golangci-lint run"
@echo " make docker - Build the canonical image ($(IMAGE)) from ./Dockerfile"
@echo " make clean - Remove build artifacts"
# Build the one binary (CPU).
build:
@echo "Building $(BINARY) (CGO_ENABLED=$(CGO_ENABLED))..."
@mkdir -p $(BINARY_DIR)
@$(GO) build -trimpath -ldflags "-s -w -X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT)" \
-o $(BINARY_DIR)/$(BINARY) ./cmd/dexd
@echo "Built $(BINARY_DIR)/$(BINARY)"
# Run the standalone venue.
run: build
@$(BINARY_DIR)/$(BINARY) run
# Tests
test:
@$(GO) test -timeout $(TEST_TIMEOUT) ./pkg/...
test-race:
@$(GO) test -race -timeout 2m ./pkg/...
bench:
@$(GO) test -bench=. -benchmem -benchtime=10s -run=^$$ ./pkg/lx/...
# Quality
vet:
@$(GO) vet ./...
fmt:
@gofmt -s -w .
lint:
@golangci-lint run --timeout 5m 2>/dev/null || echo "Install golangci-lint for linting"
coverage:
@$(GO) test -coverprofile=coverage.out -covermode=atomic ./pkg/...
@$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Modules
deps:
@$(GO) mod download
@$(GO) mod tidy
clean:
@$(GO) clean
@rm -rf $(BINARY_DIR) coverage.out coverage.html
# Canonical image (CPU dexd).
docker:
@docker build -f Dockerfile -t $(IMAGE):$(VERSION) .
# Protobuf
proto:
@protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/*.proto
# SDKs
sdk-typescript:
@cd sdk/typescript && npm install && npm run build
sdk-python:
@cd sdk/python && pip install -e .
sdk-go:
@cd sdk/go && go mod tidy && go build ./...
sdk-all: sdk-typescript sdk-python sdk-go
# CI pipeline
ci: fmt vet test build
@echo "CI complete"