微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🔄

Uniswap 流动性智能再平衡

rebalance-position · vv0.1.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
专业技能 安全 A 级 作者 wpank 公开目录收录
405 下载 106 安装 1.5k 收藏 13.8k 浏览

简介

基于 Uniswap V3/V4 协议的 LP 管理工具,自动将超出价格范围的流动性仓位重置至当前价位区间,恢复手续费收益并优化资本效率。

原始描述

Rebalance an out-of-range Uniswap V3/V4 LP position by closing the old position and opening a new one centered on the current price. Handles fee collection, removal, range calculation, and re-entry in a single workflow. Use when a position is out of range and needs adjustment.

通过你的 Agent 添加

安装目录:rebalance-position/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/rebalance-position/
Codex CLI~/.codex/skills/rebalance-position/
DeepSeek Harness~/.agents/skills/rebalance-position/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

rebalance-position 技能专为 Uniswap V3/V4 流动性提供者(LP)设计,用于自动化处理超出价格区间的 LP 头寸。当市场价格超出用户设定的流动性范围,头寸将停止赚取手续费,形成“闲置资产”。该技能通过委托 liquidity-manager 子代理,在一个完整的工作流中依次完成:收集未领取的手续费、移除旧头寸的流动性、根据当前市场价格计算新的最优区间,并重新添加流动性。此过程包含详细的“重新平衡计划”,涵盖盈亏平衡时间(Break-even Time)和 Gas 费估算,且仅会在用户明确确认后才执行。

显著优点

  1. 提升资金效率:自动恢复头寸的收益状态,解决因监控不及时导致的 15-30% APY 潜在损失。
  2. 一体化的安全流程:内置成本效益分析(如拒绝大小于 10 倍 Gas 的头寸)、价格边界判断及盈亏平衡计算,避免在经济上不合理的操作。
  3. 交互式决策支持:在执行前展示完整的缩进式规划视图,包含头寸状态、新旧区间对比和每一步的交易哈希,提供极强的操作透明度。

潜在缺点或局限性

  1. 无常损失实现:关闭旧头寸会将任何无常损失(IL)转化为实际损失,用户需有心理预期。
  2. Gas 成本敏感性:在以太坊主网,完整重平衡成本高达 30-60 美元,对小规模头寸可能不划算。
  3. 依赖下层代理的安全性:技能本身仅是指令集,实际资金操作由 liquidity-manager 子代理执行,若子代理存在漏洞或执行异常,可能影响资产安全。
  4. NFT ID 变更:重平衡后会销毁旧 NFT 并生成新代币 ID,可能不符合某些依赖原始 ID 的追踪习惯。

适合的目标群体

  • DeFi 主动做市商:需要频繁调整 Uniswap V3/V4 头寸以最大化费用收入的用户。
  • 流动性挖矿参与者:希望自动化监控钱包并修复“出区间”头寸的普通 LP,尤其适合多链(如 Base、Arbitrum)小额头寸持有者。
  • 加密资产管理人:寻求通过自动化工具减少手动干预频率,同时保持头寸生产效率的投资者。

使用该技能可能存在的常规风险

  1. 资产安全风险:该技能来源为个人开发者(T3),信任度相对较低,其委托的子代理在链上直接处理用户资产(代币转账和授权),存在因代码缺陷或恶意行为导致资产丢失的风险。
  2. 性能与依赖风险:完全依赖 Uniswap MCP 工具和外部 RPC 节点的稳定性,若服务受限或网络拥堵,可能引发交易确认延迟或失败。
  3. 工具运行风险:如移除流动性成功但添加新流动性因滑点或 Gas 不足而失败(文档中已预警 Add tx failed 场景),虽资金会退回钱包,但头寸将意外变为单一资产,需手动二次处理。

技能正文


name: rebalance-position description: Rebalance an out-of-range Uniswap V3/V4 LP position by closing the old position and opening a new one centered on the current price. Handles fee collection, removal, range calculation, and re-entry in a single workflow. Use when a position is out of range and needs adjustment. model: opus allowed-tools: [Task(subagent_type:liquidity-manager), mcp__uniswap__get_positions_by_owner, mcp__uniswap__get_position, mcp__uniswap__get_pool_info]

Rebalance Position

Overview

When a V3/V4 LP position goes out of range, it stops earning fees. This skill handles the full rebalance workflow: collect accumulated fees, close the old position, calculate a new optimal range centered on the current price, and open a new position — all in a single operation.

This is a high-value skill because out-of-range positions are effectively dead capital. The difference between a monitored position that gets rebalanced promptly and an unmonitored one can be 15-30% APY in lost fee revenue.

When to Use

Activate when the user says:

  • "Rebalance my position"
  • "My position is out of range"
  • "Adjust my LP range"
  • "Re-center my liquidity"
  • "Position #12345 is out of range, fix it"
  • "My ETH/USDC position stopped earning"
  • "Move my range to the current price"
  • "My LP isn't earning fees anymore"

Also proactively suggest rebalancing when:

  • A track-performance or portfolio-report shows an out-of-range position
  • The user asks "why am I not earning fees?"

Parameters

Parameter Required Default How to Extract
positionId No* — Position ID, or "my ETH/USDC position" (resolved by search)
chain No ethereum Chain where the position lives
newRange No Auto-optimal "narrow" (±5%), "medium" (±15%), "wide" (±50%)

*If no position ID: search with get_positions_by_owner, filter for out-of-range positions, and confirm with the user.

Workflow

Pre-Rebalance Analysis

Before executing anything, gather data and present the situation to the user:

Step 1: IDENTIFY THE POSITION
├── If position ID given → fetch via get_position
├── If "my X/Y position" → search via get_positions_by_owner
│   ├── Filter by token pair and out-of-range status
│   ├── If multiple out-of-range → list all, ask which one
│   └── If none out-of-range → "All your positions are in range!"
└── Validate: confirm the position IS actually out of range

Step 2: ANALYZE CURRENT SITUATION
├── Current pool state via get_pool_info
│   ├── Current price
│   ├── Pool TVL, volume, fee APY
│   └── Tick distribution (where is liquidity concentrated?)
├── Position details
│   ├── Current tick range (lower, upper)
│   ├── How far out of range (above or below?)
│   ├── Uncollected fees
│   ├── Current token balances in position
│   └── Time since going out of range (if estimable)
└── Cost-benefit calculation
    ├── Estimated gas cost for full rebalance (remove + add = ~$30-60 on mainnet)
    ├── Estimated daily fee revenue if rebalanced (from pool APY + position size)
    ├── Break-even time: gas_cost / daily_revenue
    └── If break-even > 30 days → WARN that rebalancing may not be worth it

Present the Rebalance Plan

Before executing, show the user exactly what will happen:

Rebalance Plan for Position #12345

  Current Situation:
    Pool:      WETH/USDC 0.05% (V3, Ethereum)
    Status:    OUT OF RANGE ⚠ (price moved above your range)
    Current:   $1,963
    Your range: $1,500 - $1,800 (position is 9% above upper bound)
    
  Uncollected Fees: 0.01 WETH ($19.60) + 15.20 USDC ($15.20)
  Position Value: ~$3,940

  Proposed New Range:
    Strategy: Medium (±15%)
    Lower:    $1,668 (current - 15%)
    Upper:    $2,258 (current + 15%)
    Expected time-in-range: ~80-85%

  Cost:
    Gas (remove + add): ~$35
    Break-even: ~2 days at current fee APY

  Steps:
    1. Collect uncollected fees ($34.80)
    2. Remove all liquidity from position #12345
    3. Add liquidity at new range ($1,668 - $2,258)
    4. New position created with new NFT ID

  Proceed? (yes/no)

Execution (after user confirms)

Step 3: DELEGATE TO LIQUIDITY-MANAGER
├── The agent executes atomically:
│   a. Collect fees from old position
│   b. Remove 100% liquidity from old position
│   c. Calculate new tick range based on:
│      - Current pool price
│      - Selected range strategy (narrow/medium/wide)
│      - Pool tick spacing
│   d. Approve tokens for new position (if needed)
│   e. Add liquidity at new range
│   f. Each step validated by safety-guardian
└── Returns: old position closed, fees collected, new position ID, new range, tx hashes

