Skip to content

feat(oracle): add finalized Polymarket settlement source - #420

Merged
ByteYue merged 1 commit into
mainfrom
codex/oracle-polymarket-provider
Aug 3, 2026
Merged

feat(oracle): add finalized Polymarket settlement source#420
ByteYue merged 1 commit into
mainfrom
codex/oracle-polymarket-provider

Conversation

@ByteYue

@ByteYue ByteYue commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add relayer source type 6 for one-shot Polymarket CTF settlement mirrors
  • scan validator-local Polygon RPC endpoints through bounded finalized ranges
  • validate the exact CTF contract, indexed condition, source chain, event identity, payout vector, and returned log range
  • emit the final PolymarketSettlementPayload ABI consumed by gravity_chain_core_contracts#115
  • route agreed unsupported-JWK bytes through NativeOracle.recordBatch with the standard 500000 callback gas limit
  • document market discovery, task registration, finality, cursor, nonce, and restart semantics

Task URI

gravity://6/<mirrorId>/polymarket_settlement?ctf=<ctf>&condition=<conditionId>&fromBlock=<cursor>&chainId=137&maxBlocksPerPoll=1000

RPC URLs and credentials remain validator-local. The on-chain URI contains only deterministic consensus configuration.

Finality and idempotency

  • verifies eth_chainId == 137
  • takes the upper watermark from eth_getBlockByNumber("finalized", false)
  • scans at most maxBlocksPerPoll blocks per poll
  • persists empty finalized scans so restarts do not repeatedly rescan the same range
  • sorts by (blockNumber, logIndex, transactionHash) and deduplicates only identical log identities
  • fails closed without cursor progress when more than one distinct terminal settlement is returned
  • uses one terminal delivery nonce, exactly 1; confirmed nonce 1 disables further Polygon RPC calls
  • keeps the settlement block (sourcePosition) separate from the later scan cursor

Contract compatibility

The provider recomputes:

conditionId == keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount))

Its resolver payload is decoded field-for-field in unit tests against the final struct merged in Galxe/gravity_chain_core_contracts#115. The outer wrapper remains:

abi.encode(uint128 nonce, uint256 sourcePosition, bytes callbackPayload)

No dependency or lockfile changes are included.

Validation

  • cargo test -p reth-pipe-exec-layer-relayer --no-fail-fast: 59 passed, 0 failed, 1 external-RPC test ignored
  • cargo test -p reth-pipe-exec-layer-ext-v2 onchain_config::jwk_oracle --no-fail-fast: 10 passed
  • cargo test -p reth-pipe-exec-layer-ext-v2 onchain_config::oracle_task_helpers --lib --no-fail-fast: 1 passed
  • cargo +nightly fmt --all -- --check: passed
  • cargo clippy -p reth-pipe-exec-layer-relayer --all-targets: passed; reported only pre-existing warnings in untouched code
  • full execute library suite: 96 passed, 1 known baseline failure in system_caller_migration::tests::test_migration_defensive_when_system_caller_absent; its source and dependency inputs are unchanged by this PR

The relayer tests inject an in-memory Polygon RPC and do not contact an external endpoint.

Scope

This is the single remaining gravity-reth Polymarket provider PR in the oracle split tracked by Galxe/gravity-audit#1038. SDK/product E2E wiring follows only after this provider is merged.

Add sourceType=6 for one-shot Polygon CTF settlement mirrors. Validators scan bounded finalized ranges, verify the source chain and CTF condition identity, derive canonical resolver bytes, and persist empty-scan watermarks without inventing delivery nonces.

Wire discovery and execution through the existing unsupported-JWK path with the standard 500,000 callback gas limit. Document the market-discovery boundary, URI runbook, finality and idempotency semantics, and final contract ABI.

Tested with the offline relayer suite (59 passed, 1 ignored), focused JWK execution tests (10 passed), oracle task helper test, rustfmt, and clippy. No external Polygon endpoint is contacted by the test suite.
@ByteYue
ByteYue force-pushed the codex/oracle-polymarket-provider branch from 9ee0cf8 to ff233f5 Compare August 3, 2026 15:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ee0cf8a2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +361 to +362
if self.chain_verified.load(Ordering::Acquire) {
return Ok(());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revalidate the RPC chain before every scan

When a long-lived RPC URL changes backend after its first successful poll—for example, a load-balanced endpoint fails over to a non-Polygon chain—this early return skips eth_chainId verification forever. poll() can then trust the foreign chain's finalized height and persist an empty-scan cursor past unscanned Polygon blocks; restoring the Polygon backend will not revisit them, so the terminal ConditionResolution may be missed permanently. Recheck the chain ID before each scan or otherwise bind each watermark and log response to a verified Polygon backend.

Useful? React with 👍 / 👎.

@ByteYue
ByteYue merged commit 0c038e1 into main Aug 3, 2026
29 checks passed
@ByteYue
ByteYue deleted the codex/oracle-polymarket-provider branch August 3, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant