Skip to content

Commit 02fe840

Browse files
committed
updating version, reverting preincrement, renaming slots strict to with config in test functions
1 parent 27bf014 commit 02fe840

File tree

8 files changed

+106
-150
lines changed

8 files changed

+106
-150
lines changed

target_chains/ethereum/contracts/contracts/pyth/Pyth.sol

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -333,43 +333,48 @@ abstract contract Pyth is
333333
uint64[] memory slots
334334
)
335335
{
336-
if (msg.value < getUpdateFee(updateData)) revert PythErrors.InsufficientFee();
336+
if (msg.value < getUpdateFee(updateData))
337+
revert PythErrors.InsufficientFee();
337338

338339
// Create the context struct that holds all shared parameters
339-
PythInternalStructs.UpdateParseContext memory context = PythInternalStructs.UpdateParseContext({
340-
priceIds: priceIds,
341-
minAllowedPublishTime: minAllowedPublishTime,
342-
maxAllowedPublishTime: maxAllowedPublishTime,
343-
checkUniqueness: checkUniqueness,
344-
checkUpdateDataIsMinimal: checkUpdateDataIsMinimal,
345-
priceFeeds: new PythStructs.PriceFeed[](priceIds.length),
346-
slots: new uint64[](priceIds.length)
347-
});
340+
PythInternalStructs.UpdateParseContext
341+
memory context = PythInternalStructs.UpdateParseContext({
342+
priceIds: priceIds,
343+
minAllowedPublishTime: minAllowedPublishTime,
344+
maxAllowedPublishTime: maxAllowedPublishTime,
345+
checkUniqueness: checkUniqueness,
346+
checkUpdateDataIsMinimal: checkUpdateDataIsMinimal,
347+
priceFeeds: new PythStructs.PriceFeed[](priceIds.length),
348+
slots: new uint64[](priceIds.length)
349+
});
348350

349351
// Track total updates for minimal update data check
350352
uint64 totalUpdatesAcrossBlobs = 0;
351353

352354
unchecked {
353355
// Process each update, passing the context struct
354356
// Parsed results will be filled in context.priceFeeds and context.slots
355-
for (uint i = 0; i < updateData.length; ++i) {
357+
for (uint i = 0; i < updateData.length; i++) {
356358
totalUpdatesAcrossBlobs += _processSingleUpdateDataBlob(
357359
updateData[i],
358360
context
359361
);
360362
}
361-
362-
for (uint j = 0; j < priceIds.length; ++j) {
363+
364+
for (uint j = 0; j < priceIds.length; j++) {
363365
PythStructs.PriceFeed memory pf = context.priceFeeds[j];
364366
if (storeUpdatesIfFresh && pf.id != 0) {
365-
updateLatestPriceIfNecessary(priceIds[j], PythInternalStructs.PriceInfo({
366-
publishTime: uint64(pf.price.publishTime),
367-
expo: pf.price.expo,
368-
price: pf.price.price,
369-
conf: pf.price.conf,
370-
emaPrice: pf.emaPrice.price,
371-
emaConf: pf.emaPrice.conf
372-
}));
367+
updateLatestPriceIfNecessary(
368+
priceIds[j],
369+
PythInternalStructs.PriceInfo({
370+
publishTime: uint64(pf.price.publishTime),
371+
expo: pf.price.expo,
372+
price: pf.price.price,
373+
conf: pf.price.conf,
374+
emaPrice: pf.emaPrice.price,
375+
emaConf: pf.emaPrice.conf
376+
})
377+
);
373378
}
374379
}
375380
}
@@ -383,7 +388,7 @@ abstract contract Pyth is
383388
}
384389

385390
// Check all price feeds were found
386-
for (uint k = 0; k < priceIds.length; ++k) {
391+
for (uint k = 0; k < priceIds.length; k++) {
387392
if (context.priceFeeds[k].id == 0) {
388393
revert PythErrors.PriceFeedNotFoundWithinRange();
389394
}
@@ -695,7 +700,7 @@ abstract contract Pyth is
695700
}
696701

697702
function version() public pure returns (string memory) {
698-
return "1.4.5";
703+
return "1.4.5-alpha.1";
699704
}
700705

701706
/// @notice Calculates TWAP from two price points

target_chains/ethereum/contracts/forge-test/GasBenchmark.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
250250
0,
251251
50,
252252
false,
253-
true, // check minimal
253+
true, // check minimal
254254
false
255255
);
256256
}
@@ -265,7 +265,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
265265
0,
266266
50,
267267
false,
268-
true, // check minimal
268+
true, // check minimal
269269
false
270270
);
271271
}

target_chains/ethereum/contracts/forge-test/Pyth.t.sol

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
278278
}
279279
}
280280

