index-bot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Index Bot

指数机器人(Index Bot)

Build a weighted basket of assets from one instruction, buy the whole basket in one pass, and rebalance on a cadence when weights drift. This skill is a thin strategy layer: it decides what to buy and how much, then delegates every quote, approval, swap, and signing step to existing skills.
Runtime Compatibility: This skill uses
AskUserQuestion
for interactive prompts. If
AskUserQuestion
is not available in your runtime, collect the same parameters through natural language conversation instead.
通过一条指令构建加权资产篮子,一次性买入全部篮子资产,并在权重偏离时定期再平衡。此Skill是一个轻量策略层:它决定买入什么、买入多少,然后将每一步报价、授权、交换和签名操作都委托给现有Skill执行。
运行时兼容性: 此Skill使用
AskUserQuestion
进行交互式提示。如果你的运行时不支持
AskUserQuestion
,则通过自然语言对话收集相同的参数。

Overview

概述

From a single prompt (for example "equal-weight basket of the top 5 RWAs, rebalance weekly"), index-bot:
  1. Parses the basket spec (explicit assets with weights, or a top-N ranking request).
  2. Resolves each asset to a token address and computes per-leg sizing.
  3. Applies guardrails (spend cap, token allowlist, dry-run).
  4. Delegates each buy to the swap-integration Trading API flow on the target chain.
  5. Records target weights and the last rebalance in a state file.
On a later invocation by the host scheduler, it reads current positions, computes drift versus target weights, generates the adjusting swaps, and delegates them.
The trigger is twofold: a prompt to create the basket, and the host scheduler (cron or the agent runtime wake-up) for each rebalance run.
仅需一条提示词(例如“前5个RWA的等权重篮子,每周再平衡”),index-bot即可:
  1. 解析篮子规格(明确的带权重资产列表,或前N名排名请求)。
  2. 将每个资产解析为代币地址,并计算每笔交易的规模。
  3. 应用防护规则(支出上限、代币白名单、试运行)。
  4. 将每笔买入操作委托给目标链上的swap-integration Trading API流程。
  5. 在状态文件中记录目标权重和上次再平衡时间。
在后续由主机调度器调用时,它会读取当前持仓,计算与目标权重的偏差,生成调整交换,并委托执行。
触发方式有两种:创建篮子的提示词,以及每次再平衡运行时的主机调度器(cron或Agent运行时唤醒)。

Prerequisites

前置条件

This skill does not reimplement swap execution. It depends on:
  • swap-integration (uniswap-trading): the only execution path. Every buy and rebalance leg goes through its Trading API flow (
    check_approval
    then
    quote
    then
    swap
    , then sign and broadcast). Do not reimplement any of it.
  • v4-sdk-integration (uniswap-trading): LP execution, only if a leg also seeds or manages a liquidity position. Default index baskets are spot-only and do not need this.
  • viem-integration (uniswap-viem): accounts, signing, transaction broadcast, and reading on-chain balances for the drift calculation.
Read these plugin references before acting and treat them as ground truth:
  • selected target-chain template: chainId, chain name, contract addresses, tradable token source, funding constraints, market-data availability, and template-specific caveats. For the reference Robinhood Chain template, see
    ../../references/robinhood-chain.md
    .
  • ../../references/execution-model.md
    : the Trading API requirement, execution modes, restrictions, and disclaimer rules.
  • ../../references/strategy-state.md
    : the shared state file and scheduler pattern.
此Skill不会重新实现交换执行逻辑。它依赖于:
  • swap-integration(uniswap-trading):唯一的执行路径。每笔买入和再平衡交易都通过其Trading API流程执行(
    check_approval
    quote
    swap
    ,然后签名并广播)。请勿重新实现其中任何部分。
  • v4-sdk-integration(uniswap-trading):LP执行,仅当某笔交易还需要注入或管理流动性头寸时使用。默认指数篮子仅支持现货,不需要此依赖。
  • viem-integration(uniswap-viem):账户、签名、交易广播,以及读取链上余额用于偏差计算。
操作前请阅读以下插件参考文档,并将其作为权威依据:
  • 所选目标链模板:chainId、链名称、合约地址、可交易代币来源、资金限制、市场数据可用性,以及模板特定注意事项。关于Robinhood Chain参考模板,请参见
    ../../references/robinhood-chain.md
  • ../../references/execution-model.md
    :Trading API要求、执行模式、限制和免责声明规则。
  • ../../references/strategy-state.md
    :共享状态文件和调度器模式。

Template inputs

模板输入

The selected target-chain template must provide:
  • chain id, chain name, native gas token, and RPC / read path.
  • deployed Uniswap router, Permit2, and quoter / state-reader addresses needed by delegated execution and valuation.
  • optional v4 PoolManager / PositionManager addresses if the basket also manages LP positions.
  • tradable token resolution rules, including any token list, ranking source, or allowlist source.
  • funding constraints, market-data availability, transfer-restriction caveats, and market-hours guidance.
