Xpersona
C

Cl Lp Rebalancer

CLAWHUB · Unverified

Uniswap V3 集中流动性 LP 自动调仓策略。基于波动率自适应范围宽度:低波动率收紧范围(高资本效率),高波动率放宽范围(减少调仓和 IL)。支持趋势不对称调整、多时间框架分析、自动 claim/remove/swap/deposit 全流程。适用于 EVM L2 链上 CL LP 管理、调仓、范围优化、... Skill: Cl Lp Rebalancer Owner: synththoughts Summary: Uniswap V3 集中流动性 LP 自动调仓策略。基于波动率自适应范围宽度:低波动率收紧范围(高资本效率),高波动率放宽范围(减少调仓和 IL)。支持趋势不对称调整、多时间框架分析、自动 claim/remove/swap/deposit 全流程。适用于 EVM L2 链上 CL LP 管理、调仓、范围优化、... Tags: latest:3.9.2 Version history: v3.9.2 | 2026-04-01T15:34:02.698Z | user fix: poll redeem balance arrival (replace sleep 3s), USDC-base fallback swaps ETH before deposit, detect swap revert v3.9.1 | 20

62
Rank
84
Safety
1.3k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.3K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s17ck4tsqe5hd01dsn49q7dac183kd47:cl-lp-rebalancer
  1. Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-synththoughts-cl-lp-rebalancer/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

149,027 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: cl-lp-rebalancer
description: "Uniswap V3 集中流动性 LP 自动调仓策略。基于波动率自适应范围宽度:低波动率收紧范围(高资本效率),高波动率放宽范围(减少调仓和 IL)。支持趋势不对称调整、多时间框架分析、自动 claim/remove/swap/deposit 全流程。适用于 EVM L2 链上 CL LP 管理、调仓、范围优化、手续费最大化场景。用户查询收益、PnL、仓位、头寸状态、LP 状况、年化、手续费、无常损失时,调用 status 子命令即可获取(每 5 分钟缓存一次,秒级响应)。"
license: Apache-2.0
metadata:
  author: SynthThoughts
  version: "3.9.2"
  pattern: "pipeline, tool-wrapper"
  steps: "5"
---

# CL LP Auto-Rebalancer v1

Cron 驱动的 Uniswap V3 集中流动性自动调仓机器人,运行在 EVM L2 链上,通过 `onchainos` CLI 执行 DeFi 操作。核心思路:**波动率决定范围宽度** — 低波动率时收紧范围提高资本效率,高波动率时放宽范围减少调仓频率和无常损失。

每个 tick:获取价格 → 波动率分析 → 范围计算 → 调仓决策 → 执行调仓 → 报告。

## Architecture

```
Cron (5min) → Python script → onchainos CLI → OKX Web3 API → Chain
                  ↓                ↓
            cl_lp_state.json    Wallet (TEE signing)
                  ↓
            ┌──────────────┐
            │ Price Fetch   │ ← onchainos swap quote / market price
            │ K-line ATR    │ ← onchainos market kline (1H × 24)
            │ MTF Analysis  │ ← price_history (288 bars = 24h)
            └──────┬───────┘
                   ↓
            Range Calculation (vol-adaptive)
                   ↓
            Rebalance Decision
                   ↓
            ┌──────────────┐
            │ Claim Fees    │ ← onchainos defi claim
            │ Remove Liq    │ ← onchainos defi redeem
            │ Swap Ratio    │ ← onchainos swap swap
            │ Add Liq       │ ← onchainos defi deposit
            └──────┬───────┘
                   ↓
            Structured JSON output
```

**OKX Skill Dependencies** (via `onchainos` CLI — 处理认证、链解析、错误重试):

- Price: `onchainos market price --address <token> --chain <chain>`
- K-line: `onchainos market kline --address <token> --chain <chain> --bar 1H --limit 24`
- Quote: `onchainos swap quote --from <A> --to <B> --amount <amt> --chain <chain>`
- Swap: `onchainos swap swap --from <A> --to <B> --amount <amt> --chain <chain> --wallet <addr> --slippage <pct>`
- Approve: `onchainos swap approve --token <addr> --amount <amt> --chain <chain>`
- Pool Search: `onchainos defi search --chain <chain> --token "<token0>,<token1>" --product-group DEX_POOL`
- Pool Detail: `onchainos defi detail --investment-id <id> --chain <chain>`
- Calculate Entry: `onchainos defi calculate-entry --investment-id <id> --chain <chain> --tick-lower <tick> --tick-upper <tick>`
- Deposit: `onchainos defi deposit --investment-id <id> --chain <chain> --amount0 <amt> --amount1 <amt> --tick-lower <tick> --tick-upper <tick>`
- Redeem: `onchainos defi redeem --investment-id <id> --chain <chain> --token-id <id> --percent 100`
- Claim Fees: `onchainos defi claim --investment-id <id> --chain <chain> --token-id <id>`
- Positions: `onchainos defi positions --chain <chain>`
- Position Detail: `onchainos defi position-detail --investment-id <id> --chain <chain> --token-id <id>`

## Step 0: Pool Selection (First-Time Setup)

When user has no `config.json` or asks to set up a new pool, trigger this step.

**核心原则**:AI 

README.md

# CL LP Auto-Rebalancer

Uniswap V3 集中流动性自动调仓策略,运行在 EVM L2 链上,通过 OKX OnchainOS 执行 DeFi 操作。

**核心思路:用波动率决定范围宽度。** 低波动率收紧范围提高资本效率,高波动率放宽范围减少调仓和无常损失。结合趋势分析进行不对称调整——看涨时向上延伸范围,看跌时向下延伸。

## 特性

- **波动率自适应范围** — 基于 1H K 线 ATR 动态计算范围宽度
- **趋势不对称调整** — MTF 多时间框架分析,沿趋势方向偏移范围
- **完整调仓流水线** — claim fees → remove liquidity → swap ratio → add liquidity
- **防过度调仓** — 最小持仓时间、日频率限制、Gas 成本检查
- **风控体系** — 止损 / 追踪止损 / IL 容忍度 / 熔断 / 紧急回退部署
- **Gas 感知触发** — 仅在预期手续费收益超过 Gas 成本时调仓

## 架构

```
┌─────────────────────────────────────────────────────┐
│               AI Agent (Claude)                      │
│  策略设计 → 回测验证 → 参数调优 → 复盘迭代          │
└──────────────────────┬──────────────────────────────┘
                       │ 生成 / 优化
┌──────────────────────▼──────────────────────────────┐
│               策略脚本 (Python)                      │
│  价格采集 → 波动率分析 → 范围计算 → 调仓决策 → 执行 │
└──────────────────────┬──────────────────────────────┘
                       │ 调用
┌──────────────────────▼──────────────────────────────┐
│                 onchainos Skills                      │
│  行情 · K线 · 钱包 · LP头寸 · DeFi操作 · TEE签名   │
└──────────────────────┬──────────────────────────────┘
                       │ 上链
┌──────────────────────▼──────────────────────────────┐
│                  EVM L2 链上执行                      │
│       Uniswap V3 池 → LP NFT 头寸 → 手续费收入      │
└─────────────────────────────────────────────────────┘
```

## 范围算法

```
当前价格 → 1H K线 (24根) → ATR% → 波动率分类 → 范围宽度
                                        ↓
                                  趋势不对称调整 (MTF)
                                        ↓
                                  Tick 对齐 → 最终范围
```

| 波动率 | ATR | 范围示例 (ETH@$2000) | 资本效率 |
|--------|-----|---------------------|----------|
| Low (<1.5%) | $25 | $1950–$2050 | ~20× |
| Medium (1.5–3%) | $45 | $1865–$2135 | ~7× |
| High (3–5%) | $70 | $1650–$2350 | ~3× |
| Extreme (>5%) | $120 | $1040–$2960 | ~1× |

