basket-settle

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Basket Settle

篮子结算

Propose and finalize settlement for PolyBaskets baskets. Requires the settler role.
提议并完成PolyBaskets篮子的结算。需要settler角色权限。

Setup

配置

MAINNET ONLY. Run
vara-wallet config set network mainnet
before anything else. NEVER switch to testnet — there are no contracts there.
bash
vara-wallet config set network mainnet
BASKET_MARKET="0x702395d43248eaa5f1fd4d9eadadc75b0fb1c7c5ae9ea20bf31375fd4358f403"
_PB="${POLYBASKETS_SKILLS_DIR:-skills}"
IDL="$_PB/idl/polymarket-mirror.idl"
仅主网可用。 首先运行
vara-wallet config set network mainnet
。切勿切换到测试网——那里没有部署合约。
bash
vara-wallet config set network mainnet
BASKET_MARKET="0x702395d43248eaa5f1fd4d9eadadc75b0fb1c7c5ae9ea20bf31375fd4358f403"
_PB="${POLYBASKETS_SKILLS_DIR:-skills}"
IDL="$_PB/idl/polymarket-mirror.idl"

Verify Settler Role

验证Settler角色

Only the address assigned as
settler_role
in the contract config can call settlement methods.
bash
undefined
只有在合约配置中被指定为
settler_role
的地址才能调用结算方法。
bash
undefined

Check who has settler role

查看谁拥有settler角色

vara-wallet call $BASKET_MARKET BasketMarket/GetConfig --args '[]' --idl $IDL | jq '.settler_role'
vara-wallet call $BASKET_MARKET BasketMarket/GetConfig --args '[]' --idl $IDL | jq '.settler_role'

Check agent's address

查看Agent的地址

vara-wallet wallet list | jq -r '.[0].address'

If your address does not match `settler_role`, you cannot settle. Contact the admin.
vara-wallet wallet list | jq -r '.[0].address'

如果你的地址与`settler_role`不匹配,则无法进行结算。请联系管理员。

Settlement Flow

结算流程

1. Check basket is Active
2. Verify all items have resolved on Polymarket
3. ProposeSettlement → starts 12-minute challenge window
4. Wait for challenge_deadline to pass
5. FinalizeSettlement → basket becomes Settled, users can claim
1. 检查篮子状态为Active
2. 验证所有项目已在Polymarket上完成决议
3. 调用ProposeSettlement → 启动12分钟的挑战窗口
4. 等待challenge_deadline到期
5. 调用FinalizeSettlement → 篮子变为Settled状态,用户可领取奖励

Step 1: Check Basket Status

步骤1:检查篮子状态

bash
vara-wallet call $BASKET_MARKET BasketMarket/GetBasket \
  --args '[<basket_id>]' --idl $IDL | jq '.result.ok.status'
Must be
"Active"
.
bash
vara-wallet call $BASKET_MARKET BasketMarket/GetBasket \
  --args '[<basket_id>]' --idl $IDL | jq '.result.ok.status'
状态必须为
"Active"

Step 2: Check Polymarket Resolution

步骤2:检查Polymarket决议状态

For each item in the basket, check if the market has resolved on Polymarket:
bash
curl -s "https://gamma-api.polymarket.com/markets?slug=<poly_slug>" | jq '.[0] | {closed, outcomePrices}'
All items must be resolved (
closed: true
) with final prices near 0 or 1.
对于篮子中的每个项目,检查其在Polymarket上的市场是否已完成决议:
bash
curl -s "https://gamma-api.polymarket.com/markets?slug=<poly_slug>" | jq '.[0] | {closed, outcomePrices}'
所有项目必须已完成决议(
closed: true
),且最终价格接近0或1。

Step 3: Propose Settlement

步骤3:提议结算

Build the
item_resolutions
array — one
ItemResolution
per basket item:
json
{
  "item_index": 0,
  "resolved": "YES",
  "poly_slug": "will-btc-hit-100k",
  "poly_condition_id": "0xabc123...",
  "poly_price_yes": 9900,
  "poly_price_no": 100
}
Rules:
  • Provide exactly one resolution per basket item
  • item_index
    is 0-based, must be unique, and within basket items range
  • poly_slug
    must match the basket item's slug exactly
  • poly_price_yes
    +
    poly_price_no
    should reflect final Polymarket prices in bps
  • resolved
    is the final outcome:
    "YES"
    or
    "NO"
  • poly_condition_id
    is optional
构建
item_resolutions
数组 —— 每个篮子项目对应一个
ItemResolution
json
{
  "item_index": 0,
  "resolved": "YES",
  "poly_slug": "will-btc-hit-100k",
  "poly_condition_id": "0xabc123...",
  "poly_price_yes": 9900,
  "poly_price_no": 100
}
规则:
  • 每个篮子项目必须对应一个决议
  • item_index
    从0开始,必须唯一且在篮子项目范围内
  • poly_slug
    必须与篮子项目的slug完全匹配
  • poly_price_yes
    +
    poly_price_no
    应反映Polymarket的最终价格(单位:bps)
  • resolved
    为最终结果:
    "YES"
    "NO"
  • poly_condition_id
    为可选参数

Example: Propose settlement for a 2-item basket

示例:为包含2个项目的篮子提议结算

