Skip to content

fix(polymarket): align SQL with v0.4.0 asset_id UInt256#531

Merged
0237h merged 2 commits into
mainfrom
fix/polymarket-v0.4.0-sql
May 13, 2026
Merged

fix(polymarket): align SQL with v0.4.0 asset_id UInt256#531
0237h merged 2 commits into
mainfrom
fix/polymarket-v0.4.0-sql

Conversation

@0237h
Copy link
Copy Markdown
Collaborator

@0237h 0237h commented May 12, 2026

Summary

Companion change for substreams-polymarket v0.4.0, which changes state_orderbook.asset_id, state_fee.asset_id, and state_latest_price.asset_id from String to UInt256.

  • ohlcv.sql — drop toString(a.asset_id) from the scraper join (both sides UInt256), cast {token_id:String} input with toUInt256(), and toString(o.asset_id) in the output tuple so the response token_id field stays String.
  • positions.sql — drop toString(p.token_id) from the state_latest_price join (both UInt256).
  • market_positions.sql — cast {token_id:String} input with toUInt256() for the orderbook lookup.

Merge timing

Do not merge before substreams-polymarket v0.4.0 is deployed. The new SQL only works against the v0.4.0 schema.

Test plan

  • Existing route tests pass.
  • End-to-end verification after v0.4.0 is deployed.

🤖 Generated with Claude Code

Companion to substreams-polymarket v0.4.0, which changes
state_orderbook.asset_id, state_fee.asset_id, and
state_latest_price.asset_id from String to UInt256.

- ohlcv.sql: drop toString(a.asset_id) from the scraper join (both
  sides are now UInt256), cast {token_id:String} input with
  toUInt256(), and toString(o.asset_id) in the output tuple to
  preserve the existing token_id String response field.
- positions.sql: drop toString(p.token_id) from the latest-price
  join (both UInt256).
- market_positions.sql: cast {token_id:String} input with
  toUInt256() for the orderbook lookup.

Merge paired with the deployment of substreams-polymarket v0.4.0;
these queries require the new schema and do not work against v0.3.0.

Refs https://github.com/pinax-network/substreams-polymarket/releases/tag/v0.4.0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two additional v0.4.0 SQL companion fixes uncovered while pointing the
route SQL at production-scale data:

- positions.sql: read from the deduped `user_position` view rather than
  `state_user_position`. The state table is a refresh-MV target with
  TTL'd snapshots; multiple refresh rows can coexist for the same
  (user, token, interval_min) until merges run, and a raw SUM
  double-counts them. The `user_position` view applies FINAL.

- positions.sql + market_positions.sql: filter `interval_min = 0` (the
  all-time aggregate row) instead of `1440`. In v0.4.0 the position
  state tables are snapshot rather than time-series and `interval_min`
  names a rolling look-back window — `1440` is "last 24h", not "daily
  bars". The `/users/positions` and `/markets/positions` routes return
  lifetime portfolio state, so the `0` row is the correct source.

Same return shape and field semantics as before.

Refs https://github.com/pinax-network/substreams-polymarket/releases/tag/v0.4.0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@YaroShkvorets YaroShkvorets temporarily deployed to fix/polymarket-v0.4.0-sql - token-api PR #531 May 13, 2026 17:04 — with Render Destroyed
@0237h 0237h merged commit 54cf2a2 into main May 13, 2026
2 of 3 checks passed
@0237h 0237h deleted the fix/polymarket-v0.4.0-sql branch May 13, 2026 18:21
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.

2 participants