所选目标链模板必须提供:
  • 链ID、链名称、原生Gas代币,以及RPC/读取路径。
  • 已部署的Uniswap路由器、Permit2,以及委托执行和估值所需的报价器/状态读取器地址。
  • 可选的v4 PoolManager/PositionManager地址(如果篮子还管理LP头寸)。
  • 可交易代币解析规则,包括任何代币列表、排名来源或白名单来源。
  • 资金限制、市场数据可用性、转账限制注意事项,以及交易时间指引。

Workflow

工作流程

Step 1: Parse the basket spec

步骤1:解析篮子规格

Extract the basket definition from the prompt:
ParameterRequiredExample
AssetsYesexplicit list, or "top 5 RWAs"
WeightingYes
equal
, or custom weights summing to 1
Total sizeYes
1000 USDG
,
0.5 ETH
Funding tokenYesthe token spent to buy each leg
Rebalance cadenceYes
weekly
,
monthly
,
none
Drift thresholdNorebalance only when a leg drifts > X%
Spend capsYesper-run and per-period caps in token terms
If the prompt asks for a top-N ranking ("top 5 RWAs"), there is no default ranking source, so do NOT invent or guess a ranking. If the selected template provides an indexer or ranking source and the operator instructs you to use it, use that source. Otherwise ask the user for an explicit asset list via
AskUserQuestion
and proceed from that list. If any other required parameter is missing, including per-run or per-period spend caps, use
AskUserQuestion
with structured options to collect it.
从提示词中提取篮子定义:
参数是否必填示例
资产(Assets)明确列表,或“前5个RWA”
权重方式(Weighting)
equal
(等权重),或总和为1的自定义权重
总规模(Total size)
1000 USDG
0.5 ETH
资金代币(Funding token)用于购买每笔交易的代币
再平衡频率(Rebalance cadence)
weekly
(每周)、
monthly
(每月)、
none
(不调整)
偏差阈值(Drift threshold)仅当某笔交易偏差超过X%时再平衡
支出上限(Spend caps)以代币计价的单次运行和周期上限
如果提示词要求前N名排名(“前5个RWA”),由于没有默认排名来源,请勿编造或猜测排名。如果所选模板提供了索引器或排名来源,且操作员指示你使用它,则使用该来源。否则通过
AskUserQuestion
向用户索要明确的资产列表,然后基于该列表继续操作。如果缺少任何其他必填参数,包括单次运行或周期支出上限,请使用带结构化选项的
AskUserQuestion
来收集。

Step 2: Resolve tokens and per-leg sizing

步骤2:解析代币并计算每笔交易规模

For each asset:
  1. Resolve the symbol to a token address from the selected target-chain template and its token source. Do not maintain a local registry. If a requested asset cannot resolve from the template's token source, stop and report it rather than guessing.
  2. Compute the target notional per leg:
    legNotional = totalSize * weight
    . Price any cross-token sizing with Uniswap quotes (Trading API
    /quote
    via
    swap-integration
    , or
    V4Quoter
    via
    v4-sdk-integration
    ), never an external feed or venue-specific API.
  3. Record the funding-token amount to spend on that leg.
Verify each resolved address is a contract before sizing. If an asset cannot be resolved on the target chain, stop and report it rather than guessing.
对于每个资产:
  1. 从所选目标链模板及其代币来源将符号解析为代币地址。请勿维护本地注册表。如果请求的资产无法从模板的代币来源解析,请停止并报告,不要猜测。
  2. 计算每笔交易的目标名义价值:
    legNotional = totalSize * weight
    。任何跨代币规模计算都使用Uniswap报价(通过
    swap-integration
    调用Trading API的
    /quote
    ,或通过
    v4-sdk-integration
    调用
    V4Quoter
    ),切勿使用外部数据源或特定平台的API。
  3. 记录该笔交易要花费的资金代币数量。
在计算规模前,请验证每个解析出的地址都是合约地址。如果某个资产无法在目标链上解析,请停止并报告,不要猜测。

Step 3: Guardrails

步骤3:防护规则

Before any execution:
  • Ask the operator for any missing per-run or per-period spend cap using
    AskUserQuestion
    (or natural language if unavailable); include the funding token or denomination used for comparison. If either cap remains unset, do not enter
    autonomous
    mode.
  • Confirm the basket total is within the configured spend cap (per run and per period).
  • Confirm every leg token is on the operator's allowlist.
  • Run a dry-run first that prints each planned leg (token, amount, weight) for review.
  • Confirm equity market hours if any leg is a RWA (off-hours liquidity may be thin).
  • Per leg, check the wallet can cover that leg: it must hold enough of the funding token (
    tokenIn
    ) for the leg's buy amount and enough native gas to broadcast. If a leg is short on either, skip that leg and report it, then continue the rest of the basket. Follow the selected template's funding constraints; the skill does not auto-fund, bridge, or top up unless that behavior is explicitly provided outside the skill.