bash
vara-wallet --account agent call $BASKET_MARKET BasketMarket/ProposeSettlement --voucher $VOUCHER_ID \
  --args '[
    0,
    [
      {
        "item_index": 0,
        "resolved": "YES",
        "poly_slug": "will-btc-hit-100k",
        "poly_condition_id": null,
        "poly_price_yes": 9900,
        "poly_price_no": 100
      },
      {
        "item_index": 1,
        "resolved": "NO",
        "poly_slug": "will-eth-hit-5k",
        "poly_condition_id": null,
        "poly_price_yes": 200,
        "poly_price_no": 9800
      }
    ],
    "Resolved via Polymarket API"
  ]' \
  --idl $IDL
After proposal, the basket enters
SettlementPending
status and the 12-minute challenge window begins.
bash
vara-wallet --account agent call $BASKET_MARKET BasketMarket/ProposeSettlement --voucher $VOUCHER_ID \
  --args '[
    0,
    [
      {
        "item_index": 0,
        "resolved": "YES",
        "poly_slug": "will-btc-hit-100k",
        "poly_condition_id": null,
        "poly_price_yes": 9900,
        "poly_price_no": 100
      },
      {
        "item_index": 1,
        "resolved": "NO",
        "poly_slug": "will-eth-hit-5k",
        "poly_condition_id": null,
        "poly_price_yes": 200,
        "poly_price_no": 9800
      }
    ],
    "Resolved via Polymarket API"
  ]' \
  --idl $IDL
提议后,篮子将进入
SettlementPending
状态,12分钟的挑战窗口随即开始。

Step 4: Wait for Challenge Window

步骤4:等待挑战窗口结束

bash
undefined
bash
undefined

Check challenge deadline

查看挑战截止时间

vara-wallet call $BASKET_MARKET BasketMarket/GetSettlement
--args '[<basket_id>]' --idl $IDL | jq '.result.ok | {status, challenge_deadline, proposed_at}'

The `challenge_deadline` is a block timestamp. The liveness window is configured in `liveness_ms` (default 720000ms = 12 minutes).

Wait until the current block timestamp exceeds `challenge_deadline`.
vara-wallet call $BASKET_MARKET BasketMarket/GetSettlement
--args '[<basket_id>]' --idl $IDL | jq '.result.ok | {status, challenge_deadline, proposed_at}'

`challenge_deadline`是一个区块时间戳。存活窗口由`liveness_ms`配置(默认720000ms = 12分钟)。

等待当前区块时间戳超过`challenge_deadline`即可。

Step 5: Finalize Settlement

步骤5:完成结算

bash
vara-wallet --account agent call $BASKET_MARKET BasketMarket/FinalizeSettlement --voucher $VOUCHER_ID \
  --args '[<basket_id>]' --idl $IDL
After finalization:
  • Basket status becomes
    Settled
  • finalized_at
    is set
  • Users can now claim payouts via
    ../basket-claim/SKILL.md
bash
vara-wallet --account agent call $BASKET_MARKET BasketMarket/FinalizeSettlement --voucher $VOUCHER_ID \
  --args '[<basket_id>]' --idl $IDL
完成结算后:
  • 篮子状态变为
    Settled
  • finalized_at
    字段将被设置
  • 用户现在可通过
    ../basket-claim/SKILL.md
    领取奖励

Verify

验证结算结果

bash
vara-wallet call $BASKET_MARKET BasketMarket/GetSettlement \
  --args '[<basket_id>]' --idl $IDL | jq '.result.ok | {status, payout_per_share, finalized_at}'
bash
vara-wallet call $BASKET_MARKET BasketMarket/GetSettlement \
  --args '[<basket_id>]' --idl $IDL | jq '.result.ok | {status, payout_per_share, finalized_at}'

Common Errors

常见错误

ErrorCauseFix
Unauthorized
Not the settler roleCheck config for settler_role address
BasketNotActive
Basket already in settlementCheck status
SettlementAlreadyExists
Already proposedWait and finalize
InvalidResolutionCount
Wrong number of resolutionsProvide one per item
ResolutionSlugMismatch
Slug doesn't match basket itemUse exact slug from basket
DuplicateResolutionIndex
Same item_index twiceMake indices unique
ResolutionIndexOutOfBounds
Index >= items countUse 0 to items.length-1
ChallengeDeadlineNotPassed
Too early to finalizeWait for challenge window
SettlementNotProposed
No proposal existsPropose first
SettlementNotFinalized
Settlement not yet finalizedCall FinalizeSettlement after challenge window
错误原因解决方法
Unauthorized
无settler角色权限检查合约配置中的settler_role地址
BasketNotActive
篮子已处于结算流程中检查篮子状态
SettlementAlreadyExists
已提交过结算提议等待并完成最终结算
InvalidResolutionCount
决议数量不正确为每个项目提供一个决议
ResolutionSlugMismatch
Slug与篮子项目不匹配使用篮子项目的精确Slug
DuplicateResolutionIndex
重复使用item_index确保索引唯一
ResolutionIndexOutOfBounds
索引超出项目数量范围使用0到items.length-1之间的索引
ChallengeDeadlineNotPassed
未到最终结算时间等待挑战窗口结束
SettlementNotProposed
未提交结算提议先提交结算提议
SettlementNotFinalized
结算尚未完成挑战窗口结束后调用FinalizeSettlement