详细算法说明见 [references/range-algorithm.md](references/range-algorithm.md)。

## 快速开始

```bash
# 1. 安装
openclaw skill install cl-lp-rebalancer

# 2. 配置
cd ~/.openclaw/skills/cl-lp-rebalancer/references
cp ../.env.example .env    # 填入 API keys + 钱包地址
vi config.json             # 调整池参数

# 3. 测试(只读,安全)
python3 cl_lp.py status

# 4. 注册 cron
zeroclaw cron add '*/5 * * * *' \
  'cd ~/.openclaw/skills/cl-lp-rebalancer/references && set -a && . ../.env && set +a && python3 cl_lp.py tick'
```

## 命令

| 命令 | 用途 | 触发 |
|------|------|------|
| `tick` | 主循环:采集→分析→决策→执行 | Cron 每 5 分钟 |
| `status` | 头寸、范围可视化、收益、趋势 | 手动 |
| `report` | 每日报告 (JSON) | Cron 每天 |
| `history` | 调仓历史 | 手动 |
| `analyze` | 市场分析 + 调仓建议 | AI Agent |
| `reset` | 清除状态,从链上重新检测 | 手动 |
| `close` | 完全退出头寸 | 手动 |
| `deposit <amt>` | 记录外部存取款 | 手动 |
| `resume-trading` | 清除止损恢复交易 | 手动 |

## 目录结构

```
cl-lp-rebalancer/
├── SKILL.md              # AI Agent 核心知识(流水线、状态机、参数)
├── README.md             # 本文件
├── .env.example          # 环境变量模板
└── references/
    ├── cl_lp.py       # 策略代码(零第三方依赖)
    ├── config.json       # 参考配置(所有可调

_meta.json

{
  "ownerId": "kn77stv4k3dgdhawvv873dh7w9837caa",
  "slug": "cl-lp-rebalancer",
  "version": "3.9.2",
  "publishedAt": 1775057642698
}

references/config.json

{
  "investment_id": "326890603",
  "pool_chain": "base",
  "chain_id": "8453",
  "platform_id": "68",
  "native_token": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
  "fee_tier": 0.003,
  "tick_spacing": 60,
  "token0": {
    "symbol": "WETH",
    "address": "0x4200000000000000000000000000000000000006",
    "decimals": 18
  },
  "token1": {
    "symbol": "USDC",
    "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
    "decimals": 6
  },
  "range_mult": {
    "low": 0.5,
    "medium": 0.8,
    "high": 1.2,
    "extreme": 1.5
  },
  "min_range_pct": 0,
  "max_range_pct": 5,
  "asym_factor": 0.3,
  "min_position_age_seconds": 3600,
  "max_rebalances_24h": 6,
  "gas_to_fee_ratio": 0.5,
  "max_il_tolerance_pct": 5.0,
  "edge_proximity_threshold": 0.15,
  "stop_loss_pct": 0.15,
  "trailing_stop_pct": 0.1,
  "slippage_pct": 1,
  "gas_reserve_eth": 0.02,
  "min_trade_usd": 5.0,
  "quiet_interval_seconds": 1800,
  "max_consecutive_errors": 5,
  "cooldown_after_errors_seconds": 3600,
  "initial_investment_usd": 440
}

references/range-algorithm.md

# Range Algorithm Documentation

CL LP Auto-Rebalancer 的核心范围计算算法详解。

## Overview

核心思想:**波动率决定范围宽度**。

```
ATR(24h) → 波动率分类 → 范围乘数 → 趋势不对称调整 → tick 对齐 → 最终范围
```

低波动率时收紧范围以提高资本效率(更多手续费捕获),高波动率时放宽范围以减少调仓频率和无常损失。

## Step 1: ATR Calculation

使用 1H K 线(24 根)计算 Average True Range:

```python
def calc_atr(candles):
    """Calculate ATR from 1H OHLCV candles."""
    true_ranges = []
    for i in range(1, len(candles)):
        high = float(candles[i]["high"])
        low = float(candles[i]["low"])
        prev_close = float(candles[i-1]["close"])
        tr = max(
            high - low,              # 当前 bar 振幅
            abs(high - prev_close),  # 跳空高开
            abs(low - prev_close)    # 跳空低开
        )
        true_ranges.append(tr)
    return sum(true_ranges) / len(true_ranges) if true_ranges else 0

