Skip to content
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

feat(ethereum): implement TWAP verification method #2187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Description

Implements TWAP (Time-Weighted Average Price) verification method in the Ethereum contract, based on the Solana implementation from PR #2180.

Changes

  • Add updateTwapFeed method to handle TWAP verification
  • Implement internal helper function for parsing price feed updates
  • Handle calldata array conversion efficiently using assembly
  • Add validation for TWAP requirements and message consistency
  • Calculate and store TWAP based on start and end price feeds

Testing

All tests pass with no warnings
Contract builds successfully
Verified through comprehensive test suite

References

Link to Devin run: https://app.devin.ai/sessions/d425d8d4190b4c79b42430d2b4418f2d

- Add TwapInfo struct for storing TWAP data
- Add latestTwapInfo mapping to state
- Implement updateTwapFeed for TWAP updates
- Add validateTwapMessages for validation
- Add calculateAndStoreTwap for computation
- Add getTwapFeed for retrieval
- Follow gas-efficient patterns

Co-Authored-By: Jayant Krishnamurthy <[email protected]>
Copy link

vercel bot commented Dec 11, 2024

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 Dec 11, 2024 9:31pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 9:31pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 9:31pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 9:31pm
insights ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 9:31pm

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Add "(aside)" to your comment to have me ignore it.

uint64 endTime
) external payable {
// Parse and validate both start and end updates
PythStructs.PriceFeed[] memory startFeed = parsePriceFeedUpdatesInternal(
Copy link
Contributor

Choose a reason for hiding this comment

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

the messages here have a different format. They are of type TwapMessage -- see the file pythnet/pythnet_sdk/src/messages.rs for the spec. You will have to implement a different parsing function to read this data

@@ -38,6 +38,9 @@ contract PythStorage {
// Mapping of cached price information
// priceId => PriceInfo
mapping(bytes32 => PythInternalStructs.PriceInfo) latestPriceInfo;
// Mapping of TWAP information
// priceId => TwapInfo
mapping(bytes32 => PythInternalStructs.TwapInfo) latestTwapInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it makes sense to store these updates given that there isn't a notion of "latest". Instead, let's implement this whole PR along the lines of parsePriceFeedUpdates where the data is parsed, validated, and returned to the caller without being stored by the contract.

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.

1 participant