Convert each market's resolution rule into a structured representation: source-of-truth, condition, ambiguity score.
3. Why This Bot Matters
Free-text rule treated as if structured
Resolution rules are written in English and parsed by humans. Without a structured representation, every downstream consumer — ContradictionDetector, RuleChangeMonitor, SourceOfTruthVerifier — re-parses the same string and gets subtly different answers.
Ambiguity score not surfaced to strategies
A resolution rule with high ambiguity carries non-trivial settlement risk. Without an explicit score, strategy bots cannot down-size or skip those markets.
Source-of-truth field unused
A structured 'source-of-truth' field lets SourceOfTruthVerifier check whether the cited source actually publishes the data needed to resolve. The parser is the upstream that makes that check possible.
Rule changes hard to diff
RuleChangeMonitor needs to detect post-listing edits. Diffing structured representations catches semantic changes; diffing raw strings flags every cosmetic edit and misses meaningful ones.
4. Required Polymarket Inputs
Input
Source
Required?
Use
Market resolution_rules and resolution_source from Gamma API
gamma
Yes
Primary source for extracting and hashing resolution rules.
Market condition_id and question text
data
Yes
Cross-reference condition_id to market metadata for rule provenance.
5. Required Internal Inputs
Input
Source
Required?
Use
KillSwitch active flag
KillSwitch
Yes
Suppress all ResolutionRuleParser emissions when KillSwitch is active.
6. Parameter Guide
Parameter
Default
Warning
Hard
What it controls
poll_interval_s
300
900
3600
Seconds between Gamma API polls for resolution rule updates per active market.
staleness_threshold_s
600
1200
7200
Seconds after which a cached Gamma response is considered stale.
7. Detailed Parameter Instructions
poll_interval_s
What it means
Seconds between Gamma API polls for resolution rule updates per active market.
Default
{ "poll_interval_s": 300 }
Why this default matters
300 s (5 min) provides timely detection of rule changes without overloading Gamma API.
Threshold logic
Condition
Action
interval <= 300 s
Normal
300–900 s
WARN — reduced detection speed for rule changes
> 3600 s
Reject — PARAMETER_CHANGE_REQUIRES_APPROVAL
Developer check
if (p.poll_interval_s > p.hard) throw ConfigError('PARAMETER_CHANGE_REQUIRES_APPROVAL');
User-facing English
Resolution rules are checked regularly to detect any market condition changes.
staleness_threshold_s
What it means
Seconds after which a cached Gamma response is considered stale.
Default
{ "staleness_threshold_s": 600 }
Why this default matters
600 s matches twice the default poll interval, ensuring at least one retry before stale status.
Threshold logic
Condition
Action
age <= 600 s
Normal
600–1200 s
WARN — stale data approaching
> 7200 s
Reject — emit STALE_DATA and suppress
Developer check
if (cache_age_s > p.staleness_threshold_s.hard) emit('STALE_DATA');
User-facing English
Cached resolution rules expire regularly to ensure freshness.
Strategy paused entry on a market after rule change detected
The resolution conditions for this market were recently updated. The system flagged this for review before allowing new positions.
Resolution source shows UMA Optimistic Oracle
This market resolves via UMA's decentralised oracle, which requires a $750 pUSD bond and a 2-hour challenge window.
18. Failure-Mode Block
main_failure_mode
Gamma API outage prevents resolution rule fetching, leaving strategy layer with stale or missing rule data for active markets.
false_positive_risk
Minor whitespace or formatting changes to resolution_rules text generate false rule-change alerts despite no substantive change.
false_negative_risk
Gamma API returns cached (stale) rules during a CMS update, causing a genuine rule change to be missed until next successful fresh fetch.
safe_fallback
If Gamma API is unavailable for > staleness_threshold_s, emit STALE_DATA WARN and suppress new ObservationReports until fresh data is available. Retain last known good rules hash.
required_dependencies
Polymarket Gamma API, KillSwitch active flag, Postgres for rule snapshot storage
19. Failure-Injection Recipes
Scenario
How to inject
Expected behaviour
Recovery
GAMMA_API_DOWN
Block Gamma API for 5 min
Automatic on Gamma recovery; re-parse all active markets
RULES_CHANGE
Modify resolution_rules for a live market in test Gamma instance
Adversary modifies resolution rules in Gamma to manipulate downstream strategy behaviour
Source change spoofing to trigger false RESOLUTIONRULEPARSER_SOURCE_CHANGE alerts
Mitigations
Rules hash comparison detects any rule text changes between parses
ObservationReports are informational only — strategies independently verify before acting
24. Polymarket V2 Compatibility
Aspect
Value
CLOB version
v2
Collateral asset
pUSD
EIP-712 Exchange domain version
2
Aware of builderCode field
no
Aware of negative-risk markets
yes
Multi-chain ready
no
SDK used
py-clob-client-v2
Settlement contract
CTFExchangeV2
Notes
Parses Gamma market resolution rules; references negRisk flag for multi-outcome markets. No order signing.
API surfaces declared
gammadatainternal
Networks supported
polygon
25. Versioning & Migration
Field
Value
spec
2.0.0
implementation
0.1.0
schema
2
released
None
planned_release
Q3-2026
Migration history
Date
From
To
Reason
Action taken
2026-04-28
n/a
v2-spec
Spec drafted post-CLOB-V2 cutover; bot not yet implemented
Designed against V2 schema (pUSD, builder codes, V2 EIP-712 domain)
26. Acceptance Tests
Unit Tests
Test
Setup
Expected result
Market with valid resolution rules emits ObservationReport
Gamma returns market with resolution_rules and resolution_source populated
ObservationReport emitted with rules_hash and source
Market with empty resolution rules skips emission and emits WARN
Gamma returns market with resolution_rules=null
RESOLUTIONRULEPARSER_MISSING_RULES WARN; no ObservationReport
KillSwitch suppresses emission
killswitch.active=true; valid rules available
No ObservationReport; KILL_SWITCH_ACTIVE logged
Integration Tests
Test
Expected result
Rule change detected and emitted correctly
ObservationReport emitted with change_detected=true when rules_hash changes between polls
Gamma API outage: STALE_DATA emitted; last rules hash retained
STALE_DATA WARN; no new ObservationReports; last rules hash preserved in Postgres
Property Tests
Property
Required behaviour
ResolutionRuleParser never submits or signs orders
Always true
No ObservationReport emitted when KillSwitch is active
Always true
27. Operational Runbook
ResolutionRuleParser incidents are typically Gamma API outages or unexpected rule changes. Rule changes require prompt strategy notification.
On-call actions
Alert
First step
Diagnosis
Mitigation
Escalate to
ResolutionRuleParserMissingRulesHigh
Check Gamma API health. Verify markets have published resolution rules via Gamma dashboard.
Intelligence pod lead if > 10 markets missing rules
ResolutionRuleParserSourceChange
Review which condition_id triggered the change. Confirm with market data team if change is legitimate.
Intelligence pod lead immediately on any source change
Manual overrides
force_reparse_all — POST /internal/resolutionruleparser/reparse to trigger bulk re-parse of all active markets — After Gamma API recovery from extended outage
Healthcheck
Endpoint: /internal/health/resolutionruleparser | Green: Last parse < 60 min ago AND Postgres reachable AND Gamma API returning 200 | Red: No parse for > 2 h OR Postgres unreachable OR Gamma API down > 15 min
28. Promotion Gates
A bot does not advance to the next readiness state until every gate below is green. Gates are observable from production data — no subjective sign-off.
Promote to Shadow
Gate
How measured
Threshold
Unit tests pass for missing-rules gate, source-change detection, and KillSwitch suppression
CI test run
100% pass
Promote to Limited live
Gate
How measured
Threshold
Bulk parse of all active Gamma markets succeeds with 0 errors on staging
Integration test
0 parse errors
Promote to General live
Gate
How measured
Threshold
Rule-change detection verified on synthetic rule mutation over 7-day soak