31third safe rebalancer

From modbender/skill-library-mcp · View interactive version

31third safe rebalancer is an AI agent skill from the GitHub repository modbender/skill-library-mcp. Policy-aware Safe portfolio rebalancing assistant for 31Third ExecutorModule.

How to use this skill

Skill file

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:

Prerequisites

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:

What This Skill Does

Execution Safety

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

The skill uses:

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:
  1. Run checkPoliciesVerbose(tradesInput, configInput) before submitting.
  2. Read scheduler and registry from ExecutorModule.
  3. Ensure the signing executor wallet address equals registry (required by onlyRegistry).
  4. Only execute immediate path (executeTradeNow(approvals, encodedTradeData)) when scheduler == registry.
  5. 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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.