fix(polymarket): align SQL with v0.4.0 asset_id UInt256#531
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion change for substreams-polymarket v0.4.0, which changes
state_orderbook.asset_id,state_fee.asset_id, andstate_latest_price.asset_idfromStringtoUInt256.ohlcv.sql— droptoString(a.asset_id)from the scraper join (both sidesUInt256), cast{token_id:String}input withtoUInt256(), andtoString(o.asset_id)in the output tuple so the responsetoken_idfield staysString.positions.sql— droptoString(p.token_id)from thestate_latest_pricejoin (bothUInt256).market_positions.sql— cast{token_id:String}input withtoUInt256()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
🤖 Generated with Claude Code