basket-bet

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Basket Bet

Basket下注

Claim CHIP tokens and bet on a PolyBaskets basket via
vara-wallet
.
通过
vara-wallet
领取CHIP代币并在PolyBaskets的Basket上下注。

Setup

准备工作

MAINNET ONLY. Run
vara-wallet config set network mainnet
before anything else. NEVER switch to testnet — there are no contracts there. If a call fails, debug the error, do not fall back to testnet.
Requires vara-wallet 0.10+ for hex→bytes auto-conversion. Update with:
npm install -g vara-wallet@latest
bash
undefined
仅主网可用。 在进行任何操作前,先运行
vara-wallet config set network mainnet
。切勿切换到测试网——测试网没有相关合约。如果调用失败,请调试错误,不要回退到测试网。
需要vara-wallet 0.10及以上版本以支持十六进制转字节自动转换。更新命令:
npm install -g vara-wallet@latest
bash
undefined

Ensure mainnet (default RPC)

确保使用主网(默认RPC)

vara-wallet config set network mainnet
BASKET_MARKET="0x702395d43248eaa5f1fd4d9eadadc75b0fb1c7c5ae9ea20bf31375fd4358f403" BET_TOKEN="0x41be634b690ecde3d79f63ea2db9834b8570a6d4abb3c0be47af3947e3129ece" BET_LANE="0xf5aa436669bb3fc97c1675d06949592e8617f889cbd055451f321113b17bb564" _PB="${POLYBASKETS_SKILLS_DIR:-skills}" IDL="$_PB/idl/polymarket-mirror.idl" BET_TOKEN_IDL="$_PB/idl/bet_token_client.idl" BET_LANE_IDL="$_PB/idl/bet_lane_client.idl" BET_QUOTE_URL="https://bet-quote-service-production.up.railway.app" MY_ADDR=$(vara-wallet balance --account agent | jq -r .address) VOUCHER_URL="https://voucher-backend-production-5a1b.up.railway.app/voucher"
undefined
vara-wallet config set network mainnet
BASKET_MARKET="0x702395d43248eaa5f1fd4d9eadadc75b0fb1c7c5ae9ea20bf31375fd4358f403" BET_TOKEN="0x41be634b690ecde3d79f63ea2db9834b8570a6d4abb3c0be47af3947e3129ece" BET_LANE="0xf5aa436669bb3fc97c1675d06949592e8617f889cbd055451f321113b17bb564" _PB="${POLYBASKETS_SKILLS_DIR:-skills}" IDL="$_PB/idl/polymarket-mirror.idl" BET_TOKEN_IDL="$_PB/idl/bet_token_client.idl" BET_LANE_IDL="$_PB/idl/bet_lane_client.idl" BET_QUOTE_URL="https://bet-quote-service-production.up.railway.app" MY_ADDR=$(vara-wallet balance --account agent | jq -r .address) VOUCHER_URL="https://voucher-backend-production-5a1b.up.railway.app/voucher"
undefined

Claim Gas Voucher (required before any on-chain call)

领取Gas凭证(链上调用前必须完成)

Claim a free gas voucher. The
program
field is the contract program ID, NOT your wallet address.
bash
undefined
领取免费的Gas凭证。
program
字段是合约程序ID,而非你的钱包地址。
bash
undefined

Claim voucher for all 3 programs (re-run anytime to renew expired vouchers)

为所有3个程序领取凭证(任何时候都可重新运行以续期过期的凭证)

⚠ "program" = whitelisted contract ID, NOT your agent address

⚠ "program" = 白名单合约ID,而非你的Agent地址

VOUCHER_ID=$(curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BASKET_MARKET"'"}' | jq -r .voucherId) curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BET_TOKEN"'"}' curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BET_LANE"'"}' echo "Voucher: $VOUCHER_ID"
VOUCHER_ID=$(curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BASKET_MARKET"'"}' | jq -r .voucherId) curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BET_TOKEN"'"}' curl -s -X POST "$VOUCHER_URL"
-H 'Content-Type: application/json'
-d '{"account":"'"$MY_ADDR"'","program":"'"$BET_LANE"'"}' echo "Voucher: $VOUCHER_ID"

To check voucher status later:

后续检查凭证状态:

VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')

VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')

undefined
undefined

CHIP Lane (Primary Path)

CHIP通道(主要流程)

Most baskets use
asset_kind: "Bet"
(CHIP tokens). This is the default agent workflow.
大多数Basket使用
asset_kind: "Bet"
(CHIP代币)。这是Agent的默认工作流程。

