Skip to content

Conversation

@cctdaniel
Copy link
Contributor

@cctdaniel cctdaniel commented Apr 28, 2025

Summary

Modified parseTwapPriceFeedUpdates to properly handle multiple price feed IDs in a single call, allowing batch TWAP updates for multiple price feeds.

Rationale

  • The original implementation only supported updating a single price feed (requiring exactly 2 updates)
  • This change enables more efficient batch updates by allowing multiple price feed updates in a single transaction
  • Reduces gas costs and improves UX by avoiding multiple separate transactions for different price feeds

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Testing details:

  1. Added testParseTwapPriceFeedUpdatesMultipleFeeds() to verify:

    • Correct handling of multiple price feeds (2 feeds in test case)
    • Proper TWAP calculations for each feed
    • Correct validation of start/end times and price feed matching
  2. Added testParseTwapPriceFeedUpdatesRevertsWithMismatchedArrayLengths() to verify:

    • Rejects when too many updates provided (4 updates for 1 price feed)
    • Rejects when too few updates provided (2 updates for 2 price feeds)
    • Ensures strict validation of update data length matching price feed count
  3. Modified base test setup to include test data for multiple price feeds:

    • Extended base arrays to handle 2 price feeds
    • Added test data with different values to ensure distinct TWAP calculations

The changes maintain all existing functionality while adding support for batch updates, with comprehensive test coverage ensuring correctness and proper error handling.

@vercel
Copy link

vercel bot commented Apr 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am
entropy-explorer ❌ Failed (Inspect) May 10, 2025 7:43am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2025 7:43am

UnsafeCalldataBytesLib.toUint32(updateData[i + 1], 0) ==
ACCUMULATOR_MAGIC)
startPriceIds[i] == endPriceIds[j] && !endPriceIdMatched[j]
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we dont need this check anymore because we call processSingleTwapUpdate and in the function we call extractUpdateTypeFromAccumulatorHeader which checks for the ACCUMULATOR_MAGIC

Copy link
Contributor

@tejasbadadare tejasbadadare left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

Nice! Please address my comments before merging.

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.

4 participants