/install 31third-safe-rebalancer
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
helpfirst (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: \x3Chttps://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 \x3Chttps://31third.com/contact> or by emailing [email protected].
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
ExecutorModulein the wizard. This private key is required by the skill forexecute_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-executioncheckPoliciesVerbosevalidation and one retry on unknown execution failures. - Accepts SDK
plan_rebalanceoutput directly for execution (txData+requiredAllowances) and decodes batch trade calldata internally. - Fast-fails execution if
scheduler != registryon theExecutorModule, printing both addresses. - Generates SDK-based policy-aware trade plans (
plan_rebalance) using current Safe balances (bounded by Asset Universe when present) asbaseEntries. - 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
publicClientfor all reads. - Viem
walletClientfor execution.
Execution Contract (Important)
When using SDK/trading-api rebalancing output, execution must follow this exact pattern:
- Build approvals from
requiredAllowancesas(tokenAddress, neededAllowance). - Decode
txDataasbatchTrade(trades, config). - Re-encode
encodedTradeDataas ABI tuple:tuple(string,address,uint256,address,uint256,bytes,bytes)[]tuple(bool,bool)
- Run
checkPoliciesVerbose(tradesInput, configInput)before submitting. - Read
schedulerandregistryfrom ExecutorModule. - Ensure the signing executor wallet address equals
registry(required byonlyRegistry). - Only execute immediate path (
executeTradeNow(approvals, encodedTradeData)) whenscheduler == registry. - 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.
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install 31third-safe-rebalancer - 安装完成后,直接呼叫该 Skill 的名称或使用
/31third-safe-rebalancer触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
31Third Safe Rebalancer 是什么?
Policy-aware Safe portfolio rebalancing assistant for 31Third ExecutorModule. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 315 次。
如何安装 31Third Safe Rebalancer?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install 31third-safe-rebalancer」即可一键安装,无需额外配置。
31Third Safe Rebalancer 是免费的吗?
是的,31Third Safe Rebalancer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
31Third Safe Rebalancer 支持哪些平台?
31Third Safe Rebalancer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 31Third Safe Rebalancer?
由 Phips0812(@phips0812)开发并维护,当前版本 v0.2.0。