# ATR percentage (relative to current price)
atr_pct = (atr / current_price) * 100
```

**Why ATR over stddev?** ATR 使用 OHLC 数据(包含 bar 内波动),比收盘价标准差更准确地反映真实波动幅度。特别是在有大影线但收盘价变化不大的情况下,ATR 能捕获到 stddev 忽略的波动。

## Step 2: Volatility Classification

将 ATR 百分比映射到波动率等级:

```python
VOL_THRESHOLD_LOW = 1.5      # %
VOL_THRESHOLD_HIGH = 3.0     # %
VOL_THRESHOLD_EXTREME = 5.0  # %

def classify_volatility(atr_pct):
    if atr_pct < VOL_THRESHOLD_LOW:
        return "low"
    elif atr_pct < VOL_THRESHOLD_HIGH:
        return "medium"
    elif atr_pct < VOL_THRESHOLD_EXTREME:
        return "high"
    else:
        return "extreme"
```

| Volatility Class | ATR Range | Market Condition |
|---|---|---|
| Low | < 1.5% | 横盘/低波动,典型的低流动性时段 |
| Medium | 1.5% - 3% | 正常交易,常见日间波动 |
| High | 3% - 5% | 活跃行情,新闻驱动的波动 |
| Extreme | > 5% | 极端事件,黑天鹅,闪崩 |

## Step 3: Base Range Width

每个波动率等级对应一个 ATR 乘数:

```python
VOL_MULTIPLIERS = {
    "low":     1.0,   # 紧凑范围 → 最高资本效率 (Base gas ≈ 0)
    "medium":  2.0,   # 平衡
    "high":    3.5,   # 宽范围 → 减少调仓
    "extreme": 6.0,   # 极宽 → 安全优先
}

def calc_base_range(price, atr, vol_class):
    multiplier = VOL_MULTIPLIERS[vol_class]
    half_width = atr * multiplier
    return (price - half_width, price + half_width)
```

**Examples** (ETH at $2000):

| Vol Class | ATR | Multiplier | Half Width | Range | Width % | Capital Efficiency |
|---|---|---|---|---|---|---|
| Low | $25 (1.25%) | 2× | $50 | $1950-$2050 | 5.0% | 20× |
| Medium | $45 (2.25%) | 3× | $135 | $1865-$2135 | 13.5% | 7.4× |
| High | $70 (3.5%) | 5× | $350 | $1650-$2350 | 35.0% | 2.9× |
| Extreme | $120 (6%) | 8× | $960 | $1040-$2960 | 96.0% | 1.0× |

**Capital Efficiency** = `price / range_width`。越高表示同样的流动性能捕获更多手续费,但出范围的风险也更高。

## Step 4: Trend Asymmetry

复用 grid-trading 的多时间框架 (MTF) 趋势分析,根据趋势方向调整上下范围的不对称性:

```python
TREND_ASYM_FACTOR = 0.3      # 最大不对称比例
TREND_ASYM_THRESHOLD = 0.3   # 激活不对称的最小趋势强度

def apply_trend_asymmetry(lower, upper, price, mtf):
    """Adjust range asymmetrically based on trend direction."""
    trend = mtf.get("trend", "neutral")
    strength = mtf.get("strength", 0)

    if strength < TREND_ASYM_THRESHOLD:
        return lower, upper  # 弱趋势 → 保持对称

   

Sponsored

Ads related to Cl Lp Rebalancer and adjacent AI workflows.