Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c44181792d | |||
| 77b5304d08 |
@@ -10,6 +10,12 @@ cargo run --locked -p venue-probe
|
||||
flowchart LR
|
||||
main -->|核对 CTF 权重| ctf["src/ctf_resolution.rs"]
|
||||
main -->|核对 V2 模块权重| position["src/position_resolution.rs"]
|
||||
main -->|核对组合盘兑付| combo["src/combo_payout.rs"]
|
||||
main -->|区分互斥组直接与推导兑付| negrisk["src/neg_risk_resolution.rs"]
|
||||
negrisk -->|模块和 ABI 校验| position
|
||||
negrisk -->|最终确认区块与合约错误| rpc
|
||||
combo -->|查询模块注册表| position
|
||||
combo -->|执行最终区块调用| rpc
|
||||
position -->|解析目录及结果 ID| catalog
|
||||
position -->|读取最终确认区块| rpc["src/polygon_rpc.rs"]
|
||||
ctf -->|读取最终确认区块| rpc
|
||||
@@ -179,4 +185,67 @@ sequenceDiagram
|
||||
P-->>U: 目录结果、合约、区块、原始 ABI 和兑付状态
|
||||
```
|
||||
|
||||
`venue-probe --replay-position-resolution crates/venue-probe/fixtures/live-position-resolutions.json first` 可重放生产 Binary 样本。两个 Polygon 节点在区块 `0x5df5912` 返回同一模块地址与兑付权重 `[1000000, 0]`,对应目录第一结果获胜。空权重数组报告为 `unresolved`。已兑付状态按数组值报告为 `first`、`second`、`split` 或 `weighted`。提供预期时,任何结果不符都会在输出报告后返回非零状态。NegRisk 的权重约束有离线回归用例,生产目录与链上结果的对应仍待验证。组合盘使用独立模块,预言机证明和本地账本入账也仍待覆盖。[双节点原始样本](fixtures/live-position-resolutions.json) · [合约部署地址](https://docs.polymarket.com/resources/contracts)
|
||||
`venue-probe --replay-position-resolution crates/venue-probe/fixtures/live-position-resolutions.json first` 可重放生产 Binary 样本。两个 Polygon 节点在区块 `0x5df5912` 返回同一模块地址与兑付权重 `[1000000, 0]`,对应目录第一结果获胜。空权重数组报告为 `unresolved`。已兑付状态按数组值报告为 `first`、`second`、`split` 或 `weighted`。提供预期时,任何结果不符都会在输出报告后返回非零状态。NegRisk 的权重约束有离线回归用例,生产目录与链上结果的对应仍待验证。组合盘使用下节介绍的独立模块。预言机证明和本地账本入账仍待覆盖。[双节点原始样本](fixtures/live-position-resolutions.json) · [合约部署地址](https://docs.polymarket.com/resources/contracts)
|
||||
|
||||
## Polygon 组合盘兑付核对
|
||||
|
||||
`venue-probe --inspect-combo-payout CONDITION AMOUNT_MICROS` 读取组合条件。有登记的腿时,以同一个正整数微份数分别查询 YES 与 NO。当前结论由状态和逐侧兑付金额表达。空腿数组表示 `unprepared`,两侧均返回合约的 `PositionNotRedeemable()` 表示 `unresolved`,两侧都成功返回金额表示 `redeemable`。其他错误会使探针退出。即使 NO 兑付全额,也可能还有腿尚未裁决。[官方组合模块](https://github.com/Polymarket/polymarket-v2-external/blob/main/src/modules/CombinatorialModule.sol)
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor U as 调用者
|
||||
participant P as venue-probe
|
||||
participant R as Polygon RPC
|
||||
participant M as PositionManager
|
||||
participant C as CombinatorialModule
|
||||
U->>P: inspect-combo-payout CONDITION AMOUNT_MICROS
|
||||
P->>R: 获取 Polygon 最终确认区块
|
||||
P->>R: 在指定区块查询 moduleById(3)
|
||||
R->>M: 查询组合模块代理
|
||||
M-->>R: 模块地址
|
||||
R-->>P: 已登记的模块地址
|
||||
P->>R: 在同一区块查询 getLegs
|
||||
R->>C: 查询组合的腿
|
||||
C-->>R: Position ID 数组
|
||||
R-->>P: 原始数组
|
||||
opt 有登记的腿
|
||||
loop YES 和 NO 各一次
|
||||
P->>R: 在同一区块查询 getPayout
|
||||
R->>C: 当前方向 Position ID 和份额
|
||||
C-->>R: 兑付整数金额或合约错误
|
||||
R-->>P: 原始结果
|
||||
end
|
||||
end
|
||||
P->>R: 复核同一区块哈希
|
||||
P-->>U: 组合腿、待裁决状态或逐侧兑付
|
||||
```
|
||||
|
||||
`venue-probe --replay-combo-payout crates/venue-probe/fixtures/live-combo-payouts.json` 重放两个真实链上组合。一个组合的两侧均待裁决,另一个按 1000001 微份查询,YES 兑付 0,NO 兑付全部 1000001 微美元。该组合的 4 条腿中,一条已裁决为零赔付,另外三条仍待裁决。样本包含登记交易哈希、区块及 ABI 原始返回,仍缺少前端和 RFQ 的同盘关联。[原始样本](fixtures/live-combo-payouts.json)
|
||||
|
||||
## Polygon 互斥组的直接报告与推导
|
||||
|
||||
`venue-probe --inspect-neg-risk-event EVENT_ID INDICES` 接受 V2 互斥事件 ID 和逗号分隔的条件索引。索引从零开始,等于真实条件总数时表示合成的「其他」。命令从已确认区块读取计数与旧版迁移标记,并分别读取各选定条件的有效兑付 `getResult` 与原始存储 `result(conditionId, 0)`。有效兑付和事件计数符合推导规则且原始结果为空时,标为 `derived`。存储里有结果时标为 `stored`。RPC 或 ABI 异常会终止核对。[官方 NegRisk 模块](https://github.com/Polymarket/polymarket-v2-external/blob/main/docs/modules.md#negriskmodule-moduleid--2) · [合约原始结果定义](https://github.com/Polymarket/polymarket-v2-external/blob/main/src/modules/abstract/BaseModule.sol)
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor U as 调用者
|
||||
participant P as venue-probe
|
||||
participant R as Polygon RPC
|
||||
participant N as NegRiskModule
|
||||
U->>P: inspect-neg-risk-event EVENT_ID INDICES
|
||||
P->>R: 读取最终确认区块和模块注册表
|
||||
P->>R: 查询真实条件数、直接报告数、YES 总权重和迁移标记
|
||||
R->>N: 在指定区块读取计数
|
||||
N-->>R: 事件计数与权重
|
||||
R-->>P: ABI 整数字
|
||||
loop 选中的每个条件索引
|
||||
P->>R: 读取 getResult 和原始 result
|
||||
R->>N: 查询有效兑付和直接存储
|
||||
N-->>R: 有效数组及存储整数或空回退
|
||||
R-->>P: 两种结果的原始返回
|
||||
end
|
||||
P->>R: 复核区块哈希
|
||||
P-->>U: 逐条件兑付与可核对的来源
|
||||
```
|
||||
|
||||
离线命令为 `venue-probe --replay-neg-risk-event crates/venue-probe/fixtures/live-negrisk-resolution.json`。样本记录赢家出现前后的有效结果与直接存储。区块 `0x5df5c44` 的三条件组中,「其他」没有直接存储,但已经可以按 NO 兑付。区块 `0x5df5c62` 的 37 条件组有 33 个直接报告,四个尚未报告的真实条件仍待裁决,合成「其他」已可按 NO 兑付。旧版事件标识和链上反向映射将这些条件对应到 Gamma 的足球精确比分盘。同一区块中,四个待裁决条件对应的旧 CTF 合约兑付分母均为 1,V2 仍等待迁移裁决。[原始样本](fixtures/live-negrisk-resolution.json)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
[
|
||||
{
|
||||
"chain_id": 137,
|
||||
"block_number": "0x5df5ab2",
|
||||
"block_hash": "0x14e566bc1e5b4acf05706c9a59f0ba01d9064db8404fd020317c32894d49a83d",
|
||||
"condition_id": "0x034bd7384b7f58f2a267c90e5f2c45d865000000000000000000000000000000",
|
||||
"amount_micros": 1000001,
|
||||
"registry": "0x00000000000000000000000030000034706c7d8e12009dab006be20000c031a8",
|
||||
"legs": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b011006ceb374e5e03e0646de13010aaf710000000000000000000000000000010125dcc4e3014cac67374ad55d3bfa5039000000000000000000000000000000014ad9e4ceaa2d864b3e9eb9e685e7bf97000000000000000000000000000000015de9f8160adc8328f91acc2e9ab4465800000000000000000000000000000001820b68526eae7c48b92d51a512d4cd81000000000000000000000000000000019a1cc98bc041fbdd4ac95af0e5982dd000000000000000000000000000000101b9dec220c321c5006459f9acd1ea36ff00000000000000000000000000000101c3e3697c82867662dfcc4efa4747aaa900000000000000000000000000000101c6cc49ab6b18b159edfacedb661dcc0a00000000000000000000000000000001c8b8bb7625efac202c3857d38cc6ad0e00000000000000000000000000000001d06efb76e1836bce7f92507344277933000000000000000000000000000001",
|
||||
"payouts": [
|
||||
{
|
||||
"revert": "0xc003777b"
|
||||
},
|
||||
{
|
||||
"revert": "0xc003777b"
|
||||
}
|
||||
],
|
||||
"source": "https://polygon-bor-rpc.publicnode.com",
|
||||
"preparation_tx": "0xb826cb8d1e00086bdbb9aaecd29800cbb9b72a4311de0eac0f9cf3cfad0e81f7",
|
||||
"observed_at_ms": 1796491240143
|
||||
},
|
||||
{
|
||||
"chain_id": 137,
|
||||
"block_number": "0x5df5ab2",
|
||||
"block_hash": "0x14e566bc1e5b4acf05706c9a59f0ba01d9064db8404fd020317c32894d49a83d",
|
||||
"condition_id": "0x033f568c0a6209ea4beb141ae1e137177d000000000000000000000000000000",
|
||||
"amount_micros": 1000001,
|
||||
"registry": "0x00000000000000000000000030000034706c7d8e12009dab006be20000c031a8",
|
||||
"legs": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004014375f1cab1f5e5e98c9014fff1de38c1000000000000000000000000000000019d2d7100e42a913a5a13db0380d3aba900000000000000000000000000000101c157597d55e31bbf2a93bc0b524c189200000000000000000000000000000101e23cbfdde8c236499dd947c83faf57a6000000000000000000000000000000",
|
||||
"payouts": [
|
||||
{
|
||||
"return": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
{
|
||||
"return": "0x00000000000000000000000000000000000000000000000000000000000f4241"
|
||||
}
|
||||
],
|
||||
"source": "https://polygon-bor-rpc.publicnode.com",
|
||||
"preparation_tx": "0x8d77f8741cfbf4c6388d87aa90a6f4c2c238ac35fbecc02ab39671e2f0f8a7b9",
|
||||
"observed_at_ms": 1796491315981
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,242 @@
|
||||
[
|
||||
{
|
||||
"chain_id": 137,
|
||||
"event_id": "0x026b8d75bfa676ec6e8c8d496b03036400000300000000000000000000000000",
|
||||
"block_number": "0x5df5c43",
|
||||
"block_hash": "0x210e92e62a26f17bb75c26b905f96c83180e54b51ab634f64da83c16c30130ca",
|
||||
"registry": "0x000000000000000000000000200000900045e3b6259600682756002200028933",
|
||||
"condition_count": "0x0000000000000000000000000000000000000000000000000000000000000003",
|
||||
"conditions_reported": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"results_sum": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"conditions": [
|
||||
{
|
||||
"index": 0,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 2,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 3,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sources": [
|
||||
"https://polygon.drpc.org"
|
||||
],
|
||||
"legacy_event_id": "0x0a0374c2418aac1d34f5b9ee14f5a0446b8d75bfa676ec6e8c8d496b03036400"
|
||||
},
|
||||
{
|
||||
"chain_id": 137,
|
||||
"event_id": "0x026b8d75bfa676ec6e8c8d496b03036400000300000000000000000000000000",
|
||||
"block_number": "0x5df5c44",
|
||||
"block_hash": "0xee7aa65f66a4260474fcec3934ea21ab93f6003af041934a55d2547286cfaedb",
|
||||
"registry": "0x000000000000000000000000200000900045e3b6259600682756002200028933",
|
||||
"condition_count": "0x0000000000000000000000000000000000000000000000000000000000000003",
|
||||
"conditions_reported": "0x0000000000000000000000000000000000000000000000000000000000000003",
|
||||
"results_sum": "0x00000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"conditions": [
|
||||
{
|
||||
"index": 0,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"stored_yes": {
|
||||
"return": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"effective": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"return": "0x00000000000000000000000000000000000000000000000000000000000f4240"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 2,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"stored_yes": {
|
||||
"return": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 3,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sources": [
|
||||
"https://polygon.drpc.org"
|
||||
],
|
||||
"transition_tx": "0xaef081eb07769e30c2d79c45deff68f2c697b250d4b7c0f04afc2390e1d50250",
|
||||
"legacy_event_id": "0x0a0374c2418aac1d34f5b9ee14f5a0446b8d75bfa676ec6e8c8d496b03036400",
|
||||
"legacy_catalog": [
|
||||
{
|
||||
"condition_index": 0,
|
||||
"id": "7420052",
|
||||
"slug": "serc-acd-cit-2026-12-05-acd",
|
||||
"version": "v1",
|
||||
"conditionId": "0x031de2fd1570ce33ad6e59b50c5bf58d24661741bcc42c0dfd5e718fc4960128",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x026b8d75bfa676ec6e8c8d496b03036400000300000000000000000000000000",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 1,
|
||||
"id": "7420053",
|
||||
"slug": "serc-acd-cit-2026-12-05-draw",
|
||||
"version": "v1",
|
||||
"conditionId": "0x71e48af45160c9f56010f46ad2d0915a29c861a3250d6592c1f1977c3fbfc8cc",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"1\", \"0\"]",
|
||||
"position_condition_id": "0x026b8d75bfa676ec6e8c8d496b03036400000300000000000000000000000100",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 2,
|
||||
"id": "7420054",
|
||||
"slug": "serc-acd-cit-2026-12-05-cit",
|
||||
"version": "v1",
|
||||
"conditionId": "0xc0671fbf4755c8b5b4eb94352e7c92b832f0263a9a0460225ad04412d45ac34e",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x026b8d75bfa676ec6e8c8d496b03036400000300000000000000000000000200",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"chain_id": 137,
|
||||
"event_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000000000",
|
||||
"block_number": "0x5df5c62",
|
||||
"block_hash": "0xc60a077a550b53bb5dc4f960047b5be961f196574f6af91b799ed0f109e9e5d7",
|
||||
"registry": "0x000000000000000000000000200000900045e3b6259600682756002200028933",
|
||||
"condition_count": "0x0000000000000000000000000000000000000000000000000000000000000025",
|
||||
"conditions_reported": "0x0000000000000000000000000000000000000000000000000000000000000021",
|
||||
"results_sum": "0x00000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"conditions": [
|
||||
{
|
||||
"index": 0,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"stored_yes": {
|
||||
"return": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 32,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 33,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 34,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 35,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 37,
|
||||
"effective": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240",
|
||||
"stored_yes": {
|
||||
"revert": "0x"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sources": [
|
||||
"https://polygon.drpc.org"
|
||||
],
|
||||
"transition_tx": "0xa066409b2da62eab52aeae7e439cb11e1e28124a2e94d06c87a74bf42acc8286",
|
||||
"legacy_event_id": "0x1ec6befb358b06cb59c12fddd306b970a28dc7d450aef445cdcfc3b43a566800",
|
||||
"legacy_catalog": [
|
||||
{
|
||||
"condition_index": 0,
|
||||
"id": "7421956",
|
||||
"slug": "serc-acd-cit-2026-12-05-exact-score-0-0",
|
||||
"version": "v1",
|
||||
"conditionId": "0xaa7d72c3addfbd60609d2762ca945e39307da5e05c9aa9c24a8e979d6e2f52c0",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000000000",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 32,
|
||||
"id": "7421988",
|
||||
"slug": "serc-acd-cit-2026-12-05-exact-score-5-3",
|
||||
"version": "v1",
|
||||
"conditionId": "0x99ba4cc23d2eb8733fc92c3775951f5d020b3304134015f7b60233d24cfb77a7",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000002000",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 33,
|
||||
"id": "7421989",
|
||||
"slug": "serc-acd-cit-2026-12-05-exact-score-4-5",
|
||||
"version": "v1",
|
||||
"conditionId": "0xf2a796cbeefc2bce1bd00ce006464082eb47d08e1d0d65c93363388925e61c2c",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000002100",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 34,
|
||||
"id": "7421990",
|
||||
"slug": "serc-acd-cit-2026-12-05-exact-score-5-4",
|
||||
"version": "v1",
|
||||
"conditionId": "0xb37245a4a512fef2f2e8b687fd2820896548f5d7f54ef080b8077f457d3aca91",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000002200",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
{
|
||||
"condition_index": 35,
|
||||
"id": "7421991",
|
||||
"slug": "serc-acd-cit-2026-12-05-exact-score-5-5",
|
||||
"version": "v1",
|
||||
"conditionId": "0x8ff38f5d3a32276d5ec8cb5a6232652fa838fec77e22e081a7fd1cf1c45a33d3",
|
||||
"outcomes": "[\"Yes\", \"No\"]",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"position_condition_id": "0x02a28dc7d450aef445cdcfc3b43a566800002500000000000000000000002300",
|
||||
"legacy_ctf_denominator": "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,241 @@
|
||||
use crate::{
|
||||
polygon_rpc::{hex_data, quantity, CallOutcome, FinalizedRpc, POLYGON_CHAIN_ID},
|
||||
position_resolution::{lookup_module, module_address, uint, POSITION_MANAGER},
|
||||
};
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use reqwest::blocking::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
const MODULE: u8 = 3;
|
||||
const GET_LEGS: &str = "9989b1ed"; // getLegs(bytes31)
|
||||
const GET_PAYOUT: &str = "4c619e4c"; // getPayout(uint256,uint256)
|
||||
const NOT_REDEEMABLE: &str = "0xc003777b"; // PositionNotRedeemable()
|
||||
const MAX_LEGS: usize = 50;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Observation {
|
||||
chain_id: u64,
|
||||
block_number: String,
|
||||
block_hash: String,
|
||||
condition_id: String,
|
||||
amount_micros: u64,
|
||||
registry: String,
|
||||
legs: String,
|
||||
payouts: Option<[CallOutcome; 2]>,
|
||||
observed_at_ms: u64,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
source: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
preparation_tx: Option<String>,
|
||||
}
|
||||
|
||||
fn condition_word(condition: &str) -> Result<String> {
|
||||
let word = match condition.len() {
|
||||
64 => format!("{}00", hex_data(condition, 31)?),
|
||||
66 => hex_data(condition, 32)?.to_owned(),
|
||||
_ => anyhow::bail!("invalid combo condition ID length"),
|
||||
};
|
||||
ensure!(
|
||||
word.starts_with("03") && word.ends_with("00"),
|
||||
"expected a combinatorial condition with an empty outcome byte"
|
||||
);
|
||||
Ok(word.to_ascii_lowercase())
|
||||
}
|
||||
|
||||
fn legs(raw: &str) -> Result<Vec<&str>> {
|
||||
ensure!(
|
||||
(130..=130 + 64 * MAX_LEGS).contains(&raw.len()) && (raw.len() - 130) % 64 == 0,
|
||||
"invalid getLegs ABI size"
|
||||
);
|
||||
let data = hex_data(raw, (raw.len() - 2) / 2)?;
|
||||
let count = (data.len() - 128) / 64;
|
||||
ensure!(uint(&data[..64])? == 32, "invalid getLegs ABI offset");
|
||||
ensure!(
|
||||
uint(&data[64..128])? == count as u64,
|
||||
"invalid getLegs length"
|
||||
);
|
||||
let mut ids: Vec<&str> = Vec::with_capacity(count);
|
||||
for index in 0..count {
|
||||
let start = 128 + 64 * index;
|
||||
let id = &data[start..start + 64];
|
||||
ensure!(
|
||||
matches!(&id[..2], "01" | "02") && matches!(&id[62..], "00" | "01"),
|
||||
"invalid underlying position ID"
|
||||
);
|
||||
if let Some(previous) = ids.last() {
|
||||
ensure!(
|
||||
previous[..62].to_ascii_lowercase() < id[..62].to_ascii_lowercase(),
|
||||
"combo legs must be sorted with distinct conditions"
|
||||
);
|
||||
}
|
||||
ids.push(id);
|
||||
}
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
fn payout_status(
|
||||
payouts: Option<&[CallOutcome; 2]>,
|
||||
has_legs: bool,
|
||||
amount: u64,
|
||||
) -> Result<(&'static str, Option<[String; 2]>)> {
|
||||
match (has_legs, payouts) {
|
||||
(false, None) => Ok(("unprepared", None)),
|
||||
(true, Some([CallOutcome::Revert(yes), CallOutcome::Revert(no)]))
|
||||
if [yes, no]
|
||||
.iter()
|
||||
.all(|value| value.eq_ignore_ascii_case(NOT_REDEEMABLE)) =>
|
||||
{
|
||||
Ok(("unresolved", None))
|
||||
}
|
||||
(true, Some([CallOutcome::Return(yes), CallOutcome::Return(no)])) => {
|
||||
let yes = uint(hex_data(yes, 32)?)?;
|
||||
let no = uint(hex_data(no, 32)?)?;
|
||||
ensure!(
|
||||
yes.checked_add(no).is_some_and(|total| total <= amount),
|
||||
"combo payouts exceed the position amount"
|
||||
);
|
||||
Ok(("redeemable", Some([yes.to_string(), no.to_string()])))
|
||||
}
|
||||
_ => anyhow::bail!("inconsistent combo legs and payout responses"),
|
||||
}
|
||||
}
|
||||
|
||||
fn audit(obs: Observation) -> Result<Value> {
|
||||
ensure!(
|
||||
obs.chain_id == POLYGON_CHAIN_ID,
|
||||
"observation is not Polygon mainnet"
|
||||
);
|
||||
ensure!(obs.amount_micros > 0, "position amount must be positive");
|
||||
let block = quantity(&obs.block_number)?;
|
||||
hex_data(&obs.block_hash, 32)?;
|
||||
let condition = condition_word(&obs.condition_id)?;
|
||||
let target = module_address(&obs.registry, MODULE)?;
|
||||
let ids = legs(&obs.legs)?;
|
||||
let (status, payouts) =
|
||||
payout_status(obs.payouts.as_ref(), !ids.is_empty(), obs.amount_micros)?;
|
||||
let legs: Vec<_> = ids.iter().map(|id| format!("0x{id}")).collect();
|
||||
Ok(json!({
|
||||
"observation": obs,
|
||||
"block": block,
|
||||
"position_manager": POSITION_MANAGER,
|
||||
"module_contract": target,
|
||||
"condition_id": format!("0x{condition}"),
|
||||
"leg_position_ids": legs,
|
||||
"status": status,
|
||||
"payout_micros_yes_no": payouts,
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn inspect(client: &Client, condition: &str, amount: &str) -> Result<Value> {
|
||||
let condition = condition_word(condition)?;
|
||||
let amount_micros: u64 = amount.parse().context("invalid microshare amount")?;
|
||||
ensure!(amount_micros > 0, "position amount must be positive");
|
||||
let block = FinalizedRpc::connect(client)?;
|
||||
let registry = lookup_module(&block, MODULE)?;
|
||||
let address = module_address(®istry, MODULE)?;
|
||||
let raw_legs = block.call(&address, &format!("0x{GET_LEGS}{condition}"))?;
|
||||
let payouts = if legs(&raw_legs)?.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let call = |side: u8| {
|
||||
block.call_with_revert(
|
||||
&address,
|
||||
&format!(
|
||||
"0x{GET_PAYOUT}{}{side:02x}{amount_micros:064x}",
|
||||
&condition[..62]
|
||||
),
|
||||
NOT_REDEEMABLE,
|
||||
)
|
||||
};
|
||||
Some([call(0)?, call(1)?])
|
||||
};
|
||||
let observed_at_ms = block.confirm()?;
|
||||
audit(Observation {
|
||||
chain_id: POLYGON_CHAIN_ID,
|
||||
block_number: block.number,
|
||||
block_hash: block.hash,
|
||||
condition_id: format!("0x{condition}"),
|
||||
amount_micros,
|
||||
registry,
|
||||
legs: raw_legs,
|
||||
payouts,
|
||||
observed_at_ms,
|
||||
source: None,
|
||||
preparation_tx: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn replay(file: &str) -> Result<Vec<Value>> {
|
||||
let raw: Value = serde_json::from_reader(std::fs::File::open(file)?)?;
|
||||
let rows = match raw {
|
||||
Value::Array(rows) => rows,
|
||||
value => vec![value],
|
||||
};
|
||||
ensure!(!rows.is_empty(), "no combo observations in file");
|
||||
rows.into_iter()
|
||||
.map(|row| {
|
||||
audit(serde_json::from_value(
|
||||
row.get("observation").cloned().unwrap_or(row),
|
||||
)?)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn replays_production_combos_in_both_states() -> Result<()> {
|
||||
let [pending, terminal]: [Observation; 2] =
|
||||
serde_json::from_str(include_str!("../fixtures/live-combo-payouts.json"))?;
|
||||
let pending = audit(pending)?;
|
||||
let terminal = audit(terminal)?;
|
||||
assert_eq!(pending["status"], "unresolved");
|
||||
assert_eq!(pending["leg_position_ids"].as_array().unwrap().len(), 11);
|
||||
assert!(pending["payout_micros_yes_no"].is_null());
|
||||
assert_eq!(terminal["status"], "redeemable");
|
||||
assert_eq!(terminal["payout_micros_yes_no"], json!(["0", "1000001"]));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn separates_unprepared_zero_fractional_and_inconsistent_amounts() -> Result<()> {
|
||||
assert_eq!(payout_status(None, false, 10)?, ("unprepared", None));
|
||||
assert!(payout_status(None, true, 10).is_err());
|
||||
let success = |value: u64| CallOutcome::Return(format!("0x{value:064x}"));
|
||||
for amounts in [[0, 0], [2, 7], [10, 0]] {
|
||||
let payouts = amounts.map(success);
|
||||
assert_eq!(
|
||||
payout_status(Some(&payouts), true, 10)?,
|
||||
("redeemable", Some(amounts.map(|value| value.to_string())))
|
||||
);
|
||||
}
|
||||
assert!(payout_status(Some(&[success(4), success(7)]), true, 10).is_err());
|
||||
let pending = CallOutcome::Revert(NOT_REDEEMABLE.to_owned());
|
||||
assert!(payout_status(Some(&[success(0), pending]), true, 10).is_err());
|
||||
let unknown = || CallOutcome::Revert("0x00000000".to_owned());
|
||||
assert!(payout_status(Some(&[unknown(), unknown()]), true, 10).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_combo_condition_and_returned_leg_array() -> Result<()> {
|
||||
let condition = format!("03{}", "00".repeat(31));
|
||||
assert_eq!(
|
||||
condition_word(&format!("0x{}", &condition[..62]))?,
|
||||
condition
|
||||
);
|
||||
assert!(condition_word(&format!("0x{}01", &condition[..62])).is_err());
|
||||
let first = format!("01{}", "00".repeat(31));
|
||||
let opposite = format!("{}01", &first[..62]);
|
||||
let second = format!("02{}", "00".repeat(31));
|
||||
let array = |a: &str, b: &str| format!("0x{:064x}{:064x}{a}{b}", 32, 2);
|
||||
assert_eq!(legs(&array(&first, &second))?.len(), 2);
|
||||
assert!(legs(&array(&first, &opposite)).is_err());
|
||||
assert!(legs(&array(&second, &first)).is_err());
|
||||
assert!(legs(&array(&first, &condition)).is_err());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
mod book_audit;
|
||||
mod books;
|
||||
mod catalog;
|
||||
mod combo_payout;
|
||||
mod ctf_resolution;
|
||||
mod neg_risk_resolution;
|
||||
mod polygon_rpc;
|
||||
mod position_resolution;
|
||||
mod price_check;
|
||||
@@ -33,10 +35,48 @@ fn observe_book(client: &Client, url: reqwest::Url, token: &str) -> Result<()> {
|
||||
result
|
||||
}
|
||||
|
||||
fn polygon_client() -> Result<Client> {
|
||||
Ok(Client::builder()
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.timeout(Duration::from_secs(10))
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.user_agent("eventbook-readonly-probe/0.1")
|
||||
.build()?)
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<_> = std::env::args().skip(1).collect();
|
||||
let usage =
|
||||
"usage: venue-probe [--compare-prices | --inspect-book TOKEN | --replay-book TOKEN FILE | --replay-market FILE | --inspect-resolution CONDITION [EXPECTED] | --replay-resolution FILE [EXPECTED] | --inspect-position-resolution MARKET_JSON [EXPECTED] | --replay-position-resolution FILE [EXPECTED]]";
|
||||
"usage: venue-probe [--compare-prices | --inspect-book TOKEN | --replay-book TOKEN FILE | --replay-market FILE | --inspect-resolution CONDITION [EXPECTED] | --replay-resolution FILE [EXPECTED] | --inspect-position-resolution MARKET_JSON [EXPECTED] | --replay-position-resolution FILE [EXPECTED] | --inspect-combo-payout CONDITION AMOUNT_MICROS | --replay-combo-payout FILE | --inspect-neg-risk-event EVENT_ID INDICES | --replay-neg-risk-event FILE]";
|
||||
match args.as_slice() {
|
||||
[mode, condition, amount] if mode == "--inspect-combo-payout" => {
|
||||
println!(
|
||||
"{}",
|
||||
combo_payout::inspect(&polygon_client()?, condition, amount)?
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
[mode, file] if mode == "--replay-combo-payout" => {
|
||||
for report in combo_payout::replay(file)? {
|
||||
println!("{report}");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
[mode, event, indices] if mode == "--inspect-neg-risk-event" => {
|
||||
println!(
|
||||
"{}",
|
||||
neg_risk_resolution::inspect(&polygon_client()?, event, indices)?
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
[mode, file] if mode == "--replay-neg-risk-event" => {
|
||||
for report in neg_risk_resolution::replay(file)? {
|
||||
println!("{report}");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let [mode, value, rest @ ..] = args.as_slice() {
|
||||
if matches!(
|
||||
mode.as_str(),
|
||||
@@ -51,12 +91,7 @@ fn main() -> Result<()> {
|
||||
"--replay-resolution" => vec![ctf_resolution::replay(value, expected)?],
|
||||
"--replay-position-resolution" => position_resolution::replay(value, expected)?,
|
||||
_ => {
|
||||
let client = Client::builder()
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.timeout(Duration::from_secs(10))
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.user_agent("eventbook-readonly-probe/0.1")
|
||||
.build()?;
|
||||
let client = polygon_client()?;
|
||||
vec![if mode == "--inspect-resolution" {
|
||||
ctf_resolution::inspect(&client, value, expected)?
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
use crate::{
|
||||
polygon_rpc::{hex_data, quantity, CallOutcome, FinalizedRpc, POLYGON_CHAIN_ID},
|
||||
position_resolution::{
|
||||
lookup_module, module_address, result, uint, DENOMINATOR, GET_RESULT, POSITION_MANAGER,
|
||||
},
|
||||
};
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use reqwest::blocking::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
const MODULE: u8 = 2;
|
||||
const CONDITION_COUNT: &str = "dacc07ce"; // conditionCount(bytes29)
|
||||
const REPORTED: &str = "936830bc"; // conditionsResolved(bytes29)
|
||||
const LEGACY_EVENT: &str = "b2915f84"; // legacyEventId(bytes29)
|
||||
const RESULTS_SUM: &str = "65fe9636"; // resultsSum(bytes29)
|
||||
const STORED_RESULT: &str = "91f7d1bf"; // result(bytes31,uint256)
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Condition {
|
||||
index: u16,
|
||||
effective: String,
|
||||
stored_yes: CallOutcome,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Observation {
|
||||
chain_id: u64,
|
||||
event_id: String,
|
||||
block_number: String,
|
||||
block_hash: String,
|
||||
registry: String,
|
||||
condition_count: String,
|
||||
conditions_reported: String,
|
||||
results_sum: String,
|
||||
legacy_event_id: String,
|
||||
conditions: Vec<Condition>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
legacy_catalog: Vec<Value>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
sources: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
transition_tx: Option<String>,
|
||||
}
|
||||
|
||||
fn event_id(raw: &str) -> Result<(String, u16)> {
|
||||
let full = match raw.len() {
|
||||
60 => format!("{}000000", hex_data(raw, 29)?),
|
||||
66 => hex_data(raw, 32)?.to_owned(),
|
||||
_ => anyhow::bail!("invalid V2 event ID length"),
|
||||
};
|
||||
ensure!(
|
||||
full.starts_with("02") && full.ends_with("000000"),
|
||||
"expected a V2 NegRisk event ID"
|
||||
);
|
||||
let count = u16::from_str_radix(&full[34..38], 16)?;
|
||||
ensure!(count >= 2, "invalid V2 NegRisk event condition count");
|
||||
Ok((full.to_ascii_lowercase(), count))
|
||||
}
|
||||
|
||||
fn value(raw: &str) -> Result<u64> {
|
||||
uint(hex_data(raw, 32)?)
|
||||
}
|
||||
|
||||
fn condition_word(event: &str, index: u16) -> String {
|
||||
format!("{}{index:04x}00", &event[..58])
|
||||
}
|
||||
|
||||
fn output_condition(
|
||||
condition: &Condition,
|
||||
event: &str,
|
||||
count: u16,
|
||||
reported: u64,
|
||||
sum: u64,
|
||||
migrated_event: bool,
|
||||
) -> Result<Value> {
|
||||
ensure!(
|
||||
condition.index <= count,
|
||||
"condition index is outside this event"
|
||||
);
|
||||
let weights = result(&condition.effective, MODULE)?;
|
||||
let synthetic = condition.index == count;
|
||||
let migrated = migrated_event && !synthetic;
|
||||
// The generated array getter returns an empty revert for index 0
|
||||
// when the stored result array has no entries.
|
||||
let origin = match (&condition.stored_yes, weights) {
|
||||
(CallOutcome::Return(raw), Some([yes, _])) if value(raw)? == yes => {
|
||||
ensure!(
|
||||
yes == 0 || sum == DENOMINATOR,
|
||||
"stored YES payout is missing from the event sum"
|
||||
);
|
||||
ensure!(
|
||||
synthetic || reported > 0,
|
||||
"stored market is missing from the report count"
|
||||
);
|
||||
"stored"
|
||||
}
|
||||
(CallOutcome::Revert(data), weights) if data == "0x" => match weights {
|
||||
None => "unresolved",
|
||||
Some([0, DENOMINATOR]) if !migrated && sum == DENOMINATOR => "derived",
|
||||
Some([DENOMINATOR, 0]) if synthetic && sum == 0 && reported == u64::from(count) => {
|
||||
"derived"
|
||||
}
|
||||
_ => anyhow::bail!("unstored payout disagrees with the event counters"),
|
||||
},
|
||||
_ => anyhow::bail!("stored payout disagrees with the effective result"),
|
||||
};
|
||||
Ok(json!({
|
||||
"condition_index":condition.index,
|
||||
"condition_id":format!("0x{}",condition_word(event,condition.index)),
|
||||
"synthetic_other":synthetic,
|
||||
"legacy_migration":migrated,
|
||||
"source":origin,
|
||||
"payout_numerators":weights,
|
||||
}))
|
||||
}
|
||||
|
||||
fn audit(obs: Observation) -> Result<Value> {
|
||||
ensure!(
|
||||
obs.chain_id == POLYGON_CHAIN_ID,
|
||||
"observation is not from Polygon"
|
||||
);
|
||||
let block = quantity(&obs.block_number)?;
|
||||
hex_data(&obs.block_hash, 32)?;
|
||||
if let Some(tx) = &obs.transition_tx {
|
||||
hex_data(tx, 32)?;
|
||||
}
|
||||
let (event, count) = event_id(&obs.event_id)?;
|
||||
let module = module_address(&obs.registry, MODULE)?;
|
||||
let reported = value(&obs.conditions_reported)?;
|
||||
let sum = value(&obs.results_sum)?;
|
||||
let migrated = hex_data(&obs.legacy_event_id, 32)?
|
||||
.bytes()
|
||||
.any(|digit| digit != b'0');
|
||||
ensure!(
|
||||
value(&obs.condition_count)? == u64::from(count),
|
||||
"condition count disagrees with the event ID"
|
||||
);
|
||||
ensure!(
|
||||
reported <= u64::from(count) + 1 && matches!(sum, 0 | DENOMINATOR),
|
||||
"invalid NegRisk counters"
|
||||
);
|
||||
let mut seen = BTreeSet::new();
|
||||
ensure!(!obs.conditions.is_empty(), "no observed conditions");
|
||||
let conditions = obs
|
||||
.conditions
|
||||
.iter()
|
||||
.map(|condition| {
|
||||
ensure!(
|
||||
seen.insert(condition.index),
|
||||
"duplicate condition observation"
|
||||
);
|
||||
output_condition(condition, &event, count, reported, sum, migrated)
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
for market in &obs.legacy_catalog {
|
||||
let index = market["condition_index"]
|
||||
.as_u64()
|
||||
.context("missing legacy condition index")?;
|
||||
let index = u16::try_from(index).context("invalid legacy condition index")?;
|
||||
ensure!(
|
||||
migrated && index < count && seen.contains(&index),
|
||||
"legacy market does not identify an observed migrated condition"
|
||||
);
|
||||
let mapped = market["position_condition_id"]
|
||||
.as_str()
|
||||
.context("missing on-chain legacy mapping")?;
|
||||
ensure!(
|
||||
hex_data(mapped, 32)?.eq_ignore_ascii_case(&condition_word(&event, index)),
|
||||
"legacy market points to another condition"
|
||||
);
|
||||
hex_data(
|
||||
market["conditionId"]
|
||||
.as_str()
|
||||
.context("missing legacy CTF condition")?,
|
||||
32,
|
||||
)?;
|
||||
hex_data(
|
||||
market["legacy_ctf_denominator"]
|
||||
.as_str()
|
||||
.context("missing legacy CTF denominator")?,
|
||||
32,
|
||||
)?;
|
||||
}
|
||||
Ok(json!({
|
||||
"observation":obs,
|
||||
"event_id":format!("0x{event}"),
|
||||
"position_manager":POSITION_MANAGER,
|
||||
"module_contract":module,
|
||||
"block":block,
|
||||
"condition_count":count,
|
||||
"reported_count":reported,
|
||||
"results_sum":sum,
|
||||
"legacy_event_id":migrated.then_some(&obs.legacy_event_id),
|
||||
"payout_denominator":DENOMINATOR,
|
||||
"conditions":conditions,
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn inspect(client: &Client, event: &str, indices: &str) -> Result<Value> {
|
||||
let (event, count) = event_id(event)?;
|
||||
let mut selected = BTreeSet::new();
|
||||
for raw in indices.split(',') {
|
||||
let index: u16 = raw.parse().context("invalid condition index")?;
|
||||
ensure!(index <= count, "condition index is outside this event");
|
||||
ensure!(selected.insert(index), "duplicate condition index");
|
||||
}
|
||||
let block = FinalizedRpc::connect(client)?;
|
||||
let registry = lookup_module(&block, MODULE)?;
|
||||
let module = module_address(®istry, MODULE)?;
|
||||
let counter = |selector| block.call(&module, &format!("0x{selector}{event}"));
|
||||
let condition_count = counter(CONDITION_COUNT)?;
|
||||
let conditions_reported = counter(REPORTED)?;
|
||||
let results_sum = counter(RESULTS_SUM)?;
|
||||
let legacy_event_id = counter(LEGACY_EVENT)?;
|
||||
let conditions = selected
|
||||
.into_iter()
|
||||
.map(|index| {
|
||||
let id = condition_word(&event, index);
|
||||
Ok(Condition {
|
||||
index,
|
||||
effective: block.call(&module, &format!("0x{GET_RESULT}{id}"))?,
|
||||
stored_yes: block.call_with_revert(
|
||||
&module,
|
||||
&format!("0x{STORED_RESULT}{id}{:064x}", 0),
|
||||
"0x",
|
||||
)?,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
block.confirm()?;
|
||||
audit(Observation {
|
||||
chain_id: POLYGON_CHAIN_ID,
|
||||
event_id: format!("0x{event}"),
|
||||
block_number: block.number,
|
||||
block_hash: block.hash,
|
||||
registry,
|
||||
condition_count,
|
||||
conditions_reported,
|
||||
results_sum,
|
||||
legacy_event_id,
|
||||
conditions,
|
||||
legacy_catalog: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
transition_tx: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn replay(file: &str) -> Result<Vec<Value>> {
|
||||
let raw: Value = serde_json::from_reader(std::fs::File::open(file)?)?;
|
||||
let rows = match raw {
|
||||
Value::Array(rows) => rows,
|
||||
value => vec![value],
|
||||
};
|
||||
ensure!(!rows.is_empty(), "no NegRisk event observations in file");
|
||||
rows.into_iter()
|
||||
.map(|row| {
|
||||
audit(serde_json::from_value(
|
||||
row.get("observation").cloned().unwrap_or(row),
|
||||
)?)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn replays_reported_derived_and_legacy_pending_results() -> Result<()> {
|
||||
let [before, after, migrated]: [Observation; 3] =
|
||||
serde_json::from_str(include_str!("../fixtures/live-negrisk-resolution.json"))?;
|
||||
let before = audit(before)?;
|
||||
let after = audit(after)?;
|
||||
let migrated = audit(migrated)?;
|
||||
assert_eq!(before["reported_count"], 0);
|
||||
assert_eq!(before["conditions"][3]["source"], "unresolved");
|
||||
assert_eq!(after["reported_count"], 3);
|
||||
assert_eq!(after["conditions"][1]["source"], "stored");
|
||||
assert_eq!(
|
||||
after["conditions"][1]["payout_numerators"],
|
||||
json!([1_000_000, 0])
|
||||
);
|
||||
assert_eq!(after["conditions"][3]["source"], "derived");
|
||||
assert_eq!(
|
||||
after["conditions"][3]["payout_numerators"],
|
||||
json!([0, 1_000_000])
|
||||
);
|
||||
assert_eq!(migrated["reported_count"], 33);
|
||||
assert_eq!(migrated["condition_count"], 37);
|
||||
assert_eq!(migrated["conditions"][1]["source"], "unresolved");
|
||||
assert_eq!(migrated["conditions"][1]["legacy_migration"], true);
|
||||
assert_eq!(migrated["conditions"][5]["source"], "derived");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_synthetic_yes_rule_and_rejects_derived_migrated_sibling() -> Result<()> {
|
||||
let event = format!("02{}0002{}", "00".repeat(16), "00".repeat(13));
|
||||
let encoded = |a: u64, b: u64| format!("0x{:064x}{:064x}{a:064x}{b:064x}", 32, 2);
|
||||
let mut condition = Condition {
|
||||
index: 2,
|
||||
effective: encoded(DENOMINATOR, 0),
|
||||
stored_yes: CallOutcome::Revert("0x".into()),
|
||||
};
|
||||
assert_eq!(
|
||||
output_condition(&condition, &event, 2, 2, 0, false)?["source"],
|
||||
"derived"
|
||||
);
|
||||
assert!(output_condition(&condition, &event, 2, 1, 0, false).is_err());
|
||||
condition.index = 1;
|
||||
condition.effective = encoded(0, DENOMINATOR);
|
||||
assert_eq!(
|
||||
output_condition(&condition, &event, 2, 1, DENOMINATOR, false)?["source"],
|
||||
"derived"
|
||||
);
|
||||
assert!(output_condition(&condition, &event, 2, 1, DENOMINATOR, true).is_err());
|
||||
condition.stored_yes = CallOutcome::Return(format!("0x{DENOMINATOR:064x}"));
|
||||
assert!(output_condition(&condition, &event, 2, 1, DENOMINATOR, true).is_err());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use reqwest::{blocking::Client, Url};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
@@ -36,6 +37,27 @@ pub(crate) fn word(raw: &str) -> Result<[u8; 32]> {
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct RpcFailure {
|
||||
code: Value,
|
||||
data: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RpcFailure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "RPC rejected the request (code {})", self.code)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for RpcFailure {}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum CallOutcome {
|
||||
Return(String),
|
||||
Revert(String),
|
||||
}
|
||||
|
||||
fn rpc(client: &Client, url: &Url, method: &str, params: Value) -> Result<Value> {
|
||||
let response: Value = client
|
||||
.post(url.clone())
|
||||
@@ -53,7 +75,11 @@ fn rpc(client: &Client, url: &Url, method: &str, params: Value) -> Result<Value>
|
||||
"invalid RPC envelope for {method}"
|
||||
);
|
||||
if let Some(error) = response.get("error") {
|
||||
anyhow::bail!("{method} RPC rejected the request (code {})", error["code"]);
|
||||
return Err(anyhow::Error::new(RpcFailure {
|
||||
code: error["code"].clone(),
|
||||
data: error["data"].as_str().map(str::to_owned),
|
||||
})
|
||||
.context(format!("{method} RPC failed")));
|
||||
}
|
||||
response
|
||||
.get("result")
|
||||
@@ -116,6 +142,25 @@ impl<'a> FinalizedRpc<'a> {
|
||||
.context("invalid eth_call ABI result")
|
||||
}
|
||||
|
||||
pub(crate) fn call_with_revert(
|
||||
&self,
|
||||
contract: &str,
|
||||
data: &str,
|
||||
selector: &str,
|
||||
) -> Result<CallOutcome> {
|
||||
match self.call(contract, data) {
|
||||
Ok(value) => Ok(CallOutcome::Return(value)),
|
||||
Err(error) => match error
|
||||
.downcast_ref::<RpcFailure>()
|
||||
.and_then(|failure| failure.data.as_deref())
|
||||
.filter(|data| data.eq_ignore_ascii_case(selector))
|
||||
{
|
||||
Some(data) => Ok(CallOutcome::Revert(data.to_owned())),
|
||||
None => Err(error),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn confirm(&self) -> Result<u64> {
|
||||
// Providers may lack EIP-1898 support. Read the finalized block number,
|
||||
// then verify its hash again before accepting any of the calls.
|
||||
|
||||
@@ -7,11 +7,11 @@ use reqwest::blocking::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
const POSITION_MANAGER: &str = "0x006F54F7f9A22e0000CC2AB60031000000ae9fEF";
|
||||
pub(crate) const POSITION_MANAGER: &str = "0x006F54F7f9A22e0000CC2AB60031000000ae9fEF";
|
||||
// moduleById(uint256), getResult(bytes31)
|
||||
const MODULE_BY_ID: &str = "4d51cdf1";
|
||||
const GET_RESULT: &str = "e4939c77";
|
||||
const DENOMINATOR: u64 = 1_000_000;
|
||||
pub(crate) const GET_RESULT: &str = "e4939c77";
|
||||
pub(crate) const DENOMINATOR: u64 = 1_000_000;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Observation {
|
||||
@@ -59,7 +59,7 @@ fn market_binding(raw: &Value) -> Result<(Market, u8, &'static str)> {
|
||||
Ok((market, module, name))
|
||||
}
|
||||
|
||||
fn module_address(registry: &str, module: u8) -> Result<String> {
|
||||
pub(crate) fn module_address(registry: &str, module: u8) -> Result<String> {
|
||||
let raw = hex_data(registry, 32)?;
|
||||
ensure!(
|
||||
raw[..24].bytes().all(|digit| digit == b'0'),
|
||||
@@ -69,6 +69,7 @@ fn module_address(registry: &str, module: u8) -> Result<String> {
|
||||
let expected = match module {
|
||||
1 => "0x1000008dD9001B968442c1000017eaE6E0dA00Ba",
|
||||
2 => "0x200000900045e3B6259600682756002200028933",
|
||||
3 => "0x30000034706C7d8e12009DAB006Be20000c031A8",
|
||||
_ => anyhow::bail!("unsupported PositionManager module"),
|
||||
};
|
||||
ensure!(
|
||||
@@ -78,7 +79,7 @@ fn module_address(registry: &str, module: u8) -> Result<String> {
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
fn uint(word_hex: &str) -> Result<u64> {
|
||||
pub(crate) fn uint(word_hex: &str) -> Result<u64> {
|
||||
let data = word(&format!("0x{word_hex}"))?;
|
||||
ensure!(
|
||||
data[..24].iter().all(|&byte| byte == 0),
|
||||
@@ -87,7 +88,7 @@ fn uint(word_hex: &str) -> Result<u64> {
|
||||
Ok(u64::from_be_bytes(data[24..].try_into()?))
|
||||
}
|
||||
|
||||
fn result(raw: &str, module: u8) -> Result<Option<[u64; 2]>> {
|
||||
pub(crate) fn result(raw: &str, module: u8) -> Result<Option<[u64; 2]>> {
|
||||
let bytes = match raw.len() {
|
||||
130 => 64,
|
||||
258 => 128,
|
||||
@@ -148,6 +149,10 @@ fn audit(obs: Observation, expected: Option<&str>) -> Result<Value> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn lookup_module(block: &FinalizedRpc<'_>, module: u8) -> Result<String> {
|
||||
block.call(POSITION_MANAGER, &format!("0x{MODULE_BY_ID}{module:064x}"))
|
||||
}
|
||||
|
||||
pub(crate) fn inspect(client: &Client, file: &str, expected: Option<&str>) -> Result<Value> {
|
||||
let market: Value = serde_json::from_reader(std::fs::File::open(file)?)?;
|
||||
let (binding, module, _) = market_binding(&market)?;
|
||||
@@ -158,7 +163,7 @@ pub(crate) fn inspect(client: &Client, file: &str, expected: Option<&str>) -> Re
|
||||
31,
|
||||
)?;
|
||||
let block = FinalizedRpc::connect(client)?;
|
||||
let registry = block.call(POSITION_MANAGER, &format!("0x{MODULE_BY_ID}{module:064x}"))?;
|
||||
let registry = lookup_module(&block, module)?;
|
||||
let address = module_address(®istry, module)?;
|
||||
// Solidity bytes31 is left-aligned in its ABI word. The final byte is padding.
|
||||
let result = block.call(&address, &format!("0x{GET_RESULT}{cid}00"))?;
|
||||
|
||||
@@ -423,7 +423,17 @@ fidelity 以分钟为单位;省略或不大于零时按 1 分钟处理。相
|
||||
|
||||
### PositionManager V2 链上兑付核对
|
||||
|
||||
V2 市场以两项 Position ID 共享的高 31 字节表示条件,首字节标记模块。探针用该模块编号查询 PositionManager 注册表,再从模块读取按目录顺序排列的兑付权重。生产 Binary 样本在两个 Polygon 节点的最终确认区块 `0x5df5912` 均返回 `[1000000, 0]`,与 Gamma 第一结果获胜一致。两个权重的分母固定为 100 万,空数组表示合约当前没有可读取的结果。NegRisk 的二元约束有离线用例,仍缺少生产目录关联样本。组合盘兑付、独立链上状态证明和同步入账仍待覆盖。[探针时序与重放](../crates/venue-probe/README.md#polygon-positionmanager-v2-裁决核对) · [双节点记录](../crates/venue-probe/fixtures/live-position-resolutions.json) · [官方 V2 模块文档](https://github.com/Polymarket/polymarket-v2-external/blob/main/docs/modules.md)
|
||||
V2 市场以两项 Position ID 共享的高 31 字节表示条件,首字节标记模块。探针用该模块编号查询 PositionManager 注册表,再从模块读取按目录顺序排列的兑付权重。生产 Binary 样本在两个 Polygon 节点的最终确认区块 `0x5df5912` 均返回 `[1000000, 0]`,与 Gamma 第一结果获胜一致。两个权重的分母固定为 100 万,空数组表示合约当前没有可读取的结果。NegRisk 的二元约束有离线用例,仍缺少生产目录关联样本。组合盘的只读核对见下节。独立链上状态证明和同步入账仍待覆盖。[探针时序与重放](../crates/venue-probe/README.md#polygon-positionmanager-v2-裁决核对) · [双节点记录](../crates/venue-probe/fixtures/live-position-resolutions.json) · [官方 V2 模块文档](https://github.com/Polymarket/polymarket-v2-external/blob/main/docs/modules.md)
|
||||
|
||||
### PositionManager V2 组合兑付核对
|
||||
|
||||
组合模块保存排序后的 Binary 或 NegRisk Position ID。探针在同一最终确认区块读取登记的腿,向合约查询同样份额的 YES 和 NO 兑付。只在两侧均返回已知的待兑付错误时报告待裁决。一条已裁决腿的兑付为零时,YES 已确定为零,NO 可取得全部对应金额;其余腿仍可处于待裁决状态。其余可兑付情况以合约返回的逐侧金额为准,两个方向分别取整,兑付合计可以少于原份额对应的抵押。[官方合约](https://github.com/Polymarket/polymarket-v2-external/blob/main/src/modules/CombinatorialModule.sol)
|
||||
|
||||
区块 `0x5df5ab2` 的原始记录涵盖一份双侧待裁决的组合和一份已经可兑付的组合。后者按 1000001 微份查询返回 YES 0、NO 1000001 微美元。按链上腿顺序复查,四个兑付权重分别为待裁决、零、待裁决、待裁决。样本来自链上登记交易,仍缺少对应前端及 RFQ 的同盘关联。进一步把链上裁决导入本地账本仍待实现。[原始样本](../crates/venue-probe/fixtures/live-combo-payouts.json)
|
||||
|
||||
### V2 互斥组的推导与迁移例外
|
||||
|
||||
`getResult` 提供有效兑付,原始 `result` getter 可以核对结果是否直接写入。Polygon 区块 `0x5df5c43` 至 `0x5df5c44` 的样本中,组内出现赢家后,合成「其他」的有效权重由空变为 `[0,1000000]`,直接存储仍为空。区块 `0x5df5c62` 的另一组有 37 个真实条件,直接报告 33 个。四个未报告真实条件的有效权重仍为空,合成「其他」已有 NO 兑付。该组的链上旧盘映射将四个条件对应到 Gamma 的 5–3、4–5、5–4 和 5–5 精确比分盘。同一区块的旧 CTF 兑付分母均为 1,V2 仍待裁决。本地组合账本尚未接入这条迁移路径。原生组的未报告输家与通过全 NO 推导「其他」为 YES,仍缺生产样本。[链上样本](../crates/venue-probe/fixtures/live-negrisk-resolution.json) · [官方 NegRisk 逻辑](https://github.com/Polymarket/polymarket-v2-external/blob/main/src/modules/NegRiskModule.sol)
|
||||
|
||||
### Data API 账户持仓价值
|
||||
|
||||
|
||||
Reference in New Issue
Block a user