Explorar el Código

updating version, reverting preincrement, renaming slots strict to with config in test functions

Ayush Suresh hace 5 meses
padre
commit
02fe8404f7

+ 28 - 23
target_chains/ethereum/contracts/contracts/pyth/Pyth.sol

@@ -333,18 +333,20 @@ abstract contract Pyth is
             uint64[] memory slots
         )
     {
-        if (msg.value < getUpdateFee(updateData)) revert PythErrors.InsufficientFee();
+        if (msg.value < getUpdateFee(updateData))
+            revert PythErrors.InsufficientFee();
 
         // Create the context struct that holds all shared parameters
-        PythInternalStructs.UpdateParseContext memory context = PythInternalStructs.UpdateParseContext({
-            priceIds: priceIds,
-            minAllowedPublishTime: minAllowedPublishTime,
-            maxAllowedPublishTime: maxAllowedPublishTime,
-            checkUniqueness: checkUniqueness,
-            checkUpdateDataIsMinimal: checkUpdateDataIsMinimal,
-            priceFeeds: new PythStructs.PriceFeed[](priceIds.length),
-            slots: new uint64[](priceIds.length)
-        });
+        PythInternalStructs.UpdateParseContext
+            memory context = PythInternalStructs.UpdateParseContext({
+                priceIds: priceIds,
+                minAllowedPublishTime: minAllowedPublishTime,
+                maxAllowedPublishTime: maxAllowedPublishTime,
+                checkUniqueness: checkUniqueness,
+                checkUpdateDataIsMinimal: checkUpdateDataIsMinimal,
+                priceFeeds: new PythStructs.PriceFeed[](priceIds.length),
+                slots: new uint64[](priceIds.length)
+            });
 
         // Track total updates for minimal update data check
         uint64 totalUpdatesAcrossBlobs = 0;
@@ -352,24 +354,27 @@ abstract contract Pyth is
         unchecked {
             // Process each update, passing the context struct
             // Parsed results will be filled in context.priceFeeds and context.slots
-            for (uint i = 0; i < updateData.length; ++i) {
+            for (uint i = 0; i < updateData.length; i++) {
                 totalUpdatesAcrossBlobs += _processSingleUpdateDataBlob(
                     updateData[i],
                     context
                 );
             }
-            
-            for (uint j = 0; j < priceIds.length; ++j) {
+
+            for (uint j = 0; j < priceIds.length; j++) {
                 PythStructs.PriceFeed memory pf = context.priceFeeds[j];
                 if (storeUpdatesIfFresh && pf.id != 0) {
-                    updateLatestPriceIfNecessary(priceIds[j], PythInternalStructs.PriceInfo({
-                        publishTime: uint64(pf.price.publishTime),
-                        expo: pf.price.expo,
-                        price: pf.price.price,
-                        conf: pf.price.conf,
-                        emaPrice: pf.emaPrice.price,
-                        emaConf: pf.emaPrice.conf
-                    }));
+                    updateLatestPriceIfNecessary(
+                        priceIds[j],
+                        PythInternalStructs.PriceInfo({
+                            publishTime: uint64(pf.price.publishTime),
+                            expo: pf.price.expo,
+                            price: pf.price.price,
+                            conf: pf.price.conf,
+                            emaPrice: pf.emaPrice.price,
+                            emaConf: pf.emaPrice.conf
+                        })
+                    );
                 }
             }
         }
@@ -383,7 +388,7 @@ abstract contract Pyth is
         }
 
         // Check all price feeds were found
-        for (uint k = 0; k < priceIds.length; ++k) {
+        for (uint k = 0; k < priceIds.length; k++) {
             if (context.priceFeeds[k].id == 0) {
                 revert PythErrors.PriceFeedNotFoundWithinRange();
             }
@@ -695,7 +700,7 @@ abstract contract Pyth is
     }
 
     function version() public pure returns (string memory) {
-        return "1.4.5";
+        return "1.4.5-alpha.1";
     }
 
     /// @notice Calculates TWAP from two price points

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

@@ -250,7 +250,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
             0,
             50,
             false,
-            true,  // check minimal
+            true, // check minimal
             false
         );
     }
@@ -265,7 +265,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
             0,
             50,
             false,
-            true,  // check minimal
+            true, // check minimal
             false
         );
     }

+ 28 - 11
target_chains/ethereum/contracts/forge-test/Pyth.t.sol

@@ -278,7 +278,9 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
         }
     }
 
