-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add columns to polymarket models #9107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PR SummaryIntroduces new analytics surfaces and enriches existing Polymarket models for better querying and pricing.
Written by Cursor Bugbot for commit d775b77. Configure here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment @cursor review or bugbot run to trigger another review on this PR
...ily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_market_prices_daily.sql
Outdated
Show resolved
Hide resolved
...ects/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_protocol_tvl.sql
Outdated
Show resolved
Hide resolved
...ts/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_open_positions.sql
Outdated
Show resolved
Hide resolved
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment @cursor review or bugbot run to trigger another review on this PR
...ects/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_protocol_tvl.sql
Outdated
Show resolved
Hide resolved
...ts/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_open_positions.sql
Outdated
Show resolved
Hide resolved
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
Comment @cursor review or bugbot run to trigger another review on this PR
…values and optimise open positions
…spellbook into polymarket_table_fixes
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment @cursor review or bugbot run to trigger another review on this PR
...ts/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_open_positions.sql
Show resolved
Hide resolved
...ts/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_market_details.sql
Show resolved
Hide resolved
|
https://github.com/cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment @cursor review or bugbot run to trigger another review on this PR
| SELECT *, | ||
| CASE WHEN outcome = '50/50' THEN 0.5 | ||
| WHEN LOWER(token_outcome) = outcome THEN 1 | ||
| ELSE 0 END AS price_modifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unresolved markets incorrectly get zero price modifier
The price_modifier calculation returns 0 for markets with outcome = 'unresolved' because neither the '50/50' check nor LOWER(token_outcome) = outcome matches when outcome is 'unresolved'. This differs from the existing behavior in polymarket_polygon_market_prices_daily.sql which preserves the original market price (ELSE ff.price) for unresolved markets. When used in polymarket_polygon_positions.sql, markets past their end time but not yet resolved will incorrectly show positions as worthless (price = 0) instead of using the last traded price.
Additional Locations (1)
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment @cursor review or bugbot run to trigger another review on this PR
| , unique_key | ||
| FROM relevant_transfers | ||
| WHERE from_polymarket_wallet IS NOT NULL AND to_polymarket_wallet IS NOT NULL | ||
| AND (from_first_funded_block IS NULL OR from_first_funded_block <= block_number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal transfers create duplicate records for sender wallet
Medium Severity
When a transfer occurs between two polymarket wallets (A→B), the sender wallet A gets recorded twice: once with direction='outflow' (lines 96-98) and again with direction='internal' (lines 117-119). Both records use from_polymarket_wallet AS polymarket_wallet and capture the same amount. The outflow WHERE clause (from_polymarket_wallet IS NOT NULL) doesn't exclude internal transfers, so there's an overlap with the internal clause (from_polymarket_wallet IS NOT NULL AND to_polymarket_wallet IS NOT NULL). This could lead to double-counting in downstream aggregations that sum balance changes by wallet.
| LEFT JOIN {{ ref('polymarket_polygon_users') }} to_user ON t."to" = to_user.polymarket_wallet | ||
| LEFT JOIN {{ ref('polymarket_polygon_users') }} from_user ON t."from" = from_user.polymarket_wallet | ||
| INNER JOIN {{ source('addresses_events_polygon', 'first_funded_by')}} to_ffb ON t."to" = to_ffb.address | ||
| INNER JOIN {{ source('addresses_events_polygon', 'first_funded_by')}} from_ffb ON t."from" = from_ffb.address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INNER JOINs make NULL checks unreachable dead code
Medium Severity
The INNER JOIN on first_funded_by (lines 34-35) filters out any transfers where either the sender or receiver address doesn't exist in that table. However, the subsequent WHERE clauses include to_first_funded_block IS NULL OR ... and from_first_funded_block IS NULL OR ... checks (lines 77, 98, 119), which can never evaluate to true because the INNER JOIN guarantees these values are non-NULL. This suggests LEFT JOINs were intended, and the current INNER JOINs may silently exclude legitimate transfers involving addresses not yet in first_funded_by.
Additional Locations (1)
| FROM {{ ref('polymarket_polygon_positions_raw') }} p | ||
| INNER JOIN latest_day ld ON p.day = ld.day | ||
| INNER JOIN {{ ref('polymarket_polygon_market_details') }} mm ON p.token_id = mm.token_id | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open positions view includes zero-balance closed positions
Medium Severity
The open_positions CTE joins with positions_raw without filtering out positions where balance = 0. Since positions_raw includes all balances (including zero balances from fully exited positions), the view will return closed positions as "open." The schema describes this as "Polymarket: open positions in markets," but users who have completely sold their positions will still appear in the results. A filter like WHERE p.balance > 0 is needed in the open_positions CTE to match the semantic meaning of the table.
added columns to existing tables (needed for much more efficient queries) and created 3 tables: