← Back to Skills Marketplace
synththoughts

Cl Lp Rebalancer

by SynthThoughts · GitHub ↗ · v3.9.2 · MIT-0
cross-platform ⚠ suspicious
330
Downloads
0
Stars
0
Active Installs
68
Versions
Install in OpenClaw
/install cl-lp-rebalancer
Description
Uniswap V3 集中流动性 LP 自动调仓策略。基于波动率自适应范围宽度:低波动率收紧范围(高资本效率),高波动率放宽范围(减少调仓和 IL)。支持趋势不对称调整、多时间框架分析、自动 claim/remove/swap/deposit 全流程。适用于 EVM L2 链上 CL LP 管理、调仓、范围优化、...
README (SKILL.md)

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 \x3Ctoken> --chain \x3Cchain>
  • K-line: onchainos market kline --address \x3Ctoken> --chain \x3Cchain> --bar 1H --limit 24
  • Quote: onchainos swap quote --from \x3CA> --to \x3CB> --amount \x3Camt> --chain \x3Cchain>
  • Swap: onchainos swap swap --from \x3CA> --to \x3CB> --amount \x3Camt> --chain \x3Cchain> --wallet \x3Caddr> --slippage \x3Cpct>
  • Approve: onchainos swap approve --token \x3Caddr> --amount \x3Camt> --chain \x3Cchain>
  • Pool Search: onchainos defi search --chain \x3Cchain> --token "\x3Ctoken0>,\x3Ctoken1>" --product-group DEX_POOL
  • Pool Detail: onchainos defi detail --investment-id \x3Cid> --chain \x3Cchain>
  • Calculate Entry: onchainos defi calculate-entry --investment-id \x3Cid> --chain \x3Cchain> --tick-lower \x3Ctick> --tick-upper \x3Ctick>
  • Deposit: onchainos defi deposit --investment-id \x3Cid> --chain \x3Cchain> --amount0 \x3Camt> --amount1 \x3Camt> --tick-lower \x3Ctick> --tick-upper \x3Ctick>
  • Redeem: onchainos defi redeem --investment-id \x3Cid> --chain \x3Cchain> --token-id \x3Cid> --percent 100
  • Claim Fees: onchainos defi claim --investment-id \x3Cid> --chain \x3Cchain> --token-id \x3Cid>
  • Positions: onchainos defi positions --chain \x3Cchain>
  • Position Detail: onchainos defi position-detail --investment-id \x3Cid> --chain \x3Cchain> --token-id \x3Cid>

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 应从用户的自然语言中提取意图,自动推断尽可能多的参数,只在信息不足时才追问。

0.1 Intent Recognition

从用户输入中提取:

信息 示例用户输入 提取结果
"在 Base 上做 LP" chain = base
代币对 "ETH/USDC 的流动性" token0 = ETH, token1 = USDC
风险偏好 "稳定一点的" pool_type = stablecoin
Fee tier "0.3% 的池子" fee_tier = 0.3%

缺失信息的默认推断

  • 未指定链 → 推荐 Base(L2 gas 低,适合频繁调仓)
  • 未指定代币对 → 必须追问(核心参数,无法推断)
  • 未指定 fee tier → 根据代币对自动选 TVL 最大的池子
  • 未指定风险偏好 → 从代币对自动分类

0.2 Pool Type Classification

根据代币对自动分类,不需要问用户

类型 判断规则 默认参数集
稳定币对 两个都是稳定币(USDC/USDT/DAI/FRAX) 窄范围、低止损
Native/稳定币 一个是 ETH/WETH/WBTC,另一个是稳定币 标准参数
非稳定币对 两个都不是稳定币,但都是主流币 宽范围、高止损
含 Meme 币 代币不在主流币列表中(市值低、无 Coingecko 排名) 极宽范围 + 强制风险确认

主流币白名单:ETH, WETH, WBTC, USDC, USDT, DAI, FRAX, ARB, OP, MATIC, BNB, AVAX, SOL

0.3 Meme Coin Risk Gate

仅当检测到 meme/低市值代币时触发。MUST display warning before proceeding:

⚠️ Meme 币 LP 额外风险:
1. 极端无常损失 — 价格可能单方向暴涨/暴跌 90%+
2. 流动性枯竭 — 池子 TVL 可能骤降,头寸无法退出
3. 合约风险 — 代币可能有 honeypot/税收/暂停转账等恶意机制
4. 调仓失败 — 低流动性导致 swap 滑点过大

Must get explicit user confirmation before proceeding.

0.4 Search, Rank & Auto-Select

onchainos defi search --chain \x3Cchain> --token "\x3Ctoken0>,\x3Ctoken1>" --product-group DEX_POOL

自动选择逻辑(用户无需手动选):

  1. 按 TVL 降序排列
  2. 如果用户指定了 fee tier → 直接匹配
  3. 如果未指定 → 选 TVL 最大的池子(通常是最佳流动性)
  4. 展示选择结果供用户确认:池名、fee tier、TVL、预估池 APY(rate 字段)

Fee tier 参考(仅在用户问及或多池需选择时展示):

  • 0.01%: 稳定币对 · 0.05%: 高相关性对 · 0.3%: 主流对(推荐)· 1%: 高波动对

0.5 Generate config.json

自动 fetch detail (onchainos defi detail) 并生成 config,无需用户手动填写