在任何执行操作之前:
  • 使用
    AskUserQuestion
    (如果不可用则用自然语言)向操作员询问缺失的单次运行或周期支出上限;包含用于比较的资金代币或计价单位。如果任一上限仍未设置,请勿进入
    autonomous
    (自主)模式。
  • 确认篮子总金额在配置的支出上限(单次运行和周期)内。
  • 确认每笔交易的代币都在操作员的白名单中。
  • 先运行试运行,打印每笔计划交易(代币、金额、权重)以供审核。
  • 如果任何交易涉及RWA,请确认股票市场交易时间(非交易时间流动性可能不足)。
  • 逐笔检查钱包是否有足够资金支付:钱包必须持有足够的资金代币(
    tokenIn
    )以支付该笔买入金额,以及足够的原生Gas以广播交易。如果某笔交易的任一条件不满足,则跳过该笔交易并报告,然后继续执行篮子的其余部分。请遵循所选模板的资金限制;此Skill不会自动注资、跨链桥接或充值,除非该功能由Skill外部明确提供。

Step 4: Buy the basket (delegate)

步骤4:买入篮子(委托执行)

For each leg, delegate to the swap-integration Trading API flow:
check_approval
then
quote
then
swap
, then sign and broadcast via viem. Pass the target chain id and that chain's router / token addresses from the selected template.
Do NOT reimplement quoting, approvals, swap-body construction, or signing. Sequence legs with a short delay to respect Trading API rate limits, and handle a failed leg without abandoning the rest of the basket (report it and continue).
对于每笔交易,委托给swap-integration Trading API流程:
check_approval
quote
swap
,然后通过viem签名并广播。传入目标链ID以及所选模板中该链的路由器/代币地址。
请勿重新实现报价、授权、交换体构建或签名逻辑。每笔交易之间短暂延迟,以遵守Trading API的速率限制;处理失败的交易时不要放弃篮子的其余部分(报告失败并继续)。

Step 5: Record target weights

步骤5:记录目标权重

After the buys succeed, write the target weights and the rebalance metadata to the state file (see
../../references/strategy-state.md
). This is what later drift calculations compare against.
买入成功后,将目标权重和再平衡元数据写入状态文件(参见
../../references/strategy-state.md
)。后续偏差计算将以此为基准。

Rebalance loop

再平衡循环

On each scheduled invocation:
  1. Read state to load target weights and
    lastRebalanceAt
    .
  2. Check idempotency: if this cadence period was already rebalanced, skip.
  3. Read current on-chain balances for each leg via viem and value them in the funding token using Uniswap quotes (Trading API
    /quote
    via
    swap-integration
    , or
    V4Quoter
    /
    StateView
    via
    v4-sdk-integration
    ) to get current weights. Do not use venue-specific APIs or external price feeds; see
    ../../references/execution-model.md
    (Data and pricing).
  4. Compute drift per leg:
    drift = currentWeight - targetWeight
    . Compare the absolute drift
    |drift|
    against the threshold so both overweight (
    drift > 0
    ) and underweight (
    drift < 0
    ) legs are caught. If no leg's
    |drift|
    exceeds the drift threshold, do nothing and update
    lastRebalanceAt
    .
  5. Generate the adjusting swaps: sell overweight legs, buy underweight legs, to return each leg to its target.
  6. Delegate each adjusting swap to the swap-integration Trading API flow exactly as in Step 4.
  7. Update state with the new
    lastRebalanceAt
    and any changed positions.
在每次调度调用时:
  1. 读取状态,加载目标权重和
    lastRebalanceAt
    (上次再平衡时间)。
  2. 检查幂等性:如果该周期已经执行过再平衡,则跳过。
  3. 通过viem读取每笔交易的当前链上余额,并使用Uniswap报价(通过
    swap-integration
    调用Trading API的
    /quote
    ,或通过
    v4-sdk-integration
    调用
    V4Quoter
    /
    StateView
    )将其换算为资金代币价值,以得到当前权重。请勿使用特定平台的API或外部价格数据源;参见
    ../../references/execution-model.md
    (数据与定价)。
  4. 计算每笔交易的偏差:
    drift = currentWeight - targetWeight
    。将绝对偏差
    |drift|
    与阈值进行比较,这样超配(
    drift > 0
    )和低配(
    drift < 0
    )的交易都会被检测到。如果没有任何交易的
    |drift|
    超过偏差阈值,则不执行任何操作,仅更新
    lastRebalanceAt
  5. 生成调整交换:卖出超配的交易,买入低配的交易,使每笔交易回到目标权重。
  6. 将每笔调整交换完全按照步骤4的方式委托给swap-integration Trading API流程。
  7. 使用新的
    lastRebalanceAt
    和任何变动的头寸更新状态。

