-
Notifications
You must be signed in to change notification settings - Fork 306
refactor: Optional storage flag when parsing price feed updates #2727
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4fe1222
updated parsePriceFeedUpdatesInternal name, added flag for storeUpdat…
ayushboss 552a34f
removed TODO, updated interface
ayushboss b3cf5d3
stash while checking build errors
ayushboss 2db25fc
fixed interface header
ayushboss a1822f8
reset index.js
ayushboss 2a5b2ec
fixed mockpyth function header
ayushboss 6b4b0c8
restored update functionality upon flag
ayushboss 2e79358
working on function test case
ayushboss f1183f1
fixed store = false test
ayushboss 53690d2
added gas benchmark tests
ayushboss 0636cb1
Merge branch 'main' into parse-price-feed-update-optional-storage
ayushboss f604a13
cut down to -41 bytes
ayushboss 660717e
removed slots strict function
ayushboss 27bf014
Merge branch 'main' into parse-price-feed-update-optional-storage
ayushboss 02fe840
updating version, reverting preincrement, renaming slots strict to wi…
ayushboss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,7 +278,92 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils { | |
| } | ||
| } | ||
|
|
||
| function testParsePriceFeedUpdatesWithSlotsStrictWorks(uint seed) public { | ||
| function testParsePriceFeedUpdatesWithConfigIfStorageTrue( | ||
| uint seed | ||
| ) public { | ||
| setRandSeed(seed); | ||
| uint numMessages = 1 + (getRandUint() % 10); | ||
| ( | ||
| bytes32[] memory priceIds, | ||
| PriceFeedMessage[] memory messages | ||
| ) = generateRandomPriceMessages(numMessages); | ||
|
|
||
| ( | ||
| bytes[] memory updateData, | ||
| uint updateFee | ||
| ) = createBatchedUpdateDataFromMessages(messages); | ||
|
|
||
| (PythStructs.PriceFeed[] memory priceFeeds, ) = pyth | ||
| .parsePriceFeedUpdatesWithConfig{value: updateFee}( | ||
| updateData, | ||
| priceIds, | ||
| 0, | ||
| MAX_UINT64, | ||
| false, | ||
| true, | ||
| true | ||
| ); | ||
|
|
||
| for (uint i = 0; i < numMessages; i++) { | ||
| // Validating that returned priceIds are equal | ||
| assertEq(priceFeeds[i].id, priceIds[i]); | ||
| assertEq(priceFeeds[i].price.price, messages[i].price); | ||
| assertEq(priceFeeds[i].price.conf, messages[i].conf); | ||
| assertEq(priceFeeds[i].price.expo, messages[i].expo); | ||
| assertEq(priceFeeds[i].price.publishTime, messages[i].publishTime); | ||
| assertEq(priceFeeds[i].emaPrice.price, messages[i].emaPrice); | ||
| assertEq(priceFeeds[i].emaPrice.conf, messages[i].emaConf); | ||
| assertEq(priceFeeds[i].emaPrice.expo, messages[i].expo); | ||
| assertEq( | ||
| priceFeeds[i].emaPrice.publishTime, | ||
| messages[i].publishTime | ||
| ); | ||
|
|
||
| // Validating that prices are stored on chain | ||
| PythStructs.Price memory curPrice = pyth.getPriceUnsafe( | ||
| messages[i].priceId | ||
| ); | ||
|
|
||
| assertEq(priceFeeds[i].price.price, curPrice.price); | ||
| assertEq(priceFeeds[i].price.conf, curPrice.conf); | ||
| assertEq(priceFeeds[i].price.expo, curPrice.expo); | ||
| assertEq(priceFeeds[i].price.publishTime, curPrice.publishTime); | ||
| } | ||
| } | ||
|
|
||
| function testParsePriceFeedUpdatesWithConfigIfStorageFalse( | ||
| uint seed | ||
| ) public { | ||
| setRandSeed(seed); | ||
| uint numMessages = 1 + (getRandUint() % 10); | ||
| ( | ||
| bytes32[] memory priceIds, | ||
| PriceFeedMessage[] memory messages | ||
| ) = generateRandomPriceMessages(numMessages); | ||
|
|
||
| ( | ||
| bytes[] memory updateData, | ||
| uint updateFee | ||
| ) = createBatchedUpdateDataFromMessages(messages); | ||
|
|
||
| pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}( | ||
| updateData, | ||
| priceIds, | ||
| 0, | ||
| MAX_UINT64, | ||
| false, | ||
| true, | ||
| false | ||
| ); | ||
|
|
||
| // validate that stored prices of each priceId are still unpopulated | ||
| for (uint i = 0; i < numMessages; i++) { | ||
| vm.expectRevert(PythErrors.PriceFeedNotFound.selector); | ||
| pyth.getPriceUnsafe(priceIds[i]); | ||
| } | ||
| } | ||
|
|
||
| function testParsePriceFeedUpdatesWithConfigWorks(uint seed) public { | ||
| setRandSeed(seed); | ||
| uint numMessages = 1 + (getRandUint() % 10); | ||
| ( | ||
|
|
@@ -293,11 +378,14 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils { | |
| ( | ||
| PythStructs.PriceFeed[] memory priceFeeds, | ||
| uint64[] memory slots | ||
| ) = pyth.parsePriceFeedUpdatesWithSlotsStrict{value: updateFee}( | ||
| ) = pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}( | ||
| updateData, | ||
| priceIds, | ||
| 0, | ||
| MAX_UINT64 | ||
| MAX_UINT64, | ||
| false, | ||
| true, | ||
| false | ||
| ); | ||
|
|
||
| assertEq(priceFeeds.length, numMessages); | ||
|
|
@@ -434,7 +522,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils { | |
| ); | ||
| } | ||
|
|
||
| function testParsePriceFeedUpdatesWithSlotsStrictRevertsWithExcessUpdateData() | ||
| function testParsePriceFeedUpdatesWithConfigRevertsWithExcessUpdateData() | ||
| public | ||
| { | ||
| // Create a price update with more price updates than requested price IDs | ||
|
|
@@ -459,15 +547,18 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils { | |
|
|
||
| // Should revert in strict mode | ||
| vm.expectRevert(PythErrors.InvalidArgument.selector); | ||
| pyth.parsePriceFeedUpdatesWithSlotsStrict{value: updateFee}( | ||
| pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we update the names of these tests please |
||
| updateData, | ||
| requestedPriceIds, | ||
| 0, | ||
| MAX_UINT64 | ||
| MAX_UINT64, | ||
| false, | ||
| true, | ||
| false | ||
| ); | ||
| } | ||
|
|
||
| function testParsePriceFeedUpdatesWithSlotsStrictRevertsWithFewerUpdateData() | ||
| function testParsePriceFeedUpdatesWithConfigRevertsWithFewerUpdateData() | ||
| public | ||
| { | ||
| // Create a price update with fewer price updates than requested price IDs | ||
|
|
@@ -496,11 +587,14 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils { | |
|
|
||
| // Should revert in strict mode because we have fewer updates than price IDs | ||
| vm.expectRevert(PythErrors.InvalidArgument.selector); | ||
| pyth.parsePriceFeedUpdatesWithSlotsStrict{value: updateFee}( | ||
| pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}( | ||
| updateData, | ||
| requestedPriceIds, | ||
| 0, | ||
| MAX_UINT64 | ||
| MAX_UINT64, | ||
| false, | ||
| true, | ||
| false | ||
| ); | ||
| } | ||
|
|
||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,21 +136,6 @@ abstract contract AbstractPyth is IPyth { | |
| override | ||
| returns (PythStructs.PriceFeed[] memory priceFeeds); | ||
|
|
||
| function parsePriceFeedUpdatesWithSlotsStrict( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we squeeze within the size limit with this? :) |
||
| bytes[] calldata updateData, | ||
| bytes32[] calldata priceIds, | ||
| uint64 minPublishTime, | ||
| uint64 maxPublishTime | ||
| ) | ||
| external | ||
| payable | ||
| virtual | ||
| override | ||
| returns ( | ||
| PythStructs.PriceFeed[] memory priceFeeds, | ||
| uint64[] memory slots | ||
| ); | ||
|
|
||
| function parseTwapPriceFeedUpdates( | ||
| bytes[] calldata updateData, | ||
| bytes32[] calldata priceIds | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
let's bump the version() to 1.4.5-alpha.1