Step 1: Claim Daily CHIP

步骤1:领取每日CHIP代币

Agents get free CHIP tokens every day. Consecutive days build a streak that increases the amount (100 CHIP base, +8.33/day streak, max 150 CHIP at 7-day cap).
bash
undefined
Agent每天可领取免费的CHIP代币。连续领取天数会形成 streak,提升领取额度(基础100 CHIP,每天增加8.33 CHIP,连续7天达到上限150 CHIP)。
bash
undefined

Get your hex address (required for actor_id args — SS58 won't work)

获取你的十六进制地址(actor_id参数需要此格式——SS58格式不可用)

MY_ADDR=$(vara-wallet balance | jq -r .address)
MY_ADDR=$(vara-wallet balance | jq -r .address)

Get your voucher ID (claim one first — see Quick Start in SKILL.md)

获取你的凭证ID(先领取一个——参考SKILL.md中的快速开始)

VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')
VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')

Check if claim is available and how much you'll get

检查是否可领取以及可领取的额度

vara-wallet call $BET_TOKEN BetToken/GetClaimPreview
--args '["'$MY_ADDR'"]' --idl $BET_TOKEN_IDL
vara-wallet call $BET_TOKEN BetToken/GetClaimPreview
--args '["'$MY_ADDR'"]' --idl $BET_TOKEN_IDL

Claim daily CHIP (do this every day to build streak)

领取每日CHIP代币(每天领取以积累streak)

NOTE: --voucher is required on ALL write calls (agent has no VARA for gas)

注意:所有写入调用都需要--voucher参数(Agent没有VARA用于Gas费用)

vara-wallet --account agent call $BET_TOKEN BetToken/Claim
--args '[]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL

The response includes your `streak_days` and `total_claimed`. Higher streak = more CHIP per claim.
vara-wallet --account agent call $BET_TOKEN BetToken/Claim
--args '[]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL

响应会包含你的`streak_days`(连续天数)和`total_claimed`(累计领取额度)。连续天数越高,每次领取的CHIP越多。

Step 2: Check CHIP Balance

步骤2:检查CHIP余额

bash
vara-wallet call $BET_TOKEN BetToken/BalanceOf \
  --args '["'$MY_ADDR'"]' --idl $BET_TOKEN_IDL
bash
vara-wallet call $BET_TOKEN BetToken/BalanceOf \
  --args '["'$MY_ADDR'"]' --idl $BET_TOKEN_IDL

Step 3: Pick a Basket

步骤3:选择Basket

Browse active baskets and find one to bet on:
bash
undefined
浏览活跃的Basket并选择一个进行下注:
bash
undefined

How many baskets exist

查询Basket总数

vara-wallet call $BASKET_MARKET BasketMarket/GetBasketCount --args '[]' --idl $IDL
vara-wallet call $BASKET_MARKET BasketMarket/GetBasketCount --args '[]' --idl $IDL

View a specific basket

查看特定Basket

vara-wallet call $BASKET_MARKET BasketMarket/GetBasket --args '[0]' --idl $IDL
vara-wallet call $BASKET_MARKET BasketMarket/GetBasket --args '[0]' --idl $IDL

⚠ Response is nested under .result.ok — NOT .ok!

⚠ 响应内容嵌套在.result.ok下——而非.ok!

Example: {"result":{"ok":{"id":0,"name":"...","status":"Active","asset_kind":"Bet",...}}}

示例:{"result":{"ok":{"id":0,"name":"...","status":"Active","asset_kind":"Bet",...}}}

Use jq: | jq '.result.ok'

使用jq过滤:| jq '.result.ok'

To get just name and status: | jq '.result.ok | {name, status}'

仅查看名称和状态:| jq '.result.ok | {name, status}'


Check that `status` is `"Active"` and `asset_kind` is `"Bet"`. The basket data is at `.result.ok` in the JSON response.

**Important:** The `basket_id` for `PlaceBet` is a plain integer (e.g., `0`, `1`, `2`), not the hex program ID.

确保`status`为`"Active"`且`asset_kind`为`"Bet"`。Basket数据在JSON响应的`.result.ok`路径下。

**重要提示:** `PlaceBet`使用的`basket_id`是普通整数(例如`0`、`1`、`2`),而非十六进制程序ID。

Step 4: Approve CHIP Spend

步骤4:授权CHIP支出

Allow the BetLane contract to spend your CHIP:
bash
vara-wallet --account agent call $BET_TOKEN BetToken/Approve \
  --args '["'$BET_LANE'", <amount>]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL
Note: Approve returns
"result":false
— this is normal, it's the previous approval state (not an error). Verify with
BetToken/Allowance
if needed.
允许BetLane合约使用你的CHIP代币:
bash
vara-wallet --account agent call $BET_TOKEN BetToken/Approve \
  --args '["'$BET_LANE'", <amount>]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL
注意: Approve调用返回
"result":false
属于正常情况,这表示之前的授权状态(而非错误)。如有需要,可通过
BetToken/Allowance
验证授权情况。

Step 5: Get Signed Quote + Place Bet

步骤5:获取签名报价 + 下注

Bets require a signed quote from the bet-quote-service. The quote service fetches live Polymarket prices, computes the index, and signs the payload. The contract verifies the signature on-chain.
All-in-one command (get quote + place bet — must run together to stay within 30-second quote expiry):
bash
undefined
下注需要来自bet-quote-service的签名报价。报价服务会获取Polymarket实时价格,计算指数,并对负载进行签名。合约会在链上验证签名。
一体化命令(获取报价 + 下注——必须一起运行,以确保在30秒报价有效期内完成):
bash
undefined

Replace <BASKET_ID> and <AMOUNT_RAW> with real values

将<BASKET_ID>和<AMOUNT_RAW>替换为实际值

QUOTE=$(curl -s -X POST "$BET_QUOTE_URL/api/bet-lane/quote"
-H 'Content-Type: application/json'
-d '{"user":"'"$MY_ADDR"'","basketId":<BASKET_ID>,"amount":"<AMOUNT_RAW>","targetProgramId":"'"$BET_LANE"'"}') &&
echo "$QUOTE" | jq -e '.payload' >/dev/null 2>&1 || { echo "Quote failed: $QUOTE"; exit 1; } &&
vara-wallet --account agent call $BET_LANE BetLane/PlaceBet
--args "[<BASKET_ID>, "<AMOUNT_RAW>", $QUOTE]"
--voucher $VOUCHER_ID --idl $BET_LANE_IDL

**How it works:** vara-wallet 0.10+ auto-converts the hex signature (`"0x..."`) to a byte array for `vec u8` fields. No manual conversion needed — just pass the raw quote JSON from curl directly into `--args`.

**CRITICAL rules for placing bets:**
1. **Do NOT manually reconstruct the quote object.** The quote has a `{"payload": {...}, "signature": "0x..."}` structure — if you rebuild it without the `payload` wrapper, the contract will reject it with `InvalidIndexAtCreation`.
2. **Requires vara-wallet 0.10+.** Older versions need manual hex→bytes conversion. Check with `vara-wallet --version`.

The quote is valid for 30 seconds. If it expires, request a new one. Each quote has a unique nonce and can only be used once.

Returns `u256` -- shares received.
QUOTE=$(curl -s -X POST "$BET_QUOTE_URL/api/bet-lane/quote"
-H 'Content-Type: application/json'
-d '{"user":"'"$MY_ADDR"'","basketId":<BASKET_ID>,"amount":"<AMOUNT_RAW>","targetProgramId":"'"$BET_LANE"'"}') &&
echo "$QUOTE" | jq -e '.payload' >/dev/null 2>&1 || { echo "Quote failed: $QUOTE"; exit 1; } &&
vara-wallet --account agent call $BET_LANE BetLane/PlaceBet
--args "[<BASKET_ID>, "<AMOUNT_RAW>", $QUOTE]"
--voucher $VOUCHER_ID --idl $BET_LANE_IDL

**工作原理:** vara-wallet 0.10及以上版本会自动将十六进制签名(`"0x..."`)转换为`vec u8`字段所需的字节数组。无需手动转换——直接将curl返回的原始报价JSON传入`--args`即可。

**关键规则:**
1. **请勿手动重构报价对象。** 报价的结构为`{"payload": {...}, "signature": "0x..."}`——如果去掉`payload`包装器重构对象,合约会以`InvalidIndexAtCreation`错误拒绝。
2. **需要vara-wallet 0.10及以上版本。** 旧版本需要手动进行十六进制转字节转换。可通过`vara-wallet --version`检查版本。

报价有效期为30秒。如果过期,请重新请求新的报价。每个报价都有唯一的nonce,只能使用一次。

返回值为`u256`——获得的份额。

Complete CHIP Lane Example

完整CHIP通道示例

bash
undefined
bash
undefined

0. Vars are set in the Setup block above. If starting fresh:

0. 变量已在准备工作块中设置。如果是首次操作:

MY_ADDR=$(vara-wallet balance --account agent | jq -r .address)

MY_ADDR=$(vara-wallet balance --account agent | jq -r .address)

VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')

VOUCHER_ID=$(vara-wallet voucher list $MY_ADDR | jq -r '.[0].id // .[0].voucherId')

1. Claim daily CHIP

1. 领取每日CHIP代币

vara-wallet --account agent call $BET_TOKEN BetToken/Claim
--args '[]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL
vara-wallet --account agent call $BET_TOKEN BetToken/Claim
--args '[]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL

2. Approve BetLane to spend 100 CHIP

2. 授权BetLane使用100 CHIP

vara-wallet --account agent call $BET_TOKEN BetToken/Approve
--args '["'$BET_LANE'", "100000000000000"]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL
vara-wallet --account agent call $BET_TOKEN BetToken/Approve
--args '["'$BET_LANE'", "100000000000000"]' --voucher $VOUCHER_ID --idl $BET_TOKEN_IDL

3. Get quote + place bet (30s expiry — run together!)

3. 获取报价 + 下注(30秒有效期——必须一起运行!)

⚠ Do NOT manually reconstruct the quote. Pass the raw curl response directly.

⚠ 请勿手动重构报价,直接传入curl的原始响应。

QUOTE=$(curl -s -X POST "$BET_QUOTE_URL/api/bet-lane/quote"
-H 'Content-Type: application/json'
-d '{"user":"'"$MY_ADDR"'","basketId":0,"amount":"100000000000000","targetProgramId":"'"$BET_LANE"'"}') &&
vara-wallet --account agent call $BET_LANE BetLane/PlaceBet
--args "[0, "100000000000000", $QUOTE]"
--voucher $VOUCHER_ID --idl $BET_LANE_IDL
QUOTE=$(curl -s -X POST "$BET_QUOTE_URL/api/bet-lane/quote"
-H 'Content-Type: application/json'
-d '{"user":"'"$MY_ADDR"'","basketId":0,"amount":"100000000000000","targetProgramId":"'"$BET_LANE"'"}') &&
vara-wallet --account agent call $BET_LANE BetLane/PlaceBet
--args "[0, "100000000000000", $QUOTE]"
--voucher $VOUCHER_ID --idl $BET_LANE_IDL

5. Verify position

5. 验证持仓

vara-wallet call $BET_LANE BetLane/GetPosition
--args '["'$MY_ADDR'", 0]' --idl $BET_LANE_IDL

**Important:** CHIP has 12 decimals. 100 CHIP = `100000000000000` (100 * 10^12) in raw units.
vara-wallet call $BET_LANE BetLane/GetPosition
--args '["'$MY_ADDR'", 0]' --idl $BET_LANE_IDL

**重要提示:** CHIP有12位小数。100 CHIP = `100000000000000`(100 * 10^12)原始单位。

How the Quote Works

报价工作原理

The agent does NOT calculate
index_at_creation_bps
manually anymore. The bet-quote-service:
  1. Reads the basket from chain (validates it's active + Bet kind)
  2. Fetches live Polymarket prices for each outcome
  3. Computes the weighted
    quoted_index_bps
  4. Signs the payload with SR25519 (includes user, basket_id, amount, deadline, nonce)
  5. Returns the signed quote
The BetLane contract verifies the signature on-chain. This prevents price manipulation.
Quote properties:
  • Valid for 30 seconds (
    deadline_ms
    )
  • One-time use (nonce prevents replay)
  • Bound to specific user, basket, and amount
See
../references/index-math.md
for payout formula:
payout = shares * (settlement_index / entry_index)
.
Agent不再需要手动计算
index_at_creation_bps
。bet-quote-service的工作流程:
  1. 从链上读取Basket(验证其处于活跃状态且为Bet类型)
  2. 获取每个结果的Polymarket实时价格
  3. 计算加权
    quoted_index_bps
  4. 使用SR25519对负载进行签名(包含用户、basket_id、金额、截止时间、nonce)
  5. 返回签名后的报价
BetLane合约会在链上验证签名,防止价格操纵。
报价属性:
  • 有效期30秒(
    deadline_ms
  • 仅可使用一次(nonce防止重放攻击)
  • 绑定到特定用户、Basket和金额
奖励计算公式请参考
../references/index-math.md
payout = shares * (settlement_index / entry_index)

VARA Lane (asset_kind: Vara)

VARA通道(asset_kind: Vara)

Some baskets accept native VARA instead of CHIP. Check basket's
asset_kind
.
bash
undefined
部分Basket接受原生VARA而非CHIP。请检查Basket的
asset_kind
bash
undefined

Bet 100 VARA on basket 0 at index 6120

在Basket 0上下注100 VARA,指数为6120

vara-wallet --account agent call $BASKET_MARKET BasketMarket/BetOnBasket
--args '[0, 6120]'
--value 100
--idl $IDL

Returns `u128` — shares received (equal to VARA sent in minimal units).

Note: VARA lane may be disabled on some deployments. Check with:
```bash
vara-wallet call $BASKET_MARKET BasketMarket/IsVaraEnabled --args '[]' --idl $IDL
vara-wallet --account agent call $BASKET_MARKET BasketMarket/BetOnBasket
--args '[0, 6120]'
--value 100
--idl $IDL

返回值为`u128`——获得的份额(等于以最小单位发送的VARA数量)。

注意:部分部署可能禁用VARA通道。可通过以下命令检查:
```bash
vara-wallet call $BASKET_MARKET BasketMarket/IsVaraEnabled --args '[]' --idl $IDL

After Betting

下注后操作

Check your position (use
BetLane/GetPosition
, NOT
GetUserPositions
which doesn't exist):
bash
vara-wallet call $BET_LANE BetLane/GetPosition \
  --args '["'$MY_ADDR'", <BASKET_ID>]' --idl $BET_LANE_IDL
  • Wait for settlement, then claim payout:
    ../basket-claim/SKILL.md
  • Come back tomorrow for more CHIP: repeat Step 1
检查你的持仓(使用
BetLane/GetPosition
,不存在
GetUserPositions
接口):
bash
vara-wallet call $BET_LANE BetLane/GetPosition \
  --args '["'$MY_ADDR'", <BASKET_ID>]' --idl $BET_LANE_IDL
  • 等待结算完成后,领取奖励:
    ../basket-claim/SKILL.md
  • 明天再来领取更多CHIP:重复步骤1

Common Errors

常见错误

ErrorCauseFix
InvalidIndexAtCreation
Malformed quote struct (missing
payload
wrapper)
Do NOT manually reconstruct the quote — pipe the raw curl response through python3
InvalidQuoteSignature
Quote not signed by configured signerCheck bet-quote-service config
QuoteExpired
Quote older than 30 secondsRequest a fresh quote
QuoteNonceAlreadyUsed
Same quote submitted twiceRequest a new quote for each bet
QuoteTargetMismatch
Quote was for a different BetLaneCheck
targetProgramId
matches
$BET_LANE
InvalidBetAmount
No
--value
attached (VARA lane)
Add
--value <amount>
BasketNotActive
Basket in settlement/settledCannot bet on non-active baskets
BasketAssetMismatch
Wrong lane for basketCheck basket's
asset_kind
VaraDisabled
VARA betting offUse CHIP lane instead
AmountBelowMinBet
CHIP amount too lowCheck BetLane config for min_bet
AmountAboveMaxBet
CHIP amount too highCheck BetLane config for max_bet
BetTokenTransferFromFailed
Insufficient CHIP balance or approvalClaim more tokens or increase approval
错误原因解决方法
InvalidIndexAtCreation
报价结构错误(缺少
payload
包装器)
请勿手动重构报价——直接传入curl的原始响应
InvalidQuoteSignature
报价未由配置的签名者签名检查bet-quote-service的配置
QuoteExpired
报价已超过30秒有效期请求新的报价
QuoteNonceAlreadyUsed
同一报价提交了两次每次下注请求新的报价
QuoteTargetMismatch
报价针对的是其他BetLane检查
targetProgramId
是否与
$BET_LANE
匹配
InvalidBetAmount
未附加
--value
参数(VARA通道)
添加
--value <amount>
参数
BasketNotActive
Basket处于结算中/已结算状态无法对非活跃Basket下注
BasketAssetMismatch
使用了错误的通道检查Basket的
asset_kind
VaraDisabled
VARA下注已禁用改用CHIP通道
AmountBelowMinBet
CHIP下注金额过低检查BetLane配置的最小下注额
AmountAboveMaxBet
CHIP下注金额过高检查BetLane配置的最大下注额
BetTokenTransferFromFailed
CHIP余额不足或授权不够领取更多代币或提高授权额度