hallosoares/safertrade

GitHub: hallosoares/safertrade

一个覆盖 7 条主流公链的开源实时 DeFi 威胁检测与风险情报平台,致力于通过多引擎架构防范蜜罐、拉高出货等链上攻击。

Stars: 0 | Forks: 0

SaferTrade Logo

实时 DeFi 威胁检测与风险情报平台

License Python Redis Tests Engines Maintained PRs Welcome

## 目录 - [什么是 SaferTrade?](#what-is-safertrade) - [架构](#architecture) - [检测引擎](#detection-engines) - [快速开始](#quick-start) - [Docker (推荐)](#docker-recommended) - [手动安装](#manual-installation) - [多链支持](#multi-chain-support)

SaferTrade Logo

实时 DeFi 威胁检测与风险智能平台

License Python Redis Tests Engines Maintained PRs Welcome

## 目录 - [什么是 SaferTrade?](#what-is-safertrade) - [架构](#architecture) - [检测引擎](#detection-engines) - [快速开始](#quick-start) - [Docker(推荐)](#docker-recommended) - [手动安装](#manual-installation) - [多链支持](#multi-chain-support) - [配置](#configuration) - [API 参考](#api-reference) - [示例](#examples) - [贡献](#contributing) - [许可证](#license) ## 什么是 SaferTrade? SaferTrade 是**唯一开源、可用于生产环境**的 DeFi 威胁检测平台。当其他项目仅仅停留在记录威胁时,我们通过 10 多个专用引擎在 7 个区块链网络中实时检测它们。 **核心优势:** - 真正可运行的检测代码(不仅仅是文档) - 通过 Redis Streams 进行实时监控 - 开箱即用的多链支持 - 模块化引擎架构,具备高度可扩展性 ## 架构 ``` SAFERTRADE ARCHITECTURE ┌─────────────────────────────────────────────────────────────────────────────┐ │ DATA SOURCES │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ Ethereum │ │ Base │ │ Polygon │ │ Arbitrum │ │ Solana │ + more │ │ │ RPC │ │ RPC │ │ RPC │ │ RPC │ │ RPC │ │ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ │ │ │ │ │ │ └───────┼────────────┼────────────┼────────────┼────────────┼─────────────────┘ │ │ │ │ │ └────────────┴────────────┼────────────┴────────────┘ │ ▼ ┌───────────────────────────────────────────────────────────────────────────┐ │ DETECTION ENGINES │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Honeypot │ │ Pump & Dump │ │ Oracle │ │ │ │ Checker │ │ Detector │ │ Manipulation │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Stablecoin │ │ Token │ │ Phishing │ │ │ │ Depeg Monitor │ │ Holder Analyzer │ │ Detector │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ └───────────┼────────────────────┼────────────────────┼─────────────────────┘ │ │ │ └────────────────────┼────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────┐ │ REDIS STREAMS │ │ │ │ safertrade:results signals.honeypot signals.pump signals.oracle │ │ │ │ └──────────┼──────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────┐ │ OUTPUTS │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ REST API │ │ WebSocket │ │ Telegram │ │ Webhooks │ │ │ │ /api/v1 │ │ Alerts │ │ Alerts │ │ Callbacks │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ## 检测引擎 | 引擎 | 威胁类型 | 描述 | |--------|-------------|-------------| | `honeypot_checker` | 合约风险 | 检测阻止代币出售的蜜罐合约 | | `pump_detector` | 市场操纵 | 识别协同的拉高出货(pump-and-dump)骗局 | | `oracle_manipulation_detector` | 价格攻击 | 监控预言机价格操纵企图 | | `stablecoin_depeg_monitor` | 锚定风险 | 追踪稳定币偏离锚定汇率的情况 | | `token_holder_analyzer` | 集中度风险 | 分析巨鲸(大户)持仓集中度与代币分布 | | `phishing_detector` | 欺诈 | 识别已知的钓鱼地址和模式 | | `gas_price_optimizer` | 成本 | 监控 Gas 价格异常并进行优化 | | `health_check` | 系统 | 平台健康状态监控 | | `ohlcv_data_feed` | 数据 | 市场数据聚合与验证 | | `alert_processor` | 投递 | 告警路由与多渠道投递 | ## 快速开始 ### Docker(推荐) 最快的入门方式: ``` # Clone repository git clone https://github.com/hallosoares/safertrade.git cd safertrade # 配置环境 cp .env.example .env # 使用你的 RPC endpoints 编辑 .env # 启动一切 docker-compose up -d # 查看日志 docker-compose logs -f api # API 现在可通过 http://localhost:8000 访问 ``` **验证是否正在运行:** ``` curl http://localhost:8000/health ``` ### 手动安装 #### 前置条件 - Python 3.11+ - Redis 7.0+ - 目标链的 RPC 节点 #### 安装 ``` # Clone repository git clone https://github.com/hallosoares/safertrade.git cd safertrade # 创建虚拟环境 python -m venv venv source venv/bin/activate # Linux/Mac # 或者:venv\Scripts\activate # Windows # 安装依赖 pip install -r requirements.txt # 配置环境 cp .env.example .env # 使用你的 RPC endpoints 编辑 .env # 启动 Redis (如果未运行) redis-server & # 运行 API uvicorn api.main:app --reload ``` ## 示例 ### 检测蜜罐代币 ``` from engines.honeypot_checker.engine import HoneypotChecker from shared.redis_client import get_redis_client # 初始化 redis = get_redis_client() checker = HoneypotChecker(redis) # 检查 token result = checker.check_token("0x...") if result.is_honeypot: print(f"WARNING: Honeypot detected!") print(f"Risk score: {result.risk_score}") print(f"Reason: {result.reason}") else: print("Token appears safe") ``` ### 订阅实时告警 ``` import json from shared.redis_client import get_redis_client redis = get_redis_client() last_id = "$" print("Waiting for alerts...") while True: messages = redis.xread({"safertrade:results": last_id}, block=5000) if messages: for stream, entries in messages: for entry_id, data in entries: alert = json.loads(data.get("data", "{}")) print(f"Alert: {data.get('type')} - Risk: {alert.get('risk_score')}") last_id = entry_id ``` 查看 [examples/](examples/) 获取更多示例: - `honeypot_detection.py` - 检查代币的蜜罐特征 - `pump_dump_detection.py` - 检测拉高出货骗局 - `realtime_alerts.py` - 订阅实时告警 - `webhook_integration.py` - 将告警转发至 Discord/Slack - `multi_chain_monitoring.py` - 监控多条链 ## 多链支持 SaferTrade 跨多个网络监控威胁: | 网络 | Chain ID | 状态 | |---------|----------|--------| | Ethereum | 1 | 已支持 | | Base | 8453 | 已支持 | | Polygon | 137 | 已支持 | | Optimism | 10 | 已支持 | | Arbitrum | 42161 | 已支持 | | Blast | 81457 | 已支持 | | Solana | - | 已支持 | ## 配置 主要环境变量: | 变量 | 描述 | 必需 | |----------|-------------|----------| | `REDIS_URL` | Redis 连接字符串 | 是 | | `RPC_ETHEREUM` | Ethereum RPC 节点 | 是 | | `RPC_BASE` | Base RPC 节点 | 是 | | `RPC_POLYGON` | Polygon RPC 节点 | 可选 | | `LOG_LEVEL` | 日志详细程度 (DEBUG, INFO, WARNING) | 否 | 有关完整的配置参考,请参阅 [.env.example](.env.example)。 ## API 参考 运行 API 服务器时,可通过以下地址访问文档: - **Swagger UI**: `http://localhost:8000/docs` - **ReDoc**: `http://localhost:8000/redoc` ### 示例端点 ``` # 健康检查 curl http://localhost:8000/health # 检查 token 安全性 curl http://localhost:8000/api/v1/token/0x.../safety # 获取 whale 动态 curl "http://localhost:8000/api/v1/whale/movements?chain=ethereum&limit=100" ``` ## 项目结构 ``` safertrade/ ├── engines/ # Detection engines (modular, independent) │ ├── honeypot_checker/ │ ├── pump_detector/ │ └── ... ├── shared/ # Common utilities and clients ├── schemas/ # Data models and validation ├── data/ # Static data (phishing lists, etc.) ├── docs/ # Documentation ├── examples/ # Usage examples └── tests/ # Test suite ``` ### 开发环境设置 ``` # 安装 dev dependencies pip install -r requirements-dev.txt # 运行测试 pytest # 运行 linter ruff check . # Type checking mypy engines/ shared/ ``` 有关指南,请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。 ## 安全 有关安全漏洞,请参阅 [SECURITY.md](SECURITY.md)。请勿针对安全问题公开提交 Issue。 **负责任的披露**:security@safertrade.io ## 许可证 Business Source License 1.1 (BUSL-1.1) ### 您可以: - 将 SaferTrade 用于您自己的 DeFi 操作(个人/内部使用) - 在您自己的基础设施上运行 - 研究代码,进行分叉并贡献改进 - 用于研究、测试、学习和开发 ### 您不能(在没有商业许可证的情况下): - 将 SaferTrade 作为付费服务提供给他人 - 将其包含在您出售的商业产品中 - 在产生收入的企业中将其用于生产环境 **变更日期**:2029 年 12 月 10 日(转换为 Apache 2.0 协议) **商业许可证**:如需企业/生产环境使用,请联系维护者。 有关详细信息,请参阅 [LICENSE](LICENSE) 和 [LICENSE_FAQ.md](LICENSE_FAQ.md)。 ## 支持 - **文档**:[docs/](docs/) - **问题**:[GitHub Issues](https://github.com/hallosoares/safertrade/issues) - **讨论**:[GitHub Discussions](https://github.com/hallosoares/safertrade/discussions)

为 DeFi 社区而建。保护您的投资。

标签:AMSI绕过, CISA项目, DeFi, Python, Redis Streams, Web3安全, 加密货币安全, 区块链安全, 去中心化金融, 反诈骗, 多链支持, 威胁检测, 安全情报, 密码管理, 开源, 搜索引擎查询, 无后门, 砸盘拉盘检测, 蜜罐检测, 请求拦截, 逆向工具, 钓鱼检测, 预言机攻击, 风控引擎, 风险控制