企业级 Solana DLMM 流动性自动化管理平台
DLMM流动性管理系统是一个基于 Solana 区块链的企业级动态流动性做市商(Dynamic Liquidity Market Maker)自动化管理平台。系统采用现代化的微服务架构设计,提供完整的流动性策略管理、风险控制、收益分析和实时监控功能。
- 🏗️ 企业级架构: 基于 TypeScript + 依赖注入的模块化设计,支持高并发和故障容错
- 🤖 智能策略引擎: 内置多种流动性策略,支持自定义策略开发和热更新
- ⚡ 实时监控系统: WebSocket 驱动的实时数据监控和告警系统
- 🔒 企业级安全: 钱包加密存储、权限管理、审计日志
- 📊 数据分析平台: 完整的收益分析、风险评估和报表系统
- 🌐 现代化 Web 界面: 响应式仪表盘,直观的操作体验
- 🔄 自动化运维: 容器化部署、健康检查、故障自愈
┌─────────────────────────────────────────────────────────────┐ │ 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 // 退避因子 } } }- 安全存储: AES-256-GCM 加密存储私钥
- 多签支持: 支持多重签名钱包
- 余额管理: 实时查询 SOL 和 SPL Token 余额
- 交易签名: 安全的交易签名机制
# 创建钱包 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-
简单 Y 头寸策略 (Simple Y Strategy)
- 用途: 单侧流动性提供
- 特点: 专注单一代币流动性,风险相对较低
- 适用场景: 稳定币对、主流代币
-
连锁头寸策略 (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 头寸: 单一代币流动性头寸
- X 头寸: 对称流动性头寸
- 双向头寸: 同时持有 X 和 Y 头寸
# 创建 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- 智能路由: 自动寻找最优交易路径
- 滑点保护: 自适应滑点管理
- MEV 保护: 反 MEV 交易策略
- 批量交易: 支持批量交易执行
# 获取报价 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- 自动发现: 实时发现新的 DLMM 流动性池
- 智能筛选: 基于多维度指标筛选优质池子
- 风险评估: 自动评估池子风险等级
- 实时监控: 监控池子状态变化
{ "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 } } }- 收益分析: PnL 计算、APR/APY 分析
- 风险分析: VaR、最大回撤、夏普比率
- 策略对比: 不同策略效果对比
- 市场分析: 市场趋势、相关性分析
# 获取策略收益报告 GET /api/analytics/strategy/:instanceId/pnl # 获取头寸分析 GET /api/analytics/position/:positionAddress # 获取市场数据 GET /api/analytics/market/:poolAddress # 导出报表 GET /api/analytics/export/:type访问 http://localhost:7001 进入系统主界面
-
钱包管理页面
- 钱包创建和导入
- 余额查询和管理
- 交易历史记录
-
策略管理页面
- 策略创建向导
- 实时策略监控
- 策略配置管理
-
头寸管理页面
- 头寸创建和关闭
- 头寸实时监控
- 收益统计分析
-
交易中心页面
- Jupiter 代币交换
- 交易历史记录
- 市场数据查看
-
池爬虫页面
- 池子发现和筛选
- 过滤条件设置
- 实时监控面板
-
分析中心页面
- 收益分析报表
- 风险评估报告
- 策略效果对比
-
准备钱包
钱包管理 → 创建钱包 → 输入密码 → 保存助记词 -
选择池子
池爬虫 → 设置筛选条件 → 选择合适池子 → 复制池地址 -
创建策略
策略管理 → 创建策略 → 选择类型 → 配置参数 → 启动策略 -
监控运行
策略监控 → 查看实时状态 → 分析收益表现 → 调整参数
# 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- 系统指标: CPU、内存、磁盘使用率
- 业务指标: 策略数量、交易成功率、收益率
- 技术指标: API 响应时间、错误率、吞吐量
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);// src/server/routes/new-routes.ts import { Router } from 'express'; import { NewService } from '../../services/business/NewService'; export function createNewRoutes(newService: NewService): Router { const router = Router(); router.get('/api/new/status', async (req, res) => { try { const status = await newService.getStatus(); res.json({ success: true, data: status }); } catch (error) { res.status(500).json({ success: false, error: error.message }); } }); return router; }# 单元测试 npm test # 集成测试 npm run test:integration # 覆盖率测试 npm run test:coverage # 特定测试文件 npm test -- --testPathPattern=StrategyManager// test/services/StrategyManager.test.ts import { StrategyManager } from '../../src/services/strategy/StrategyManager'; describe('StrategyManager', () => { let strategyManager: StrategyManager; beforeEach(() => { // 初始化测试环境 }); it('should create strategy successfully', async () => { const result = await strategyManager.createStrategy({ type: 'simple_y', params: {} }); expect(result).toBeDefined(); expect(result.success).toBe(true); }); });# 查找占用端口的进程 lsof -i :7000 lsof -i :7001 # 停止进程 kill -9 <PID> # 或使用快速停止脚本 ./scripts/quick-stop.sh# 检查钱包文件权限 ls -la data/wallet.enc # 验证加密密钥 echo $WALLET_ENCRYPTION_KEY # 重新创建钱包 rm data/wallet.enc # 重新创建钱包# 测试 RPC 连接 curl -X POST \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}' \ $RPC_PRIMARY # 切换到备用 RPC export RPC_PRIMARY="https://api.mainnet-beta.solana.com"# 查看策略日志 tail -f logs/strategy.log # 检查策略状态 curl http://localhost:7000/api/strategy/list # 重启策略服务 pm2 restart dlmm-api# 检查 Web 服务状态 curl http://localhost:7001/health # 重启 Web 服务 pm2 restart dlmm-web # 清除浏览器缓存 # Ctrl+Shift+R (强制刷新)- ERROR: 系统错误,需要立即处理
- WARN: 警告信息,需要关注
- INFO: 一般信息,正常运行状态
- DEBUG: 调试信息,开发阶段使用
logs/ ├── operation.log # 操作日志 ├── strategy.log # 策略执行日志 ├── monitor.log # 监控日志 ├── api-error.log # API 错误日志 └── system.log # 系统日志- 资源配置: 建议 8GB+ 内存,SSD 存储
- 网络优化: 使用高质量 RPC 节点
- 缓存策略: 合理设置缓存 TTL
- 并发控制: 限制最大并发策略数量
- 日志管理: 定期清理旧日志文件
- 分散投资,不要将所有资金投入单一策略
- 设置合理的止损点,控制风险
- 定期评估策略表现,及时调整
- 根据市场波动性调整 Bin 范围
- 监控池子的流动性深度
- 设置合理的滑点容忍度
- 定期更新系统和依赖
- 使用强密码和加密存储
- 定期备份重要数据
- 监控异常交易和操作
MIT License - 详见 LICENSE 文件
🎉 感谢使用 DLMM 流动性管理系统!
💡 提示: 本文档会随着系统更新持续完善,建议定期查看最新版本。