企业级 Solana DLMM 流动性自动化管理平台
DLMM流动性管理系统是一个基于 Solana 区块链的企业级动态流动性做市商(Dynamic Liquidity Market Maker)自动化管理平台。系统采用现代化的微服务架构设计,提供完整的流动性策略管理、风险控制、收益分析和实时监控功能。
┌─────────────────────────────────────────────────────────────┐
│ Web 前端界面 (7001) │
│ ┌─────────────┬─────────────┬─────────────┬─────────────┐ │
│ │ 钱包管理 │ 策略管理 │ 交易中心 │ 监控中心 │ │
│ └─────────────┴─────────────┴─────────────┴─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│ WebSocket (7002/7003)
┌─────────────────────┴───────────────────────────────────────┐
│ 后端 API 服务 (7000) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ API 网关层 │ │
│ │ 路由管理 │ 认证授权 │ 限流熔断 │ 日志记录 │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 业务服务层 │ │
│ │ ┌─────────────┬─────────────┬─────────────┬──────────┐ │ │
│ │ │ 策略管理器 │ 头寸管理器 │ 钱包服务 │ 分析服务 │ │ │
│ │ └─────────────┴─────────────┴─────────────┴──────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 协议适配层 │ │
│ │ ┌─────────────┬─────────────┬─────────────┬──────────┐ │ │
│ │ │ Meteora │ Jupiter │ 多RPC │ 池爬虫 │ │ │
│ │ │ 适配器 │ 适配器 │ 管理器 │ 服务 │ │ │
│ │ └─────────────┴─────────────┴─────────────┴──────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 基础设施层 │ │
│ │ 事件总线 │ 日志服务 │ 缓存服务 │ 配置管理 │ 状态管理 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
┌─── 表示层 (Presentation Layer)
│ ├── Web 前端界面 (React-like Components)
│ ├── RESTful API 接口
│ └── WebSocket 实时通信
│
├─── 业务逻辑层 (Business Layer)
│ ├── 策略管理器 (StrategyManager)
│ ├── 头寸管理器 (PositionManager)
│ ├── 钱包管理器 (WalletService)
│ ├── 分析服务 (AnalyticsService)
│ └── 风险控制器 (RiskController)
│
├─── 服务层 (Service Layer)
│ ├── 区块链服务 (BlockchainService)
│ ├── 外部集成服务 (ExternalService)
│ └── 内部服务 (InternalService)
│
├─── 数据访问层 (Data Access Layer)
│ ├── 缓存管理 (CacheService)
│ ├── 状态存储 (StateService)
│ └── 配置管理 (ConfigService)
│
└─── 基础设施层 (Infrastructure Layer)
├── 事件总线 (EventBus)
├── 日志系统 (LoggerService)
├── 监控系统 (MonitorService)
└── 依赖注入 (DIContainer)
| 组件 | 版本要求 | 说明 |
|---|---|---|
| Node.js | >= 18.0.0 | JavaScript 运行时 |
| NPM | >= 9.0.0 | 包管理器 |
| 内存 | >= 4GB | 推荐 8GB |
| 存储 | >= 20GB | SSD 推荐 |
| 网络 | 稳定的互联网连接 | 需要访问 Solana RPC |
# 1. 克隆项目
git clone <repository-url>
cd dlmm-liquidity-manager
# 2. 安装依赖
npm install
# 3. 配置环境变量
cp env.example .env
# 编辑 .env 文件,配置必要参数
# 4. 一键启动系统
./scripts/quick-start.sh
# 5. 验证部署
curl http://localhost:7000/api/health
curl http://localhost:7001/health
# .env 配置文件
NODE_ENV=production # 运行环境
SERVER_PORT=7000 # API 服务器端口
WS_PORT=7002 # WebSocket 端口
MONITOR_PORT=7003 # 监控端口
# Solana 区块链配置
SOLANA_NETWORK=mainnet-beta # Solana 网络
SOLANA_PRIVATE_KEY=your-private-key # 钱包私钥 (Base58)
RPC_PRIMARY=https://api.mainnet-beta.solana.com
RPC_BACKUP=https://solana-api.projectserum.com
# Jupiter 交易配置
JUPITER_API_URL=https://quote-api.jup.ag/v6
JUPITER_SLIPPAGE_BPS=50 # 默认滑点 0.5%
# 安全配置
WALLET_ENCRYPTION_KEY=your-encryption-key # 钱包加密密钥
# 日志配置
LOG_LEVEL=info # 日志级别
LOG_MAX_FILE_SIZE=2097152 # 单个日志文件最大大小 (2MB)
LOG_MAX_FILES=5 # 最大日志文件数量
// config/default.json
{
"strategy": {
"defaultTimeout": 1800000, // 策略执行超时 (30分钟)
"monitorInterval": 30000, // 监控间隔 (30秒)
"maxActiveStrategies": 10, // 最大并发策略数
"defaultParams": {
"slippageBps": 100, // 默认滑点 1%
"binRange": 69, // 默认 Bin 范围
"outOfRangeTimeoutMinutes": 30, // 超出范围超时
"stopLossBinOffset": 5 // 止损 Bin 偏移
}
},
"solana": {
"priorityFee": 200000, // 优先级费用
"commitment": "confirmed", // 确认级别
"timeout": 30000, // RPC 超时
"retries": {
"maxRetries": 3, // 最大重试次数
"retryDelayMs": 2000, // 重试延迟
"backoffFactor": 2 // 退避因子
}
}
}
# 创建钱包
POST /api/wallet/create
{
"password": "your-secure-password"
}
# 解锁钱包
POST /api/wallet/unlock
{
"password": "your-secure-password"
}
# 获取余额
GET /api/wallet/balance
GET /api/wallet/balance/:tokenMint
# 锁定钱包
POST /api/wallet/lock
适用场景: 稳定币对、主流代币
连锁头寸策略 (Chain Position Strategy)
{
"type": "simple_y",
"params": {
"poolAddress": "pool_address_here",
"yAmount": 1000000, // Y 代币数量 (最小单位)
"binRange": 69, // Bin 范围
"slippageBps": 100, // 滑点容忍度 (1%)
"autoRebalance": true, // 自动重平衡
"stopLoss": {
"enabled": true,
"binOffset": 5, // 止损触发偏移
"percentage": 10 // 止损百分比
},
"monitoring": {
"interval": 30000, // 监控间隔 (30秒)
"outOfRangeTimeout": 1800000 // 超出范围超时 (30分钟)
}
}
}
# 创建策略
POST /api/strategy/create
{
"type": "simple_y",
"name": "USDC-SOL流动性策略",
"params": { ... }
}
# 启动策略
POST /api/strategy/:instanceId/start
# 暂停策略
POST /api/strategy/:instanceId/pause
# 恢复策略
POST /api/strategy/:instanceId/resume
# 停止策略
POST /api/strategy/:instanceId/stop
# 获取策略状态
GET /api/strategy/:instanceId
# 获取所有策略
GET /api/strategy/list
# 创建 Y 头寸
POST /api/position/y/create
{
"poolAddress": "pool_address",
"amount": "1000000",
"binRange": 69,
"slippageBps": 100
}
# 创建 X 头寸
POST /api/position/x/create
{
"poolAddress": "pool_address",
"amount": "1000000",
"binRange": 69,
"slippageBps": 100
}
# 关闭头寸
DELETE /api/position/:positionAddress
# 收取手续费
POST /api/position/:positionAddress/harvest
# 获取头寸信息
GET /api/position/:positionAddress
# 获取用户所有头寸
GET /api/position/user/:userAddress
# 获取报价
POST /api/jupiter/quote
{
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"amount": "1000000",
"slippageBps": 50
}
# 执行交易
POST /api/jupiter/swap
{
"route": { ... },
"userPublicKey": "user_public_key"
}
# 获取交易历史
GET /api/jupiter/history/:userAddress
{
"filters": {
"meteorScore": {
"min": 70,
"max": 100
},
"tvl": {
"min": 10000,
"max": 10000000
},
"age": {
"minHours": 24,
"maxHours": 720
},
"apr": {
"min24h": 5,
"max24h": 1000
},
"volume": {
"min24h": 10000,
"max24h": 100000000
},
"fdv": {
"min": 1000000,
"max": 1000000000
}
}
}
# 获取策略收益报告
GET /api/analytics/strategy/:instanceId/pnl
# 获取头寸分析
GET /api/analytics/position/:positionAddress
# 获取市场数据
GET /api/analytics/market/:poolAddress
# 导出报表
GET /api/analytics/export/:type
访问 http://localhost:7001 进入系统主界面
交易历史记录
策略管理页面
策略配置管理
头寸管理页面
收益统计分析
交易中心页面
市场数据查看
池爬虫页面
实时监控面板
分析中心页面
准备钱包
钱包管理 → 创建钱包 → 输入密码 → 保存助记词
选择池子
池爬虫 → 设置筛选条件 → 选择合适池子 → 复制池地址
创建策略
策略管理 → 创建策略 → 选择类型 → 配置参数 → 启动策略
监控运行
策略监控 → 查看实时状态 → 分析收益表现 → 调整参数
# docker-compose.yml
version: '3.8'
services:
dlmm-manager:
build: .
ports:
- "7000:7000" # API 服务
- "7001:7001" # Web 界面
- "7002:7002" # WebSocket
- "7003:7003" # 监控
environment:
- NODE_ENV=production
- SERVER_PORT=7000
- WS_PORT=7002
- MONITOR_PORT=7003
volumes:
- ./data:/app/data
- ./logs:/app/logs
- ./config:/app/config
env_file:
- .env
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7000/api/health"]
interval: 30s
timeout: 10s
retries: 3
# 构建和启动
docker-compose up -d
# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down
# 更新服务
docker-compose pull && docker-compose up -d
# 1. 安装 Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# 2. 克隆项目
git clone <repository-url>
cd dlmm-liquidity-manager
# 3. 安装依赖
npm install --production
# 4. 配置环境
cp env.example .env
# 编辑配置文件
# 5. 构建项目
npm run build
# 6. 使用 PM2 管理进程
npm install -g pm2
pm2 start ecosystem.config.js
pm2 save
pm2 startup
// ecosystem.config.js
module.exports = {
apps: [{
name: 'dlmm-api',
script: 'dist/app.js',
instances: 2,
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 7000
},
error_file: './logs/api-error.log',
out_file: './logs/api-out.log',
log_file: './logs/api.log',
time: true
}, {
name: 'dlmm-web',
script: 'web/server.js',
instances: 1,
env: {
NODE_ENV: 'production',
PORT: 7001
}
}]
}
# API 服务健康检查
curl http://localhost:7000/api/health
# Web 服务健康检查
curl http://localhost:7001/health
# 系统状态检查
curl http://localhost:7000/api/system/status
# 查看实时日志
tail -f logs/operation.log
tail -f logs/strategy.log
tail -f logs/monitor.log
# 日志轮转
./scripts/rotate-logs.sh
# 清理旧日志
./scripts/clean-logs.sh
dlmm-liquidity-manager/
├── src/ # 源代码目录
│ ├── app.ts # 应用程序入口
│ ├── di/ # 依赖注入
│ │ └── container.ts # DI 容器配置
│ ├── server/ # API 服务器
│ │ ├── api-server.ts # Express 服务器
│ │ ├── routes/ # API 路由
│ │ └── middleware/ # 中间件
│ ├── services/ # 服务层
│ │ ├── blockchain/ # 区块链服务
│ │ ├── business/ # 业务服务
│ │ ├── external/ # 外部服务
│ │ ├── internal/ # 内部服务
│ │ └── strategy/ # 策略服务
│ ├── infrastructure/ # 基础设施
│ │ ├── EventBus.ts # 事件总线
│ │ ├── logging/ # 日志系统
│ │ └── StateService.ts # 状态管理
│ ├── types/ # 类型定义
│ └── utils/ # 工具函数
├── web/ # Web 前端
│ ├── public/ # 静态资源
│ │ ├── js/ # JavaScript 文件
│ │ │ ├── components/ # 组件
│ │ │ ├── services/ # 前端服务
│ │ │ └── utils/ # 工具函数
│ │ └── css/ # 样式文件
│ └── server.js # Web 服务器
├── config/ # 配置文件
├── scripts/ # 脚本文件
├── test/ # 测试文件
├── logs/ # 日志目录
└── data/ # 数据目录
// src/services/business/NewService.ts
import { injectable, inject } from 'tsyringe';
import { TYPES, ILoggerService } from '../../types/interfaces';
@injectable()
export class NewService {
constructor(
@inject(TYPES.LoggerService) private logger: ILoggerService
) {}
async initialize(): Promise<void> {
await this.logger.logSystem('INFO', '新服务初始化');
}
async doSomething(): Promise<void> {
// 实现业务逻辑
}
}
// src/di/container.ts
import { NewService } from '../services/business/NewService';
// 在 registerServiceLayer 方法中添加
container.registerSingleton('NewService', NewService);
```typescript // src/server/routes/new-routes.ts import { Router } from 'express'; import { NewService } from '../../services/business/NewService';
export function createNewRoutes(
$ claude mcp add meteora2 \
-- python -m otcore.mcp_server <graph>