Execution mode

执行模式

This skill exposes the shared execution mode from
../../references/execution-model.md
:
ModeBehavior
confirm
(default)
Ask the user to approve every transaction before broadcast.
autonomous
Execute without per-transaction prompts, only within guardrails.
Default to
confirm
. Autonomous mode requires all of: a spend cap (per run and per period), a token allowlist, a dry-run first, and a kill switch. A basket buy is many transactions, so under
confirm
summarize the full basket and confirm once per run where the runtime allows, otherwise per leg.
此Skill提供
../../references/execution-model.md
中定义的共享执行模式:
模式行为描述
confirm
(默认)
每笔交易广播前都要求用户批准。
autonomous
(自主)
无需逐笔交易提示,仅在防护规则范围内执行。
默认为
confirm
模式。自主模式需要满足所有以下条件:支出上限(单次运行和周期)、代币白名单、先试运行、紧急停止开关。篮子买入涉及多笔交易,因此在
confirm
模式下,如果运行时允许,请汇总整个篮子的信息,每次运行确认一次,否则逐笔确认。

State

状态

State follows
../../references/strategy-state.md
. index-bot stores the target weights and the last rebalance so drift can be computed on the next run:
Each run reads state first and updates it only after a successful broadcast, so reruns within a period do not double-buy or double-rebalance.
状态遵循
../../references/strategy-state.md
的规范。index-bot存储目标权重和上次再平衡时间,以便下次运行时计算偏差:
每次运行都会先读取状态,仅在广播成功后才更新状态,因此同一周期内的重复运行不会导致重复买入或重复再平衡。

Restrictions and Disclaimers

限制与免责声明

RWA gating is template-specific and may be enforced at the token level (transfer-restricted ERC-20s), so a leg can revert at transfer time even when the router accepts the quote. This skill must:
  1. Handle transfer-restriction reverts per leg gracefully and report which leg reverted.
  2. Not assume a pool-level or router-level allowlist exists.
  3. Respect equity market hours; some RWAs may have off-hours liquidity limits.
  4. Surface the financial disclaimers in the repo root
    DISCLAIMER.md
    before executing.
See
../../references/execution-model.md
for the full restrictions and disclaimer rules.
RWA准入是模板特定的,可能在代币层面强制执行(受转账限制的ERC-20),因此即使路由器接受了报价,交易也可能在转账时失败。此Skill必须:
  1. 优雅处理每笔交易的转账限制失败,并报告哪笔交易失败。
  2. 不要假设存在池层面或路由器层面的白名单。
  3. 遵守股票市场交易时间;部分RWA在非交易时间可能有流动性限制。
  4. 执行前展示仓库根目录
    DISCLAIMER.md
    中的财务免责声明。
完整的限制和免责声明规则请参见
../../references/execution-model.md

Input validation

输入验证

Before interpolating ANY user-provided value into generated code, API calls, or shell commands:
  • Token addresses: MUST match
    ^0x[a-fA-F0-9]{40}$
    ; reject otherwise.
  • Amounts and notionals: MUST be non-negative numeric values matching
    ^[0-9]+\.?[0-9]*$
    .
  • Weights: MUST each be in
    [0, 1]
    and the full set MUST sum to
    1
    (within a small tolerance). Reject a basket whose weights do not sum to 1.
  • Chain id: MUST be the operator-configured target chain id, read from the selected template rather than hardcoded.
  • API keys: MUST come from environment variables, never hardcoded.
  • REJECT any input containing shell metacharacters:
    ;
    ,
    |
    ,
    &
    ,
    $
    ,
    `
    ,
    (
    ,
    )
    ,
    >
    ,
    <
    ,
    \
    ,
    '
    ,
    "
    , newlines.
在将任何用户提供的值插入生成的代码、API调用或Shell命令之前:
  • 代币地址:必须匹配
    ^0x[a-fA-F0-9]{40}$
    ;否则拒绝。
  • 金额和名义价值:必须为非负数值,匹配
    ^[0-9]+\.?[0-9]*$
  • 权重:每个权重必须在
    [0, 1]
    范围内,且所有权重之和必须为
    1
    (在小误差范围内)。拒绝权重总和不为1的篮子。
  • 链ID:必须是操作员配置的目标链ID,从所选模板读取,而非硬编码。
  • API密钥:必须来自环境变量,绝对不能硬编码。
  • 拒绝任何包含Shell元字符的输入:
    ;
    |
    &
    $
    `
    (
    )
    >
    <
    \
    '
    "
    、换行符。