31Third Safe Rebalancer:感知策略的 Safe 投资组合再平衡 - Openclaw Skills

作者:互联网

2026-04-17

AI教程

什么是 31Third Safe Rebalancer?

31Third Safe Rebalancer 是一款专门用于维护 Gnosis Safe 账户目标资产配置的工具。通过利用 31Third ExecutorModule,它在投资组合策略与链上执行之间提供了安全桥梁。该技能是 Openclaw Skills 去中心化金融的核心组件,使用户能够自动化监控投资组合偏离并生成符合策略的交易计划。

该工具专注于安全性和合规性,通过读取活跃的链上策略,确保每笔交易都符合定义的滑点边界和资产范围。对于需要严格验证和自动化心跳监控以保持投资组合与投资指令一致的基金管理人和 DAO 库库来说,它具有极高的价值。

下载入口:https://github.com/openclaw/skills/tree/main/skills/phips0812/31third-safe-rebalancer

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install 31third-safe-rebalancer

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 31third-safe-rebalancer。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

31Third Safe Rebalancer 应用场景

  • 自动化 Gnosis Safe 金库的投资组合偏离监控。
  • 执行符合预定义链上安全策略的批量交易。
  • 根据滑点和资产范围限制验证复杂的 DeFi 交易计划。
  • 作为更广泛的 Openclaw Skills 自动化工作流的一部分,实施基于心跳的再平衡警报。
  • 通过单一命令简化从偏离检测到交易执行的再平衡生命周期。
31Third Safe Rebalancer 工作原理
  1. 该技能使用 Viem 连接到区块链,从 31Third ExecutorModule 读取当前余额和活跃的链上策略。
  2. 它计算当前投资组合状态与目标分配权重之间的偏离。
  3. 如果偏离超过阈值,该技能将使用 31Third SDK 生成交易计划,确保所有操作都感知策略。
  4. 它执行详细的策略检查,以验证拟议的交易不会违反任何智能合约限制。
  5. 获得批准后,它会准备必要的代币授权,并通过执行者钱包执行再平衡批量操作。

31Third Safe Rebalancer 配置指南

确保您已安装 Node.js 22+ 和 npm。按照以下步骤将其集成到您的 Openclaw Skills 环境中:

npm install
npm run build

.env 文件中配置您的环境变量:

SAFE_ADDRESS=0xYourSafe
CHAIN_ID=8453
TOT_API_KEY=your_api_key
RPC_URL=https://mainnet.base.org
EXECUTOR_MODULE_ADDRESS=0xYourExecutorModule
EXECUTOR_WALLET_PRIVATE_KEY=0xYourPrivateKey

在运行再平衡器之前,您必须通过 31Third 仪表板部署您的策略栈。

31Third Safe Rebalancer 数据架构与分类体系

该技能管理与投资组合状态、交易配置和执行元数据相关的数据。使用以下架构作为 Openclaw Skills 处理此类数据的指南:

组件 格式 描述
投资组合偏离 百分比 (BPS) 计算出的与目标权重的偏离度。
交易计划 JSON 对象 包含批次的 txDatarequiredAllowances
策略元数据 链上数据 活跃限制,包括资产范围和滑点。
执行结果 交易哈希 链上完成再平衡的记录。
心跳有效载荷 JSON 当满足偏离阈值时触发的警报数据。
name: 31third-safe-rebalancer
description: Policy-aware Safe portfolio rebalancing assistant for 31Third ExecutorModule.
homepage: https://31third.com

31Third Safe Rebalancer

This skill helps you monitor portfolio drift and prepare/execute policy-compliant rebalances on a Gnosis Safe through the 31Third ExecutorModule.

Best-practice usage:

  • Use one-step execution by default: npm run cli -- rebalance-now.
  • Only use separated tools (check_drift, plan_rebalance, execute_rebalance, etc.) if you explicitly understand each step and want manual control.
  • If unsure, run help first (npm run cli -- help) and follow that guidance.

Prerequisites

  • Node.js 22+
  • npm

Local Setup

npm install
npm run build

Getting Started

If you have not deployed your policy stack yet, deploy it first: https://app.31third.com/safe-policy-deployer

Set required environment variables:

