index-bot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIndex 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 usesfor interactive prompts. IfAskUserQuestionis not available in your runtime, collect the same parameters through natural language conversation instead.AskUserQuestion
通过一条指令构建加权资产篮子,一次性买入全部篮子资产,并在权重偏离时定期再平衡。此Skill是一个轻量策略层:它决定买入什么、买入多少,然后将每一步报价、授权、交换和签名操作都委托给现有Skill执行。
运行时兼容性: 此Skill使用进行交互式提示。如果你的运行时不支持AskUserQuestion,则通过自然语言对话收集相同的参数。AskUserQuestion
Overview
概述
From a single prompt (for example "equal-weight basket of the top 5 RWAs, rebalance weekly"), index-bot:
- Parses the basket spec (explicit assets with weights, or a top-N ranking request).
- Resolves each asset to a token address and computes per-leg sizing.
- Applies guardrails (spend cap, token allowlist, dry-run).
- Delegates each buy to the swap-integration Trading API flow on the target chain.
- 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即可:
- 解析篮子规格(明确的带权重资产列表,或前N名排名请求)。
- 将每个资产解析为代币地址,并计算每笔交易的规模。
- 应用防护规则(支出上限、代币白名单、试运行)。
- 将每笔买入操作委托给目标链上的swap-integration Trading API流程。
- 在状态文件中记录目标权重和上次再平衡时间。
在后续由主机调度器调用时,它会读取当前持仓,计算与目标权重的偏差,生成调整交换,并委托执行。
触发方式有两种:创建篮子的提示词,以及每次再平衡运行时的主机调度器(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 (then
check_approvalthenquote, then sign and broadcast). Do not reimplement any of it.swap - 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 - : the Trading API requirement, execution modes, restrictions, and disclaimer rules.
../../references/execution-model.md - : the shared state file and scheduler pattern.
../../references/strategy-state.md
此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 - :Trading API要求、执行模式、限制和免责声明规则。
../../references/execution-model.md - :共享状态文件和调度器模式。
../../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:
| Parameter | Required | Example |
|---|---|---|
| Assets | Yes | explicit list, or "top 5 RWAs" |
| Weighting | Yes | |
| Total size | Yes | |
| Funding token | Yes | the token spent to buy each leg |
| Rebalance cadence | Yes | |
| Drift threshold | No | rebalance only when a leg drifts > X% |
| Spend caps | Yes | per-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 and proceed from that list. If any other required parameter is missing, including per-run or per-period spend caps, use with structured options to collect it.
AskUserQuestionAskUserQuestion从提示词中提取篮子定义:
| 参数 | 是否必填 | 示例 |
|---|---|---|
| 资产(Assets) | 是 | 明确列表,或“前5个RWA” |
| 权重方式(Weighting) | 是 | |
| 总规模(Total size) | 是 | |
| 资金代币(Funding token) | 是 | 用于购买每笔交易的代币 |
| 再平衡频率(Rebalance cadence) | 是 | |
| 偏差阈值(Drift threshold) | 否 | 仅当某笔交易偏差超过X%时再平衡 |
| 支出上限(Spend caps) | 是 | 以代币计价的单次运行和周期上限 |
如果提示词要求前N名排名(“前5个RWA”),由于没有默认排名来源,请勿编造或猜测排名。如果所选模板提供了索引器或排名来源,且操作员指示你使用它,则使用该来源。否则通过向用户索要明确的资产列表,然后基于该列表继续操作。如果缺少任何其他必填参数,包括单次运行或周期支出上限,请使用带结构化选项的来收集。
AskUserQuestionAskUserQuestionStep 2: Resolve tokens and per-leg sizing
步骤2:解析代币并计算每笔交易规模
For each asset:
- 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.
- Compute the target notional per leg: . Price any cross-token sizing with Uniswap quotes (Trading API
legNotional = totalSize * weightvia/quote, orswap-integrationviaV4Quoter), never an external feed or venue-specific API.v4-sdk-integration - 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.
对于每个资产:
- 从所选目标链模板及其代币来源将符号解析为代币地址。请勿维护本地注册表。如果请求的资产无法从模板的代币来源解析,请停止并报告,不要猜测。
- 计算每笔交易的目标名义价值:。任何跨代币规模计算都使用Uniswap报价(通过
legNotional = totalSize * weight调用Trading API的swap-integration,或通过/quote调用v4-sdk-integration),切勿使用外部数据源或特定平台的API。V4Quoter - 记录该笔交易要花费的资金代币数量。
在计算规模前,请验证每个解析出的地址都是合约地址。如果某个资产无法在目标链上解析,请停止并报告,不要猜测。
Step 3: Guardrails
步骤3:防护规则
Before any execution:
- Ask the operator for any missing per-run or per-period spend cap using (or natural language if unavailable); include the funding token or denomination used for comparison. If either cap remains unset, do not enter
AskUserQuestionmode.autonomous - 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 () 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.
tokenIn
在任何执行操作之前:
- 使用(如果不可用则用自然语言)向操作员询问缺失的单次运行或周期支出上限;包含用于比较的资金代币或计价单位。如果任一上限仍未设置,请勿进入
AskUserQuestion(自主)模式。autonomous - 确认篮子总金额在配置的支出上限(单次运行和周期)内。
- 确认每笔交易的代币都在操作员的白名单中。
- 先运行试运行,打印每笔计划交易(代币、金额、权重)以供审核。
- 如果任何交易涉及RWA,请确认股票市场交易时间(非交易时间流动性可能不足)。
- 逐笔检查钱包是否有足够资金支付:钱包必须持有足够的资金代币()以支付该笔买入金额,以及足够的原生Gas以广播交易。如果某笔交易的任一条件不满足,则跳过该笔交易并报告,然后继续执行篮子的其余部分。请遵循所选模板的资金限制;此Skill不会自动注资、跨链桥接或充值,除非该功能由Skill外部明确提供。
tokenIn
Step 4: Buy the basket (delegate)
步骤4:买入篮子(委托执行)
For each leg, delegate to the swap-integration Trading API flow: then then , then sign and broadcast via viem. Pass the target chain id and that chain's router / token addresses from the selected template.
check_approvalquoteswapDo 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流程: → → ,然后通过viem签名并广播。传入目标链ID以及所选模板中该链的路由器/代币地址。
check_approvalquoteswap请勿重新实现报价、授权、交换体构建或签名逻辑。每笔交易之间短暂延迟,以遵守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 ). This is what later drift calculations compare against.
../../references/strategy-state.md买入成功后,将目标权重和再平衡元数据写入状态文件(参见)。后续偏差计算将以此为基准。
../../references/strategy-state.mdRebalance loop
再平衡循环
On each scheduled invocation:
- Read state to load target weights and .
lastRebalanceAt - Check idempotency: if this cadence period was already rebalanced, skip.
- Read current on-chain balances for each leg via viem and value them in the funding token using Uniswap quotes (Trading API via
/quote, orswap-integration/V4QuoterviaStateView) to get current weights. Do not use venue-specific APIs or external price feeds; seev4-sdk-integration(Data and pricing).../../references/execution-model.md - Compute drift per leg: . Compare the absolute drift
drift = currentWeight - targetWeightagainst the threshold so both overweight (|drift|) and underweight (drift > 0) legs are caught. If no leg'sdrift < 0exceeds the drift threshold, do nothing and update|drift|.lastRebalanceAt - Generate the adjusting swaps: sell overweight legs, buy underweight legs, to return each leg to its target.
- Delegate each adjusting swap to the swap-integration Trading API flow exactly as in Step 4.
- Update state with the new and any changed positions.
lastRebalanceAt
在每次调度调用时:
- 读取状态,加载目标权重和(上次再平衡时间)。
lastRebalanceAt - 检查幂等性:如果该周期已经执行过再平衡,则跳过。
- 通过viem读取每笔交易的当前链上余额,并使用Uniswap报价(通过调用Trading API的
swap-integration,或通过/quote调用v4-sdk-integration/V4Quoter)将其换算为资金代币价值,以得到当前权重。请勿使用特定平台的API或外部价格数据源;参见StateView(数据与定价)。../../references/execution-model.md - 计算每笔交易的偏差:。将绝对偏差
drift = currentWeight - targetWeight与阈值进行比较,这样超配(|drift|)和低配(drift > 0)的交易都会被检测到。如果没有任何交易的drift < 0超过偏差阈值,则不执行任何操作,仅更新|drift|。lastRebalanceAt - 生成调整交换:卖出超配的交易,买入低配的交易,使每笔交易回到目标权重。
- 将每笔调整交换完全按照步骤4的方式委托给swap-integration Trading API流程。
- 使用新的和任何变动的头寸更新状态。
lastRebalanceAt
Execution mode
执行模式
This skill exposes the shared execution mode from :
../../references/execution-model.md| Mode | Behavior |
|---|---|
| Ask the user to approve every transaction before broadcast. |
| Execute without per-transaction prompts, only within guardrails. |
Default to . 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 summarize the full basket and confirm once per run where the runtime allows, otherwise per leg.
confirmconfirm此Skill提供中定义的共享执行模式:
../../references/execution-model.md| 模式 | 行为描述 |
|---|---|
| 每笔交易广播前都要求用户批准。 |
| 无需逐笔交易提示,仅在防护规则范围内执行。 |
默认为模式。自主模式需要满足所有以下条件:支出上限(单次运行和周期)、代币白名单、先试运行、紧急停止开关。篮子买入涉及多笔交易,因此在模式下,如果运行时允许,请汇总整个篮子的信息,每次运行确认一次,否则逐笔确认。
confirmconfirmState
状态
State follows . index-bot stores the target weights and the last rebalance so drift can be computed on the next run:
../../references/strategy-state.mdEach run reads state first and updates it only after a successful broadcast, so reruns within a period do not double-buy or double-rebalance.
状态遵循的规范。index-bot存储目标权重和上次再平衡时间,以便下次运行时计算偏差:
../../references/strategy-state.md每次运行都会先读取状态,仅在广播成功后才更新状态,因此同一周期内的重复运行不会导致重复买入或重复再平衡。
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:
- Handle transfer-restriction reverts per leg gracefully and report which leg reverted.
- Not assume a pool-level or router-level allowlist exists.
- Respect equity market hours; some RWAs may have off-hours liquidity limits.
- Surface the financial disclaimers in the repo root before executing.
DISCLAIMER.md
See for the full restrictions and disclaimer rules.
../../references/execution-model.mdRWA准入是模板特定的,可能在代币层面强制执行(受转账限制的ERC-20),因此即使路由器接受了报价,交易也可能在转账时失败。此Skill必须:
- 优雅处理每笔交易的转账限制失败,并报告哪笔交易失败。
- 不要假设存在池层面或路由器层面的白名单。
- 遵守股票市场交易时间;部分RWA在非交易时间可能有流动性限制。
- 执行前展示仓库根目录中的财务免责声明。
DISCLAIMER.md
完整的限制和免责声明规则请参见。
../../references/execution-model.mdInput validation
输入验证
Before interpolating ANY user-provided value into generated code, API calls, or shell commands:
- Token addresses: MUST match ; reject otherwise.
^0x[a-fA-F0-9]{40}$ - Amounts and notionals: MUST be non-negative numeric values matching .
^[0-9]+\.?[0-9]*$ - Weights: MUST each be in and the full set MUST sum to
[0, 1](within a small tolerance). Reject a basket whose weights do not sum to 1.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元字符的输入:、
;、|、&、$、`、(、)、>、<、\、'、换行符。"