CawTrade BNB - Autonomous DeFi Trading Agent v1.1.0
Production-ready autonomous trading agent for BNB Chain testnet & mainnet. Features 3 intelligent strategies, real-time performance analytics, on-chain event logging, and self-improving reinforced learning.
Core Features
🤖 Three Autonomous Strategies
- 1. Compound Yield - Auto-reinvest harvested rewards for exponential growth
- Rebalance - Move capital from low-APR to high-APR vaults automatically
- Dynamic Harvest - Intelligent harvesting based on gas cost optimization
🌐 Network Switching
- - Instant testnet ↔ mainnet toggle (no restart)
- Separate configs per network (gas, thresholds, RPCs)
- Contract address mapping per chain
- Persistent network preferences
📊 Real-Time Analytics
- - Realized APR (actual, based on historical yields)
- Per-vault performance breakdown
- Strategy effectiveness scoring
- Success rate tracking (target: >90%)
- Failure pattern detection
🧠 Reinforced Learning
- - Auto-learns from past failures
- Dynamically optimizes strategy parameters
- Adjusts thresholds based on success rates
- Confidence scoring per strategy
- Self-improving over time
⛓️ On-Chain Event Logging
- - All actions logged with TX hashes
- Auditable blockchain trail
- BNB Testnet Scanner links
- Complete execution history
🎮 Control Panel CLI
- - Interactive command-line interface
- Network management commands
- Performance metrics dashboard
- Learning progress tracking
- Real-time optimization
Installation & Setup
1. Install Skill
CODEBLOCK0
2. Configure Environment
CODEBLOCK1
3. Set Private Key (Secure)
CODEBLOCK2
4. Verify Setup
CODEBLOCK3
Quick Start - 3 Commands
CODEBLOCK4
Architecture
CODEBLOCK5
Configuration Files
config.deployed.json - Contract addresses & ABIs
CODEBLOCK6
config.scheduler.json - Strategy thresholds
CODEBLOCK7
Strategy Decision Logic
Each 60-second cycle:
- 1. COMPOUND YIELD
- Check pending rewards per vault
- If pending ≥ $25 → Harvest + Re-deposit
- Log action with TX hash
- 2. REBALANCE
- Compare APRs across all vaults
- If top APR > bottom APR by ≥ 2% → Rebalance
- Move 20% from worst to best vault
- Log action with TX hash
- 3. DYNAMIC HARVEST
- Estimate gas cost per harvest
- Only harvest if pending > 2x gas cost
- Maximize profitability per action
- Log action with TX hash
Example Output:
CODEBLOCK8
CLI Commands
Network Management
CODEBLOCK9
Performance Monitoring
CODEBLOCK10
Reinforced Learning
CODEBLOCK11
Supported Networks
| Network | Chain ID | Use Case | Harvest Min | Gas Multiplier |
|---|
| BNB Testnet | 97 | Development | $25 | 1.2x |
| BNB Mainnet |
56 | Production | $100 | 1.5x |
Network Switching
Switch instantly without restarting:
CODEBLOCK12
Security & Safety
On-Chain Auditing
- - ✅ Every action logged with transaction hash
- ✅ Blockchain verification via BNB Testnet/Mainnet Scanner
- ✅ Append-only execution log (execution-log.jsonl)
- ✅ Complete audit trail for compliance
Risk Management
- - ✅ Deterministic decision logic (reproducible, auditable)
- ✅ Success rate monitoring (>90% target)
- ✅ Confidence thresholds per strategy
- ✅ Graceful error handling & recovery
- ✅ Automatic parameter optimization via learning
Private Key Security
- - ✅ Never hardcoded - use environment variables only
- ✅ .env file git-ignored
- ✅ Testnet for development, mainnet when ready
- ✅ For production: use hardware wallet support (future)
File Structure
CODEBLOCK13
Integration with Other Skills
This is a standalone, complete skill. It can also integrate with:
- - Telegram Notifications - Send alerts to OpenClaw users
- Email Reports - Daily performance summaries
- Database Logging - Store metrics in persistent DB
- Webhook Integrations - Trigger external services
Documentation
| File | Purpose |
|---|
| INLINECODE0 | Complete user guide |
| INLINECODE1 |
Strategy details & examples |
|
README_ADVANCED.md | Network switching & reinforced learning |
|
SKILL.md | This installation & architecture guide |
What You Get
✅ Production-ready code (tested, documented, error-handling)
✅ 3 profitable strategies (auto-optimizing, self-learning)
✅ Real-time dashboard (React, live updates)
✅ CLI control panel (manage from terminal)
✅ On-chain logging (auditable, transparent)
✅ Network switching (testnet → mainnet in seconds)
✅ Self-improvement (learns from failures automatically)
✅ Complete documentation (guides, examples, FAQ)
Replicating This Skill
For someone else to replicate:
- 1. Install
CODEBLOCK14
- 2. Configure
CODEBLOCK15
- 3. Deploy Contracts (if using new vaults)
CODEBLOCK16
- 4. Run
CODEBLOCK17
- 5. Monitor
- Dashboard: http://localhost:5173
- Logs: execution-log.jsonl
- Analytics: node agent-cli.js perf report
Total setup time: ~15 minutes
Support & Community
- - GitHub Issues: https://github.com/open-web-academy/clawtrade-bnb-bnb
- ClawHub: https://clawhub.com (search: clawtrade-bnb)
- Discord: https://discord.com/invite/clawd
Version History
- - v1.1.0 (2026-02-18) - Network switcher, analytics, reinforced learning, CLI
- v1.0.0 (2026-02-17) - Initial release, 3 strategies, on-chain logging
License
MIT - Free to use, modify, and distribute
技能名称: clawtrade-bnb
详细描述:
CawTrade BNB - 自主DeFi交易代理 v1.1.0
生产级自主交易代理,适用于BNB Chain测试网与主网。具备3种智能策略、实时性能分析、链上事件日志记录以及自我改进的强化学习功能。
核心功能
🤖 三种自主策略
- 1. 复利收益 - 自动复投已收获奖励,实现指数级增长
- 再平衡 - 自动将资金从低APR金库转移至高APR金库
- 动态收获 - 基于Gas成本优化进行智能收获
🌐 网络切换
- - 测试网 ↔ 主网即时切换(无需重启)
- 每个网络独立配置(Gas、阈值、RPC)
- 每条链的合约地址映射
- 持久化网络偏好设置
📊 实时分析
- - 已实现APR(基于历史收益的实际值)
- 每个金库的性能分解
- 策略有效性评分
- 成功率追踪(目标:>90%)
- 失败模式检测
🧠 强化学习
- - 从过往失败中自动学习
- 动态优化策略参数
- 基于成功率调整阈值
- 每个策略的置信度评分
- 随时间自我改进
⛓️ 链上事件日志
- - 所有操作均记录交易哈希
- 可审计的区块链追溯
- BNB测试网扫描器链接
- 完整的执行历史记录
🎮 控制面板CLI
- - 交互式命令行界面
- 网络管理命令
- 性能指标仪表盘
- 学习进度追踪
- 实时优化
安装与设置
1. 安装技能
bash
clawhub install clawtrade-bnb
cd ~/.openclaw/workspace/skills/clawtrade-bnb
npm install
2. 配置环境
bash
复制示例配置
cp config.deployed.json config.live.json
编辑您的设置
nano config.live.json
设置RPC端点、合约地址、钱包
3. 设置私钥(安全)
bash
选项A:环境变量(推荐)
export PRIVATE
KEY=yourtestnet
privatekey
选项B:.env文件(被git忽略)
echo PRIVATE
KEY=yourkey >> .env
注意:切勿提交私钥!
4. 验证设置
bash
测试连接和合约
node agent-cli.js network status
检查钱包余额
npm run verify
快速启动 - 3条命令
bash
终端1:运行策略引擎(60秒周期)
node strategy-scheduler.js
终端2:实时仪表盘
npm run dev:dashboard
→ 打开 http://localhost:5173
终端3:控制面板
node agent-cli.js
示例命令:
node agent-cli.js network testnet # 切换网络
node agent-cli.js perf summary # 查看性能
node agent-cli.js learn now # 优化策略
架构
DeFi策略引擎
├─ 复利收益策略
│ └─ 待领取金额 > $25时收获 → 重新存入
├─ 再平衡策略
│ └─ 将20%资金从低APR金库转移至高APR金库
└─ 动态收获策略
└─ 仅当待领取金额 > 2倍Gas成本时收获
↓(每60秒运行一次)
策略调度器
├─ 读取金库APR和待领取奖励
├─ 执行所有3种策略
└─ 记录操作 + 交易哈希
↓(记录到区块链)
链上日志记录器
├─ execution-log.jsonl(仅追加)
├─ performance-metrics.json(累积)
└─ learning-state.json(优化历史)
↓(持续分析)
强化学习系统
├─ 追踪每个策略的成功率
├─ 检测失败模式
├─ 自动调整阈值
└─ 生成改进报告
↓(实时显示)
仪表盘 + 控制面板
├─ React仪表盘(http://localhost:5173)
├─ 代理CLI(网络、性能、学习命令)
└─ 性能API(/api/logs, /api/health)
配置文件
config.deployed.json - 合约地址与ABI
json
{
chainId: 97,
network: BNB Testnet,
contracts: [
{
vaultId: vaultethstaking_001,
address: 0x588eD88A145144F1E368D624EeFC336577a4276b,
strategy: Ethereum 2.0 Staking,
risk_score: 0.3
}
]
}
config.scheduler.json - 策略阈值
json
{
scheduler: {
executionintervalseconds: 60,
enabled: true
},
agent: {
harvestthresholdusd: 25,
rebalanceaprdelta: 2.0,
maxallocationpercent: 0.35,
min_confidence: 0.6
}
}
策略决策逻辑
每个60秒周期:
- 1. 复利收益
- 检查每个金库的待领取奖励
- 如果待领取金额 ≥ $25 → 收获 + 重新存入
- 记录操作及交易哈希
- 2. 再平衡
- 比较所有金库的APR
- 如果最高APR比最低APR高 ≥ 2% → 再平衡
- 将20%资金从最差金库转移至最佳金库
- 记录操作及交易哈希
- 3. 动态收获
- 估算每次收获的Gas成本
- 仅当待领取金额 > 2倍Gas成本时收获
- 最大化每次操作的盈利能力
- 记录操作及交易哈希
示例输出:
周期 #42 @ 2026-02-18T18:00:00Z
✓ vaultethstaking_001: 复利(收获$45.50)
✓ vaulthighrisk_001: 再平衡(APR差值2.1%)
✓ vaultlinkoracle_001: 收获(待领取$12.30)
✅ 总奖励:$57.80 | 复利金额:$45.50
CLI命令
网络管理
bash
node agent-cli.js network status # 当前网络配置
node agent-cli.js network testnet # 切换到测试网
node agent-cli.js network mainnet # 切换到主网(⚠️ 生产环境)
性能监控
bash
node agent-cli.js perf summary # 快速统计
node agent-cli.js perf report # 详细分析
node agent-cli.js perf vaults # 每个金库分解
node agent-cli.js perf strategies # 策略有效性
强化学习
bash
node agent-cli.js learn now # 分析与优化
node agent-cli.js learn report # 查看改进
node agent-cli.js learn reset # 重置学习状态
支持的网络
| 网络 | 链ID | 用途 | 最低收获额 | Gas倍数 |
|---|
| BNB测试网 | 97 | 开发 | $25 | 1.2倍 |
| BNB主网 |
56 | 生产 | $100 | 1.5倍 |
网络切换
无需重启即可即时切换:
bash
当前配置
node agent-cli.js network status
→ BNB测试网
切换到生产环境
node agent-cli.js network mainnet
→ 已更新RPC、合约地址和阈值
所有设置自动更新
安全与保障
链上审计
- - ✅ 每个操作均记录交易哈希
- ✅ 通过BNB测试网/主网扫描器进行区块链验证
- ✅ 仅追加的执行日志(execution-log.jsonl)
- ✅ 完整的合规审计追踪
风险管理
- - ✅ 确定性决策逻辑(可复现、可审计)
- ✅ 成功率监控(目标>90%)
- ✅ 每个策略的置信度阈值
- ✅ 优雅的错误处理与恢复
- ✅ 通过学习自动优化参数
私钥安全
- - ✅ 绝不硬编码 - 仅使用环境变量
- ✅ .env文件被git忽略
- ✅ 测试网用于开发,主网准备就绪时使用
- ✅ 生产环境:支持硬件钱包(未来功能)
文件结构
clawtrade-bnb