Skip to content

fix: mark twaps as completed - #4

Merged
kernelwhisperer merged 3 commits into
mainfrom
fix/mark-twap-completed
Sep 9, 2026
Merged

fix: mark twaps as completed#4
kernelwhisperer merged 3 commits into
mainfrom
fix/mark-twap-completed

Conversation

@kernelwhisperer

@kernelwhisperer kernelwhisperer commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

The indexer updates each TWAP part when its order status changes. However, it did not update the parent after the final part became terminal.

For example, parent 0x20d0260a39328b530d4644dc07718409ad294f6afdb8970d63b63275cedab1a5 remained Active after both parts became fulfilled.

The indexer only detected parent completion during initial discovery. Therefore, TWAP orders that settled later remained Active.

Changes

  • Replace the TWAP totals refresh with a TWAP execution-state refresh.
  • Aggregate executed amounts and count open parts in the same query.
  • Mark a changed parent as Completed when:
    • All candidates are known.
    • At least one part exists.
    • No open part remains.
    • No candidate remains.
  • Refresh the parent after status updates, candidate updates, orderbook updates, and part expiration.
  • Limit reconciliation to changed TWAP parents.

How to Test

  1. Deploy the indexer and trigger a full reindex.
  2. Find parent 0x20d0260a39328b530d4644dc07718409ad294f6afdb8970d63b63275cedab1a5.
  3. Make sure that its status is Completed.
  4. Create a new TWAP with two parts.
  5. While one part is open, make sure that the parent remains Active.
  6. After both parts become terminal, make sure that the parent becomes Completed.

Checklist

  • Tests pass locally
  • Linting passes
  • Documentation updated (not needed)
  • Breaking changes documented (not applicable)
image

@kernelwhisperer kernelwhisperer self-assigned this Sep 4, 2026

@yvesfracari yvesfracari left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code looks good to me, just double confirm that logic is reorg friendly.

Comment on lines +107 to +112
const isComplete =
generator.status === "Active" &&
generator.allCandidatesKnown &&
aggregate != null &&
aggregate.partCount > 0 &&
aggregate.openPartCount === 0 &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, a child can be changed back to open on reorgs. In that case, I don't see any handler that will change the parent back to incomplete.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in f4a27a7

((aggregate?.openPartCount ?? 0) > 0 ||
candidateGeneratorIds.has(generator.eventId));

await context.db

@Danziger Danziger Sep 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to collect the individual updates and send them together using db.batch: https://orm.drizzle.team/docs/batch-api, rather than awaiting inside the loop.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no batch on this object https://ponder.sh/docs/indexing/write#store-api

image

@Danziger Danziger left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, but approving already.

@kernelwhisperer
kernelwhisperer merged commit ac3353d into main Sep 9, 2026
4 checks passed
@kernelwhisperer
kernelwhisperer deleted the fix/mark-twap-completed branch September 9, 2026 07:47
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.

3 participants