A backend system for a Solana DEX routing and order execution engine (MOCK), built with Node.js, Fastify, BullMQ, Redis, and PostgreSQL.
- Market Order Execution: Supports immediate execution with best-price routing.
- Mock DEX Router: Simulates quotes from Raydium and Meteora with price variations and delays.
- Queue System: Uses BullMQ for handling orders with a max concurrency of 10 and rate limiting.
- WebSocket Streaming: Real-time order status updates (pending, routing, building, submitted, confirmed, failed).
- Data Persistence: Stores all orders and execution logs in PostgreSQL.
- Runtime: Node.js + TypeScript
- Server: Fastify + @fastify/websocket
- Queue: BullMQ + Redis
- Database: PostgreSQL + Prisma ORM
- Validation: Zod
- Testing: Jest
-
Prerequisites:
- Node.js (v16+)
- Docker & Docker Compose
-
Installation:
npm install -
Environment Variables: Create a
.envfile:PORT=3000 REDIS_HOST=localhost REDIS_PORT=6379 DATABASE_URL="postgresql://user:password@localhost:5432/dex_routing?schema=public"
-
Start Infrastructure:
docker-compose up -d -
Run Migrations:
npx prisma migrate dev --name init -
Start Server:
npm run dev
Endpoint: POST http://localhost:3000/api/orders/execute
Body:
{
"inputToken": "SOL",
"outputToken": "USDC",
"amount": 10
}Response:
{
"success": true,
"orderId": "uiqueorderId-string",
"message": "Order queued. Connect to WebSocket for updates."
}URL: ws://localhost:3000/ws/orders/<orderId>
Messages:
{ "status": "routing" }
{ "status": "building" }
{ "status": "submitted" }
{ "status": "confirmed", "txHash": "...", "price": 102.5, "dex": "Raydium" }- API Layer: Receives requests, validates input, creates DB record, and pushes to Queue.
- Queue Layer: BullMQ handles async processing, retries, and concurrency control.
- Worker Layer: Processes orders, calls the Router, and updates DB/WebSocket.
- Router Layer: Simulates DEX interactions.
- WebSocket Layer: Streams updates to the client.