From 2e440ea0862216e77b93195ed0c929cc85b5c90e Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Thu, 12 Sep 2024 18:44:08 +0200 Subject: [PATCH] fix(refactor): dataId -> feedId --- solidity/src/PragmaDecoder.sol | 66 +++++++++++------------ solidity/test/PragmaDecoder.t.sol | 28 +++++----- solidity/test/TestUtils.sol | 2 +- solidity/test/utils/PragmaTestUtils.t.sol | 4 +- 4 files changed, 49 insertions(+), 51 deletions(-) diff --git a/solidity/src/PragmaDecoder.sol b/solidity/src/PragmaDecoder.sol index 616d392f..e992c265 100644 --- a/solidity/src/PragmaDecoder.sol +++ b/solidity/src/PragmaDecoder.sol @@ -157,7 +157,7 @@ contract PragmaDecoder { function extractDataInfoFromUpdate(bytes calldata encoded, uint256 offset, bytes32 checkpointRoot) internal - returns (uint256 endOffset, ParsedData memory parsedData, bytes32 dataId, uint64 publishTime) + returns (uint256 endOffset, ParsedData memory parsedData, bytes32 feedId, uint64 publishTime) { unchecked { bytes calldata encodedUpdate; @@ -181,7 +181,7 @@ contract PragmaDecoder { bool valid; (valid, endOffset) = _isProofValid(encodedProof, offset, checkpointRoot, encodedUpdate); if (!valid) revert ErrorsLib.InvalidHyperlaneCheckpointRoot(); - (parsedData, dataId, publishTime) = parseDataFeed(fulldataFeed); + (parsedData, feedId, publishTime) = parseDataFeed(fulldataFeed); endOffset += 40; } } @@ -189,13 +189,13 @@ contract PragmaDecoder { function parseDataFeed(bytes calldata encodedDataFeed) private pure - returns (ParsedData memory parsedData, bytes32 dataId, uint64 publishTime) + returns (ParsedData memory parsedData, bytes32 feedId, uint64 publishTime) { parsedData = DataParser.parse(encodedDataFeed); - // Assuming dataId and publishTime are appended at the end of encodedDataFeed - uint256 offset = encodedDataFeed.length - 40; // 32 bytes for dataId, 8 bytes for publishTime - dataId = bytes32(UnsafeCalldataBytesLib.toUint256(encodedDataFeed, offset)); + // Assuming feedId and publishTime are appended at the end of encodedDataFeed + uint256 offset = encodedDataFeed.length - 40; // 32 bytes for feedId, 8 bytes for publishTime + feedId = bytes32(UnsafeCalldataBytesLib.toUint256(encodedDataFeed, offset)); offset += 32; publishTime = UnsafeBytesLib.toUint64(encodedDataFeed, offset); } @@ -213,10 +213,10 @@ contract PragmaDecoder { unchecked { for (uint256 i = 0; i < numUpdates; i++) { ParsedData memory parsedData; - bytes32 dataId; + bytes32 feedId; uint64 publishTime; - (offset, parsedData, dataId, publishTime) = extractDataInfoFromUpdate(encoded, offset, checkpointRoot); - updateLatestDataInfoIfNecessary(dataId, parsedData, publishTime); + (offset, parsedData, feedId, publishTime) = extractDataInfoFromUpdate(encoded, offset, checkpointRoot); + updateLatestDataInfoIfNecessary(feedId, parsedData, publishTime); } } // We check that the offset is at the end of the encoded data. @@ -224,40 +224,38 @@ contract PragmaDecoder { if (offset != encoded.length) revert ErrorsLib.InvalidUpdateData(); } - function updateLatestDataInfoIfNecessary(bytes32 dataId, ParsedData memory parsedData, uint64 publishTime) + function updateLatestDataInfoIfNecessary(bytes32 feedId, ParsedData memory parsedData, uint64 publishTime) internal { - if (publishTime > latestPublishTimes[dataId]) { - latestPublishTimes[dataId] = publishTime; + if (publishTime > latestPublishTimes[feedId]) { + latestPublishTimes[feedId] = publishTime; if (parsedData.dataType == FeedType.SpotMedian) { - spotMedianFeeds[dataId] = parsedData.spot; - _latestPriceInfo[dataId] = - DataFeed(dataId, publishTime, parsedData.spot.metadata.numberOfSources, parsedData.spot.price); - emit EventsLib.SpotMedianUpdate(dataId, publishTime, parsedData.spot); + spotMedianFeeds[feedId] = parsedData.spot; + _latestPriceInfo[feedId] = + DataFeed(feedId, publishTime, parsedData.spot.metadata.numberOfSources, parsedData.spot.price); + emit EventsLib.SpotMedianUpdate(feedId, publishTime, parsedData.spot); } else if (parsedData.dataType == FeedType.Twap) { - twapFeeds[dataId] = parsedData.twap; - _latestPriceInfo[dataId] = DataFeed( - dataId, publishTime, parsedData.twap.metadata.numberOfSources, parsedData.twap.twapPrice - ); - emit EventsLib.TWAPUpdate(dataId, publishTime, parsedData.twap); + twapFeeds[feedId] = parsedData.twap; + _latestPriceInfo[feedId] = + DataFeed(feedId, publishTime, parsedData.twap.metadata.numberOfSources, parsedData.twap.twapPrice); + emit EventsLib.TWAPUpdate(feedId, publishTime, parsedData.twap); } else if (parsedData.dataType == FeedType.RealizedVolatility) { - rvFeeds[dataId] = parsedData.rv; - _latestPriceInfo[dataId] = - DataFeed(dataId, publishTime, parsedData.rv.metadata.numberOfSources, parsedData.rv.endPrice); - emit EventsLib.RealizedVolatilityUpdate(dataId, publishTime, parsedData.rv); + rvFeeds[feedId] = parsedData.rv; + _latestPriceInfo[feedId] = + DataFeed(feedId, publishTime, parsedData.rv.metadata.numberOfSources, parsedData.rv.endPrice); + emit EventsLib.RealizedVolatilityUpdate(feedId, publishTime, parsedData.rv); } else if (parsedData.dataType == FeedType.Options) { - optionsFeeds[dataId] = parsedData.options; - _latestPriceInfo[dataId] = DataFeed( - dataId, publishTime, parsedData.options.metadata.numberOfSources, parsedData.options.optionPrice + optionsFeeds[feedId] = parsedData.options; + _latestPriceInfo[feedId] = DataFeed( + feedId, publishTime, parsedData.options.metadata.numberOfSources, parsedData.options.optionPrice ); - emit EventsLib.OptionsUpdate(dataId, publishTime, parsedData.options); + emit EventsLib.OptionsUpdate(feedId, publishTime, parsedData.options); } else if (parsedData.dataType == FeedType.Perpetuals) { - perpFeeds[dataId] = parsedData.perp; - _latestPriceInfo[dataId] = DataFeed( - dataId, publishTime, parsedData.perp.metadata.numberOfSources, parsedData.perp.markPrice - ); - emit EventsLib.PerpUpdate(dataId, publishTime, parsedData.perp); + perpFeeds[feedId] = parsedData.perp; + _latestPriceInfo[feedId] = + DataFeed(feedId, publishTime, parsedData.perp.metadata.numberOfSources, parsedData.perp.markPrice); + emit EventsLib.PerpUpdate(feedId, publishTime, parsedData.perp); } else { revert ErrorsLib.InvalidDataFeedType(); } diff --git a/solidity/test/PragmaDecoder.t.sol b/solidity/test/PragmaDecoder.t.sol index 28701696..345a4fc7 100644 --- a/solidity/test/PragmaDecoder.t.sol +++ b/solidity/test/PragmaDecoder.t.sol @@ -22,32 +22,32 @@ contract PragmaDecoderHarness is PragmaDecoder { return updateDataInfoFromUpdate(updateData); } - function exposed_spotMedianFeeds(bytes32 dataId) external view returns (SpotMedian memory) { - return spotMedianFeeds[dataId]; + function exposed_spotMedianFeeds(bytes32 feedId) external view returns (SpotMedian memory) { + return spotMedianFeeds[feedId]; } - function exposed_twapFeeds(bytes32 dataId) external view returns (TWAP memory) { - return twapFeeds[dataId]; + function exposed_twapFeeds(bytes32 feedId) external view returns (TWAP memory) { + return twapFeeds[feedId]; } - function exposed_rvFeeds(bytes32 dataId) external view returns (RealizedVolatility memory) { - return rvFeeds[dataId]; + function exposed_rvFeeds(bytes32 feedId) external view returns (RealizedVolatility memory) { + return rvFeeds[feedId]; } - function exposed_optionsFeeds(bytes32 dataId) external view returns (Options memory) { - return optionsFeeds[dataId]; + function exposed_optionsFeeds(bytes32 feedId) external view returns (Options memory) { + return optionsFeeds[feedId]; } - function exposed_latestPriceInfo(bytes32 dataId) external view returns (DataFeed memory) { - return _latestPriceInfo[dataId]; + function exposed_latestPriceInfo(bytes32 feedId) external view returns (DataFeed memory) { + return _latestPriceInfo[feedId]; } - function exposed_latestPublishTimes(bytes32 dataId) external view returns (uint64) { - return latestPublishTimes[dataId]; + function exposed_latestPublishTimes(bytes32 feedId) external view returns (uint64) { + return latestPublishTimes[feedId]; } - function exposed_perpFeeds(bytes32 dataId) external view returns (Perp memory) { - return perpFeeds[dataId]; + function exposed_perpFeeds(bytes32 feedId) external view returns (Perp memory) { + return perpFeeds[feedId]; } function _isProofValid(bytes calldata encodedProof, uint256 offset, bytes32 root, bytes calldata leafData) diff --git a/solidity/test/TestUtils.sol b/solidity/test/TestUtils.sol index 453a97ea..cc3a29c7 100644 --- a/solidity/test/TestUtils.sol +++ b/solidity/test/TestUtils.sol @@ -117,7 +117,7 @@ library TestUtils { uint16(proof.length), proof, updateData, - feedId, // dataId + feedId, // feedId uint64(block.timestamp) // publishTime ); diff --git a/solidity/test/utils/PragmaTestUtils.t.sol b/solidity/test/utils/PragmaTestUtils.t.sol index e8f47781..d18847b1 100644 --- a/solidity/test/utils/PragmaTestUtils.t.sol +++ b/solidity/test/utils/PragmaTestUtils.t.sol @@ -37,7 +37,7 @@ abstract contract PragmaTestUtils is Test, RandTestUtils, HyperlaneTestUtils { // Utilities to help generating data feed messages and Hyperlane Checkpoints for them struct DataFeedMessage { - bytes32 dataId; + bytes32 feedId; int64 value; int32 expo; uint64 publishTime; @@ -62,7 +62,7 @@ abstract contract PragmaTestUtils is Test, RandTestUtils, HyperlaneTestUtils { for (uint256 i = 0; i < dataFeedMessages.length; i++) { encodedDataFeedMessages[i] = abi.encodePacked( uint8(DataFeedType.SpotMedian), - dataFeedMessages[i].dataId, + dataFeedMessages[i].feedId, dataFeedMessages[i].value, dataFeedMessages[i].expo, dataFeedMessages[i].publishTime,