字段映射

  • investment_id ← search investmentId
  • chain_id ← search chainIndex
  • platform_id ← detail analysisPlatformId(注意不是 platformId
  • fee_tier ← search feeRate
  • tick_spacing ← 根据 fee tier 推导:0.01%→1, 0.05%→10, 0.3%→60, 1%→200
  • token0/token1 ← detail underlyingToken。如果 token 是 native ETH(0xeee...),LP 合约用 WETH,需映射(Base: 0x4200000000000000000000000000000000000006
  • native_token ← 始终 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(用于 swap 和余额查询)
  • 其余参数 ← 根据 pool type 自动填入下表默认值
{
  "investment_id": "\x3Cauto>",
  "pool_chain": "\x3Cauto>",
  "chain_id": "\x3Cauto>",
  "platform_id": "\x3Cauto>",
  "native_token": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
  "fee_tier": "\x3Cauto>",
  "tick_spacing": "\x3Cauto>",
  "token0": { "symbol": "\x3Cauto>", "address": "\x3Cauto>", "decimals": "\x3Cauto>" },
  "token1": { "symbol": "\x3Cauto>", "address": "\x3Cauto>", "decimals": "\x3Cauto>" },
  "range_mult": { "low": 1.0, "medium": 1.2, "high": 1.5, "extreme": 2.0 },
  "min_range_pct": 2,
  "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
}

Pool-type-specific defaults(自动应用,无需用户选择):

Parameter 稳定币对 Native/稳定币 非稳定币 Meme 池
min_range_pct 0.5 2 3 5
max_range_pct 2 5 8 15
range_mult.low 0.5 1.0 1.2 1.5
range_mult.extreme 1.0 2.0 2.5 3.0
stop_loss_pct 0.05 0.15 0.20 0.30
trailing_stop_pct 0.03 0.10 0.15 0.20
max_il_tolerance_pct 1.0 5.0 8.0 15.0
gas_reserve_eth 0.005 0.02 0.02 0.02

0.6 Gate

  • config.json written with valid investment_id, token0, token1
  • .env configured (copy from .env.example, fill in API credentials + WALLET_ADDR)
  • onchainos wallet balance returns valid balances for the target chain
  • If meme pool: user has explicitly confirmed risk warning

Pipeline: Runtime Steps

CRITICAL RULE: Steps MUST execute in order. Do NOT skip steps or proceed past a gate that has not been satisfied.

Step 1: Data Acquisition

Actions:

  1. Fetch current price via onchainos market price or onchainos swap quote
  2. Fetch current position detail via onchainos defi position-detail (if position exists)
  3. Update price_history (append, cap at 288 = 24h @ 5min)
  4. Fetch on-chain balances via onchainos wallet balance

Gate (ALL must pass):

  • Price is non-null and > 0
  • Circuit breaker not active (consecutive_errors \x3C 5)
  • Stop not triggered (stop_triggered == null)

Step 2: Volatility & Trend Analysis

Actions:

  1. Fetch K-line data (1H candles, 24 bars) → compute ATR-based volatility (hourly cache)
  2. Classify volatility: low (\x3C1.5%), medium (1.5-3%), high (3-5%), extreme (>5%)
  3. Compute multi-timeframe trend analysis (复用 grid-trading MTF):
    • Short EMA (25min), Medium EMA (1h), Long EMA (4h)
    • EMA alignment → trend direction (bullish/bearish/neutral) + strength (0-1)
    • 8h structure detection (uptrend/downtrend/ranging)
  4. Compute 1h and 4h momentum

Output: atr_pct float, vol_class string, mtf dict

Gate:

  • atr_pct is non-null and > 0
  • vol_class is one of: low, medium, high, extreme
  • mtf dict has trend and strength fields (graceful fallback to neutral)

Step 3: Range Calculation

Actions:

  1. Compute range width based on volatility class:
    • Low (\x3C1.5%): 2 × ATR each side → tight range, max capital efficiency
    • Medium (1.5-3%): 3 × ATR each side → balanced
    • High (3-5%): 5 × ATR each side → wide range, fewer rebalances
    • Extreme (>5%): 8 × ATR each side → safety first
  2. Apply trend asymmetry (if trend strength > 0.3):
    • Bullish: upper side wider, lower side tighter (跟随上涨空间)
    • Bearish: lower side wider, upper side tighter (防御下跌空间)
  3. Convert price range to tick range (aligned to pool's tick_spacing)
  4. Compute capital efficiency estimate: price / (upper - lower)

Output: tick_lower, tick_upper, range_width_pct, capital_efficiency

Gate:

  • tick_lower \x3C current_tick \x3C tick_upper
  • Range width >= minimum (2 × tick_spacing)
  • tick values aligned to pool's tick_spacing

Step 4: Rebalance Decision

Actions:

  1. If no existing position → always deploy (first run)
  2. Check rebalance triggers:
    • Out of range: price \x3C lower or price > upper → MUST rebalance
  3. Anti-churn checks:
    • Position age >= MIN_POSITION_AGE (2h)
    • Rebalance count \x3C MAX_REBALANCES_24H (6/day)
    • Gas cost \x3C GAS_TO_FEE_RATIO × expected fees (50%)
    • New range differs >5% from current range
  4. Check stop conditions: stop-loss, trailing stop, IL tolerance

Gate:

  • Rebalance trigger identified, OR no rebalance needed (skip to Step 5)
  • All anti-churn checks passed (if rebalancing)
  • No stop condition triggered

Step 5: Execution & Notification

Actions (if rebalancing):

  1. Claim accumulated fees: onchainos defi claim
  2. Remove liquidity: onchainos defi redeem --percent 100
  3. Calculate target token ratio for new range: onchainos defi calculate-entry
  4. Swap to correct ratio: onchainos swap swap (if needed)
  5. Deposit at new range: onchainos defi deposit
  6. On failure at any sub-step: emergency fallback deploy at 3× normal width
  7. Record rebalance in state, update position info

Actions (always): 8. Calculate performance metrics (PnL, fees claimed, IL, time-in-range) 9. Build structured notification output (see Notification Tiers below)

Output: tiered notification JSON (via ---JSON--- block)

Tool Wrapper: onchainos CLI Reference

Prerequisites

which onchainos  # must be installed
# Auth via environment variables
OKX_API_KEY=...
OKX_SECRET_KEY=...
OKX_PASSPHRASE=...

Core DeFi Operations

Operation Command Key Parameters
Search Pools onchainos defi search --chain base --token "ETH,USDC" --product-group DEX_POOL chain, token, product-group
Pool Detail onchainos defi detail --investment-id \x3Cid> --chain base investment-id
Calculate Entry onchainos defi calculate-entry --investment-id \x3Cid> --chain base --tick-lower \x3Ct> --tick-upper \x3Ct> ticks, amounts
Deposit onchainos defi deposit --investment-id \x3Cid> --chain base --amount0 \x3Ca> --amount1 \x3Ca> --tick-lower \x3Ct> --tick-upper \x3Ct> amounts, ticks
Redeem onchainos defi redeem --investment-id \x3Cid> --chain base --token-id \x3Cnft> --percent 100 token-id, percent
Claim Fees onchainos defi claim --investment-id \x3Cid> --chain base --token-id \x3Cnft> token-id
My Positions onchainos defi positions --chain base chain
Position Detail onchainos defi position-detail --investment-id \x3Cid> --chain base --token-id \x3Cnft> token-id

Market & Swap Operations

Operation Command Key Parameters
Get Price onchainos market price --address \x3Ctoken> --chain base token address
Get K-line onchainos market kline --address \x3Ctoken> --chain base --bar 1H --limit 24 bar size, limit
Swap Quote onchainos swap quote --from \x3CA> --to \x3CB> --amount \x3Camt> --chain base tokens, amount
Execute Swap onchainos swap swap --from \x3CA> --to \x3CB> --amount \x3Camt> --chain base --wallet \x3Caddr> --slippage 1 wallet, slippage
Approve Token onchainos swap approve --token \x3Caddr> --amount \x3Camt> --chain base token, amount

Error Handling Protocol

Every function returns (result, failure_info). Failure info is structured:

failure_info = {
    "reason": str,      # machine-readable: "claim_failed", "redeem_failed", "deposit_failed", etc.
    "detail": str,      # human-readable context
    "retriable": bool,  # safe to auto-retry?
    "hint": str         # "transient_api_error", "retry_with_fresh_quote", "insufficient_balance"
}

Auto-retry policy: 1 retry for retriable=True with 3s delay.

Rebalance failure fallback: if deposit fails after remove, emergency deploy at 3× normal width.

Tunable Parameters

Range Configuration

Parameter Default Description
VOL_MULTIPLIER_LOW 2.0 ATR multiplier for low volatility (\x3C1.5%)
VOL_MULTIPLIER_MED 3.0 ATR multiplier for medium volatility (1.5-3%)
VOL_MULTIPLIER_HIGH 5.0 ATR multiplier for high volatility (3-5%)
VOL_MULTIPLIER_EXTREME 8.0 ATR multiplier for extreme volatility (>5%)
VOL_THRESHOLD_LOW 1.5 Low/medium volatility boundary (%)
VOL_THRESHOLD_HIGH 3.0 Medium/high volatility boundary (%)
VOL_THRESHOLD_EXTREME 5.0 High/extreme volatility boundary (%)
TREND_ASYM_FACTOR 0.3 Max trend asymmetry ratio (0=symmetric, 1=fully asymmetric)
TREND_ASYM_THRESHOLD 0.3 Minimum trend strength to activate asymmetry

Rebalance Triggers

Parameter Default Description
MIN_RANGE_CHANGE_PCT 0.05 Skip rebalance if new range \x3C5% different

Anti-Churn Controls

Parameter Default Description
MIN_POSITION_AGE 7200 2h minimum position hold time (seconds)
MAX_REBALANCES_24H 6 Maximum rebalances per 24h period
GAS_TO_FEE_RATIO 0.5 Skip if gas > 50% of expected fees

Multi-Timeframe Analysis

Parameter Default Description
MTF_SHORT_PERIOD 5 5-bar EMA (25min @ 5min tick)
MTF_MEDIUM_PERIOD 12 12-bar EMA (1h @ 5min tick)
MTF_LONG_PERIOD 48 48-bar EMA (4h @ 5min tick)
MTF_STRUCTURE_PERIOD 96 96-bar (8h) for structure detection

Risk Controls

Parameter Default Description
STOP_LOSS_PCT 0.15 Stop if portfolio drops 15% below cost basis
TRAILING_STOP_PCT 0.10 Stop if portfolio drops 10% from peak
MAX_IL_TOLERANCE_PCT 0.05 Hard stop if IL exceeds 5%
MAX_CONSECUTIVE_ERRORS 5 Circuit breaker threshold
COOLDOWN_AFTER_ERRORS 3600 1h cooldown after circuit breaker trips
GAS_RESERVE 0.003 Native token reserved for gas

Execution

Parameter Default Description
SLIPPAGE_PCT 1 Slippage tolerance for swaps
EMERGENCY_WIDTH_MULT 3.0 Emergency fallback range = 3× normal width
DRY_RUN false Fetch real data but simulate operations

Risk Control Flow

[1] stop_triggered → refuse all operations, emit alert JSON
[2] circuit_breaker (consecutive_errors >= 5) → 1h cooldown, refuse
[3] data validation (price/balance/position null) → refuse
[4] stop-loss / trailing-stop / IL tolerance → set stop_triggered, alert
[5] rebalance frequency (>6/day) → skip rebalance
[6] position age (\x3C2h) → skip rebalance
[7] gas cost check (>50% of expected fees) → skip rebalance
[8] minimum range change (\x3C5%) → skip rebalance
[9] execute rebalance → success / failure with emergency fallback

Operational Interface

Sub-Commands

Command Purpose Trigger Notification
tick 主循环:采集→分析→决策→执行,结果缓存到 _cached_snapshot Cron 每 5min 🔔 Trade Alert / ⚠️ Risk Alert / 📊 Hourly Pulse
status 用户查询入口:Portfolio 总览 + 头寸 + 收益 + 范围。优先读 5min 缓存(秒级响应),过期才实时查询 用户主动 终端输出(不推送)
report 每日绩效报告 Cron 每日 00:00 UTC 📈 Daily Report
history 调仓历史 用户主动 终端输出(不推送)
analyze 详细 JSON 分析(波动率、范围、效率) AI agent 终端输出(不推送)
reset 关闭头寸并重新部署 手动 🔔 Trade Alert
close 完全退出头寸 手动 🔔 Trade Alert

status 触发词(用户说以下任意内容时应调用 status):

  • 查询收益、收益怎么样、赚了多少、PnL、盈亏
  • 查询仓位、头寸状态、LP 状况、仓位情况
  • 年化多少、APY、费用收入、手续费
  • 无常损失、IL
  • 总资产、Portfolio、余额
  • LP 里有多少 ETH / USDC
COMMANDS = {
    "tick": tick, "status": status, "report": report,
    "history": history_cmd, "reset": reset, "close": close,
    "analyze": analyze
}
if __name__ == "__main__":
    cmd = sys.argv[1] if len(sys.argv) > 1 else "tick"
    COMMANDS.get(cmd, tick)()

Notification Tiers

脚本内部封装完整的消息格式化和可视化逻辑,通过 ---JSON--- 块输出结构化数据(含 notification 渲染块),由调度器路由到通信渠道。

Tier 触发条件 推送
Trade Alert 调仓成功或失败 每次交易立即推送
Risk Alert 止损/熔断/连续错误 立即推送
Hourly Pulse 距上次推送 ≥ QUIET_INTERVAL 且无交易 每小时推送
Daily Report report 命令 (cron daily) 每日推送

status/analyze 命令为用户主动查询,直接输出到终端,不推送。status 优先从 _cached_snapshot(每 5min tick 时写入)读取已计算好的数据,无需任何 API 调用即可返回完整状态(Portfolio 跨平台总览 + 头寸 + PnL + IL + APY + LP 代币拆分)。缓存过期(>360s)时自动 fallback 到实时查询。

脚本负责:消息标题、字段组织、范围位置可视化、颜色级别、footer 上下文。调度器只需透传 notification 块到通信平台。

State Schema

{
  "version": 1,
  "pool": {
    "investment_id": "uniswap-v3-base-eth-usdc-3000",
    "chain": "base",
    "chain_id": 8453,
    "token0": "0x4200000000000000000000000000000000000006",
    "token1": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "fee_tier": 3000,
    "tick_spacing": 60
  },
  "position": {
    "token_id": null,
    "tick_lower": null,
    "tick_upper": null,
    "price_lower": null,
    "price_upper": null,
    "created_at": null,
    "created_atr_pct": null,
    "created_vol_class": null
  },
  "price_history": [],
  "vol_history": [],
  "rebalance_history": [
    {
      "time": "ISO timestamp",
      "trigger": "out_of_range",
      "old_range": [-198120, -197400],
      "new_range": [-198300, -197100],
      "fees_claimed_usd": 1.25
    }
  ],
  "stats": {
    "total_rebalances": 0,
    "total_fees_claimed_usd": 0,
    "unclaimed_fee_usd": 0,
    "time_in_range_pct": 100,
    "initial_portfolio_usd": null,
    "total_deposits_usd": 0,
    "portfolio_peak_usd": null,
    "started_at": null,
    "last_check": null
  },
  "errors": {
    "consecutive": 0,
    "cooldown_until": null
  },
  "stop_triggered": null,
  "kline_cache": null,
  "mtf_cache": null,
  "last_quiet_report": null
}

Key fields:

  • pool: target pool configuration (chain, tokens, fee tier, tick spacing)
  • position.token_id: NFT position ID (null if no active position)
  • position.created_atr_pct: ATR at position creation (for vol shift detection)
  • rebalance_history: full audit trail of all rebalances with costs
  • stats.time_in_range_pct: key performance metric — % of ticks where price was in range
  • stats.initial_portfolio_usd + total_deposits_usd: PnL 计算的成本基准
  • stats.total_fees_claimed_usd + unclaimed_fee_usd: LP 手续费总收入,用于推导 IL
  • stop_triggered: string describing trigger condition, or null

Core Algorithm

1. Fetch current price
2. Fetch position detail (if exists)
3. Update price_history (cap at 288 = 24h)
4. Fetch K-line data (1H × 24) → compute ATR volatility (hourly cache)
5. Classify volatility → vol_class (low/medium/high/extreme)
6. Multi-timeframe analysis → trend/strength/momentum/structure
7. Compute optimal range:
   a. Base width = VOL_MULTIPLIER[vol_class] × ATR each side
   b. Apply trend asymmetry (upper/lower sides)
   c. Convert to ticks, align to tick_spacing
8. Check rebalance triggers:
   a. Out of range → must rebalance
9. Anti-churn gates (position age, frequency, gas cost, range change)
10. If rebalancing:
    a. Claim fees → remove liquidity → swap to ratio → deposit at new range
    b. On failure: emergency fallback at 3× width
11. Check stop conditions (stop-loss, trailing stop, IL tolerance)
12. Calculate performance metrics
13. Report status (structured JSON)

Deployment

OpenClaw Cron (recommended)

# Register tick (every 5 minutes)
zeroclaw cron add '*/5 * * * *' \
  'cd ~/.openclaw/skills/cl-lp-rebalancer/references && set -a && . ../.env && set +a && python3 cl_lp.py tick'

# Register daily report (08:00 CST = 00:00 UTC)
zeroclaw cron add '0 0 * * *' \
  'cd ~/.openclaw/skills/cl-lp-rebalancer/references && set -a && . ../.env && set +a && python3 cl_lp.py report'

Manual

# Single tick
python3 cl_lp.py tick

# Dry run (fetch real data, simulate operations)
DRY_RUN=true python3 cl_lp.py tick

# Status check
python3 cl_lp.py status

# Close position and exit
python3 cl_lp.py close

Failure & Rollback

IF rebalance sub-step fails:
  1. Log failure reason to cl_lp.log
  2. Increment errors.consecutive
  3. If errors.consecutive >= 5: trigger circuit breaker (1h cooldown)
  4. If failure after remove liquidity: emergency deploy at 3× normal width
     (priority: get funds back into a position, even if suboptimal)
  5. Report failure via JSON output
  6. On next tick: retry from last successful sub-step if possible

Anti-Patterns

Pattern Problem
Rebalance every tick Gas costs eat all fee income
Too tight range in high vol Constant out-of-range, excessive rebalancing
Too wide range in low vol Capital inefficiency, minimal fee capture
No minimum position age Rapid back-and-forth rebalancing (churn)
Skip emergency fallback Funds sit idle after failed rebalance (zero yield)
Ignore gas costs L1 gas can exceed daily fee income
Symmetric range in trends Miss upside in bull, excess downside in bear
No IL tracking Cannot detect when IL exceeds fee income
Rebalance on vol change alone Minor ATR fluctuations cause unnecessary churn — only rebalance when out of range
No time-in-range tracking Cannot measure strategy effectiveness
Usage Guidance
This skill implements a plausible LP rebalancer, but it reads and will try to use multiple credentials and local config files that were not declared in the registry metadata. Before installing or running it: 1) Inspect the .env.example and config.json in the skill and do not populate unnecessary credentials (use a dedicated, low-value wallet and scoped API keys). 2) Grep cl_lp.py for places it reads home files (~/.openclaw/openclaw.json, ~/.zeroclaw config files) and remove or sandbox those files if you don't want the skill to access them. 3) Run only safe read-only commands first (python3 cl_lp.py status) and check behavior; do not run tick/tick-loop until you fully trust the CLI (onchainos) and the OKX API key/wallet setup. 4) If you use notification integrations (Telegram/Discord), prefer creating new bot tokens/chat IDs dedicated to this skill and avoid reusing tokens that grant broader access. 5) Consider running the skill in an isolated environment (VM/container) and with minimal funds; revoke or rotate any keys used for testing. If you want a lower-risk alternative, ask the author to remove automatic home-directory/config probing and to explicitly document required environment variables in the registry metadata.
Capability Analysis
Type: OpenClaw Skill Name: cl-lp-rebalancer Version: 3.9.2 The cl-lp-rebalancer skill is a sophisticated Uniswap V3 liquidity management tool that uses volatility-adaptive strategies to adjust LP ranges. The core logic in cl_lp.py is well-structured, implementing ATR-based volatility analysis, multi-timeframe trend detection, and automated DeFi operations (claim, redeem, swap, deposit) via the onchainos CLI. It includes robust risk controls such as stop-losses, trailing stops, and circuit breakers, and provides legitimate portfolio tracking for Binance and Hyperliquid. The SKILL.md instructions correctly guide the AI agent through setup and monitoring, including a mandatory risk gate for high-volatility tokens, and the script follows secure coding practices like atomic file writes and safe subprocess execution.
Capability Assessment
Purpose & Capability
The name, README, SKILL.md and Python code consistently implement a Uniswap V3 concentrated-liquidity rebalancer that calls onchainos CLI and OKX APIs — that is coherent. However the packaged code also includes optional integrations (Binance, Hyperliquid, Discord, Telegram) that go beyond the minimal rebalancer requirements; those integrations can be useful but are not declared in the skill metadata.
Instruction Scope
SKILL.md instructs use of onchainos and to create a local .env with API keys (expected). The actual runtime script (_cl_lp.py_) reads many other local config files (e.g., ~/.openclaw/openclaw.json and multiple dotfiles), environment variables, and may pull notification credentials from unrelated configs. Reading home-directory application config files and multiple credential sources is outside the explicit instructions and grants broader data access than the SKILL.md claims.
Install Mechanism
No install spec is provided (instruction-only with included Python scripts). No external downloads or archive extraction are specified, so there is low install-time risk from arbitrary remote code retrieval.
Credentials
The registry metadata declares no required env vars, but the code expects/uses OKX API keys and passphrase, and optionally TELEGRAM_BOT_TOKEN/CHAT_ID, DISCORD_BOT_TOKEN/CHANNEL_ID, BINANCE_API_KEY/SECRET, HL_WALLET_ADDR, etc. The script also attempts to read those tokens from other local configs. Declaring no required credentials while the code accesses many secrets is a mismatch and increases risk of accidental credential exposure.
Persistence & Privilege
The skill is not always-enabled and does not request elevated platform privileges. It writes state and logs locally in its references directory (cl_lp_state.json, cl_lp.log) which is expected for a scheduler/agent. The README suggests user-installed cron jobs but the skill itself does not appear to auto-register persistent system-wide changes.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install cl-lp-rebalancer
  3. After installation, invoke the skill by name or use /cl-lp-rebalancer
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v3.9.2
fix: poll redeem balance arrival (replace sleep 3s), USDC-base fallback swaps ETH before deposit, detect swap revert
v3.9.1
fix: correct USDC sufficiency check after pre-swap; increase balance poll timeout
v3.9.0
feat: auto-swap ETH/USDC to balance ratio before deposit; fix None TypeError in estimate_il
v3.8.2
refactor: remove _emergency_deposit fallback, retry normal path on failure
v3.8.1
fix: dual-token deposit in execute_rebalance and _emergency_deposit via defi_calculate_entry
v3.8.0
feat: verify TX receipts on-chain + dual USD/ETH PnL tracking
v3.7.1
fix: only adopt positions created after deposit, not old ones with wrong tick ranges
v3.7.0
feat: adopt unverified positions instead of creating dust — prevent dust NFTs at source
v3.6.3
refactor: threshold-based cleanup — ratio 1 for normal, user-input for dust NFTs
v3.6.2
fix: pass exact token amounts in V3 redeem to prevent dust NFT residuals
v3.6.1
feat: auto-cleanup orphaned LP positions throughout rebalance lifecycle
v3.5.4
fix: defensive type check for errors state field — handles legacy list format
v3.6.0
fix: add auto-resume limit (2/24h), deposit verification retry (3x), and auto-pause on consecutive deposit failures
v3.5.3
添加残余仓位自动清理、钱包地址追踪、deposit验证重试
v3.5.2
fix: coinAmount in deposit now uses minimal units (70 USDC = 70000000), was incorrectly passing human-readable amount. Also add --force balance refresh on critical paths to bypass stale cache.
v3.5.1
fix: verify on-chain position value after deposit, fallback to emergency if tx reverted
v3.5.0
fix: properly track LP fee claims in close(), reset(), and skip-claim+redeem paths
v3.4.2
fix: stop sending Discord notifications on rebalance failure
v3.4.1
perf: tighten range multipliers (low=0.5, med=0.8, high=1.2, extreme=1.5), remove min_range_pct floor
v3.4.0
refactor: only rebalance on out_of_range; removed time_decay and volatility_shift triggers
Metadata
Slug cl-lp-rebalancer
Version 3.9.2
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 68
Frequently Asked Questions

What is Cl Lp Rebalancer?

Uniswap V3 集中流动性 LP 自动调仓策略。基于波动率自适应范围宽度:低波动率收紧范围(高资本效率),高波动率放宽范围(减少调仓和 IL)。支持趋势不对称调整、多时间框架分析、自动 claim/remove/swap/deposit 全流程。适用于 EVM L2 链上 CL LP 管理、调仓、范围优化、... It is an AI Agent Skill for Claude Code / OpenClaw, with 330 downloads so far.

How do I install Cl Lp Rebalancer?

Run "/install cl-lp-rebalancer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Cl Lp Rebalancer free?

Yes, Cl Lp Rebalancer is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Cl Lp Rebalancer support?

Cl Lp Rebalancer is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Cl Lp Rebalancer?

It is built and maintained by SynthThoughts (@synththoughts); the current version is v3.9.2.

💬 Comments