-
Notifications
You must be signed in to change notification settings - Fork 202
fix(monitor-v2): add per-proposal time filtering for fill events #4926
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: master
Are you sure you want to change the base?
fix(monitor-v2): add per-proposal time filtering for fill events #4926
Conversation
…onitor
Replace API-based deeplink fetching with deterministic URL calculation.
The new format is: {baseUrl}/{proposalHash}?index={eventIndex}
- Remove fetchLatestAIDeepLink() and related async HTTP request logic
- Add simple generateAIDeepLink() function
- Remove AIConfig interface, use aiResultsBaseUrl string directly
- Remove aiDeeplinkHttpClient and aiDeeplinkTimeout from MonitoringParams
- Require AI_RESULTS_BASE_URL environment variable
After aggregating fetchOrderFilledEventsBounded across all proposal tokens, FILL_EVENTS_LOOKBACK_SECONDS and FILL_EVENTS_PROPOSAL_GAP_SECONDS no longer applied per-proposal. The code computed per-proposal fromBlocks but only used the global minimum, with no subsequent per-proposal filtering. Pass a per-proposal fromTimestamp into processProposal and filter trades by timestamp >= fromTimestamp before checking price discrepancies.
…-missing-after-aggregated-fill
Adds a test that specifically verifies FILL_EVENTS_PROPOSAL_GAP_SECONDS and FILL_EVENTS_LOOKBACK_SECONDS apply per-proposal: - Creates two proposals at different blocks (5000 and 9000) - Sets up a trade with a timestamp that falls between the two proposals' fromTimestamp thresholds - Verifies only the older proposal triggers an alert, while the newer proposal correctly filters out the trade
… data flow Instead of maintaining separate fromTimestampsMap and aiDeeplinksMap, augment the bundles directly with per-proposal context (fromTimestamp, aiDeeplink, fromBlock). This: - Eliminates map lookups and duplicate key computations - Removes non-null assertions - Makes data flow more explicit - each bundle owns its context - Reduces code by ~10 lines Also makes aiDeeplink non-optional in ProposalProcessingContext since it's always computed, and fixes test timing issues with trade timestamps.
2afa6b4 to
23345aa
Compare
| const fromBlock = Math.max(Number(proposal.proposalBlockNumber) + gapBlocks, currentBlock - lookbackBlocks); | ||
| const fromTimestamp = currentTimestamp - Math.round((currentBlock - fromBlock) / blocksPerSecond); |
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.
This introduces slight inconsistency as fromBlock is derived from the latest block number while fromTimestamp derives from bot's system time. Not that it is critical for the trade filtering case, but we could optimize this to drop timestamps altogether and do trade filtering only based on block numbers. But I recognize this also might involve reworking quite some of the tests, so could be left as a follow-up.
| boundedTradesMap: Map<string, PolymarketTradeInformation[]>; | ||
| aiDeeplink?: string; | ||
| aiDeeplink: string; | ||
| fromTimestamp: 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.
nit: might want to expand the naming to make it clear that this is used for trade data filtering
- Fetch currentTimestamp from provider.getBlock() instead of Date.now() to ensure consistency with block-derived fromBlock calculation - Rename fromTimestamp to tradeFilterFromTimestamp for clarity - Update test mocks to include getBlock stub
Motivation
After aggregating
fetchOrderFilledEventsBoundedacross all proposal tokens,FILL_EVENTS_LOOKBACK_SECONDSandFILL_EVENTS_PROPOSAL_GAP_SECONDSno longer appliedper-proposal. The code computed per-proposal
fromBlocksbut only used the global minimum, with no subsequent filtering.Summary
Pass a per-proposal
fromTimestampintoprocessProposaland filter trades bytimestamp >= fromTimestampbefore checking price discrepancies.Details
fromTimestamptoProposalProcessingContextfromTimestampsMapfor each proposal based on its specificfromBlockprocessProposalbefore discrepancy checksTesting
Issue(s)
Fixes UMA-3016