Step 4: PRESENT RESULT
├── Confirmation of old position closure
├── Fees collected (amounts + USD)
├── New position details (ID, range, amounts deposited)
├── Total gas cost for the operation
├── Net cost/benefit of the rebalance
└── Next steps for monitoring

Range Strategy Guide

When the user doesn't specify a range, use this decision framework:

Pair Type Recommended Range Width Rationale
Stable-stable Narrow ±0.5% Price barely moves; maximize capital efficiency
Stable-volatile Medium ±15% Balance between earning and avoiding rebalance
Volatile-volatile Wide ±30% Reduce rebalance frequency; accept lower APY
User says "aggressive" Narrow ±5% Higher fees but frequent rebalancing needed
User says "passive" Wide ±50% Low maintenance, lower returns
Small position (<$1K) Wide ±50% Gas costs make frequent rebalancing uneconomical

When NOT to Rebalance

Proactively advise against rebalancing in these situations:

Situation Advice
Position size < 10x gas cost "Gas would cost ${gas} but your position is only ${value}."
Price is near range boundary (within 2%) "Price is close to your range — wait to see if it re-enters."
Position went out of range < 1 hour ago "Give it time — price may return to your range."
User has no strong view on direction "Consider a wider range to reduce future rebalances."
Break-even time > 14 days "At current fee rates, rebalancing won't pay for itself for {days} days."

Output Format

Successful Rebalance

Position Rebalanced Successfully

  Old Position: #12345 (CLOSED)
    Received: 0.52 WETH + 950 USDC ($1,970)
    Fees collected: 0.01 WETH + 15.20 USDC ($34.80)

  New Position: #67890
    Pool: WETH/USDC 0.05% (V3, Ethereum)
    Deposited: 0.51 WETH + 965 USDC ($1,960)
    Range: $1,668 - $2,258 (medium, ±15%)
    Current: $1,963 — IN RANGE ✓
    
  Cost:
    Gas: $32.50 (2 transactions)
    
  Net: Position rebalanced with $2.30 lost to gas
       Now earning ~15-21% APY in fees

  Txs:
    Remove: https://etherscan.io/tx/0x...
    Add:    https://etherscan.io/tx/0x...

  Monitor: "How are my positions doing?" or "Track position #67890"

Position Already In Range

Position #12345 is IN RANGE ✓

  Pool:    WETH/USDC 0.05% (V3, Ethereum)
  Current: $1,963
  Range:   $1,700 - $2,300
  Status:  Actively earning fees

  No rebalance needed. Your position is healthy.
  
  Uncollected fees: $34.80
  Want to collect them? (This doesn't affect your position.)

Important Notes

  • Always confirm before executing. Rebalancing involves closing and reopening a position — it's irreversible.
  • Gas matters. On Ethereum mainnet, a full rebalance costs $30-60 in gas. On L2s (Base, Arbitrum), it's < $1. Factor this into recommendations.
  • IL is locked in. When you close a position, any impermanent loss becomes realized. Mention this if the position has significant IL.
  • New NFT ID. The rebalanced position gets a new NFT token ID. The old one is burned. Make sure the user understands this.
  • V2 positions cannot be rebalanced — they have full range. If a user asks to rebalance a V2 position, explain that V2 positions cover the entire price range and don't go "out of range."
  • Slippage on exit. For large positions relative to pool TVL, exiting may cause slippage. Warn if position is > 5% of pool TVL.

Error Handling

Error User-Facing Message Suggested Action
Position not found "Position #{id} not found." Check ID and chain
Position already in range "Position is already in range — no rebalance needed." Show position status instead
V2 position "V2 positions cover the full price range and can't go out of range." Explain V2 vs V3 differences
Wallet not configured "No wallet configured for transactions." Set WALLET_TYPE + PRIVATE_KEY
Insufficient gas "Not enough ETH for gas." Fund wallet with ETH
Safety check failed "Safety blocked the rebalance: {reason}" Review safety configuration
Remove tx failed "Failed to remove liquidity: {reason}" Check position status and try again
Add tx failed "Removed old position but failed to add new one." Tokens are in wallet; retry add manually
liquidity-manager unavailable "Liquidity agent is not available." Check agent configuration

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

finance-accountingautomationdefiblockchain

同类 Skill