Merge/v2 - #1
Merged
Merged
Conversation
Unifies V1 and V2 indexing under a single database so the analytics dashboard can query across both generations. V2 entities are prefixed with V2 to avoid collisions (notably on Market), reuse v1's getEventKey helper and the marketMetadata effect (extended with outcomePrices + conditionId), and ship with the same @index patterns v1 uses for efficient frontend queries. Audited against docs.polymarket.com/v2-migration: all claimed event signatures (OrderFilled with builder/metadata, FeeCharged, UserPaused, Wrapped/Unwrapped) match, and the two undocumented addresses (third CTFExchangeV2 0xe2222d...0036 and Rewards 0xdd8db7...e8b) were verified deployed on Polygon via cast code before inclusion. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Envio 3.0.0-alpha.18 → 3.0.0-alpha.21 to match what polymarket-v2-indexer was built against. The bump brings two breaking changes: * TestHelpers.processEvent API is gone. All 10 v1 unit tests + 3 v2 unit tests rewritten onto createTestIndexer() + simulate. The pre-existing 48 counter-doubling failures are gone: the new API doesn't preload-run handlers twice in tests. Result: 133/133 passing, up from 117/165. * BigDecimal scalar is now a bignumber.js BigNumber. scaleBigInt and calculatePrices return BigNumber, and zero-initialized "scaled..." fields in Exchange/FPMMFactory/FixedProductMarketMaker seed rows now use the ZERO_BD constant exported from utils/fpmm.ts. Also copies the latest .claude/skills/ from polymarket-v2-indexer so the in-repo guidance matches alpha.21 (testing skill now describes createTestIndexer, etc). Finally, adds pUSD-flow attribution via two new adapter contracts: * CtfCollateralAdapter (0xADa100...) — emits PositionSplit / PositionsMerge / PayoutRedemption on pUSD-backed CTF positions. Captured as V2CtfSplit / V2CtfMerge / V2CtfRedemption entities, rolled up in V2CtfAdapterStats. * NegRiskCtfCollateralAdapter (0xAdA200...) — emits the same position events (tagged isNegRisk=true) plus Wrapped/Unwrapped specific to the neg-risk flow, which flow into V2PolyUSDWrap with eventType="wrap_negrisk_ctf" / "unwrap_negrisk_ctf". V2PolyUSDWrap also gets a txFrom field so wraps routed through an onramp can still be attributed to the originating EOA. CollateralOnramp and CollateralOfframp were investigated via Polygonscan and skipped: they only emit Paused/Unpaused/RolesUpdated directly; all real wrap/unwrap activity bubbles up through the pUSD and adapter contracts we already index. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previous v2 entities over-indexed vs v1's patterns. Matching v1 now: - Max 2 composite indexes per entity (not 3-4) - Field-level @index only on high-cardinality lookup columns - No @index on transactionHash (dedup only, not queried) - No @index on low-cardinality bools (isNegRisk, withdrawn) - No @index on taker/to-style redundant foreign keys Keeps the hot-path queries fast (user activity, market activity, sponsor history) while cutting write amplification + index storage on high-volume entities like V2OrderFill and V2PolyUSDTransfer. Verified in a v2-only dev run: indexer boots cleanly, Gamma API enrichment populates V2Market, ExchangeStats and PolyUSDStats rollups are internally consistent, txFrom correctly attributes wraps mediated by CollateralOnramp. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Market metadata from the Gamma API (question, slug, outcomes, conditionId) is immutable once a market exists — there's no reason to re-fetch it every time a tokenId is seen. Flipping cache=false → cache=true means: * Handlers that run twice (preload + real) hit the API once instead of twice. * Across long reindex runs, repeat lookups on the same tokenId become free. * At a Gamma limit of 300 req/10s, the cache frees up real headroom for first-time market lookups instead of burning it on duplicates. outcomePrices is the one field that's NOT truly immutable — it's a snapshot at first fetch. Live prices should come from the CLOB orderbook, not the indexer. Noted in a comment on the effect. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
moose-code
added a commit
that referenced
this pull request
Jul 13, 2026
feat: envio 3.2.1 + V2 PnL accounting, audit fixes
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.
No description provided.