SAFE_ADDRESS=0xYourSafe
CHAIN_ID=8453
TOT_API_KEY=your_api_key
RPC_URL=https://mainnet.base.org
EXECUTOR_MODULE_ADDRESS=0xYourExecutorModule
EXECUTOR_WALLET_PRIVATE_KEY=0x...
ORACLE_MAX_AGE_SECONDS=3600
HEARTBEAT_INTERVAL_SECONDS=21600

TOT_API_KEY (31Third API key) can be requested via https://31third.com/contact or by emailing dev@31third.com.

Wallet model and key handling:

  • Safe owner wallet: controls Safe ownership/governance operations. Never share this private key with the skill.
  • Executor wallet: configured as executor on ExecutorModule in the wizard. This private key is required by the skill for execute_rebalance.
  • The final step of the 31Third wizard provides an overview of all required environment variables. Use that as source of truth when configuring this skill.

What This Skill Does

  • Reads active on-chain policies from ExecutorModule.
  • Computes current-vs-target drift (check_drift).
  • Validates trades against Asset Universe + Slippage boundaries (validate_trade).
  • Runs a configurable heartbeat monitor (automation) and returns an alert payload when drift exceeds threshold.
  • Simulates and executes approved rebalance batches (execute_rebalance) with pre-execution checkPoliciesVerbose validation and one retry on unknown execution failures.
  • Accepts SDK plan_rebalance output directly for execution (txData + requiredAllowances) and decodes batch trade calldata internally.
  • Fast-fails execution if scheduler != registry on the ExecutorModule, printing both addresses.
  • Generates SDK-based policy-aware trade plans (plan_rebalance) using current Safe balances (bounded by Asset Universe when present) as baseEntries.
  • Provides one-command execution (rebalance_now) for non-technical users: drift check -> SDK plan -> execution.
  • Returns setup and capability guidance (help).

Execution Safety

Before execution, the agent provides a clear reason, for example:

  • BTC is at 54.00%, target is 50.00% (drift 400 bps). Rebalance required.

The skill uses:

  • Viem publicClient for all reads.
  • Viem walletClient for execution.

Execution Contract (Important)

When using SDK/trading-api rebalancing output, execution must follow this exact pattern:

  1. Build approvals from requiredAllowances as (tokenAddress, neededAllowance).
  2. Decode txData as batchTrade(trades, config).
  3. Re-encode encodedTradeData as ABI tuple:
    • tuple(string,address,uint256,address,uint256,bytes,bytes)[]
    • tuple(bool,bool)
  4. Run checkPoliciesVerbose(tradesInput, configInput) before submitting.
  5. Read scheduler and registry from ExecutorModule.
  6. Ensure the signing executor wallet address equals registry (required by onlyRegistry).
  7. Only execute immediate path (executeTradeNow(approvals, encodedTradeData)) when scheduler == registry.
  8. If scheduler != registry, fail fast and show both addresses.

This is the required execution semantics for this skill and should not be changed to raw passthrough calldata execution.

CLI

Run the bundled CLI:

npm run cli -- help
npm run cli -- check-drift
npm run cli -- automation --last-heartbeat-ms 0
npm run cli -- plan-rebalance --signer 0xYourSigner --min-trade-value 100
npm run cli -- rebalance-now
npm run cli -- validate-trade --trade '{"from":"0x...","to":"0x...","fromAmount":"1000000000000000000","minToReceiveBeforeFees":"990000000000000000"}'
npm run cli -- execute-rebalance --trades '[{"exchangeName":"0x","from":"0x...","fromAmount":"1000000000000000000","to":"0x...","minToReceiveBeforeFees":"990000000000000000","data":"0x...","signature":"0x..."}]' --approvals '[{"token":"0x...","amount":"1000000000000000000"}]'
npm run cli -- execute-rebalance --rebalancing '{"txData":"0x...","requiredAllowances":[{"token":{"address":"0x..."},"neededAllowance":"1000000000000000000"}]}'

Read-only smoke preflight:

npm run smoke -- --signer 0xYourSigner
npm run smoke -- --trades '[...]' --approvals '[...]'

Notes

  • This skill is automation infrastructure, not investment advice.
  • Validate behavior in test/staging before running in production.

相关推荐