Skip to content

Commit 275c7b8

Browse files
authored
[eth] Add parsePriceFeedUpdates method (#392)
* Add the implementation with tests and benchmark * Refactor the contract to reduce redundancy * Reduce optimization runs as the contract was huge It has 177 more gas usage on some benchmark tests
1 parent 598b0dd commit 275c7b8

File tree

7 files changed

+825
-166
lines changed

7 files changed

+825
-166
lines changed

ethereum/contracts/pyth/Pyth.sol

Lines changed: 229 additions & 121 deletions
Large diffs are not rendered by default.

ethereum/forge-test/GasBenchmark.t.sol

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
8686

8787
function generateUpdateDataAndFee(PythStructs.Price[] memory prices) internal returns (bytes[] memory updateData, uint updateFee) {
8888
bytes memory vaa = generatePriceFeedUpdateVAA(
89-
priceIds,
90-
prices,
89+
pricesToPriceAttestations(priceIds, prices),
9190
sequence,
9291
NUM_GUARDIAN_SIGNERS
9392
);
@@ -122,6 +121,29 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
122121
pyth.updatePriceFeedsIfNecessary{value: cachedPricesUpdateFee}(cachedPricesUpdateData, priceIds, cachedPricesPublishTimes);
123122
}
124123

124+
function testBenchmarkParsePriceFeedUpdatesForOnePriceFeed() public {
125+
bytes32[] memory ids = new bytes32[](1);
126+
ids[0] = priceIds[0];
127+
128+
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee}(freshPricesUpdateData, ids, 0, 50);
129+
}
130+
131+
function testBenchmarkParsePriceFeedUpdatesForTwoPriceFeed() public {
132+
bytes32[] memory ids = new bytes32[](2);
133+
ids[0] = priceIds[0];
134+
ids[1] = priceIds[1];
135+
136+
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee}(freshPricesUpdateData, ids, 0, 50);
137+
}
138+
139+
function testBenchmarkParsePriceFeedUpdatesForOnePriceFeedNotWithinRange() public {
140+
bytes32[] memory ids = new bytes32[](1);
141+
ids[0] = priceIds[0];
142+
143+
vm.expectRevert(bytes("1 or more price feeds are not found in the updateData or they are out of the given time range"));
144+
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee}(freshPricesUpdateData, ids, 50, 100);
145+
}
146+
125147
function testBenchmarkGetPrice() public {
126148
// Set the block timestamp to 0. As prices have < 10 timestamp and staleness
127149
// is set to 60 seconds, the getPrice should work as expected.

0 commit comments

Comments
 (0)