← 返回
未分类 Key 中文

31Third Safe Rebalancer

Policy-aware Safe portfolio rebalancing assistant for 31Third ExecutorModule.
政策感知的安全投资组合再平衡助手,适用于31Third执行模块
phips0812 phips0812 来源
未分类 clawhub v0.2.0 1 版本 99852.9 Key: 需要
★ 0
Stars
📥 679
下载
💾 1
安装
1
版本
#alpha#latest

概述

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:

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 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.

版本历史

共 1 个版本

  • v0.2.0 当前
    2026-05-03 04:24 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

professional

All-Market Financial Data Hub

financial-ai-analyst
基于东方财富数据库,支持自然语言查询金融数据,覆盖A股、港股、美股、基金、债券等资产,提供实时行情、公司信息、估值、财务报表等,适用于投资研究、交易复盘、市场监控、行业分析、信用研究、财报审计、资产配置等场景,满足机构与个人需求。返回结果为
★ 125 📥 41,755
professional

Stock Market Pro

kys42
Yahoo Finance (yfinance) 驱动的股票分析技能:行情报价、基本面、ASCII 趋势图、高分辨率图表(RSI/MACD/BB/VWAP/ATR),以及可选的网络...
★ 162 📥 40,105
professional

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 190 📥 62,438