281-
function testParsePriceFeedUpdatesWithConfigIfStorageTrue(uint seed) public {
281+
function testParsePriceFeedUpdatesWithConfigIfStorageTrue(
282+
uint seed
283+
) public {
282284
setRandSeed(seed);
283285
uint numMessages = 1 + (getRandUint() % 10);
284286
(
@@ -291,9 +293,16 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
291293
uint updateFee
292294
) = createBatchedUpdateDataFromMessages(messages);
293295

294-
(PythStructs.PriceFeed[] memory priceFeeds,) = pyth.parsePriceFeedUpdatesWithConfig{
295-
value: updateFee
296-
}(updateData, priceIds, 0, MAX_UINT64, false, true, true);
296+
(PythStructs.PriceFeed[] memory priceFeeds, ) = pyth
297+
.parsePriceFeedUpdatesWithConfig{value: updateFee}(
298+
updateData,
299+
priceIds,
300+
0,
301+
MAX_UINT64,
302+
false,
303+
true,
304+
true
305+
);
297306

298307
for (uint i = 0; i < numMessages; i++) {
299308
// Validating that returned priceIds are equal
@@ -322,7 +331,9 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
322331
}
323332
}
324333

325-
function testParsePriceFeedUpdatesWithConfigIfStorageFalse(uint seed) public {
334+
function testParsePriceFeedUpdatesWithConfigIfStorageFalse(
335+
uint seed
336+
) public {
326337
setRandSeed(seed);
327338
uint numMessages = 1 + (getRandUint() % 10);
328339
(
@@ -335,9 +346,15 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
335346
uint updateFee
336347
) = createBatchedUpdateDataFromMessages(messages);
337348

338-
pyth.parsePriceFeedUpdatesWithConfig{
339-
value: updateFee
340-
}(updateData, priceIds, 0, MAX_UINT64, false, true, false);
349+
pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}(
350+
updateData,
351+
priceIds,
352+
0,
353+
MAX_UINT64,
354+
false,
355+
true,
356+
false
357+
);
341358

342359
// validate that stored prices of each priceId are still unpopulated
343360
for (uint i = 0; i < numMessages; i++) {
@@ -346,7 +363,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
346363
}
347364
}
348365

349-
function testParsePriceFeedUpdatesWithSlotsStrictWorks(uint seed) public {
366+
function testParsePriceFeedUpdatesWithConfigWorks(uint seed) public {
350367
setRandSeed(seed);
351368
uint numMessages = 1 + (getRandUint() % 10);
352369
(
@@ -505,7 +522,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
505522
);
506523
}
507524

508-
function testParsePriceFeedUpdatesWithSlotsStrictRevertsWithExcessUpdateData()
525+
function testParsePriceFeedUpdatesWithConfigRevertsWithExcessUpdateData()
509526
public
510527
{
511528
// Create a price update with more price updates than requested price IDs
@@ -541,7 +558,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
541558
);
542559
}
543560

544-
function testParsePriceFeedUpdatesWithSlotsStrictRevertsWithFewerUpdateData()
561+
function testParsePriceFeedUpdatesWithConfigRevertsWithFewerUpdateData()
545562
public
546563
{
547564
// Create a price update with fewer price updates than requested price IDs

target_chains/ethereum/sdk/solidity/IPyth.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ interface IPyth is IPythEvents {
136136
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
137137
/// `getUpdateFee` with the length of the `updateData` array.
138138
///
139-
/// This method will eventually allow the caller to determine whether parsed price feeds should update
139+
/// This method will eventually allow the caller to determine whether parsed price feeds should update
140140
/// the stored values as well.
141141
///
142142
/// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is
@@ -145,7 +145,7 @@ interface IPyth is IPythEvents {
145145
/// @param priceIds Array of price ids.
146146
/// @param minAllowedPublishTime minimum acceptable publishTime for the given `priceIds`.
147147
/// @param maxAllowedPublishTime maximum acceptable publishTime for the given `priceIds`.
148-
/// @param storeUpdatesIfFresh flag for the parse function to
148+
/// @param storeUpdatesIfFresh flag for the parse function to
149149
/// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
150150
function parsePriceFeedUpdatesWithConfig(
151151
bytes[] calldata updateData,
@@ -155,7 +155,13 @@ interface IPyth is IPythEvents {
155155
bool checkUniqueness,
156156
bool checkUpdateDataIsMinimal,
157157
bool storeUpdatesIfFresh
158-
) external payable returns ( PythStructs.PriceFeed[] memory priceFeeds, uint64[] memory slots);
158+
)
159+
external
160+
payable
161+
returns (
162+
PythStructs.PriceFeed[] memory priceFeeds,
163+
uint64[] memory slots
164+
);
159165

160166
/// @notice Parse time-weighted average price (TWAP) from two consecutive price updates for the given `priceIds`.
161167
///

target_chains/ethereum/sdk/solidity/MockPyth.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ contract MockPyth is AbstractPyth {
9797
)
9898
public
9999
payable
100-
returns (
101-
PythStructs.PriceFeed[] memory feeds,
102-
uint64[] memory slots
103-
)
100+
returns (PythStructs.PriceFeed[] memory feeds, uint64[] memory slots)
104101
{
105102
uint requiredFee = getUpdateFee(updateData);
106103
if (msg.value < requiredFee) revert PythErrors.InsufficientFee();
@@ -132,7 +129,8 @@ contract MockPyth is AbstractPyth {
132129
if (
133130
minAllowedPublishTime <= publishTime &&
134131
publishTime <= maxAllowedPublishTime &&
135-
(!checkUniqueness || prevPublishTime < minAllowedPublishTime)
132+
(!checkUniqueness ||
133+
prevPublishTime < minAllowedPublishTime)
136134
) {
137135
break;
138136
} else {

target_chains/ethereum/sdk/solidity/abis/AbstractPyth.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,31 @@
599599
},
600600
{
601601
"internalType": "uint64",
602-
"name": "minPublishTime",
602+
"name": "minAllowedPublishTime",
603603
"type": "uint64"
604604
},
605605
{
606606
"internalType": "uint64",
607-
"name": "maxPublishTime",
607+
"name": "maxAllowedPublishTime",
608608
"type": "uint64"
609+
},
610+
{
611+
"internalType": "bool",
612+
"name": "checkUniqueness",
613+
"type": "bool"
614+
},
615+
{
616+
"internalType": "bool",
617+
"name": "checkUpdateDataIsMinimal",
618+
"type": "bool"
619+
},
620+
{
621+
"internalType": "bool",
622+
"name": "storeUpdatesIfFresh",
623+
"type": "bool"
609624
}
610625
],
611-
"name": "parsePriceFeedUpdatesWithSlotsStrict",
626+
"name": "parsePriceFeedUpdatesWithConfig",
612627
"outputs": [
613628
{
614629
"components": [

target_chains/ethereum/sdk/solidity/abis/IPyth.json

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -587,106 +587,6 @@
587587
"type": "uint64[]"
588588
}
589589
],
590-
"stateMutability": "nonpayable",
591-
"type": "function"
592-
},
593-
{
594-
"inputs": [
595-
{
596-
"internalType": "bytes[]",
597-
"name": "updateData",
598-
"type": "bytes[]"
599-
},
600-
{
601-
"internalType": "bytes32[]",
602-
"name": "priceIds",
603-
"type": "bytes32[]"
604-
},
605-
{
606-
"internalType": "uint64",
607-
"name": "minPublishTime",
608-
"type": "uint64"
609-
},
610-
{
611-
"internalType": "uint64",
612-
"name": "maxPublishTime",
613-
"type": "uint64"
614-
}
615-
],
616-
"name": "parsePriceFeedUpdatesWithSlotsStrict",
617-
"outputs": [
618-
{
619-
"components": [
620-
{
621-
"internalType": "bytes32",
622-
"name": "id",
623-
"type": "bytes32"
624-
},
625-
{
626-
"components": [
627-
{
628-
"internalType": "int64",
629-
"name": "price",
630-
"type": "int64"
631-
},
632-
{
633-
"internalType": "uint64",
634-
"name": "conf",
635-
"type": "uint64"
636-
},
637-
{
638-
"internalType": "int32",
639-
"name": "expo",
640-
"type": "int32"
641-
},
642-
{
643-
"internalType": "uint256",
644-
"name": "publishTime",
645-
"type": "uint256"
646-
}
647-
],
648-
"internalType": "struct PythStructs.Price",
649-
"name": "price",
650-
"type": "tuple"
651-
},
652-
{
653-
"components": [
654-
{
655-
"internalType": "int64",
656-
"name": "price",
657-
"type": "int64"
658-
},
659-
{
660-
"internalType": "uint64",
661-
"name": "conf",
662-
"type": "uint64"
663-
},
664-
{
665-
"internalType": "int32",
666-
"name": "expo",
667-
"type": "int32"
668-
},
669-
{
670-
"internalType": "uint256",
671-
"name": "publishTime",
672-
"type": "uint256"
673-
}
674-
],
675-
"internalType": "struct PythStructs.Price",
676-
"name": "emaPrice",
677-
"type": "tuple"
678-
}
679-
],
680-
"internalType": "struct PythStructs.PriceFeed[]",
681-
"name": "priceFeeds",
682-
"type": "tuple[]"
683-
},
684-
{
685-
"internalType": "uint64[]",
686-
"name": "slots",
687-
"type": "uint64[]"
688-
}
689-
],
690590
"stateMutability": "payable",
691591
"type": "function"
692592
},

0 commit comments

Comments
 (0)