Tidak Ada Deskripsi

zhangchunrui ca8740f0f0 feat: swap完成后发送Discord通知 1 bulan lalu
src ca8740f0f0 feat: swap完成后发送Discord通知 1 bulan lalu
.env.example ded880da9b feat: implement byreal sniper bot with onchain monitoring 1 bulan lalu
.gitignore ded880da9b feat: implement byreal sniper bot with onchain monitoring 1 bulan lalu
Dockerfile 02777b36ef fix: update Jupiter price API endpoint and add Dockerfile 1 bulan lalu
README.md a9c5ec37be Initial commit: Byreal sniper bot with modular ES module architecture 1 bulan lalu
index.js a9c5ec37be Initial commit: Byreal sniper bot with modular ES module architecture 1 bulan lalu
package.json ded880da9b feat: implement byreal sniper bot with onchain monitoring 1 bulan lalu
pnpm-lock.yaml ded880da9b feat: implement byreal sniper bot with onchain monitoring 1 bulan lalu
test-copy.js 4f6dae6685 fix: 余额检查改用代币数量直接比较,避免 priceUsd 为空时误 swap 1 bulan lalu
test-target-value.js ded880da9b feat: implement byreal sniper bot with onchain monitoring 1 bulan lalu
test-tx-analysis.js 02777b36ef fix: update Jupiter price API endpoint and add Dockerfile 1 bulan lalu
test-tx-parse.js 8aa22654d8 test: add transaction parse test script 1 bulan lalu

README.md

Byreal Sniper Bot 🎯

一个自动狙击 Byreal DEX 上目标地址 LP 仓位的机器人。当目标地址开仓时,自动以更快速度和设定倍数跟单;当目标地址平仓时,自动跟随平仓。

功能特性

  • 🎯 自动狙击: 监控目标钱包地址的所有 LP 仓位变动
  • 📈 倍数跟单: 可配置复制倍数(例如 1.5x 目标仓位)
  • 🔄 自动平衡: 余额不足时通过 Jupiter 自动兑换所需代币
  • 💰 风险控制: 设置最大/最小仓位金额限制
  • 🚪 自动平仓: 目标平仓时自动跟随关闭对应仓位
  • 💾 状态持久化: 自动保存已复制和已关闭的仓位,防止重复操作
  • 高速轮询: 可配置的轮询间隔(默认 10 秒)
  • 🧩 模块化架构: 易于扩展和维护

项目结构

byreal-sniper/
├── index.js                 # 入口文件
├── package.json
├── .env.example
├── .gitignore
├── README.md
├── src/
│   ├── config/             # 配置管理
│   │   └── index.js
│   ├── core/               # 核心逻辑
│   │   ├── sniper.js       # 狙击引擎
│   │   └── index.js
│   ├── services/           # 外部服务
│   │   ├── jupiter.js      # Jupiter 兑换服务
│   │   ├── byreal.js       # Byreal API 服务
│   │   └── index.js
│   ├── utils/              # 工具函数
│   │   ├── cache.js        # 缓存管理
│   │   ├── helpers.js      # 辅助函数
│   │   ├── logger.js       # 日志工具
│   │   └── index.js
│   └── commands/           # CLI 命令
│       └── index.js
└── data/                   # 数据目录(自动生成)
    ├── .copied-positions.json
    └── .closed-positions.json

安装

# 进入项目目录
cd byreal-sniper

# 安装依赖
npm install

# 复制环境变量模板
cp .env.example .env

# 编辑 .env 文件,配置你的私钥和其他设置

使用方法

启动狙击机器人

# 默认启动
npm start

# 或者
node index.js
node index.js start

查看当前状态

npm run status
# 或者
node index.js status

清除缓存

npm run clear
# 或者
node index.js clear

查看帮助

node index.js help

配置

编辑 .env 文件:

# Solana RPC URL
RPC_URL=https://mainnet.helius-rpc.com/?api-key=20f2bda7-11af-4e71-a3c3-a8fd6567df80

# 你的钱包私钥 (Base58 编码,从 Phantom 或其他钱包导出)
PRIVATE_KEY=your_private_key_here

# 跟单倍数 (1.5 = 复制目标仓位的 1.5 倍金额)
COPY_MULTIPLIER=1.5

# 最大/最小仓位金额 (USD)
MAX_USD_VALUE=10
MIN_USD_VALUE=0.1

# Jupiter 兑换滑点 (100 = 1%)
SLIPPAGE_BPS=100

# 轮询间隔 (毫秒,10000 = 10秒)
POLL_INTERVAL_MS=10000

# 数据目录
DATA_DIR=./data

扩展模块

项目采用模块化架构,便于添加新功能:

添加新的服务

src/services/ 目录创建新服务文件:

// src/services/newService.js
export class NewService {
  static async doSomething() {
    // 你的逻辑
  }
}

然后在 src/services/index.js 中导出:

export { NewService } from './newService.js';

添加新的命令

src/commands/index.js 中添加新命令函数:

export function newCommand() {
  // 命令逻辑
}

index.js 中添加命令处理:

case 'newcommand':
  newCommand();
  break;

添加新的工具函数

src/utils/ 目录创建新文件并导出:

// src/utils/newUtil.js
export function newHelper() {
  // 工具函数
}

工作原理

  1. 监控阶段: 每 10 秒轮询一次目标地址的活跃仓位
  2. 分析阶段:
    • 检查仓位是否在当前价格范围内
    • 验证是否已复制过
    • 计算复制金额(目标金额 × 倍数)
  3. 准备阶段:
    • 检查钱包余额
    • 如余额不足,通过 Jupiter 自动兑换所需代币
  4. 执行阶段:
    • 调用 Byreal API 复制仓位
    • 保存仓位到本地缓存
  5. 平仓阶段:
    • 检测目标地址已关闭的仓位
    • 自动关闭对应的复制仓位

技术栈

  • Node.js 18+ - 运行时环境
  • ES Modules - 模块化系统
  • Axios - HTTP 请求
  • @solana/web3.js - Solana 区块链交互
  • @solana/spl-token - SPL 代币操作
  • dotenv - 环境变量管理
  • bs58 - Base58 编码/解码

目标地址

默认监控地址: dryuRNL9YcdLnhKFgLfdoj1g2suWcZp97G8XiH8U49e

可在 src/config/index.js 中修改 TARGET_WALLET 配置。

安全提示

⚠️ 警告:

  • 请仅在测试网或小金额下测试
  • 确保私钥安全,不要分享给任何人
  • 建议先使用小额资金测试策略
  • DeFi 存在无常损失风险,请充分了解 LP 机制
  • 切勿将 .env 文件提交到版本控制

故障排除

启动失败

  • 检查 Node.js 版本是否 >= 18
  • 检查 .env 文件是否存在且配置正确
  • 确认私钥格式正确(Base58 编码)

无法获取仓位

  • 检查 RPC URL 是否可用
  • 确认目标地址有活跃的 LP 仓位

兑换失败

  • 确认钱包有足够 SOL 支付交易费用
  • 检查 Jupiter API 是否可用

API 错误

  • 确认 AUTH_HEADER 配置正确
  • 检查 Byreal API 状态

许可证

ISC

免责声明

此工具仅供学习和研究使用。使用本工具进行的所有交易和操作均由用户自行承担风险。作者不对任何资金损失负责。请在使用前充分了解 DeFi 风险。