-    function testParsePriceFeedUpdatesWithConfigIfStorageTrue(uint seed) public {
+    function testParsePriceFeedUpdatesWithConfigIfStorageTrue(
+        uint seed
+    ) public {
         setRandSeed(seed);
         uint numMessages = 1 + (getRandUint() % 10);
         (
@@ -291,9 +293,16 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
             uint updateFee
         ) = createBatchedUpdateDataFromMessages(messages);
 
-        (PythStructs.PriceFeed[] memory priceFeeds,) = pyth.parsePriceFeedUpdatesWithConfig{
-            value: updateFee
-        }(updateData, priceIds, 0, MAX_UINT64, false, true, true);
+        (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
@@ -322,7 +331,9 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
         }
     }
 
-    function testParsePriceFeedUpdatesWithConfigIfStorageFalse(uint seed) public {
+    function testParsePriceFeedUpdatesWithConfigIfStorageFalse(
+        uint seed
+    ) public {
         setRandSeed(seed);
         uint numMessages = 1 + (getRandUint() % 10);
         (
@@ -335,9 +346,15 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
             uint updateFee
         ) = createBatchedUpdateDataFromMessages(messages);
 
-        pyth.parsePriceFeedUpdatesWithConfig{
-            value: updateFee
-        }(updateData, priceIds, 0, MAX_UINT64, false, true, false);
+        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++) {
@@ -346,7 +363,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
         }
     }
 
-    function testParsePriceFeedUpdatesWithSlotsStrictWorks(uint seed) public {
+    function testParsePriceFeedUpdatesWithConfigWorks(uint seed) public {
         setRandSeed(seed);
         uint numMessages = 1 + (getRandUint() % 10);
         (
@@ -505,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
@@ -541,7 +558,7 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
         );
     }
 
-    function testParsePriceFeedUpdatesWithSlotsStrictRevertsWithFewerUpdateData()
+    function testParsePriceFeedUpdatesWithConfigRevertsWithFewerUpdateData()
         public
     {
         // Create a price update with fewer price updates than requested price IDs

+ 9 - 3
target_chains/ethereum/sdk/solidity/IPyth.sol

@@ -136,7 +136,7 @@ interface IPyth is IPythEvents {
     /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
     /// `getUpdateFee` with the length of the `updateData` array.
     ///
-    /// This method will eventually allow the caller to determine whether parsed price feeds should update 
+    /// This method will eventually allow the caller to determine whether parsed price feeds should update
     /// the stored values as well.
     ///
     /// @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 {
     /// @param priceIds Array of price ids.
     /// @param minAllowedPublishTime minimum acceptable publishTime for the given `priceIds`.
     /// @param maxAllowedPublishTime maximum acceptable publishTime for the given `priceIds`.
-    /// @param storeUpdatesIfFresh flag for the parse function to 
+    /// @param storeUpdatesIfFresh flag for the parse function to
     /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
     function parsePriceFeedUpdatesWithConfig(
         bytes[] calldata updateData,
@@ -155,7 +155,13 @@ interface IPyth is IPythEvents {
         bool checkUniqueness,
         bool checkUpdateDataIsMinimal,
         bool storeUpdatesIfFresh
-    ) external payable returns ( PythStructs.PriceFeed[] memory priceFeeds, uint64[] memory slots);
+    )
+        external
+        payable
+        returns (
+            PythStructs.PriceFeed[] memory priceFeeds,
+            uint64[] memory slots
+        );
 
     /// @notice Parse time-weighted average price (TWAP) from two consecutive price updates for the given `priceIds`.
     ///

+ 3 - 5
target_chains/ethereum/sdk/solidity/MockPyth.sol

@@ -97,10 +97,7 @@ contract MockPyth is AbstractPyth {
     )
         public
         payable
-        returns (
-            PythStructs.PriceFeed[] memory feeds,
-            uint64[] memory slots
-        )
+        returns (PythStructs.PriceFeed[] memory feeds, uint64[] memory slots)
     {
         uint requiredFee = getUpdateFee(updateData);
         if (msg.value < requiredFee) revert PythErrors.InsufficientFee();
@@ -132,7 +129,8 @@ contract MockPyth is AbstractPyth {
                     if (
                         minAllowedPublishTime <= publishTime &&
                         publishTime <= maxAllowedPublishTime &&
-                        (!checkUniqueness || prevPublishTime < minAllowedPublishTime)
+                        (!checkUniqueness ||
+                            prevPublishTime < minAllowedPublishTime)
                     ) {
                         break;
                     } else {

+ 18 - 3
target_chains/ethereum/sdk/solidity/abis/AbstractPyth.json

@@ -599,16 +599,31 @@
       },
       {
         "internalType": "uint64",
-        "name": "minPublishTime",
+        "name": "minAllowedPublishTime",
         "type": "uint64"
       },
       {
         "internalType": "uint64",
-        "name": "maxPublishTime",
+        "name": "maxAllowedPublishTime",
         "type": "uint64"
+      },
+      {
+        "internalType": "bool",
+        "name": "checkUniqueness",
+        "type": "bool"
+      },
+      {
+        "internalType": "bool",
+        "name": "checkUpdateDataIsMinimal",
+        "type": "bool"
+      },
+      {
+        "internalType": "bool",
+        "name": "storeUpdatesIfFresh",
+        "type": "bool"
       }
     ],
-    "name": "parsePriceFeedUpdatesWithSlotsStrict",
+    "name": "parsePriceFeedUpdatesWithConfig",
     "outputs": [
       {
         "components": [

+ 0 - 100
target_chains/ethereum/sdk/solidity/abis/IPyth.json

@@ -587,106 +587,6 @@
         "type": "uint64[]"
       }
     ],
-    "stateMutability": "nonpayable",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      {
-        "internalType": "bytes[]",
-        "name": "updateData",
-        "type": "bytes[]"
-      },
-      {
-        "internalType": "bytes32[]",
-        "name": "priceIds",
-        "type": "bytes32[]"
-      },
-      {
-        "internalType": "uint64",
-        "name": "minPublishTime",
-        "type": "uint64"
-      },
-      {
-        "internalType": "uint64",
-        "name": "maxPublishTime",
-        "type": "uint64"
-      }
-    ],
-    "name": "parsePriceFeedUpdatesWithSlotsStrict",
-    "outputs": [
-      {
-        "components": [
-          {
-            "internalType": "bytes32",
-            "name": "id",
-            "type": "bytes32"
-          },
-          {
-            "components": [
-              {
-                "internalType": "int64",
-                "name": "price",
-                "type": "int64"
-              },
-              {
-                "internalType": "uint64",
-                "name": "conf",
-                "type": "uint64"
-              },
-              {
-                "internalType": "int32",
-                "name": "expo",
-                "type": "int32"
-              },
-              {
-                "internalType": "uint256",
-                "name": "publishTime",
-                "type": "uint256"
-              }
-            ],
-            "internalType": "struct PythStructs.Price",
-            "name": "price",
-            "type": "tuple"
-          },
-          {
-            "components": [
-              {
-                "internalType": "int64",
-                "name": "price",
-                "type": "int64"
-              },
-              {
-                "internalType": "uint64",
-                "name": "conf",
-                "type": "uint64"
-              },
-              {
-                "internalType": "int32",
-                "name": "expo",
-                "type": "int32"
-              },
-              {
-                "internalType": "uint256",
-                "name": "publishTime",
-                "type": "uint256"
-              }
-            ],
-            "internalType": "struct PythStructs.Price",
-            "name": "emaPrice",
-            "type": "tuple"
-          }
-        ],
-        "internalType": "struct PythStructs.PriceFeed[]",
-        "name": "priceFeeds",
-        "type": "tuple[]"
-      },
-      {
-        "internalType": "uint64[]",
-        "name": "slots",
-        "type": "uint64[]"
-      }
-    ],
     "stateMutability": "payable",
     "type": "function"
   },

+ 18 - 3
target_chains/ethereum/sdk/solidity/abis/MockPyth.json

@@ -738,16 +738,31 @@
       },
       {
         "internalType": "uint64",
-        "name": "minPublishTime",
+        "name": "minAllowedPublishTime",
         "type": "uint64"
       },
       {
         "internalType": "uint64",
-        "name": "maxPublishTime",
+        "name": "maxAllowedPublishTime",
         "type": "uint64"
+      },
+      {
+        "internalType": "bool",
+        "name": "checkUniqueness",
+        "type": "bool"
+      },
+      {
+        "internalType": "bool",
+        "name": "checkUpdateDataIsMinimal",
+        "type": "bool"
+      },
+      {
+        "internalType": "bool",
+        "name": "storeUpdatesIfFresh",
+        "type": "bool"
       }
     ],
-    "name": "parsePriceFeedUpdatesWithSlotsStrict",
+    "name": "parsePriceFeedUpdatesWithConfig",
     "outputs": [
       {
         "components": [