MCPcopy Index your code
hub / github.com/cryptocj520/meteora2

github.com/cryptocj520/meteora2 @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
4,283 symbols 11,608 edges 135 files 2,021 documented · 47%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🏗️ DLMM 流动性管理系统

企业级 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 余额
  • 交易签名: 安全的交易签名机制

API 接口

# 创建钱包
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

📊 策略管理系统

策略类型

  1. 简单 Y 头寸策略 (Simple Y Strategy)
  2. 用途: 单侧流动性提供
  3. 特点: 专注单一代币流动性,风险相对较低
  4. 适用场景: 稳定币对、主流代币

  5. 连锁头寸策略 (Chain Position Strategy)

  6. 用途: 多层级流动性管理
  7. 特点: 创建连续的流动性区间,自动调整
  8. 适用场景: 高波动性代币对

策略配置

{
  "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

🪐 Jupiter 交易集成

交易功能

  • 智能路由: 自动寻找最优交易路径
  • 滑点保护: 自适应滑点管理
  • 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

🌐 Web界面使用指南

📊 仪表盘概览

访问 http://localhost:7001 进入系统主界面

主要功能模块

  1. 钱包管理页面
  2. 钱包创建和导入
  3. 余额查询和管理
  4. 交易历史记录

  5. 策略管理页面

  6. 策略创建向导
  7. 实时策略监控
  8. 策略配置管理

  9. 头寸管理页面

  10. 头寸创建和关闭
  11. 头寸实时监控
  12. 收益统计分析

  13. 交易中心页面

  14. Jupiter 代币交换
  15. 交易历史记录
  16. 市场数据查看

  17. 池爬虫页面

  18. 池子发现和筛选
  19. 过滤条件设置
  20. 实时监控面板

  21. 分析中心页面

  22. 收益分析报表
  23. 风险评估报告
  24. 策略效果对比

🖱️ 操作流程

创建第一个策略

  1. 准备钱包 钱包管理 → 创建钱包 → 输入密码 → 保存助记词

  2. 选择池子 池爬虫 → 设置筛选条件 → 选择合适池子 → 复制池地址

  3. 创建策略 策略管理 → 创建策略 → 选择类型 → 配置参数 → 启动策略

  4. 监控运行 策略监控 → 查看实时状态 → 分析收益表现 → 调整参数

🐳 部署和运维

📦 Docker 部署

使用 Docker Compose (推荐)

# 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

🖥️ 传统部署

Ubuntu 服务器部署

# 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

PM2 配置文件

// 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);

创建 API 路由

```typescript // src/server/routes/new-routes.ts import { Router } from 'express'; import { NewService } from '../../services/business/NewService';

export function createNewRoutes(

Extension points exported contracts — how you extend this code

IService (Interface)
(no doc) [20 implementers]
src/types/interfaces.ts
IStrategyExecutor (Interface)
(no doc) [4 implementers]
src/services/strategy/StrategyRegistry.ts
IEventBus (Interface)
(no doc) [2 implementers]
src/infrastructure/EventBus.ts
TokenAmount (Interface)
(no doc)
src/utils/TokenPrecisionConverter.ts
IPositionManager (Interface)
(no doc) [4 implementers]
src/types/interfaces.ts
DataCollectionState (Interface)
* 数据收集状态
src/services/modules/ChainPositionDataAdapter.ts
IStateService (Interface)
(no doc) [2 implementers]
src/infrastructure/StateService.ts
TokenPair (Interface)
(no doc)
src/utils/TokenPrecisionConverter.ts

Core symbols most depended-on inside this repo

now
called by 662
src/infrastructure/logging/TimeFormatter.ts
logSystem
called by 523
src/types/logging.ts
logError
called by 312
src/services/strategy/executors/simple-y-modules/types.ts
error
called by 293
web/public/js/components/wallet/wallet-manager.js
get
called by 274
src/services/internal/ConfigService.ts
get
called by 185
src/types/interfaces.ts
logBusinessOperation
called by 177
src/types/logging.ts
logOperation
called by 146
src/services/strategy/executors/simple-y-modules/types.ts

Shape

Method 3,338
Function 404
Class 318
Interface 217
Enum 6

Languages

TypeScript100%

Modules by API surface

web/public/js/libs/chart.min.js953 symbols
src/types/interfaces.ts273 symbols
web/public/js/app.js71 symbols
web/public/js/components/pool-crawler/PoolCrawlerMonitor.js67 symbols
web/public/js/api.js65 symbols
src/services/strategy/executors/ChainPositionExecutor.ts60 symbols
src/services/business/analytics/UnifiedDataProvider.ts58 symbols
web/public/js/components/wallet/wallet-manager.js56 symbols
src/types/pool-crawler-types.ts50 symbols
web/public/js/components/strategy-monitor/UIManager.js49 symbols
web/public/js/components/simple-y-monitor/UIManager.js49 symbols
web/public/js/components/simple-y-create/SimpleYCreator.js47 symbols

For agents

$ claude mcp add meteora2 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact