Uniswap AI交易代理Monorepo
基于Base链的Uniswap V3完整的人工智能交易系统,由MCP(模型上下文协议)服务器和智能交易代理组成。
🏗️ 建筑
此monorepo包含两个主要组件:
uniswap-trader-mcp/-提供Uniswap交易功能的MCP服务器ai-agent/-使用MCP服务器执行交易的AI交易代理
🚀 快速开始
先决条件
- Node.js>=18.0.0
- npm>=8.0.0
- Git
1.克隆和设置
git clone
cd uniswap-agent
npm install2.环境配置
MCP服务器环境
创建 uniswap-trader-mcp/.env:
cp uniswap-trader-mcp/.env.example uniswap-trader-mcp/.env
# Edit the file with your configuration所需变量:
INFURA_KEY-您的Infura API密钥WALLET_PRIVATE_KEY-您的钱包私钥
AI代理环境
创建 ai-agent/.env:
cp ai-agent/env.example ai-agent/.env
# Edit the file with your configuration3.启动系统
选项A:自动启动(推荐)
npm run start:system
# or
./start-trading-system.sh选项B:手动启动
终端1-启动MCP服务器:
npm run start:mcp
# or
cd uniswap-trader-mcp && npm run start:http终端2-启动AI代理:
npm run start:ai-agent
# or
cd ai-agent && npm start📋 可用脚本
根级别命令
| 命令 | 描述 |
|---|---|
npm install | 安装所有工作区的所有依赖项 |
npm run build | 构建所有需要构建的项目 |
npm run start:system | 启动MCP服务器和AI代理 |
npm run start:ai-agent | 仅启动AI代理 |
npm run start:mcp | 仅启动MCP服务器 |
npm run dev:ai-agent | 在开发模式下启动AI代理 |
npm run dev:mcp | 以开发模式启动MCP服务器 |
npm run clean | 清理所有构建工件和node_modules |
单个工作区命令
AI代理(ai-agent/)
cd ai-agent
npm run build # Build TypeScript to JavaScript
npm start # Start the built application
npm run dev # Start in development mode with ts-node
npm run watch # Start with file watchingMCP服务器(uniswap-trader-mcp/)
cd uniswap-trader-mcp
npm start # Start MCP server
npm run start:http # Start HTTP server (port 3000)
npm run dev # Start with file watching🌐 服务端点
运行时,将提供以下服务:
- MCP HTTP服务器: http://localhost:3000
- 健康检查: http://localhost:3000/health
- AI 代理:在后台运行,登录到
ai-agent/logs/trading-agent.log
📁 项目结构
uniswap-agent/
├── package.json # Root package.json with workspaces
├── README.md # This file
├── .gitignore # Git ignore rules
├── start-trading-system.sh # Automated startup script
├── ai-agent/ # AI Trading Agent
│ ├── package.json
│ ├── src/ # TypeScript source code
│ │ ├── main.ts # Entry point
│ │ ├── config/ # Configuration
│ │ ├── services/ # Business logic services
│ │ ├── strategies/ # Trading strategies
│ │ ├── types/ # TypeScript type definitions
│ │ └── utils/ # Utility functions
│ ├── dist/ # Compiled JavaScript (generated)
│ ├── logs/ # Log files (generated)
│ ├── env.example # Environment variables template
│ └── tsconfig.json # TypeScript configuration
└── uniswap-trader-mcp/ # MCP Server
├── package.json
├── index.js # MCP server entry point
├── http-server.js # HTTP server entry point
├── chainConfigs.js # Blockchain configurations
└── Dockerfile # Docker configuration🔧 发展
添加依赖关系
对于特定的工作空间:
npm install
--workspace=ai-agent
npm install
--workspace=uniswap-trader-mcp到root(共享依赖项):
npm install
建筑
AI代理在运行前需要构建:
npm run build:ai-agentMCP服务器直接从源代码运行,不需要构建。
日志
- AI代理日志:
ai-agent/logs/trading-agent.log - MCP服务器日志:检查服务器运行的终端输出
要实时跟踪AI代理日志:
tail -f ai-agent/logs/trading-agent.log🐳 Docker支持
MCP服务器支持Docker。看 uniswap-trader-mcp/Dockerfile 了解详情。
🔒 安全说明
- 永不承诺
.env文件到版本控制 - 确保您的私钥安全
- 对所有敏感配置使用环境变量
- 考虑将硬件钱包用于生产部署
🚨 故障排除
常见问题
- 端口3000已在使用中
lsof -ti:3000 | xargs kill -9- AI代理中的构建错误
cd ai-agent
npm run clean
npm install
npm run build- MCP服务器没有响应
- 检查是否 .env 文件存在于 uniswap-trader-mcp/ - 验证您的Infura密钥和钱包私钥 - 检查终端输出是否有错误消息
- AI代理未启动
- 确保MCP服务器首先运行 - 检查是否 ai-agent/.env 文件存在并已配置 - 验证构建是否成功: ls ai-agent/dist/
获取帮助
- 检查登录
ai-agent/logs/trading-agent.log - 验证所有环境变量是否设置正确
- 确保安装了所有依赖项:
npm install - 尝试自动启动脚本:
./start-trading-system.sh
📄 许可证
MIT许可证-有关详细信息,请参阅单独的package.json文件。
🤝 贡献
- 复刻仓库
- 创建要素分支
- 进行更改
- 彻底测试
- 提交拉取请求
📞 支持
对于问题和疑问:
- 检查上面的故障排除部分
- 查看日志中的错误消息
- 在存储库中打开问题
